-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathMakefile.test
194 lines (169 loc) · 6.92 KB
/
Makefile.test
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
#*************************************************
#
# ELVEX
#
# Copyright 2014-2023 LABRI,
# CNRS (UMR 5800), the University of Bordeaux,
# and the Bordeaux INP
#
# Author:
# Lionel Clément
# LaBRI - Université Bordeaux
# 351, cours de la Libération
# 33405 Talence Cedex - France
# lionel.clement@u-bordeaux.fr
#
# This file is part of ELVEX.
#
#**************************************************
# Phony targets to avoid conflicts with files of the same name
.PHONY: test all_pdf clean
.SUFFIXES: .input .rules .lexicon .output .xml .dot .pdf .fsa .html .morpho .pattern .fromScratch .stdin
# Name of the Elvex program
elvex = bin/elvex
elvexlexicon = bin/elvexlexicon
# Check the existence of dot (Graphviz)
DOT = $(shell command -v dot 2> /dev/null)
# Check the existence of xsltproc
XSLTPROC = $(shell command -v xsltproc 2> /dev/null)
xslfile = xsl/xml2CS-dot-graph.xsl
python = python3
# Directory where test files are located
test_dir = test
# List of all input files
input_files = $(wildcard $(test_dir)/*.input)
stdin_files = $(wildcard $(test_dir)/*.stdin)
# Specific targets to generate all *.output files
output_files = $(patsubst $(test_dir)/%.input,$(test_dir)/%.output,$(input_files))
output_files += $(patsubst $(test_dir)/%.stdin,$(test_dir)/%.output,$(stdin_files))
# Target to run tests
test: $(output_files)
@for file in $(output_files); do \
base=$$(basename $$file .output); \
sort $(test_dir)/$$base.output > $(test_dir)/$$base.output.sorted; \
sort $(test_dir)/$$base.test > $(test_dir)/$$base.test.sorted; \
if diff $(test_dir)/$$base.output.sorted $(test_dir)/$$base.test.sorted> /dev/null 2>&1; then \
echo "Test $$base passed."; \
else \
echo "Test $$base failed. Please check the trace with --trace options."; \
fi; \
rm $(test_dir)/$$base.output.sorted $(test_dir)/$$base.test.sorted; \
done
# Specific targets to generate all *.pdf files
all_pdf: $(patsubst $(test_dir)/%.input,$(test_dir)/%.pdf,$(input_files))
# Rule to generate an *.output file from an *.input file
%.output: %.input %.rules %.lexicon $(elvex)
@echo "build $@ from $^"
@if test -f $*.fromScratch; then \
make -f Makefile.test $*.pattern $*.morpho ; \
fi
@if test -f $*.pattern; then \
make -f Makefile.test $*.fsa ; \
$(if $(wildcard $*.macros), \
$(elvex) -macrosFile $*.macros -cld test -clf $(notdir $(basename $<)) -rulesFile $*.rules -lexiconFile $*.lexicon -inputFile $< > $@, \
$(elvex) -cld test -clf $(notdir $(basename $<)) -rulesFile $*.rules -lexiconFile $*.lexicon -inputFile $< > $@); \
else \
$(if $(wildcard $*.macros),\
$(elvex) -macrosFile $*.macros -rulesFile $*.rules -lexiconFile $*.lexicon -inputFile $< > $@, \
$(elvex) -rulesFile $*.rules -lexiconFile $*.lexicon -inputFile $< > $@); \
fi
# Rule to generate an *.output file from an *.input file
%.output: %.rules %.lexicon %.stdin $(elvex)
@echo "build $@ from $^"
@if test -f $*.fromScratch; then \
make -f Makefile.test $*.pattern $*.morpho < $*.stdin ; \
fi
@if test -f $*.pattern; then \
make -f Makefile.test $*.fsa ; \
$(if $(wildcard $*.macros), \
$(elvex) -macrosFile $*.macros -cld test -clf $(notdir $(basename $<)) -rulesFile $*.rules -lexiconFile $*.lexicon < $*.stdin > $@, \
$(elvex) -cld test -clf $(notdir $(basename $<)) -rulesFile $*.rules -lexiconFile $*.lexicon < $*.stdin > $@); \
else \
$(if $(wildcard $*.macros),\
$(elvex) -macrosFile $*.macros -rulesFile $*.rules -lexiconFile $*.lexicon < $*.stdin > $@, \
$(elvex) -rulesFile $*.rules -lexiconFile $*.lexicon < $*.stdin > $@); \
fi
# Rule to generate an *.output file from an *.input file
%.html: %.input %.rules %.lexicon $(elvex)
@echo "build $@ from $^"
@if test -f $*.pattern; then \
make -f Makefile.test $*.fsa ; \
$(if $(wildcard $*.macros), \
$(elvex) --trace -macrosFile $*.macros -cld test -clf $(notdir $(basename $<)) -rulesFile $*.rules -lexiconFile $*.lexicon -inputFile $< > $@, \
$(elvex) --trace -cld test -clf $(notdir $(basename $<)) -rulesFile $*.rules -lexiconFile $*.lexicon -inputFile $< > $@); \
else \
$(if $(wildcard $*.macros),\
$(elvex) --trace -macrosFile $*.macros -rulesFile $*.rules -lexiconFile $*.lexicon -inputFile $< > $@, \
$(elvex) --trace -rulesFile $*.rules -lexiconFile $*.lexicon -inputFile $< > $@); \
fi
%.xml: %.input %.rules %.lexicon $(elvex)
@echo "build $@ from $^"
@if test -f $*.pattern; then \
make -f Makefile.test $*.fsa ; \
$(if $(wildcard $*.macros), \
$(elvex) -macrosFile $*.macros -cld test -clf $(notdir $(basename $<)) -rulesFile $*.rules -lexiconFile $*.lexicon -inputFile $< -xml $*.xml > /dev/null 2>&1, \
$(elvex) -cld test -clf $(notdir $(basename $<)) -rulesFile $*.rules -lexiconFile $*.lexicon -inputFile $< -xml $*.xml > /dev/null 2>&1); \
else \
$(if $(wildcard $*.macros),\
$(elvex) -macrosFile $*.macros -rulesFile $*.rules -lexiconFile $*.lexicon -inputFile $< -xml $*.xml > /dev/null 2>&1, \
$(elvex) -rulesFile $*.rules -lexiconFile $*.lexicon -inputFile $< -xml $*.xml > /dev/null 2>&1); \
fi
# Check the existence of xsltproc
%.dot: %.xml $(xslfile)
@echo "build $@ from $^"
@if test -z "$(XSLTPROC)"; then \
echo "Error: xsltproc is not installed."; \
else \
$(XSLTPROC) $(xslfile) $*.xml > $@; \
fi
# Check the existence of dot (Graphviz)
%.pdf: %.dot
@echo "build $@ from $^"
@if test -z "$(DOT)" ; then \
echo "Error: dot (Graphviz) is not installed."; \
else \
$(DOT) -T pdf -o $@ $<; \
fi
%.fsa: %.tmp-morpho %.tmp-pattern
@echo "build $@ from $^"
@$(if $(wildcard $*.macros), \
$(elvexlexicon) -cld . -clf $* -macrosFile $*.macros -patternFile $*.tmp-pattern -morphoFile $*.tmp-morpho build, \
$(elvexlexicon) -cld . -clf $* -patternFile $*.tmp-pattern -morphoFile $*.tmp-morpho build ); \
%.tmp-morpho: %.tmp-form %.tmp-pos %.tmp-lemma %.tmp-features
@echo "build $@ from $^"
@paste $*.tmp-form $*.tmp-pos $*.tmp-lemma $*.tmp-features > $@
%.tmp-form: %.tmp-fplf
@echo "build $@ from $^"
@grep -v '^//' < $< | cut -f1 > $@
%.tmp-pos: %.tmp-fplf
@echo "build $@ from $^"
@grep -v '^//' < $< | cut -f2 > $@
%.tmp-lemma: %.tmp-fplf
@echo "build $@ from $^"
@cut -f3 < $< | tr '\-/\.' '____' > $@
%.tmp-features: %.tmp-fplf
@echo "build $@ from $^"
@cut -f4 < $< | tr '\-/\.' '____' > $@
%.tmp-pattern: %.pattern
@echo "build $@ from $^"
@sed -e '/^#/d' -e '/^\/\//d' -e '/^[ ]*$$/d' < $< | tr '\-/\.' '____' | sort -u > $@
%.tmp-fplf: %.morpho
@echo "build $@ from $^"
@sed -e '/^#/d' -e '/^\/\//d' -e '/^[ ]*$$/d' < $< | sort -u > $@
%.morpho:
@echo "build $@"
@if [ -e $*.fromScratch ]; then \
$(python) script.py $@ $*.pattern; \
fi
%.pattern:
@echo "build $@"
@if [ -e $*.fromScratch ]; then \
$(python) script.py $@ $*.pattern; \
fi
# Cleaning generated files
clean:
@rm -f $(test_dir)/*.output $(test_dir)/*.pdf $(test_dir)/*.fsa $(test_dir)/*.tbl
@for fromScratchFile in $(test_dir)/*.fromScratch; do \
base=$$(basename $$fromScratchFile .fromScratch); \
rm -f $(test_dir)/$$base.morpho $(test_dir)/$$base.pattern; \
done