-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMakefile
68 lines (55 loc) · 2 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
.PHONY: build build-for-docker test clean release single_release
CMD_DIR:=cmd/volume-manager
# make directory and store path to variable
BUILDS_DIR:=$(PWD)/build
EXECUTABLE:=volume-manager
LDFLAGS=-X 'main.version=$(VERSION)' -w -s -extldflags '-static'
# go has build artifacts caching so soruce tracking not needed
build:
@echo "Building mail-templater for current OS/architecture"
@echo $(LDFLAGS)
@CGO_ENABLED=0 go build -v -ldflags="$(LDFLAGS)" -tags="jsoniter" -o $(BUILDS_DIR)/$(EXECUTABLE) ./$(CMD_DIR)
build-for-docker:
@echo $(LDFLAGS)
@CGO_ENABLED=0 go build -v -ldflags="$(LDFLAGS)" -tags="jsoniter" -o /tmp/$(EXECUTABLE) ./$(CMD_DIR)
test:
@echo "Running tests"
@go test -v ./...
clean:
@rm -rf $(BUILDS_DIR)
install:
@go install -ldflags="$(LDFLAGS)"
# lambda to generate build dir name using os,arch,version
temp_dir_name=$(EXECUTABLE)_$(1)_$(2)_v$(3)
pack_win=zip -r -j $(1).zip $(1) && rm -rf $(1)
pack_nix=tar -C $(1) -cpzf $(1).tar.gz ./ && rm -rf $(1)
define build_release
@echo "Building release package for OS $(1), arch $(2)"
$(eval temp_build_dir=$(BUILDS_DIR)/$(call temp_dir_name,$(1),$(2),$(VERSION)))
@mkdir -p $(temp_build_dir)
$(eval ifeq ($(1),windows)
temp_executable=$(temp_build_dir)/$(EXECUTABLE).exe
else
temp_executable=$(temp_build_dir)/$(EXECUTABLE)
endif)
@echo go build -tags="dev" -ldflags="$(RELEASE_LDFLAGS)" -v -o $(temp_executable) ./$(CMD_DIR)
@GOOS=$(1) GOARCH=$(2) go build -tags="dev" -ldflags="$(RELEASE_LDFLAGS)" -v -o $(temp_executable) ./$(CMD_DIR)
$(eval ifeq ($(1),windows)
pack_cmd = $(call pack_win,$(temp_build_dir))
else
pack_cmd = $(call pack_nix,$(temp_build_dir))
endif)
@$(pack_cmd)
endef
release:
$(call build_release,linux,amd64)
$(call build_release,linux,386)
$(call build_release,linux,arm)
$(call build_release,darwin,amd64)
$(call build_release,windows,amd64)
$(call build_release,windows,386)
single_release:
$(call build_release,$(OS),$(ARCH))
dev:
@echo building $(VERSION)
go build -v -tags="dev" -ldflags="$(LDFLAGS)" ./$(CMD_DIR)