-
Notifications
You must be signed in to change notification settings - Fork 5
/
Makefile
244 lines (208 loc) · 9.67 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
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
# Copyright (C) 2021-2024 Viklauverk AB (agpl-3.0-or-later)
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
ifeq ($(wildcard build/spec.mk),)
$(error Please run configure!)
endif
include build/spec.mk
# Create a version number based on the latest git tag.
COMMIT_HASH?=$(shell git log --pretty=format:'%H' -n 1)
TAG?=$(shell git describe --tags)
BRANCH?=$(shell git rev-parse --abbrev-ref HEAD)
CHANGES?=$(shell git status -s | grep -v '?? ')
# Prefix with any development branch.
ifeq ($(BRANCH),main)
BRANCH:=
else
BRANCH:=$(BRANCH)_
endif
# The version is the git tag or tag-N-hash if there are N commits after the tag.
VERSION:=$(BRANCH)$(TAG)
ifneq ($(strip $(CHANGES)),)
# There are local non-committed changes! Add this to the version string as well!
VERSION:=$(VERSION) with local changes
COMMIT_HASH:=$(COMMIT_HASH) with local changes
endif
VERSION_FILE:=$(GEN_SRC)/version/com/viklauverk/evbt/core/Version.java
$(shell mkdir -p $(dir $(VERSION_FILE)))
$(shell echo "package com.viklauverk.evbt.core;" > $(VERSION_FILE))
$(shell echo "public class Version {" >> $(VERSION_FILE))
$(shell echo " public static String version = \"$(VERSION)\"; " >> $(VERSION_FILE))
$(shell echo " public static String commit = \"$(COMMIT_HASH)\"; " >> $(VERSION_FILE))
$(shell echo "}" >> $(VERSION_FILE))
$(info Building $(VERSION))
AT=@
DROP_ROOT=$(subst $(GIT_ROOT)/,./,$1)
# You have to perform the mvn build first to have the project deps installed.
mvn: $(BUILD_MVN_BIN)/evbt
@rm -f evbt
@ln -s $(BUILD_MVN_BIN)/evbt
@echo Use ./evbt
# Now you can perform a javac compile with a slightly quicker rebuild time.
# It cannot rebuild the generated classes from antlr, so if you change the grammar
# then you have to rerun "make mvn"
javac: $(BUILD_JAVAC_BIN)/evbt
@rm -f evbt
@ln -s $(BUILD_JAVAC_BIN)/evbt
@echo Use ./evbt
# Or a native compile, with a much much longer rebuild time.
# Do this when you have a build that passes the test suite.
graal: $(BUILD_GRAAL_BIN)/evbt
@rm -f evbt
@ln -s $(BUILD_GRAAL_BIN)/evbt
@echo Use ./evbt
# Make sure the output directories exist.
$(shell mkdir -p $(BUILD) $(PROJECT_DEPS) $(GEN_ANTLR4))
# Locate the jar dependencies automatically downloaded by maven.
JARS:=$(shell find $(PROJECT_DEPS)/ -name "*.jar" | tr '\n' ':')
# Find all java sources.
SOURCES:=$(shell find src/main/java/ -type f -name "*.java")
# Find all antlr generated sources.
ANTLR_SOURCES:=$(shell find $(GEN_ANTLR4) -type f -name "*.java")
# Find the version source.
VERSION_SOURCES:=$(shell find $(GEN_SRC)/version -type f -name "*.java")
# Templates contains tex templates for document generation included from the templates directory.
TEMPLATES_JAVA:=src/main/java/com/viklauverk/evbt/core/Templates.java
pom.xml: pom.xmq
$(XMQ) pom.xmq to-xml > $@
$(BUILD_MVN_BIN)/evbt: pom.xml scripts/run.sh $(TEMPLATES_JAVA) $(PROJECT_DEPS)/updated.timestamp $(SOURCES) $(ANTLR_SOURCES) $(VERSION_SOURCES) $(LOGMODULES_SOURCE)
@echo Compiling using maven
@mkdir -p $(BUILD_MVN_BIN) $(GEN_ANTLR4)
$(AT)mvn -B -q package
$(AT)cat scripts/run.sh $(BUILD)/EVBT-1.0-exec.jar > $@
@chmod a+x $@
@echo Generated $(call DROP_ROOT,$@)
$(BUILD_JAVAC_BIN)/evbt: scripts/evbt.sh $(TEMPLATES_JAVA) $(PROJECT_DEPS)/updated.timestamp $(SOURCES) $(ANTLR_SOURCES) $(VERSION_SOURCES) $(LOGMODULES_SOURCE)
@echo Compiling using javac
@mkdir -p $(BUILD_JAVAC_BIN)
$(AT)javac -cp $(JARS) -Xlint:all,-this-escape -d $(BUILD)/classes -sourcepath src/main/java:$(BUILD)/generated-sources/antlr4:$(BUILD)/generated-sources/version $(filter %.java,$?) $(SOURCES)
$(AT)sed 's|replaced_with_build_dir|$(BUILD)|' < scripts/evbt.sh > $@
$(AT)chmod a+x $@
@echo Generated $(call DROP_ROOT,$@)
# To trace neeed resources for runtime, use -agentlib:native-image-agent=config-output-dir=myrun/config-dir/
# Then compare the contents of myrun/config-dir with make/native-image-config-dir
#--no-fallback
$(BUILD_GRAAL_BIN)/evbt: mvn
@echo Compiling using graal
@if [ "$$(java -version 2>&1 | grep -m 1 -o Graal)" != "Graal" ]; then \
echo You have to use the Graal JVM to generate native code!; exit 1; fi
@mkdir -p $(BUILD_GRAAL_BIN)
# --verbose --allow-incomplete-classpath --link-at-build-time
$(AT)native-image --install-exit-handlers -ea --no-fallback --initialize-at-build-time=org.dom4j.dom.DOMDocument --initialize-at-build-time=org.dom4j.dom.DOMDocumentFactory -H:TraceClassInitialization=true -H:ResourceConfigurationFiles=make/native-image-config-dir/resource-config.json -H:+ReportExceptionStackTraces -cp $(BUILD)/classes:$(JARS) com.viklauverk.evbt.Main $@
@echo Generated $(call DROP_ROOT,$@)
# The mvn tree command generates lines like this:
# [INFO] \- org.jsoup:jsoup:jar:1.11.3:compile
# from this info build the path:
# ~/.m2/repository/org/jsoup/jsoup/1.11.3/jsoup-1.11.3.jar
$(PROJECT_DEPS)/updated.timestamp: pom.xml
@rm -rf $(PROJECT_DEPS)
@mkdir -p $(PROJECT_DEPS)
@echo Downloading dependencies into .m2 ...
@mvn -q dependency:go-offline
@echo Initializeing...
@mvn -q initialize
@echo Storing java dependencies into $(PROJECT_DEPS)
@DEPS=`mvn dependency:tree | grep INFO | grep compile | grep -oE '[^ ]+$$'` ; \
sleep 2 ; \
for DEP in $$DEPS ; do \
GROU=$$(echo $$DEP | cut -f 1 -d ':' | sed 's|\.|/|g') ; \
ARTI=$$(echo $$DEP | cut -f 2 -d ':') ; \
SUFF=$$(echo $$DEP | cut -f 3 -d ':') ; \
VERS=$$(echo $$DEP | cut -f 4 -d ':') ; \
JAR="$$GROU/$$ARTI/$$VERS/$$ARTI-$$VERS.$$SUFF" ; \
echo Stored $$JAR ; \
cp ~/.m2/repository/$$JAR $(PROJECT_DEPS) ; \
done
@touch $(PROJECT_DEPS)/updated.timestamp
$(foreach templ,$(wildcard templates/*),$(eval $(TEMPLATES_JAVA):$(templ)))
$(TEMPLATES_JAVA):
@echo Rebuilding templates.
@echo "// Copyright (C) Viklauverk AB 2021-2023 (agpl-3.0-or-later)" > $(TEMPLATES_JAVA)
@echo "// Generated by \"make templates\"" >> $(TEMPLATES_JAVA)
@echo "package com.viklauverk.evbt.core;" >> $(TEMPLATES_JAVA)
@echo "public class Templates {" >> $(TEMPLATES_JAVA)
@echo "public static String empty = \"\";" >> $(TEMPLATES_JAVA);
@$(foreach templ,\
$(wildcard templates/*),\
echo "public static String $(notdir $(templ)) =" >> $(TEMPLATES_JAVA); \
cat $(templ) | sed 's/\\/\\\\/g' | sed 's/"/\\"/g' | sed 's/\(.*\)/"\1\\n"+/' >> $(TEMPLATES_JAVA); \
echo "\"\";" >> $(TEMPLATES_JAVA); \
)
@echo "public static final String[] templates = {" >> $(TEMPLATES_JAVA)
@$(foreach templ,\
$(wildcard templates/*),\
echo -n "\"$(notdir $(templ))\",$(notdir $(templ))," >> $(TEMPLATES_JAVA); \
)
@echo "\"empty\",empty};" >> $(TEMPLATES_JAVA)
@echo "}" >> $(TEMPLATES_JAVA)
templates: $(TEMPLATES_JAVA)
ifeq ($(MOST_RECENT),mvn)
test: testm
endif
ifeq ($(MOST_RECENT),javac)
test: testj
endif
ifeq ($(MOST_RECENT),graal)
test: testg
endif
testinternals:
@echo "Testing $(call DROP_ROOT,$(BUILD)/$(MOST_RECENT)_bin/evbt)"
@echo " dir $(call DROP_ROOT,$(BUILD)/test_$(MOST_RECENT))"
@java -ea -cp $(BUILD)/classes:$(BUILD)/generated-sources:$(JARS) com.viklauverk.evbt.TestInternals
@echo "OK Tested internals."
@java -ea -cp $(BUILD)/classes:$(BUILD)/generated-sources:$(JARS) com.viklauverk.evbt.core.TestInternals
@echo "OK Tested core internals."
testm:
@./tests/test.sh $(BUILD)/mvn_bin/evbt mvn
@(cd models; make EVBT=$(BUILD)/mvn_bin/evbt CLEAN=true && make reset_pdfs)
testj: testinternals
@./tests/test.sh $(BUILD)/javac_bin/evbt javac
@(cd models; make EVBT=$(BUILD)/javac_bin/evbt CLEAN=true && make reset_pdfs)
testg: testinternals
@./tests/test.sh $(BUILD)/graal_bin/evbt graal
@(cd models; make EVBT=$(BUILD)/graal_bin/evbt CLEAN=true && make reset_pdfs)
PREFIX=/usr/local
install:
@rm -f $(PREFIX)/bin/evbt*
@if [ -x $(BUILD_MVN_BIN)/evbt ]; then cp $(BUILD_MVN_BIN)/evbt $(PREFIX)/bin/evbt.mvn ; fi
@if [ -x $(BUILD_JAVAC_BIN)/evbt ]; then cp $(BUILD_JAVAC_BIN)/evbt $(PREFIX)/bin/evbt.javac ; fi
@if [ -x $(BUILD_GRAAL_BIN)/evbt ]; then cp $(BUILD_GRAAL_BIN)/evbt $(PREFIX)/bin/evbt.graal ; fi
@chmod a+x $(PREFIX)/bin/evbt*
@ln -s $(PREFIX)/bin/evbt.$(MOST_RECENT) $(PREFIX)/bin/evbt
@echo "Installed evbt.$(MOST_RECENT) as $(PREFIX)/bin/evbt"
@rm -f $(PREFIX)/share/man/man1/evbt.1.gz
@mkdir -p $(PREFIX)/share/man/man1
@gzip -c doc/evbt.1 > $(PREFIX)/share/man/man1/evbt.1.gz
@echo Installed evbt man page into $(PREFIX)/share/man/man1
@(export TEXMF=`kpsewhich -var-value=TEXMFHOME` ; \
export BSYMB=`kpsewhich bsymb.sty` ; \
if [ "$$BSYMB" = "" ]; then echo "Installed bsymb.sty in $${TEXMF}" ; mkdir -p "$${TEXMF}/tex/latex/local/" ; cp doc/bsymb.sty "$${TEXMF}/tex/latex/local/" ; chown -R $$USER:$$USER "$${TEXMF}" ; else echo "bsymb.sty alread installed" ; fi)
clean:
@echo -n "Removing build directory..."
@rm -rf build
@echo "done."
clean-tests:
@echo -n "Removing $$(echo build/test_*) ..."
@rm -rf build/test_*
@echo "done."
# Rodin touchs bps and some other files when a workspace is opened.
# To prevent cluttering the git history, you can easily revert such changes.
reset-models:
(cd models; make reset)
doc:
@mkdir -p $(BUILD)/doc
$(AT)evbt docmod tex doc/article.tex $(BUILD)/doc/art.tex
$(AT)(cd $(BUILD)/doc/ ; xelatex art.tex && mv art.pdf article.pdf)
.PHONY: doc logmodulenames templates install clean doc
MAKEFLAGS += --no-builtin-rules