-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile
76 lines (57 loc) · 1.73 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
export GOPATH ?= $(HOME)/go
GOPATH_CB = $(GOPATH)/src/github.com/hiroshi/cb
SRCS = ../main.go
OSARCH = $(or $(subst _, ,$(OS_ARCH)),$(subst /, ,$(lastword $(shell go version))))
GOOS ?= $(firstword $(OSARCH))
GOARCH ?= $(lastword $(OSARCH))
CB = bin/$(GOOS)_$(GOARCH)/cb
OS_ARCHS = darwin_amd64 linux_amd64 windows_amd64
# build
build: $(CB)
$(CB): main.go
GOOS=$(GOOS) GOARCH=$(GOARCH) go build -o $@
build_all: $(foreach x,$(OS_ARCHS),build-$(x))
build-%:
make build OS_ARCH=$*
clobber:
rm -rf bin
# release
release: create_release upload_all
create_release:
curl https://api.github.com/repos/hiroshi/cb/releases \
-H "Authorization: token $$GITHUB_TOKEN" \
-d '{"tag_name":"latest"}'
RELEASE_ID = $(shell \
curl -s https://api.github.com/repos/hiroshi/cb/releases/latest \
-H "Authorization: token $$GITHUB_TOKEN" \
| jq .id)
ZIP = bin/cb-latest-$(GOOS)-$(GOARCH).zip
upload: $(ZIP)
curl https://uploads.github.com/repos/hiroshi/cb/releases/$(RELEASE_ID)/assets?name=$(notdir $(ZIP)) \
-H "Authorization: token $$GITHUB_TOKEN" \
-H "Accept: application/vnd.github.manifold-preview" \
-H "Content-Type: application/zip" \
--data-binary @$(ZIP)
$(ZIP):
zip -j $(ZIP) $(CB)
upload_all: $(foreach x,$(OS_ARCHS),upload-$(x))
upload-%:
make upload OS_ARCH=$*
# quick install
install: symlink
rm $(GOPATH)/bin/cb
cd $(GOPATH_CB) && go install -v
# development
goget: symlink
cd $(GOPATH_CB) && go get -v
symlink: | $(dir $(GOPATH_CB))
ln -snf $(shell pwd) $(GOPATH_CB)
$(dir $(GOPATH_CB)):
mkdir -p $@
run-example:
cd examples && make
# build single binary cb image
cb-build: source.tar.gz
cd $(GOPATH_CB) && go run main.go $< --config config.yml
source.tar.gz: main.go Dockerfile Dockerfile.build
tar czvf $@ $^