-
Notifications
You must be signed in to change notification settings - Fork 18
/
Makefile
152 lines (126 loc) · 5.24 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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
SHELL := /bin/bash
THIS_FILE := $(lastword $(MAKEFILE_LIST))
TARGET_SOURCE = $(shell find main.go g cmd common -name '*.go')
CMD = aggregator graph hbs judge nodata query sender task transfer fe alarm agent mysqlapi f2e-api
TARGET = open-falcon
VERSION := $(shell cat VERSION)
##################################################
# Variables for Different OS information
##################################################
OSTYPE := $(shell echo $$OSTYPE)
# // :~)
##################################################
# For the target of "fmt", "misspell", "fmt-check", and "misspell-check",
# it is possible the listing of files too long to run in shell.
#
# Following variables defines arguments used by "xargs" command
##################################################
# Maximum characters fed to "xargs -s xx"
XARGS_ARGS :=
ifeq ($(findstring cygwin,$(OSTYPE)), cygwin)
XARGS_ARGS := --max-procs=1 --max-chars=16384
else ifeq ($(findstring linux,$(OSTYPE)), linux)
XARGS_ARGS := --max-procs=1 --max-chars=65536
else ifeq ($(findstring darwin,$(OSTYPE)), darwin)
XARGS_ARGS := -P 1 -s 65536
endif
CMD_LIST_GO_FILES := find . -name "*.go" -type f ! -path "./vendor/*"
# Temporary file used to keep listing of go files
LISTFILE_OF_GO_FILES := $(shell mktemp).gofiles.list
XARGS_CMD := xargs $(XARGS_ARGS)
# // :~)
GOFMT ?= gofmt -s
# The folder of GoLang used to search testing package
GO_TEST_FOLDER := common modules
# You should assign the path starting with any of $(GO_TEST_FOLDER)
GO_TEST_EXCLUDE := modules/agent modules/f2e-api modules/fe
GO_TEST_FLAGS :=
GO_TEST_VERBOSE :=
GO_TEST_PROPS :=
mp =
GO_TEST_PROPS_SEP :=
GO_TEST_PROPS_FILE :=
GO_TEST_COVERAGE_FILE :=
all: install $(CMD) $(TARGET)
misspell: build_gofile_listfile .get_misspell
@echo "Inline fix mis-spelled files.";
$(XARGS_CMD) misspell -w <$(LISTFILE_OF_GO_FILES);
misspell-check: build_gofile_listfile .get_misspell
check_cmd="$(XARGS_CMD) misspell -error <$(LISTFILE_OF_GO_FILES)"; \
echo $$check_cmd; \
check_output=$$(eval "$$check_cmd"); \
test -z "$$check_output" || { \
echo -e "misspell capture error:\n $$check_output\n"; \
echo "[HELP]" Use \"make misspell\" to fix files inline."(Don't forget to commit changed files)"; \
exit 1; \
}
fmt: build_gofile_listfile
@echo "Inline fix mis-formatted files.";
$(XARGS_CMD) $(GOFMT) -l -w <$(LISTFILE_OF_GO_FILES);
fmt-check: build_gofile_listfile
check_cmd="$(XARGS_CMD) $(GOFMT) -d <$(LISTFILE_OF_GO_FILES)"; \
echo $$check_cmd; \
check_output=$$(eval "$$check_cmd"); \
test -z "$$check_output" || { \
echo -e "gofmt capture error:\n $$check_output\n"; \
echo "[HELP]" Use \"make fmt\" to fix files inline."(Don't forget to commit changed files)"; \
exit 1; \
}
build_gofile_listfile:
echo Generate "$(LISTFILE_OF_GO_FILES)" file for GoLang files.
$(CMD_LIST_GO_FILES) >$(LISTFILE_OF_GO_FILES)
echo -e There are \"`wc -l <$(LISTFILE_OF_GO_FILES)`\" GoLang files."\n"
.get_misspell:
type -p misspell &>/dev/null || { \
cmd="go get -v -u github.com/client9/misspell/cmd/misspell"; \
echo $$cmd; \
$$cmd; \
}
go-test:
./go-test-all.sh \
-t "$(GO_TEST_FOLDER)" -e "$(GO_TEST_EXCLUDE)" \
$(if $(strip $(GO_TEST_COVERAGE_FILE)),-c "$(GO_TEST_COVERAGE_FILE)",) \
$(if $(strip $(GO_TEST_PROPS_FILE)),-f "$(GO_TEST_PROPS_FILE)",) \
$(if $(strip $(GO_TEST_PROPS)),-p "$(GO_TEST_PROPS)",) \
$(if $(strip $(GO_TEST_PROPS_SEP)),-s "$(GO_TEST_PROPS_SEP)",) \
$(if $(strip $(GO_TEST_FLAGS)),-a "$(GO_TEST_FLAGS)",) \
$(if $(filter yes,$(GO_TEST_VERBOSE)),-v,)
$(CMD):
go build -ldflags "-X main.GitCommit=`git log -n1 --pretty=format:%h modules/$@` -X main.Version=${VERSION}" -o bin/$@/falcon-$@ ./modules/$@
$(TARGET): $(TARGET_SOURCE)
go build -ldflags "-X main.GitCommit=`git rev-parse --short HEAD` -X main.Version=$(VERSION)" -o $@
checkvendor:
@hash govendor > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
go get -u github.com/kardianos/govendor; \
fi
install: checkvendor
govendor sync
checkbin: bin/ config/ open-falcon cfg.json
pack: checkbin
@if [ -e out ] ; then rm -rf out; fi
@mkdir out
@$(foreach var,$(CMD),mkdir -p ./out/$(var)/bin;)
@$(foreach var,$(CMD),mkdir -p ./out/$(var)/config;)
@$(foreach var,$(CMD),mkdir -p ./out/$(var)/logs;)
@$(foreach var,$(CMD),cp ./config/$(var).json ./out/$(var)/config/cfg.json;)
@$(foreach var,$(CMD),cp ./bin/$(var)/falcon-$(var) ./out/$(var)/bin;)
@cp -r ./modules/query/js ./modules/query/conf/lambdaSetup.json ./out/query/config
@cp -r ./modules/fe/{static,views,scripts} ./out/fe/bin
@cp -r ./modules/alarm/{static,views} ./out/alarm/bin
@cp -r ./modules/agent/public ./out/agent/bin
@cp -r ./modules/f2e-api/data ./out/f2e-api/bin
@cp -r ./modules/f2e-api/lambda_extends/js ./out/f2e-api/bin
@cp -r ./modules/f2e-api/lambda_extends/conf/lambdaSetup.json ./out/f2e-api/config
@cp cfg.json ./out/cfg.json
@bash ./config/confgen.sh
@cp $(TARGET) ./out/$(TARGET)
tar -C out -zcf open-falcon-v$(VERSION).tar.gz .
@rm -rf out
clean:
@rm -rf ./bin
@rm -rf ./out
@rm -rf ./$(TARGET)
@rm -rf open-falcon-v$(VERSION).tar.g
.PHONY: install clean all aggregator graph hbs judge nodata query sender task transfer fe f2e-api coverage
.PHONY: fmt misspell fmt-check misspell-check .get_misspell build_gofile_listfile go-test
.SILENT: build_gofile_listfile misspell-check fmt-check go-test .get_misspell