summaryrefslogtreecommitdiff
path: root/Makefile
diff options
context:
space:
mode:
authornytpu <alex@nytpu.com>2021-03-16 10:19:42 -0600
committernytpu <alex@nytpu.com>2021-03-16 10:19:42 -0600
commitf82e0905779c9d88140403778f7b3b35a1d03420 (patch)
tree68a906f8f6b53ae04660c57ff0d1cd5d252d3a05 /Makefile
initial commit
Diffstat (limited to 'Makefile')
-rw-r--r--Makefile73
1 files changed, 73 insertions, 0 deletions
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..e5fac00
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,73 @@
+.POSIX:
+
+NAME := comitium
+
+# will automatically set main.Version with this string
+VERSION ?= 0.0.1
+
+# source dirs & files #
+GOSRC := $(shell find . -type f -name '*.go')
+GOSRC += go.mod go.sum
+SCDDIR := doc
+
+BUILDDIR ?= build
+
+# install dirs #
+PREFIX ?= /usr/local
+BINDIR ?= $(PREFIX)/bin
+MANDIR ?= $(PREFIX)/share/man
+
+# program paths and flags #
+GO ?= go
+# purely statically link (useful for cross compiling)
+#GO ?= CGO_ENABLED=0 go
+GOFLAGS ?=
+GOLDFLAGS ?= -X main.Version=$(VERSION) -X main.Commit=$(COMMIT)
+# also strips executable, significantly reduces size
+#GOLDFLAGS ?= -s -w -X main.Version=$(VERSION) -X main.Commit=$(COMMIT)$(GITDIRTY)
+SCDOC ?= scdoc
+MKDIR ?= mkdir -p
+RM ?= rm -f
+RMDIR ?= rmdir --ignore-fail-on-non-empty
+GITC = $(shell git rev-parse --short HEAD)
+GITDIRTY = $(shell git diff --quiet || echo "-dirty")
+
+# build with `make COMMIT=tarball` if building outside of git repo
+COMMIT ?= $(GITC)$(GITDIRTY)
+
+.PHONY: all clean install uninstall test
+.DEFAULT_GOAL := all
+
+all: $(BUILDDIR)/$(NAME) $(BUILDDIR)/$(NAME).1
+
+
+$(BUILDDIR):
+ @$(MKDIR) $(BUILDDIR)
+
+
+$(BUILDDIR)/$(NAME): $(GOSRC) | $(BUILDDIR)
+ $(GO) build $(GOFLAGS) -ldflags "$(GOLDFLAGS)" -o $@
+
+
+$(BUILDDIR)/%.1: doc/%.1.scd | $(BUILDDIR)
+ $(SCDOC) < $< > $@
+
+
+clean:
+ -$(RM) -r $(BUILDDIR)
+
+
+install: all
+ @$(MKDIR) -m755 $(DESTDIR)$(MANDIR)/man1 $(DESTDIR)$(BINDIR)
+ install -m755 $(BUILDDIR)/$(NAME) $(DESTDIR)$(BINDIR)/$(NAME)
+ install -m644 $(BUILDDIR)/$(NAME).1 $(DESTDIR)$(MANDIR)/man1/$(NAME).1
+
+uninstall:
+ $(RM) $(DESTDIR)$(BINDIR)/$(NAME)
+ $(RM) $(DESTDIR)$(MANDIR)/man1/$(NAME).1
+ -@$(RMDIR) $(DESTDIR)$(BINDIR)
+ -@$(RMDIR) $(DESTDIR)$(MANDIR)/man1
+
+
+test:
+ $(GO) test ./...