forked from geneweb/geneweb
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMakefile
More file actions
285 lines (252 loc) · 9.75 KB
/
Makefile
File metadata and controls
285 lines (252 loc) · 9.75 KB
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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
ifneq ($(MAKECMDGOALS),ci)
Makefile.config: configure.ml
@if [ -e "$@" ]; then \
echo "configure file has changed. Please rerun ocaml ./configure.ml"; exit 1; \
else \
echo "Please run ocaml ./configure.ml first"; exit 1; \
fi
include Makefile.config
endif
-include Makefile.local
# Variables for packagers.
DISTRIB_DIR=distribution
BUILD_DIR=_build/default
BUILD_DISTRIB_DIR=$(BUILD_DIR)/bin/
ODOC_DIR=$(BUILD_DIR)/_doc/_html
# [BEGIN] Generated files section
COMPIL_DATE := $(shell date +'%Y-%m-%d')
COMMIT_DATE := $(shell git show -s --date=short --pretty=format:'%cd')
COMMIT_ID := $(shell git rev-parse --short HEAD)
COMMIT_TITLE := $(shell git log -1 --pretty="%s" | sed "s/\"/\\\"/g")
COMMIT_COMMENT:= $(shell git log -1 --pretty="%b" | sed "s/\"/\\\"/g")
BRANCH := $(shell git symbolic-ref --quiet --short HEAD || git branch -r --contains HEAD | head -n1 | tr -d ' ')
SOURCE := $(shell git remote get-url origin | sed -n 's|^.*github.com.\([^/]\+/[^/.]\+\)\(.git\)\?|\1|p')
VERSION := $(shell awk -F\" '/^let ver =/ {print $$2}' lib/version.txt)
OCAMLV := $(shell ocamlopt --version)
info:
@printf 'Building \033[1;1mGeneweb $(VERSION)\033[0m with OCaml $(OCAMLV).\n\n'
@printf 'Repository \033[1;1m$(SOURCE)\033[0m. Branch \033[1;1m$(BRANCH)\033[0m. '
@printf 'Last commit \033[1;1m$(COMMIT_ID)\033[0m message:\n\n'
@printf ' \033[1;1m%s\033[0m\n' '$(subst ','\'',$(COMMIT_TITLE))'
ifneq ($(COMMIT_COMMENT),)
@printf '\n$(subst ','\'',$(COMMIT_COMMENT))' | fmt -w 80
endif
@printf '\n\033[1;1mGenerating configuration files\033[0m\n'
.PHONY: info
fmt build build-geneweb gwd install uninstall: info
fmt: ## Format Ocaml code
@printf "\n\033[1;1mOcamlformat\033[0m\n"
dune build @fmt --auto-promote
.PHONY: clean-version
clean-version:
@rm -f $(BUILD_DIR)/lib/version.ml
build: clean-version
dune build
build-geneweb: clean-version ## Build the geneweb package (libraries and binaries)
@printf "\n\033[1;1mBuilding executables\033[0m\n"
dune build @bin/all @lib/all
@printf "Done."
build-geneweb-rpc: ## Build the geneweb-rpc package
@printf "\033[1;1mBuilding Geneweb RPC package\033[0m\n"
dune build @rpc/all
@printf "Done."
gwd: clean-version ## Build ondy gwd/gwc executables
@printf "\n\033[1;1mBuilding only gwd and gwc executables\033[0m\n"
dune build bin/gwd bin/gwc
@printf "Done."
install: ## Install geneweb using dune
dune build @install
dune install
.PHONY: install
uninstall: ## Uninstall geneweb using dune
dune build @install
dune uninstall
distrib: info ## Build the project and copy what is necessary for distribution
dune build --release @bin/all @lib/all
@printf "Done.\n"
@rm -rf $(DISTRIB_DIR)
@printf "\n\033[1;1mCreating distribution directory\033[0m\n"
mkdir $(DISTRIB_DIR)
mkdir -p $(DISTRIB_DIR)/bases
cp CHANGES $(DISTRIB_DIR)/CHANGES.txt
cp LICENSE $(DISTRIB_DIR)/LICENSE.txt
cp etc/README.txt $(DISTRIB_DIR)/.
cp etc/LISEZMOI.txt $(DISTRIB_DIR)/.
cp etc/START.htm $(DISTRIB_DIR)/.
ifeq ($(OS_TYPE),Win)
cp etc/Windows/gwd.bat $(DISTRIB_DIR)
cp etc/Windows/gwsetup.bat $(DISTRIB_DIR)
cp -f etc/Windows/README.txt $(DISTRIB_DIR)/README.txt
cp -f etc/Windows/LISEZMOI.txt $(DISTRIB_DIR)/LISEZMOI.txt
cp -f etc/ROBOT.txt $(DISTRIB_DIR)/ROBOT.txt
else ifeq ($(OS_TYPE),Darwin)
cp etc/gwd.sh $(DISTRIB_DIR)/gwd.command
cp etc/gwsetup.sh $(DISTRIB_DIR)/gwsetup.command
cp etc/geneweb.sh $(DISTRIB_DIR)/geneweb.command
else
cp etc/gwd.sh $(DISTRIB_DIR)/gwd.sh
cp etc/gwsetup.sh $(DISTRIB_DIR)/gwsetup.sh
cp etc/geneweb.sh $(DISTRIB_DIR)/geneweb.sh
endif
mkdir $(DISTRIB_DIR)/gw
cp etc/a.gwf $(DISTRIB_DIR)/gw/.
echo "-setup_link" > $(DISTRIB_DIR)/gw/gwd.arg
echo "-bd" >> $(DISTRIB_DIR)/gw/gwd.arg
echo "./bases" >> $(DISTRIB_DIR)/gw/gwd.arg
@printf "\n\033[1;1m└ Copy binaries in $(DISTRIB_DIR)/gw/\033[0m\n"
cp $(BUILD_DISTRIB_DIR)connex/connex.exe $(DISTRIB_DIR)/gw/connex$(EXT)
cp $(BUILD_DISTRIB_DIR)consang/consang.exe $(DISTRIB_DIR)/gw/consang$(EXT)
cp $(BUILD_DISTRIB_DIR)fixbase/gwfixbase.exe $(DISTRIB_DIR)/gw/gwfixbase$(EXT)
cp $(BUILD_DISTRIB_DIR)ged2gwb/ged2gwb.exe $(DISTRIB_DIR)/gw/ged2gwb$(EXT)
cp $(BUILD_DISTRIB_DIR)gwb2ged/gwb2ged.exe $(DISTRIB_DIR)/gw/gwb2ged$(EXT)
cp $(BUILD_DISTRIB_DIR)cache_files/cache_files.exe $(DISTRIB_DIR)/gw/cache_files$(EXT)
cp $(BUILD_DISTRIB_DIR)gwc/gwc.exe $(DISTRIB_DIR)/gw/gwc$(EXT)
cp $(BUILD_DISTRIB_DIR)gwd/gwd.exe $(DISTRIB_DIR)/gw/gwd$(EXT)
cp $(BUILD_DISTRIB_DIR)gwdiff/gwdiff.exe $(DISTRIB_DIR)/gw/gwdiff$(EXT)
cp $(BUILD_DISTRIB_DIR)gwu/gwu.exe $(DISTRIB_DIR)/gw/gwu$(EXT)
cp $(BUILD_DISTRIB_DIR)robot/robot.exe $(DISTRIB_DIR)/gw/robot$(EXT)
cp $(BUILD_DISTRIB_DIR)setup/setup.exe $(DISTRIB_DIR)/gw/gwsetup$(EXT)
cp $(BUILD_DISTRIB_DIR)update_nldb/update_nldb.exe $(DISTRIB_DIR)/gw/update_nldb$(EXT)
@printf "\n\033[1;1m└ Copy templates in $(DISTRIB_DIR)/gw/\033[0m\n"
cp -R hd/* $(DISTRIB_DIR)/gw/
rm $(DISTRIB_DIR)/gw/dune
rm $(DISTRIB_DIR)/gw/etc/js/checkdata.js
rm $(DISTRIB_DIR)/gw/etc/js/p_mod.js
rm $(DISTRIB_DIR)/gw/etc/js/relationmatrix.js
rm $(DISTRIB_DIR)/gw/etc/js/fanchart.js
@printf "\n\033[1;1m└ Compressing large JS/CSS assets\033[0m\n"
@for f in $(DISTRIB_DIR)/gw/etc/js/*.min.js; do \
if [ -f "$$f" ] && [ $$(stat -c%s "$$f" 2>/dev/null || stat -f%z "$$f") -gt 4500 ]; then \
printf "gzip -9 -k %s\n" "$$f"; \
gzip -9 -k -f "$$f"; \
printf "brotli %s\n" "$$f"; \
brotli -f -q 11 "$$f"; \
fi; \
done
@for f in $(DISTRIB_DIR)/gw/etc/css/*.css; do \
if [ -f "$$f" ] && [ $$(stat -c%s "$$f" 2>/dev/null || stat -f%z "$$f") -gt 10000 ]; then \
printf "gzip -9 -k %s\n" "$$f"; \
gzip -9 -k -f "$$f"; \
printf "brotli %s\n" "$$f"; \
brotli -f -q 11 "$$f"; \
fi; \
done
mkdir $(DISTRIB_DIR)/gw/setup
cp bin/setup/intro.txt $(DISTRIB_DIR)/gw/setup/
mkdir $(DISTRIB_DIR)/gw/setup/lang
cp bin/setup/setup.gwf $(DISTRIB_DIR)/gw/setup/
cp bin/setup/setup.css $(DISTRIB_DIR)/gw/setup/
cp bin/setup/lang/*.htm $(DISTRIB_DIR)/gw/setup/lang/
cp bin/setup/lang/lexicon.txt $(DISTRIB_DIR)/gw/setup/lang/
cp bin/setup/lang/intro.txt $(DISTRIB_DIR)/gw/setup/lang/
@printf "\n\033[1;1m└ Copy plugins in $(DISTRIB_DIR)/gw/plugins\033[0m\n"
mkdir $(DISTRIB_DIR)/gw/plugins
@for P in $(shell ls plugins); do \
if [ -f $(BUILD_DIR)/plugins/$$P/plugin_$$P.cmxs ] ; then \
mkdir $(DISTRIB_DIR)/gw/plugins/$$P; \
printf "cp %s %s\n" "$(BUILD_DIR)/plugins/$$P/plugin_$$P.cmxs" "$(DISTRIB_DIR)/gw/plugins/$$P/"; \
cp $(BUILD_DIR)/plugins/$$P/plugin_$$P.cmxs $(DISTRIB_DIR)/gw/plugins/$$P/; \
if [ -d plugins/$$P/assets ] ; then \
printf "cp -R %s %s\n" "$(BUILD_DIR)/plugins/$$P/assets" "$(DISTRIB_DIR)/gw/plugins/$$P/"; \
cp -R $(BUILD_DIR)/plugins/$$P/assets $(DISTRIB_DIR)/gw/plugins/$$P/; \
fi; \
if [ -f $(BUILD_DIR)/plugins/$$P/META ] ; then \
printf "cp %s %s\n" "$(BUILD_DIR)/plugins/$$P/META" "$(DISTRIB_DIR)/gw/plugins/$$P/"; \
cp $(BUILD_DIR)/plugins/$$P/META $(DISTRIB_DIR)/gw/plugins/$$P/; \
fi; \
fi; \
done
@printf "Done.\n\n\033[1;1mDistribution complete\033[0m\n"
@printf "You can launch Geneweb with “\033[1;1mcd $(DISTRIB_DIR)\033[0m” followed by “\033[1;1mgw/gwd$(EXT)\033[0m”.\n\n"
distrib-rpc: build-geneweb-rpc
@printf "\n\n\033[1;1m└ Copy RPC server executable and js client to distribution\033[0m\n"
mkdir -p $(DISTRIB_DIR)/gw/etc/js
cp $(BUILD_DIR)/rpc/server/server.exe $(DISTRIB_DIR)/gw/rpc_server$(EXT)
cp $(BUILD_DIR)/rpc/test/client.bc.js $(DISTRIB_DIR)/gw/etc/js/rpc_client.min.js
gzip -9 -k -f $(DISTRIB_DIR)/gw/etc/js/rpc_client.min.js
@echo "Done."
.PHONY: build build-geneweb build-geneweb-rpc gwd fmt install uninstall distrib
# [END] Installation / Distribution section
doc: ## Documentation generation
doc:
dune build @doc
.PHONY: doc
opendoc: doc
xdg-open $(ODOC_DIR)/index.html
.PHONY: opendoc
test: ## Run tests
test:
@dune build @runtest
.PHONY: test
bench: ## Run benchmarks
bench:
dune build @runbench
.PHONY: bench
BENCH_FILE?=geneweb-bench.bin
bench-marshal: ## Run benchmarks and record the result
bench-marshal:
ifdef BENCH_NAME
dune exec benchmark/bench.exe -- --marshal --name ${BENCH_NAME} ${BENCH_FILE}
else
$(error BENCH_NAME variable is empty)
endif
.PHONY: bench-marshal
bench-tabulate: ## Read BENCH_FILE and print a report
bench-tabulate:
dune exec benchmark/bench.exe -- --tabulate ${BENCH_FILE}
@rm -f $(BENCH_FILE)
.PHONY: bench-tabulate
clean:
@echo -n "Cleaning…"
@rm -rf $(DISTRIB_DIR)
@rm -rf _build
@echo " Done."
.PHONY: clean
ci: ## Run tests, skip known failures
ci:
@GENEWEB_CI=on dune build @runtest
ocp-indent: ## Run ocp-indent (inplace edition)
ocp-indent:
for f in `find lib bin -type f -regex .*[.]ml[i]?` ; do \
echo $$f ; \
ocp-indent -i $$f ; \
done
.PHONY: ocp-indent
.DEFAULT_GOAL := help
help:
@clear;grep -E '(^[a-zA-Z_-]+:.*?##.*$$)|(^##)' Makefile | awk 'BEGIN {FS = ":.*?#\
# "}; {printf "\033[32m%-30s\033[0m %s\n", $$1, $$2}' | sed -e 's/\[32m## /[33m/'
.PHONY: help
bundle: distrib ## Create macOS app bundle
ifeq ($(OS_TYPE),Darwin)
@printf "\n\033[1;1m=== Creating macOS bundle ===\033[0m\n"
@if [ ! -f "create_bundle.sh" ]; then \
echo "❌ create_bundle.sh not found"; \
exit 1; \
fi
./create_bundle.sh
@printf "\n\033[1;1m✅ Bundle created: GeneWeb.app\033[0m\n"
else
@echo "❌ Bundle creation is only supported on macOS"
endif
.PHONY: bundle
dmg: bundle ## Create macOS DMG installer
ifeq ($(OS_TYPE),Darwin)
@printf "\n\033[1;1m=== Creating DMG installer ===\033[0m\n"
@if [ ! -f "create_dmg.sh" ]; then \
echo "❌ create_dmg.sh not found"; \
exit 1; \
fi
./create_dmg.sh
@printf "\n\033[1;1m✅ DMG created\033[0m\n"
else
@echo "❌ DMG creation is only supported on macOS"
endif
.PHONY: dmg
clean-bundle: ## Remove generated bundle and DMG
@echo "Cleaning macOS artifacts…"
@rm -rf GeneWeb.app
@rm -f GeneWeb-*.dmg
@rm -f install_geneweb.sh
@echo "Done."
.PHONY: clean-bundle