-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
71 lines (51 loc) · 2.25 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
NAME = invoice-generator
DIRS := \
. \
.DEFAULT_GOAL := install
uniq = $(if $1,$(firstword $1) $(call uniq,$(filter-out $(firstword $1),$1)))
gofiles = $(foreach d,$(1),$(wildcard $(d)/*.go))
fmt = $(addprefix fmt-,$(1))
outsuffix = bin/$(NAME)
build: bin-linux-amd64 bin-linux-arm bin-windows-amd64 bin-windows-arm bin-darwin-amd64 bin-darwin-arm64
sha = $(shell git rev-parse --short HEAD || cat SHA | tr -d ' \n')
ifeq ($(VERSION),)
VERSION = $(shell git describe --tags --match 'v*' | tr -d 'v \n')
realv = $(shell printf $(VERSION) | cut -d'-' -f1)
ifneq ($(VERSION),$(realv))
commits = $(shell printf $(VERSION) | cut -d'-' -f2)
VERSION := $(realv).$(commits).$(sha)
endif
endif
dirty = $(shell git diff --shortstat 2> /dev/null | tail -n1 | tr -d ' \n')
ifneq ($(dirty),)
VERSION := $(VERSION).dev
endif
id = $(shell head -c20 /dev/urandom|od -An -tx1|tr -d ' \n')
bin-linux-amd64: $(outsuffix).linux-amd64
bin-linux-arm: $(outsuffix).linux-arm
bin-windows-amd64: $(outsuffix).windows-amd64.exe
bin-windows-arm: $(outsuffix).windows-arm.exe
bin-darwin-amd64: $(outsuffix).darwin-amd64
bin-darwin-arm64: $(outsuffix).darwin-arm64
ldflags = -ldflags '-s -w -extldflags "-static" -X "main.ver=$(VERSION)" -X "main.sha=$(sha)" -B 0x$(id)'
install: $(call gofiles,$(DIRS))
go install -ldflags '-s -w -X "main.ver=$(VERSION)" -X "main.sha=$(sha)" -B 0x$(id)' .
$(outsuffix).linux-amd64: $(call gofiles,$(DIRS))
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -x -v $(ldflags) -o $@ .
$(outsuffix).linux-arm: $(call gofiles,$(DIRS))
CGO_ENABLED=0 GOOS=linux GOARCH=arm go build $(ldflags) -o $@ .
$(outsuffix).windows-amd64.exe: $(call gofiles,$(DIRS))
CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build $(ldflags) -o $@ .
$(outsuffix).windows-arm.exe: $(call gofiles,$(DIRS))
CGO_ENABLED=0 GOOS=windows GOARCH=arm GOARM=7 go build $(ldflags) -o $@ .
$(outsuffix).darwin-amd64: $(call gofiles,$(DIRS))
CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build $(ldflags) -o $@ .
$(outsuffix).darwin-arm64: $(call gofiles,$(DIRS))
CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 go build $(ldflags) -o $@ .
clean:
rm -f bin/*
.PHONY: clean build \
bin-linux-amd64 bin-linux-arm bin-windows-amd64 bin-windows-arm bin-darwin-amd64 bin-darwin-arm64
.PHONY: version
version:
@echo $(VERSION)