-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
70 lines (58 loc) · 1.63 KB
/
Makefile
File metadata and controls
70 lines (58 loc) · 1.63 KB
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
64
65
66
67
68
69
70
SRC = $(wildcard *.go */*.go)
Q ?= @
vV := $(shell git describe --tags)
V := $(vV:v%=%)
T := $(shell date -u +%Y-%m-%dT%H:%M:%SZ)
GOFLAGS += -ldflags "-X main.version=$V -X main.buildtime=$T"
OSES ?= darwin linux windows
darwin_ARCH := 386 amd64
linux_ARCH := 386 amd64
windows_ARCH := 386 amd64
windows_EXT := .exe
windows_TGZ := zip
default_TGZ := tgz
NAME_386 := x86
NAME_amd64 := x64
default: quicktest
name = mktmpio-v$(V)-$(1)-$(firstword $(NAME_$(2)) $(2))
define build_t
$(3)/mktmpio$($(1)_EXT): $(3)
$(3)/mktmpio$($(1)_EXT): GOOS=$(1)
$(3)/mktmpio$($(1)_EXT): GOARCH=$(2)
$(3).$(firstword $($(1)_TGZ) $(default_TGZ)): $(3)/mktmpio$($(1)_EXT)
$(eval TARBALLS += $(3).$(firstword $($(1)_TGZ) $(default_TGZ)))
$(eval BINARIES += $(3)/mktmpio$($(1)_EXT))
$(eval DIRS += $(3))
endef
# Generate targets and variables for all the supported OS/ARCH combinations
$(foreach os,$(OSES), \
$(foreach arch,$($(os)_ARCH), \
$(eval \
$(call build_t,$(os),$(arch),$(call name,$(os),$(arch))) \
) \
) \
)
test: Q =
test: quicktest $(BINARIES)
quicktest: cli
$Q go test ./commands && echo "ok - test"
$Q ./cli help | grep -q "mktmpio" && echo "ok - help"
$Q ./cli legal | grep -q "Artistic" && echo "ok - legal"
$Q ./cli --version | grep -q "mktmpio" && echo "ok - version"
$Q echo "ok"
get:
go get -t -v ./...
cli: ${SRC}
$Q go build ${GOFLAGS}
release: $(TARBALLS)
# All binaries are built using the same recipe
$(BINARIES): ${SRC}
GOOS=$(GOOS) GOARCH=$(GOARCH) go build -o $@ $(GOFLAGS) mktmpio.go
$(DIRS): README.md LICENSE
mkdir -p $@
cp $^ $@
# How to build an archive from a directory
%.zip : %
zip -r $@ $<
%.tgz : %
tar -czf $@ $<