-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
138 lines (106 loc) · 2.66 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
135
136
137
INSTALL ?= install
INSTALL_DIR = $(INSTALL) -d
INSTALL_DATA = $(INSTALL) -m0644
INSTALL_PROGRAM = $(INSTALL) -m0755
TAR ?= tar
ZIP ?= zip
UNZIP ?= unzip
SUDO ?= sudo
PREFIX ?= /usr/local
GITHUB_ENV ?= /dev/null
GITHUB_PATH ?= /dev/null
GO ?= go
GOOS ?= $(shell $(GO) env GOOS)
GOARCH ?= $(shell $(GO) env GOARCH)
GOBUILD_TAGS ?=
GOBUILD_FLAGS ?=
GOLD_FLAGS ?= -s -w
GOTEST_FLAGS ?=
GOFMT_FLAGS ?=
GOVET_FLAGS ?=
CGO_ENABLED ?= 0
GO_DO := GOOS=$(GOOS) GOARCH=$(GOARCH) CGO_ENABLED=$(CGO_ENABLED) $(GO)
ifeq ($(GOOS),windows)
EXE_EXT := .exe
LIB_EXT := .dll
DIST_EXT := .zip
else
EXE_EXT :=
LIB_EXT := .so
DIST_EXT := .tgz
endif
PROJECT := encval
ENTRYPOINTS := $(notdir $(patsubst %/main.go,%,$(wildcard ./cmd/*/main.go)))
PROGRAM_files := $(addsuffix $(EXE_EXT),$(ENTRYPOINTS))
TARGET_TRIPLE := $(PROJECT)_$(GOOS)_$(GOARCH)$(GOARM)
.PHONY: all
all: binaries plugins
.PHONY: binaries
binaries: $(PROGRAM_files)
.PHONY: plugins
plugins:
$(MAKE) -C plugins
$(PROGRAM_files):
$(GO_DO) build \
$(GOBUILD_FLAGS) \
-tags "$(GOBUILD_TAGS)" \
-ldflags "$(GOLD_FLAGS)" \
-o $@ \
./cmd/$(basename $@)
.PHONY: dist
dist: $(TARGET_TRIPLE)$(DIST_EXT)
.PHONY: $(TARGET_TRIPLE)
$(TARGET_TRIPLE): LICENSE.txt
$(INSTALL_DATA) -D -t $@ $^
.PHONY: $(TARGET_TRIPLE)/bin
$(TARGET_TRIPLE)/bin: $(PROGRAM_files)
$(INSTALL_PROGRAM) -D -t $@ $^
.PHONY: $(TARGET_TRIPLE)/lib
$(TARGET_TRIPLE)/lib: plugins
$(INSTALL_DATA) -D -t $@ $(wildcard plugins/*$(LIB_EXT))
$(TARGET_TRIPLE).tgz: $(TARGET_TRIPLE) $(TARGET_TRIPLE)/bin $(TARGET_TRIPLE)/lib
cd $< ; $(TAR) -czf ../$@ *
$(TARGET_TRIPLE).zip: $(TARGET_TRIPLE) $(TARGET_TRIPLE)/bin
cd $< ; $(ZIP) -r ../$@ *
.PHONY: ci-deps
ci-deps:
$(SUDO) apt-get update -qq
$(SUDO) apt-get install -y --no-install-recommends \
build-essential
.PHONY: ci-env
ci-env:
echo "LD_LIBRARY_PATH=$(DESTDIR)$(PREFIX)/lib" >> $(GITHUB_ENV)
echo "$(DESTDIR)$(PREFIX)/bin" >> $(GITHUB_PATH)
.PHONY: test
test:
$(GO_DO) test $(GOTEST_FLAGS) ./...
.PHONY: format
format:
$(GO_DO) fmt $(GOFMT_FLAGS) ./...
.PHONY: lint
lint:
$(GO_DO) vet $(GOVET_FLAGS) ./...
.PHONY: update-deps
update-deps:
$(GO_DO) mod tidy
.PHONY: install
install: $(PROGRAM_files)
$(INSTALL_PROGRAM) -D -t $(DESTDIR)$(PREFIX)/bin $^
.PHONY: install-dist
install-dist: install$(DIST_EXT)
$(DESTDIR)$(PREFIX):
$(INSTALL_DIR) $(DESTDIR)$(PREFIX)
.PHONY: install.tgz
install.tgz: $(TARGET_TRIPLE).tgz $(DESTDIR)$(PREFIX)
$(TAR) -xzf $< -C $(DESTDIR)$(PREFIX)
.PHONY: install.zip
install.zip: $(TARGET_TRIPLE).zip $(DESTDIR)$(PREFIX)
$(UNZIP) $< -d $(DESTDIR)$(PREFIX)
.PHONY: clean
clean:
$(RM) *.zip *.tgz
$(RM) $(PROGRAM_files)
$(RM) -r $(PROJECT)_*
.PHONY: %-all
%-all: %
$(MAKE) -C plugins $*