-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
49 lines (37 loc) · 1.39 KB
/
Makefile
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
PROJECT :=safe
DESTDIR ?=/usr/local
RELEASE_ROOT ?=release
TARGETS ?=linux/amd64 linux/arm64 darwin/amd64 darwin/arm64 windows/amd64
SAFE_PATH ?=./$(PROJECT)
TEST_PATH ?=./ci/script/tests
VAULT_VERSIONS ?=
GO_LDFLAGS := -ldflags="-X main.Version=$(VERSION)"
.PHONY: use build test install require-% release-% clean
use:
@echo "Using $(shell $(SAFE_PATH) -v 2>&1) at location $(SAFE_PATH)"
build:
go build $(GO_LDFLAGS) -o $(SAFE_PATH)
$(SAFE_PATH) -v
test: $(if $(wildcard $(SAFE_PATH)),use,build)
$(TEST_PATH) $(SAFE_PATH) ${VAULT_VERSIONS}
install: build
mkdir -p $(DESTDIR)/bin
cp safe $(DESTDIR)/bin
require-%:
@ if [ "${${*}}" = "" ]; then \
echo "Environment variable $* not set"; \
exit 1; \
fi
RELEASES := $(foreach target,$(TARGETS),release-$(target)-$(PROJECT))
release-all: $(RELEASES)
define build-target
release-$(1)/$(2)-$(PROJECT): require-VERSION
@echo "Building $(PROJECT) $(VERSION) ($(1)/$(2)) ..."
GOOS=$(1) GOARCH=$(2) go build -o $(RELEASE_ROOT)/$(PROJECT)-$(VERSION)-$(1)-$(2)$(if $(patsubst windows,,$(1)),,.exe) $(GO_LDFLAGS)
@ls -la $(RELEASE_ROOT)/$(PROJECT)-$(VERSION)-$(1)-$(2)$(if $(patsubst windows,,$(1)),,.exe)
@echo ""
endef
$(foreach target,$(TARGETS),$(eval $(call build-target,$(word 1, $(subst /, ,$(target))),$(word 2, $(subst /, ,$(target))))))
clean:
rm -rf $(SAFE_PATH) $(RELEASE_ROOT)
.DEFAULT_GOAL := release-all