-
Notifications
You must be signed in to change notification settings - Fork 4
/
Makefile
99 lines (76 loc) · 2.74 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
.PHONY: build compress prepareDev dev prepareRelase release test bench profile deploy clean deepclean
SHELL := /bin/bash
CMD_DIR=cmd/bamstats
CMD:= bamstats
LDFLAGS :=
OS := $(shell go env GOOS)
ARCH := $(shell go env GOARCH)
ENVS := \
linux/386 \
linux/amd64 \
darwin/386 \
darwin/amd64 \
BINARIES := $(ENVS:%=bin/%/$(CMD))
COMPRESSED_BINARIES := $(BINARIES:=.tar.bz2)
build: $(BINARIES)
compress: build $(COMPRESSED_BINARIES)
prepareDev:
$(eval COMMIT := $(shell git rev-parse --short HEAD))
$(eval LDFLAGS := -ldflags "-X github.com/guigolab/bamstats.GitCommit=$(COMMIT)")
dev: prepareDev build
$(ENVS):
@$(MAKE) bin/"$@"/$(CMD)
$(BINARIES): $(CMD_DIR)/*.go */*.go *.go
$(eval TERMS := $(subst /, ,"$@"))
$(eval GOOS := $(word 2, $(TERMS)))
$(eval GOARCH := $(word 3, $(TERMS)))
@echo -n Building $(GOOS)-$(GOARCH)...
@GOARCH=$(GOARCH) GOOS=$(GOOS) go build $(LDFLAGS) -o "$@" ./$(CMD_DIR)
@echo DONE
$(COMPRESSED_BINARIES): $(BINARIES)
$(eval BINARY := $(subst .tar.bz2,,"$@"))
@echo -n Compressing $(BINARY)...
@tar -jcf "$@" $(BINARY)
@echo DONE
$(COMPRESSED_BINARIES:%=upload-%): upload-%: prepareRelease
$(eval FILE := $(subst upload-,,"$@"))
$(eval INFO := $(subst /, ,"$(subst /$(CMD),,$(FILE))"))
@github-release upload -t $(TAG) -n $(CMD)-$(TAG)-$(word 2, $(INFO))-$(word 3, $(INFO)) -f $(FILE) || true
prepareRelease:
$(eval TAG := $(shell git describe --abbrev=0 --tags))
$(eval NAME := $(shell git cat-file -p $(shell git rev-parse $(TAG)) | tail -n+6))
$(eval LDFLAGS := -ldflags "-X github.com/guigolab/bamstats.PreVersionString=")
$(eval PRE := -p)
release: prepareRelease compress
pushRelease: release
$(eval VER := $(shell bin/$(OS)/$(ARCH)/bamstats --version | cut -d' ' -f3 | sed 's/^/v/'))
@[[ $(VER) == $(TAG) ]] && git push && git push --tags || echo "Wrong release version"
@[[ $(VER) == $(TAG) ]] && (github-release release -t $(TAG) $(PRE) -n "$(NAME)" || true) || true
@[[ $(VER) == $(TAG) ]] && $(MAKE) $(COMPRESSED_BINARIES:%=upload-%) || true
test:
@go test -cpu=1,2 ./annotation
@go test -cpu=1,2 ./config
@go test -cpu=1,2 ./sam
@go test -cpu=1,2 ./stats
@go test -cpu=1,2 ./utils
@go test -cpu=1,2 .
race:
@go test -cpu=1,2 -race ./annotation
@go test -cpu=1,2 -race ./config
@go test -cpu=1,2 -race ./sam
@go test -cpu=1,2 -race ./stats
@go test -cpu=1,2 -race ./utils
@go test -cpu=1,2 -race .
bench:
@go test -cpu=1,2,4 -bench . -run NOTHING -benchtime 4s -cpuprofile cpu.prof -memprofile prof.mem
profile: cpu.prof
@go tool pprof bamstats.test $?
install: prepareDev $(CMD_DIR)/*.go */*.go *.go
@go install $(LDFLAGS) ./$(CMD_DIR)
ant: prepareDev bin/linux/amd64/$(CMD)
$(eval BIN := $(word 2, $?))
@scp $(BIN) ant:~/bin/$(CMD)
clean:
@rm -rf bin/*
deepclean: clean
@rm bamstats.test cpu.prof