1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
|
PREFIX := /usr/local
BINDIR := $(PREFIX)/bin
LIBDIR := $(PREFIX)/lib
SHRDIR := $(PREFIX)/share
MANDIR := $(PREFIX)/share/man
BINS = $(filter-out %_test.go,$(notdir $(wildcard cmd/*)))
TAG = $(shell git describe --abbrev=0 --tags)
VERSION = $(shell git describe --abbrev=7 | sed 's/-/./g;s/^v//;')
MANPAGES = \
man/ssh-tpm-hostkeys.1 \
man/ssh-tpm-agent.1 \
man/ssh-tpm-keygen.1 \
man/ssh-tpm-add.1
all: man build
build: $(BINS)
man: $(MANPAGES)
.PHONY: $(addprefix bin/,$(BINS))
$(addprefix bin/,$(BINS)):
go build -buildmode=pie -trimpath -o $@ ./cmd/$(@F)
# TODO: Needs to be better written
$(BINS): $(addprefix bin/,$(BINS))
.PHONY: install
install: $(BINS)
@for bin in $(BINS); do \
install -Dm755 "bin/$$bin" -t '$(DESTDIR)$(BINDIR)'; \
done;
for manfile in $(MANPAGES); do \
install -Dm644 "$$manfile" -t '$(DESTDIR)$(MANDIR)/man'"$${manfile##*.}"; \
done;
@install -dm755 $(DESTDIR)$(LIBDIR)/systemd/system
@install -dm755 $(DESTDIR)$(LIBDIR)/systemd/user
@DESTDIR=$(DESTDIR) PREFIX=$(PREFIX) bin/ssh-tpm-hostkeys --install-system-units
@TEMPLATE_BINARY=$(BINDIR)/ssh-tpm-agent DESTDIR=$(DESTDIR) PREFIX=$(PREFIX) bin/ssh-tpm-agent --install-user-units --install-system
.PHONY: lint
lint:
go vet ./...
staticcheck ./...
.PHONY: test
test:
go test -v ./...
.PHONY: clean
clean:
rm -rf bin/
rm -f $(MANPAGES)
sign-release:
gh release download $(TAG)
gpg --sign ssh-tpm-agent-$(TAG)-linux-amd64.tar.gz
gpg --sign ssh-tpm-agent-$(TAG)-linux-arm64.tar.gz
gpg --sign ssh-tpm-agent-$(TAG)-linux-arm.tar.gz
bash -c "gh release upload $(TAG) ssh-tpm-agent-$(TAG)*.gpg"
man/%: man/%.adoc Makefile
asciidoctor -b manpage -amansource="ssh-tpm-agent $(VERSION)" -amanversion="$(VERSION)" $<
|