-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathGNUmakefile
156 lines (124 loc) · 3.79 KB
/
GNUmakefile
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
prefix = /usr/local
bindir = $(DESTDIR)$(prefix)/bin
sharedir = $(DESTDIR)$(prefix)/share
docdir = $(DESTDIR)$(prefix)/share/doc
BUILD_ID = $(shell ./utils/build-id)
EVWEB_INPUT_DIRS = . ../data # relative to the evweb directory
BIN_DIR ?= bin
GO_PKGS = \
github.com/exograd/eventline/cmd/eventline \
$(EVCLI_PKG)
EVCLI_PKG = github.com/exograd/eventline/cmd/evcli
GO_TEST_OPTIONS ?= -count 1
define evweb_make1
$(MAKE) -C evweb --no-print-directory \
$2 INPUT_DIR=$1 OUTPUT_DIR=../data/assets
endef
define evweb_make
$(foreach dir,$(EVWEB_INPUT_DIRS),$(call evweb_make1,$(dir),$1)
)
endef
define go_make1
CGO_ENABLED=0 \
go build -o $(BIN_DIR) \
-ldflags="-X 'main.buildId=$(BUILD_ID)'" \
$1
endef
define go_make
$(foreach dir,$(GO_PKGS),$(call go_make1,$(dir))
)
endef
DOC_HTML = doc/handbook/handbook.html
ASCIIDOCTOR_OPTIONS = -v -a revnumber=$(BUILD_ID)
DOCKER_IMAGES = \
exograd/eventline
define docker_build1
DOCKER_BUILDKIT=1 \
docker build --no-cache \
--label org.opencontainers.image.created=$(shell date -u +%FT%TZ) \
--label org.opencontainers.image.version=$(BUILD_ID) \
--label org.opencontainers.image.revision=$(shell git rev-parse HEAD) \
--tag $1:$(patsubst v%,%,$(BUILD_ID)) \
--tag $1:latest \
.
endef
define docker_build
$(foreach image,$(DOCKER_IMAGES),$(call docker_build1,$(image))
)
endef
all: build
assets:
$(call evweb_make,build)
build: assets FORCE
$(call go_make)
evcli: FORCE
$(call go_make1,$(EVCLI_PKG))
check: vet
vet:
go vet ./...
test:
go test $(GO_TEST_OPTIONS) ./...
doc: doc-html
doc-html: $(DOC_HTML)
.SECONDEXPANSION:
%.html: $$(wildcard doc/**/*.adoc) doc/theme.css $$(wildcard doc/**/js/*.js)
asciidoctor --backend html \
--destination-dir $(dir $@) \
-a docinfo=shared \
-a nofooter \
-a rouge-style=base16.dark \
-a stylesdir=.. \
-a stylesheet=theme.css \
$(ASCIIDOCTOR_OPTIONS) \
$(subst .html,.adoc,$@)
# For some reason, using the compressed style breaks @font-face blocks. I have
# no idea why it breaks here but not in Eventline. I will take a patch to fix
# this if someone find the root cause.
doc/theme.css: doc/theme.scss
sass --no-error-css --no-source-map --style expanded $<:$@
docker-images: build doc FORCE
$(call docker_build)
install: build doc
mkdir -p $(bindir)
cp $(wildcard bin/*) $(bindir)
mkdir -p $(sharedir)/licenses/eventline
cp LICENSE $(sharedir)/licenses/eventline
mkdir -p $(sharedir)/eventline
cp -r data/assets $(sharedir)/eventline
cp -r data/pg $(sharedir)/eventline
cp -r data/templates $(sharedir)/eventline
mkdir -p $(docdir)/eventline
mkdir -p $(docdir)/eventline/html
cp CHANGELOG.md $(docdir)/eventline
cp -r $(DOC_HTML) $(docdir)/eventline/html
cp -r $(dir $(DOC_HTML))images $(docdir)/eventline/html
cp -r $(dir $(DOC_HTML))js $(docdir)/eventline/html
mkdir -p $(docdir)/eventline/fonts
cp -r doc/fonts/*.woff2 $(docdir)/eventline/fonts
install-flat: build doc
@if [ -z "$(DESTDIR)" ]; then echo "DESTDIR not set" >&2; exit 1; fi
mkdir -p $(DESTDIR)
cp $(wildcard bin/*) $(DESTDIR)
cp LICENSE $(DESTDIR)
mkdir -p $(DESTDIR)/data
cp -r data/assets $(DESTDIR)/data
cp -r data/pg $(DESTDIR)/data
cp -r data/templates $(DESTDIR)/data
mkdir -p $(DESTDIR)/doc
mkdir -p $(DESTDIR)/doc/html
cp CHANGELOG.md $(DESTDIR)/doc
cp -r $(DOC_HTML) $(DESTDIR)/doc/html
cp -r $(dir $(DOC_HTML))images $(DESTDIR)/doc/html
cp -r $(dir $(DOC_HTML))js $(DESTDIR)/doc/html
mkdir -p $(DESTDIR)/doc/fonts
cp -r doc/fonts/*.woff2 $(DESTDIR)/doc/fonts
clean:
$(call evweb_make,clean)
$(RM) $(BIN_DIR)/*
$(RM) $(DOC_HTML) doc/theme.css
FORCE:
.PHONY: all assets build evcli clean
.PHONY: check vet test
.PHONY: doc doc-html
.PHONY: docker-images
.PHONY: install install-flat