Debian Codegraph @

importers/ding2tei/GNUmakefile

raw symbols SCIP
1 #
2 # GNU Makefile
3 #
4 # Copyright 2021,2022 Einhard Leichtfuß
5 #
6 # This file is part of ding2tei-haskell.
7 #
8 # ding2tei-haskell is free software: you can redistribute it and/or modify
9 # it under the terms of the GNU Affero General Public License as published
10 # by the Free Software Foundation, either version 3 of the License, or
11 # (at your option) any later version.
12 #
13 # ding2tei-haskell is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU Affero General Public License for more details.
17 #
18 # You should have received a copy of the GNU Affero General Public License
19 # along with ding2tei-haskell. If not, see <https://www.gnu.org/licenses/>.
20 #
21
22 SHELL = /bin/sh
23
24 # Note: ghc probably cannot be substituted due to the use of GHC extensions.
25 HC = ghc
26 HAPPY = happy
27 ALEX = alex
28
29 INSTALL = install
30 INSTALL_PROGRAM = $(INSTALL) -m 755
31 INSTALL_DATA = $(INSTALL) -m 644
32 INSTALL_DIR = $(INSTALL) -d -m 755
33 DOWNLOAD = curl
34
35 # Notes:
36 # * Consider to manually add `-jN'.
37 # * Some of the below -Wx flags may have merged into -Wall in later releases
38 # of ghc.
39 HCFLAGS = -Wall -Wcompat \
40 -Wincomplete-uni-patterns -Wincomplete-record-updates \
41 -Wmissing-export-lists \
42 -Widentities -Wredundant-constraints -Wpartial-fields -Wcpp-undef \
43 -O2
44
45 # Notes:
46 # * In production, omit `--info'.
47 # * Consider the option `--array'.
48 # * The option `--coerce'
49 # - is claimed to generate
50 # - "smaller faster parsers",
51 # - at the cost of "some type safety".
52 # - Thus, one should always make sure the result compiles w/o the flag.
53 # - actually seems to increase run-time.
54 HAPPYFLAGS = --ghc --info=$(@:.hs=.info)
55
56 # Note: In production, omit `--info'.
57 ALEXFLAGS = --ghc --info=$(@:.hs=.info)
58
59 # Clear suffixes, no implicit rules needed.
60 .SUFFIXES :
61
62 srcdir = src
63 builddir = build
64 dictdir = dict
65 dingdir = $(dictdir)/ding
66 teidir = $(dictdir)/tei
67
68 .DEFAULT_GOAL = ding2tei
69
70 SRCS_ALEX = $(srcdir)/Language/Ding/AlexScanner.x
71 SRCS_HAPPY = $(srcdir)/Language/Ding/Parser/Line.y
72 SRCS_HS := $(filter-out $(srcdir)/Test.hs,$(shell find $(srcdir) -name '*.hs'))
73 SRCS_SED = $(wildcard $(srcdir)/preprocess/de-en/*.sed)
74 SRCS = $(SRCS_ALEX) $(SRCS_HAPPY) $(SRCS_HS) $(SRCS_SED)
75
76 SRCS_HS_GEN = $(patsubst $(srcdir)/%.x,$(builddir)/%.hs,$(SRCS_ALEX)) \
77 $(patsubst $(srcdir)/%.y,$(builddir)/%.hs,$(SRCS_HAPPY))
78
79 # Notes:
80 # * We could also use `ghc -M' to generate the dependencies in make format.
81 # * Prefer $(builddir) over $(srcdir) for `-i' such that $(SRCS_HS_GEN)
82 # are always found first in the former.
83 ding2tei : $(SRCS_HS) $(SRCS_HS_GEN)
84 $(HC) $(HCFLAGS) --make \
85 -i -i$(builddir):$(srcdir) -outputdir $(builddir) \
86 -XRecursiveDo \
87 -o $@ \
88 $(srcdir)/Main.hs
89
90 .PHONY : haskell-source-files
91 haskell-source-files : $(SRCS_HS_GEN)
92
93 $(builddir)/%.hs : $(srcdir)/%.y
94 $(INSTALL_DIR) $(@D)
95 $(HAPPY) $(HAPPYFLAGS) $< -o $@
96
97 $(builddir)/%.hs : $(srcdir)/%.x
98 $(INSTALL_DIR) $(@D)
99 $(ALEX) $(ALEXFLAGS) $< -o $@
100
101 .PHONY : clean
102 clean : clean-objcode clean-dicts
103
104 .PHONY : clean-objcode
105 clean-objcode :
106 rm -f -r $(builddir)/
107 rm -f ding2tei
108
109 .PHONY : clean-dicts
110 clean-dicts :
111 rm -f $(dingdir)/de-en.txt.pp
112 rm -f $(teidir)/deu-eng/deu-eng.tei
113 rm -f $(teidir)/eng-deu/eng-deu.tei
114
115 .PHONY : clean-ding
116 clean-ding :
117 rm -f $(dingdir)/de-en.txt
118
119 .PHONY : deu-eng
120 deu-eng : $(teidir)/deu-eng/deu-eng.tei
121 $(teidir)/deu-eng/deu-eng.tei : $(dingdir)/de-en.txt.pp ding2tei
122 $(INSTALL_DIR) $(@D)
123 ./ding2tei -- $< $@
124
125 .PHONY : eng-deu
126 eng-deu : $(teidir)/eng-deu/eng-deu.tei
127 $(teidir)/eng-deu/eng-deu.tei : $(dingdir)/de-en.txt.pp ding2tei
128 $(INSTALL_DIR) $(@D)
129 ./ding2tei --inverse -- $< $@
130
131 .PHONY : validate-ding
132 validate-ding : $(dingdir)/de-en.txt.pp ding2tei
133 ./ding2tei --validate -- $<
134
135 .PHONY : preprocess
136 preprocess : $(dingdir)/de-en.txt.pp
137 $(dingdir)/de-en.txt.pp : $(dingdir)/de-en.txt \
138 $(srcdir)/preprocess/de-en/all.bash $(SRCS_SED)
139 $(srcdir)/preprocess/de-en/all.bash < $< > $@
140
141 # This target must be specified explicitly and fails otherwise.
142 .PHONY : download-ding-1.9
143 download-ding-1.9 : $(dingdir)/de-en.txt
144 $(dingdir)/de-en.txt :
145 ifneq (,$(filter download-ding-1.9,$(MAKECMDGOALS)))
146 $(INSTALL_DIR) $(@D)
147 $(DOWNLOAD) \
148 'https://ftp.tu-chemnitz.de/pub/Local/urz/ding/de-en/de-en.txt.xz' > [email protected]
149 printf '%s %s\n' \
150 7373b16fccc5c167298b6cde8e4cdd78b3d48941711f10f39429e761742e3068 [email protected] \
151 | sha256sum -c
152 xz -d [email protected]
153 else
154 $(warning Run `make download-ding-1.9` first.)
155 $(error Refusing to implicitly download Ding source)
156 endif