This repository has been archived by the owner on Aug 17, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 190
/
Makefile
134 lines (101 loc) · 4 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
SHELL := /bin/bash
# name of the binary created
TARGET := goad
# Prepend our vendor directory to the system GOPATH
# so that import path resolution will prioritize
# our third party snapshots.
GOPATH := ${PWD}/vendor:${GOPATH}
export GOPATH
# These will be provided to the target
VERSION := 2.0.0-rc1x
BUILD := `git rev-parse HEAD`
# Timestamp of last commit to allow for reproducable builds
TIMESTAMP := `git log -1 --date=format:%Y%m%d%H%M --pretty=format:%cd`
# Use linker flags to provide version/build settings to the target
LDFLAGS = -ldflags "-X=github.com/goadapp/goad/version.version=$(VERSION) -X=github.com/goadapp/goad/version.build=$(BUILD) -X=github.com/goadapp/goad/version.travisTag=$(TRAVIS_TAG)"
# go source files, ignore vendor directory
SRC = $(shell find . -type f -name '*.go' -not -path "./vendor/*")
# go source folders to test
TEST = $(shell go list ./... | grep -v /vendor/)
# $(GO-BUILD) command
GO-BUILD = go build $(LDFLAGS)
# $(ZIP) command ignoring timestamps and using UTC timezone
ZIP = TZ=UTC zip -jrX
.PHONY: lambda bindata clean all-zip all linux32 linux64 osx64 win32 win64 deb32 deb64 rpm32 rpm64 rpm check fmt test install uninstall
all: osx64 linux32 linux64 win32 win64
test: bindata
@go test $(TEST)
lambda:
@GOOS=linux GOARCH=amd64 $(GO-BUILD) -o data/lambda/goad-lambda ./lambda
@find data/lambda -exec touch -t $(TIMESTAMP) {} \; # strip timestamp
@$(ZIP) data/lambda data/lambda
bindata: lambda
@go get github.com/jteeuwen/go-bindata/...
@go-bindata -modtime $(TIMESTAMP) -nocompress -pkg infrastructure -o infrastructure/bindata.go data/lambda.zip
linux64: bindata
@GOOS=linux GOARCH=amd64 $(GO-BUILD) -o build/linux/x86-64/$(TARGET)
linux32: bindata
@GOOS=linux GOARCH=386 $(GO-BUILD) -o build/linux/x86/$(TARGET)
osx64: bindata
@GOOS=darwin GOARCH=amd64 $(GO-BUILD) -o build/osx/x86-64/$(TARGET)
win64: bindata
@GOOS=windows GOARCH=amd64 $(GO-BUILD) -o build/windows/x86-64/$(TARGET)
win32: bindata
@GOOS=windows GOARCH=386 $(GO-BUILD) -o build/windows/x86/$(TARGET)
clean:
@rm -rf data/lambda/goad-lambda
@rm -rf data/lambda.zip
@rm -rf build
@rm -rf infrastructure/bindata.go
build: bindata
@$(GO-BUILD) $(LDFLAGS) -o build/$(TARGET)
install: bindata
@go install $(LDFLAGS)
uninstall: clean
@go clean -i
fmt:
@gofmt -l -w $(SRC)
simplify:
@gofmt -s -l -w $(SRC)
check:
@test -z $(shell gofmt -l main.go | tee /dev/stderr) || echo "[WARN] Fix formatting issues with 'make fmt'"
@for d in $$(go list ./... | grep -v /vendor/); do golint $${d}; done
@go tool vet ${SRC}
DEB64-PATH = build/goad_amd64
deb64: linux64
@mkdir -p ./$(DEB64-PATH)/usr/bin
@cp build/linux/x86-64/goad $(DEB64-PATH)/usr/bin/
@cp -r DEBIAN/ $(DEB64-PATH)
@sed -i s/{{ARCH}}/amd64/ $(DEB64-PATH)/DEBIAN/control
@sed -i s/{{VERSION}}/$(VERSION)/ $(DEB64-PATH)/DEBIAN/control
@sed -i s/{{MAINTAINER}}/$(MAINTAINER)/ $(DEB64-PATH)/DEBIAN/control
@dpkg-deb --build $(DEB64-PATH)
@rm -rf $(DEB64-PATH)
DEB32-PATH = build/goad_i386
deb32: linux32
@mkdir -p ./$(DEB32-PATH)/usr/bin
@cp build/linux/x86/goad $(DEB32-PATH)/usr/bin/
@cp -r DEBIAN/ $(DEB32-PATH)
@sed -i s/{{ARCH}}/i386/ $(DEB32-PATH)/DEBIAN/control
@sed -i s/{{VERSION}}/$(VERSION)/ $(DEB32-PATH)/DEBIAN/control
@sed -i s/{{MAINTAINER}}/$(MAINTAINER)/ $(DEB32-PATH)/DEBIAN/control
@dpkg-deb --build $(DEB32-PATH)
@rm -rf $(DEB32-PATH)
all-zip: all
@mkdir -p ./build/zip
@find build -exec touch -t $(TIMESTAMP) {} \; # strip timestamp
@$(ZIP) ./build/zip/goad-osx-x86-64 ./build/osx/x86-64/goad
@$(ZIP) ./build/zip/goad-linux-x86-64 ./build/linux/x86-64/goad
@$(ZIP) ./build/zip/goad-linux-x86 ./build/linux/x86/goad
@$(ZIP) ./build/zip/goad-windows-x86-64 ./build/windows/x86-64/goad
@$(ZIP) ./build/zip/goad-windows-x86 ./build/windows/x86/goad
rpm32: deb32
@pushd build && \
sudo alien --to-rpm -k goad_i386.deb && \
mv goad-$(VERSION).i386.rpm goad.i386.rpm
rpm64: deb64
@pushd build && \
sudo alien --to-rpm -k goad_amd64.deb && \
mv goad-$(VERSION).x86_64.rpm goad.x86_64.rpm
rpm: rpm32 rpm64
linux-packages: deb32 deb64 rpm