forked from jasonish/evebox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
163 lines (143 loc) · 4.43 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
153
154
155
156
157
158
159
160
161
162
163
# EveBox Makefile
#
# Requirements:
# - GNU Make
# Version info.
VERSION_SUFFIX := dev
VERSION := 0.9.1
BUILD_REV := $(shell git rev-parse --short HEAD)
BUILD_DATE ?= $(shell git log --pretty=format:%ct -1)
export BUILD_DATE
BUILD_REV_VAR := github.com/jasonish/evebox/core.BuildRev
BUILD_VER_VAR := github.com/jasonish/evebox/core.BuildVersion
LDFLAGS := -X \"$(BUILD_REV_VAR)=$(BUILD_REV)\" \
-X \"$(BUILD_VER_VAR)=$(VERSION)$(VERSION_SUFFIX)\" \
HOST_GOOS := $(shell go env GOOS)
HOST_GOARCH := $(shell go env GOARCH)
HOST_DIST := $(HOST_GOOS)/$(HOST_GOARCH)
GOOS ?= $(shell go env GOOS)
GOARCH ?= $(shell go env GOARCH)
DIST := $(GOOS)/$(GOARCH)
ifeq ($(HOST_DIST),$(DIST))
CGO_ENABLED := 1
TAGS += fts5 json1
endif
APP := evebox
GO_SRCS := $(shell find . -name \*.go | grep -v /vendor/)
GO_PACKAGES := $(shell go list ./... | grep -v /vendor/)
WEBAPP_SRCS := $(shell find webapp -type f | grep -v node_modules)
GOPATH ?= $(HOME)/go
all: public evebox
install-deps:
# NPM
$(MAKE) -C webapp $@
go get -u github.com/golang/dep/cmd/dep
go get -u github.com/cespare/reflex
go get -u github.com/gobuffalo/packr/packr
$(GOPATH)/bin/dep ensure -v
clean:
rm -rf dist
rm -f evebox
rm -rf resources/public
$(GOPATH)/bin/packr clean
find . -name \*~ -exec rm -f {} \;
distclean: clean
rm -rf vendor
$(MAKE) -C webapp $@
.PHONY: dist rpm deb
resources/public/_done: $(WEBAPP_SRCS)
cd webapp && $(MAKE)
touch $@
public: resources/public/_done
# Build's EveBox for the host platform.
evebox: Makefile $(GO_SRCS)
$(GOPATH)/bin/packr -z
CGO_ENABLED=$(CGO_ENABLED) go build --tags "$(TAGS)" \
-ldflags "$(LDFLAGS)" \
cmd/evebox.go
# Format all go source code except in the vendor directory.
gofmt:
@go fmt $(GO_PACKAGES)
dist: GOARCH ?= $(shell go env GOARCH)
dist: GOOS ?= $(shell go env GOOS)
dist: DISTARCH := $(GOARCH)
ifeq ($(GOARCH),amd64)
dist: DISTARCH := x64
endif
ifeq ($(GOARCH),386)
dist: DISTARCH := x32
endif
ifneq ($(VERSION_SUFFIX),)
dist: VERSION := latest
endif
dist: DISTNAME ?= ${APP}$(DIST_SUFFIX)-${VERSION}-${GOOS}-${DISTARCH}
dist: LDFLAGS += -s
dist: CGO_ENABLED ?= $(CGO_ENABLED)
ifeq ($(GOOS),windows)
dist: APP_EXT := .exe
endif
dist: public
@echo "Building EveBox rev $(BUILD_REV)."
$(GOPATH)/bin/packr -z
CGO_ENABLED=$(CGO_ENABLED) GOARCH=$(GOARCH) GOOS=$(GOOS) \
go build -tags "$(TAGS)" -ldflags "$(LDFLAGS)" \
-o dist/$(DISTNAME)/${APP}${APP_EXT} cmd/evebox.go
cp agent.yaml.example dist/$(DISTNAME)
cp evebox.yaml.example dist/$(DISTNAME)
cd dist && zip -r ${DISTNAME}.zip ${DISTNAME}
# Debian packaging. Due to a versioning screwup early on, we now need
# to set the epoch to 1 for those updating with apt.
deb: EPOCH := 1
ifneq ($(VERSION_SUFFIX),)
deb: TILDE := ~$(VERSION_SUFFIX)$(BUILD_DATE)
deb: EVEBOX_BIN := dist/${APP}-latest-linux-x64/evebox
deb: OUTPUT := dist/evebox-latest-amd64.deb
else
deb: EVEBOX_BIN := dist/${APP}-${VERSION}-linux-x64/evebox
deb: OUTPUT := dist/
endif
deb:
fpm --force -s dir \
-t deb \
-p $(OUTPUT) \
-n evebox \
--epoch $(EPOCH) \
-v $(VERSION)$(TILDE) \
--after-install=deb/after-install.sh \
--after-upgrade=deb/after-upgrade.sh \
--deb-no-default-config-files \
--config-files /etc/default/evebox \
${EVEBOX_BIN}=/usr/bin/evebox \
evebox.yaml.example=/etc/evebox/evebox.yaml.example \
agent.yaml.example=/etc/evebox/agent.yaml.example \
deb/evebox.default=/etc/default/evebox \
deb/evebox.service=/lib/systemd/system/evebox.service \
deb/evebox-agent.service=/lib/systemd/system/evebox-agent.service
# RPM packaging.
ifneq ($(VERSION_SUFFIX),)
# Setup non-release versioning.
rpm: RPM_ITERATION := 0.$(VERSION_SUFFIX)$(BUILD_DATE)
rpm: EVEBOX_BIN := dist/${APP}-latest-linux-x64/evebox
rpm: OUTPUT := dist/evebox-latest-x86_64.rpm
else
# Setup release versioning.
rpm: RPM_ITERATION := 1
rpm: EVEBOX_BIN := dist/${APP}-${VERSION}-linux-x64/evebox
rpm: OUTPUT := dist/
endif
rpm:
fpm --force -s dir \
-t rpm \
-p $(OUTPUT) \
-n evebox \
-v $(VERSION) \
--iteration $(RPM_ITERATION) \
--before-install=rpm/before-install.sh \
--after-upgrade=rpm/after-upgrade.sh \
--config-files /etc/sysconfig/evebox \
${EVEBOX_BIN}=/usr/bin/evebox \
evebox.yaml.example=/etc/evebox/evebox.yaml.example \
agent.yaml.example=/etc/evebox/agent.yaml.example \
rpm/evebox.sysconfig=/etc/sysconfig/evebox \
rpm/evebox.service=/lib/systemd/system/evebox.service \
rpm/evebox-agent.service=/lib/systemd/system/evebox-agent.service