diff options
Diffstat (limited to 'Makefile')
| -rw-r--r-- | Makefile | 73 |
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 ./... |
