Checkpoint ongoing work.
[compilerz] / antlr4.make
1 #
2 # Copyright (C) 2023 Michael Zucchi
3 #
4 # This is the copyright for antlr4.make
5 #
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
10 #
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 # GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License
17 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
18 #
19
20 # This processes antlr4 files.  Include after java.make, before maven.make.
21
22 # <module>_ANTLR4 = list of grammar files without '.g4' extension.
23
24 # They must be in src/<module>/gen/<grammar>.g4
25 # The sources are generated in the usual gen directory
26
27 antlr4 = org.antlr:antlr4:4.12.0                \
28         org.antlr:antlr4-runtime:4.12.0         \
29         org.antlr:antlr-runtime:3.5.3           \
30         org.antlr:ST4:4.3.4 \
31
32 maven_central_JARS += $(antlr4)
33
34 antlr4_CLASSPATH=.lib/antlr4-4.12.0.jar         \
35         .lib/antlr4-runtime-4.12.0.jar          \
36         .lib/antlr-runtime-3.5.3.jar            \
37         .lib/ST4-4.3.4.jar
38
39 dist_EXTRA+=antlr4.make
40
41 define antlr4_targets=
42 $(if $($1-$2_ANTLR4PACKAGE),,$(error src/gen/$1/gen/gen.make: no $1-$2_ANTLR4PACKAGE defined))
43 bin/status/$1-$2.antlr: src/$1/gen/$2.g4
44         mkdir -p bin/gen/$1/gen bin/status
45         cd src/$1/gen && \
46         $(JAVA) -cp $(subst $S,:,$(realpath $(antlr4_CLASSPATH))) \
47                 org.antlr.v4.Tool \
48                 -o ../../../bin/gen/$1/classes/$(subst .,/,$($1-$2_ANTLR4PACKAGE)) \
49                 -package $($1-$2_ANTLR4PACKAGE) \
50                 $($1-$2_ANTLR4FLAGS) \
51                 $2.g4
52         touch $$@
53 bin/status/$1.depjava: bin/status/$1-$2.antlr
54 endef
55
56 #$(foreach m,$(java_MODULES),$(foreach g,$($m_ANTLR4),$(info $(call antlr4_targets,$m,$g))))
57 $(foreach m,$(java_MODULES),$(foreach g,$($m_ANTLR4),$(eval $(call antlr4_targets,$m,$g))))