-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathMakefile
99 lines (70 loc) · 2.47 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
# Cross platorm build with docker
# ----------------------------------------------------------------------------
ROOT_DIR := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
BUILD_PROG := $(ROOT_DIR)/ah
CROSS_BUILD_DIR := $(ROOT_DIR)/build
GOLANG_AH := github.com/9seconds/ah
LINUX_ARCH := amd64 386 arm
DARWIN_ARCH := amd64 386
FREEBSD_ARCH := amd64 386 arm
DOCKER_PROG := docker
DOCKER_GOPATH := /go
DOCKER_WORKDIR := $(DOCKER_GOPATH)/src/$(GOLANG_AH)
DOCKER_IMAGE := golang:1.4.1-cross
# ----------------------------------------------------------------------------
define crosscompile
GOOS=$(1) GOARCH=$(2) go build -a -o $(CROSS_BUILD_DIR)/$(1)-$(2) $(GOLANG_AH)
endef
# ----------------------------------------------------------------------------
all: tools prog-build
tools: fix lint
cross: cross-linux cross-darwin cross-freebsd
clean: prog-clean cross-clean
ci: tools cross
# ----------------------------------------------------------------------------
fix:
go fix $(GOLANG_AH)/...
lint: golint
golint $(GOLANG_AH)/...
fmt:
go fmt $(GOLANG_AH)/...
godep:
go get github.com/tools/godep || true
golint:
go get github.com/golang/lint/golint || true
save: godep
godep save
restore: godep
godep restore
prog-build: restore prog-clean
go build -a -o $(BUILD_PROG) $(GOLANG_AH)
install: restore
go install -a $(GOLANG_AH)
prog-clean:
rm -f $(BUILD_PROG)
update:
grep -v $(GOLANG_AH) $(ROOT_DIR)/Godeps/Godeps.json \
| awk '/ImportPath/ {gsub(/"|,/, ""); print $$2}' \
| xargs -n 1 godep update
upgrade_deps:
grep -v $(GOLANG_AH) $(ROOT_DIR)/Godeps/Godeps.json \
| awk '/ImportPath/ {gsub(/"|,/, ""); print $$2}' \
| xargs -n 1 -P 4 go get -u
# ----------------------------------------------------------------------------
cross-linux: $(addprefix cross-linux-,$(LINUX_ARCH))
cross-freebsd: $(addprefix cross-freebsd-,$(FREEBSD_ARCH))
cross-darwin: $(addprefix cross-darwin-,$(DARWIN_ARCH))
cross-clean:
rm -rf $(CROSS_BUILD_DIR)
cross-build-directory: cross-clean
mkdir -p $(CROSS_BUILD_DIR)
cross-linux-%: restore cross-build-directory
$(call crosscompile,linux,$*)
cross-darwin-%: restore cross-build-directory
$(call crosscompile,darwin,$*)
cross-freebsd-%: restore cross-build-directory
$(call crosscompile,freebsd,$*)
cross-docker:
$(DOCKER_PROG) run --rm -i -t -v "$(ROOT_DIR)":$(DOCKER_WORKDIR) -w $(DOCKER_WORKDIR) $(DOCKER_IMAGE) \
bash -i -c "make -j 4 cross"
sudo chown -R $(USER):$(USER) $(CROSS_BUILD_DIR)