Debian Codegraph @

tests/compile-tests/Makefile

raw symbols SCIP
1 # Makefile to exercise Faust compiler output across many backends.
2 # Default target builds C/C++, Cmajor, JSFX, Julia, etc. into a directory
3 # named after the Faust version (e.g., 2.82.5/...). Additional targets
4 # cover JSON generation/compare, platform-specific runs, and tracer demos.
5 system := $(shell uname -s)
6 system := $(shell echo $(system) | grep MINGW > /dev/null && echo MINGW || echo $(system))
7 ifeq ($(system), MINGW)
8 FAUST ?= ../../build/bin/faust.exe
9 else
10 FAUST ?= ../../build/bin/faust
11 endif
12 MAKE ?= make
13 FAUSTBENCH ?= faustbench -single
14 BENCH_OPTIONS ?=
15 BENCH_WARN_MIN ?= 5
16
17 # Source locations and includes shared across targets
18 SAMPLESROOT := ../..
19 REGRESSION := ..
20 FAUSTLIBS1 ?= ../../libraries
21 FAUSTLIBS2 ?= ../../libraries/old
22 FAUSTINC ?= ../../architecture/faust
23
24 # Lists of DSPs used by the JSON targets (examples + codegen-tests, minus exclusions)
25 DSP_EXAMPLES := $(shell find $(SAMPLESROOT)/examples -name "*.dsp" | grep -v "TODO\|old\|faust-stk\|SAM\|autodiff")
26 DSP_REGRESSION := $(shell find $(REGRESSION)/codegen-tests -name "*.dsp" | grep -v BUG)
27
28 # Capture current Faust version to segregate outputs
29 version := $(shell $(FAUST) --version | grep Version | sed -e 's/^..*Version //')
30
31 cxxfiles = $(shell find $(version) -name "*.cpp")
32 cfiles = $(shell find $(version) -name "*.c")
33 cppobj := $(cxxfiles:%.cpp=%.o)
34 cobj := $(cfiles:%.c=%.o)
35
36 CXX ?= g++
37 GCC ?= gcc
38
39 CPP_OPTIONS := -std=c++14 -Wno-unused-command-line-argument -I$(FAUSTINC)
40
41 C_OPTIONS := -Wno-unused-command-line-argument -I$(FAUSTINC)
42
43 BENCH_REF_VERSION ?= $(version)
44 BENCH_REF_DIR := $(BENCH_REF_VERSION)/bench-reference
45 BENCH_CSV ?=
46
47 # Common helpers for faustbench runs in this Makefile.
48 # Tools: faustbench, grep, sed, awk, mktemp.
49 define BENCH_SETUP
50 @set -e; \
51 bench_value() { \
52 : Run faustbench and echo the parsed MBytes/sec value.; \
53 file="$$1"; \
54 tmp=$$(mktemp); \
55 if $(FAUSTBENCH) $(BENCH_OPTIONS) -I $(FAUSTLIBS1) -I $(FAUSTLIBS2) "$$file" > "$$tmp" 2>&1; then \
56 line="$$(grep -m1 'MBytes/sec' "$$tmp" || true)"; \
57 if [ -n "$$line" ]; then \
58 val="$$(printf '%s\n' "$$line" | sed -nE 's/.*: ([0-9.]+) MBytes\/sec.*/\1/p')"; \
59 rm -f "$$tmp"; \
60 if [ -n "$$val" ]; then \
61 printf '%s' "$$val"; \
62 return 0; \
63 fi; \
64 fi; \
65 fi; \
66 rm -f "$$tmp"; \
67 return 1; \
68 }; \
69 rel_path() { \
70 : Map an absolute example path to a samples-root-relative path.; \
71 case "$$1" in \
72 $(SAMPLESROOT)/*) printf '%s' "$${1#$(SAMPLESROOT)/}";; \
73 esac; \
74 }; \
75 bench_ref_path() { \
76 : Compute the reference file path for a given DSP file.; \
77 rel=$$(rel_path "$$1"); \
78 printf '%s/%s/%s.bench' "$(BENCH_REF_DIR)" "$$(dirname -- "$$rel")" "$$(basename "$$1")"; \
79 };
80 endef
81
82 # Default: run all backends plus native C/C++ compilation checks
83 all:
84 $(MAKE) -f Make.lang outdir=cpp lang=cpp ext=cpp FAUSTOPTIONS=" -a ./min.cpp"
85 $(MAKE) -f Make.lang outdir=ocpp lang=ocpp ext=cpp FAUSTOPTIONS=" -a ./min.cpp"
86 $(MAKE) -f Make.lang outdir=c lang=c ext=c FAUSTOPTIONS=" -a ./min.c"
87 $(MAKE) -f Make.lang outdir=cmajor lang=cmajor ext=cmajor FAUSTOPTIONS=""
88 $(MAKE) -f Make.lang outdir=codebox lang=codebox ext=codebox FAUSTOPTIONS=""
89 $(MAKE) -f Make.lang outdir=dlang lang=dlang ext=dlang FAUSTOPTIONS=""
90 $(MAKE) -f Make.lang outdir=fir lang=fir ext=fir FAUSTOPTIONS=""
91 $(MAKE) -f Make.lang outdir=julia lang=julia ext=julia FAUSTOPTIONS=""
92 $(MAKE) -f Make.lang outdir=jsfx lang=jsfx ext=jsfx FAUSTOPTIONS=""
93 $(MAKE) -f Make.lang outdir=interp lang=interp ext=fbc FAUSTOPTIONS=""
94 $(MAKE) -f Make.lang outdir=jax lang=jax ext=jax FAUSTOPTIONS=""
95 $(MAKE) -f Make.lang outdir=llvm lang=llvm ext=bc FAUSTOPTIONS=""
96 $(MAKE) -f Make.lang outdir=rust lang=rust ext=rs FAUSTOPTIONS=""
97 $(MAKE) -f Make.lang outdir=wasm lang=wasm ext=wasm FAUSTOPTIONS=""
98 $(MAKE) -f Make.lang outdir=wast lang=wast ext=wast FAUSTOPTIONS=""
99 $(MAKE) gcc1
100 $(MAKE) gcc2
101
102 json: # Generate JSON descriptors only (-json/-O)
103 $(call GENJSON,$(version)/json)
104
105 json-compare:
106 @olddir=$(version)/json; newdir=$(version)/json-new; \
107 if [ ! -d $$olddir ]; then \
108 echo "Reference JSON directory '$$olddir' not found; run 'make json' first."; \
109 exit 1; \
110 fi; \
111 rm -rf $$newdir; \
112 $(call GENJSON,$$newdir); \
113 diff -ru $$olddir $$newdir
114
115 check:
116 export FAUST_DEBUG=FIR_VAR_CHECKER; \
117 $(MAKE) -f Make.lang outdir=cpp lang=cpp ext=cpp FAUSTOPTIONS=" -a ./min.cpp"
118
119 release:
120 $(MAKE) c
121 $(MAKE) os
122 $(MAKE) gcc1
123 $(MAKE) gcc2
124 $(MAKE) interp
125 $(MAKE) trace
126
127 web:
128 $(MAKE) -f Make.lang outdir=wasm lang=wasm ext=wasm FAUSTOPTIONS=""
129 $(MAKE) -f Make.lang outdir=wast lang=wast ext=wast FAUSTOPTIONS=""
130
131 os:
132 $(MAKE) -f Make.lang outdir=cppos0 lang=cpp ext=cpp FAUSTOPTIONS=" -os -a ./min.cpp"
133 $(MAKE) -f Make.lang outdir=cos0 lang=c ext=c FAUSTOPTIONS="-lang c -os -a ./min.c"
134
135 c: # Only C and C++ backends with minimal arch files
136 $(MAKE) -f Make.lang outdir=cpp lang=cpp ext=cpp FAUSTOPTIONS=" -a ./min.cpp"
137 $(MAKE) -f Make.lang outdir=ocpp lang=ocpp ext=o.cpp FAUSTOPTIONS=" -a ./min.cpp"
138 $(MAKE) -f Make.lang outdir=c lang=c ext=c FAUSTOPTIONS=" -a ./min.c"
139
140 llvm: # LLVM backend (scalar + vector)
141 $(MAKE) -f Make.lang outdir=llvm lang=llvm ext=llvm FAUSTOPTIONS=""
142 $(MAKE) -f Make.lang outdir=llvm/vec lang=llvm ext=llvm FAUSTOPTIONS=" -vec -lv 1"
143
144 julia: # Julia backend
145 $(MAKE) -f Make.lang outdir=julia lang=julia ext=julia FAUSTOPTIONS=""
146
147 rust: # Rust backend
148 $(MAKE) -f Make.lang outdir=rust lang=rust ext=rust FAUSTOPTIONS=""
149
150 trace: # Interpreter tracer demo
151 $(MAKE) -f Make.lang interp-tracer
152
153 jtrace: # Julia tracer demo
154 $(MAKE) -f Make.lang julia-tracer
155
156 cmajor: # faust2cmajor wrapper
157 $(MAKE) -f Make.lang cmajor
158
159 rnbo: # faust2rnbo wrapper
160 $(MAKE) -f Make.lang rnbo
161
162 doc: # Markdown/SVG documentation generation
163 $(MAKE) -f Make.lang doc
164
165 me: # C++ backend with -me option
166 $(MAKE) -f Make.lang outdir=cpp lang=cpp ext=cpp FAUSTOPTIONS=" -me -a ./min.cpp"
167
168 #########################################################################
169 # interp lang has a special status since the corresponding backend may not
170 # be available due to gcc specific extensions
171 interp:
172 $(MAKE) -f Make.lang outdir=interp lang=interp ext=fbc FAUSTOPTIONS=""
173 $(MAKE) -f Make.lang outdir=interp/vec lang=interp ext=fbc FAUSTOPTIONS=" -vec -lv 1"
174
175 bench-reference: # Create benchmark reference for example DSPs using faustbench
176 $(BENCH_SETUP) \
177 for file in $(DSP_EXAMPLES); do \
178 printf '[bench-reference] %s\n' "$$file"; \
179 ref=$$(bench_ref_path "$$file"); \
180 if [ -f "$$ref" ]; then \
181 printf '[bench-reference] skip existing %s\n' "$$ref"; \
182 continue; \
183 fi; \
184 mkdir -p "$$(dirname -- "$$ref")"; \
185 if val="$$(bench_value "$$file")"; then \
186 printf '%s\n' "$$val" > "$$ref"; \
187 else \
188 printf '[warn] could not parse bench output for %s\n' "$$file" >&2; \
189 fi; \
190 done
191
192 bench-check: # Check current benchmarks against reference for example DSPs
193 $(BENCH_SETUP) \
194 refdir=$(BENCH_REF_DIR); \
195 if [ ! -d "$$refdir" ]; then \
196 echo "Reference benchmark directory '$$refdir' not found; run 'make bench-reference' first."; \
197 exit 1; \
198 fi; \
199 if [ -n "$(BENCH_CSV)" ]; then \
200 mkdir -p "$$(dirname -- "$(BENCH_CSV)")"; \
201 printf 'file,ref,cur,diff_pct\n' > "$(BENCH_CSV)"; \
202 fi; \
203 total=0; better=0; worse=0; \
204 for file in $(DSP_EXAMPLES); do \
205 printf '[bench-check] %s\n' "$$file"; \
206 ref=$$(bench_ref_path "$$file"); \
207 if [ ! -f "$$ref" ]; then \
208 printf '[skip] missing reference for %s\n' "$$file" >&2; \
209 continue; \
210 fi; \
211 if cur="$$(bench_value "$$file")"; then \
212 refval="$$(cat "$$ref")"; \
213 if [ -n "$$cur" ] && [ -n "$$refval" ]; then \
214 printf '[bench-check] ref %s cur %s for %s\n' "$$refval" "$$cur" "$$file"; \
215 total=$$((total + 1)); \
216 diff="$$(LC_ALL=C awk -v cur="$$cur" -v ref="$$refval" 'BEGIN { if (ref == 0) { print "inf"; } else { d=(cur-ref)/ref*100; if (d < 0) d=-d; printf "%.2f", d; } }')"; \
217 delta="$$(LC_ALL=C awk -v cur="$$cur" -v ref="$$refval" 'BEGIN { if (ref == 0) { print "inf"; } else { d=(cur-ref)/ref*100; printf "%.2f", d; } }')"; \
218 if [ -n "$(BENCH_CSV)" ]; then \
219 printf '%s,%s,%s,%s\n' "$$(basename "$$file")" "$$refval" "$$cur" "$$delta" >> "$(BENCH_CSV)"; \
220 fi; \
221 if [ "$$diff" = "inf" ]; then \
222 printf '[warn] zero reference for %s (ref %s)\n' "$$file" "$$refval" >&2; \
223 else \
224 is_warn=0; \
225 if LC_ALL=C awk -v d="$$diff" -v min="$(BENCH_WARN_MIN)" 'BEGIN { exit !(d >= min) }'; then \
226 is_warn=1; \
227 fi; \
228 if LC_ALL=C awk -v d="$$delta" 'BEGIN { exit !(d > 0) }'; then \
229 better=$$((better + 1)); \
230 printf '\033[32m[better]\033[0m %s +%s%% (ref %s, cur %s)\n' "$$file" "$$diff" "$$refval" "$$cur" >&2; \
231 elif LC_ALL=C awk -v d="$$delta" 'BEGIN { exit !(d < 0) }'; then \
232 worse=$$((worse + 1)); \
233 printf '\033[31m[worse]\033[0m %s -%s%% (ref %s, cur %s)\n' "$$file" "$$diff" "$$refval" "$$cur" >&2; \
234 else \
235 printf '[same] %s 0.00%% (ref %s, cur %s)\n' "$$file" "$$refval" "$$cur" >&2; \
236 fi; \
237 if [ "$$is_warn" -eq 1 ]; then \
238 printf '[warn] %s exceeds %s%% threshold\n' "$$file" "$(BENCH_WARN_MIN)" >&2; \
239 fi; \
240 fi; \
241 else \
242 printf '[warn] could not parse bench output for %s\n' "$$file" >&2; \
243 fi; \
244 else \
245 printf '[warn] could not parse bench output for %s\n' "$$file" >&2; \
246 fi; \
247 done; \
248 if [ "$$total" -gt 0 ]; then \
249 better_pct="$$(LC_ALL=C awk -v b="$$better" -v t="$$total" 'BEGIN { printf "%.1f", (b / t) * 100 }')"; \
250 worse_pct="$$(LC_ALL=C awk -v w="$$worse" -v t="$$total" 'BEGIN { printf "%.1f", (w / t) * 100 }')"; \
251 else \
252 better_pct="0.0"; \
253 worse_pct="0.0"; \
254 fi; \
255 printf '[bench-check] total: %s, better: %s (%s%%), worse: %s (%s%%)\n' "$$total" "$$better" "$$better_pct" "$$worse" "$$worse_pct"
256
257 help:
258 @echo "-------- FAUST compilation tests --------"
259 @echo "Available targets are:"
260 @echo " 'all' (default): compiles all the dsp found in the examples and regression"
261 @echo " folders using all backends (apart the interp backend)"
262 @echo " C and C++ output are also compile using $(GCC) and $(CXX)"
263 @echo " Output is located in a folder named using faust version ($(version))"
264 @echo " 'release' to test C++, C backend, 'os', 'interp' and 'trace' specific targets"
265 @echo "Specific targets:"
266 @echo " 'gcc1' : compiles the C and C++ output of the 'cpp' and 'ocpp' backends"
267 @echo " 'gcc2' : compiles the C and C++ output of the 'c' backend"
268 @echo " 'c' : compiles using the 'cpp', 'ocpp' and 'c' backends"
269 @echo " 'os' : compiles using the 'cpp' and 'c' backends in -osX mode"
270 @echo " 'llvm' : compiles using the LLVM backend"
271 @echo " 'interp' : compiles using the interpreter backend"
272 @echo " 'julia' : compiles using the Julia backend"
273 @echo " 'rust' : compiles using the Rust backend"
274 @echo " 'web' : compiles using the wast/wasm backends"
275 @echo " 'cmajor' : compiles using faust2cmajor"
276 @echo " 'rnbo' : compiles using faust2rnbo"
277 @echo " 'trace' : compiles using the interp-tracer application"
278 @echo " 'jtrace' : compiles using Julia minimal-control architecture"
279 @echo " 'json' : generates JSON descriptions with '-json' and keeps them"
280 @echo " 'json-compare': regenerates JSON (-json) and diffs against existing $(version)/json"
281 @echo " 'me' : compiles using the C++ backend with -me option"
282 @echo " 'check' : compiles using the C++ backend and FAUST_DEBUG=FIR_VAR_CHECKER"
283 @echo " 'bench-reference' : creates faustbench references for example DSPs"
284 @echo " Use FAUSTBENCH to setup the benchmark tool (default to 'faustbench -single')"
285 @echo " Example: make bench-reference FAUSTBENCH=\"faustbench-llvm -scalar\""
286 @echo " Use BENCH_OPTIONS to add additional compiler options"
287 @echo " Example: make bench-reference BENCH_OPTIONS=\"-lang ocpp\""
288 @echo " 'bench-check' : compares current faustbench results to references"
289 @echo " Use BENCH_OPTIONS to add additional compiler options"
290 @echo " Example: make bench-check BENCH_OPTIONS=\"-lang ocpp\""
291 @echo " Use BENCH_REF_VERSION to compare against another compiler's refs"
292 @echo " Example: make bench-check BENCH_REF_VERSION=2.81.0"
293 @echo " Use BENCH_WARN_MIN for percent warning threshold (default: 5)"
294 @echo " Example: make bench-check BENCH_WARN_MIN=10"
295 @echo " Use BENCH_CSV to write CSV output (file,ref,cur,diff_pct)"
296 @echo " Example: make bench-check BENCH_CSV=bench-check.csv"
297 @echo " 'doc' : test the -mdoc, -svg options"
298
299 @echo " 'clean' : to remove the folder named using faust version"
300 @echo "Using a specific version of Faust libraries:"
301 @echo " 'make FAUSTLIBS=/path/to/libraries'"
302
303 gcc1: $(cppobj)
304
305 gcc2: $(cobj)
306
307 clean:
308 rm -rf $(version)
309
310 # Generate JSON files only (no .o/.cpp) into a versioned directory using -json/-O.
311 #
312 # $(1): output root directory (e.g., $(version)/json or $(version)/json-new)
313 define GENJSON
314 @outdir=$(1); \
315 mkdir -p $$outdir; \
316 for file in $(DSP_EXAMPLES) $(DSP_REGRESSION); do \
317 case $$file in \
318 $(SAMPLESROOT)/*) rel=$${file#$(SAMPLESROOT)/};; \
319 $(REGRESSION)/*) rel=$${file#$(REGRESSION)/};; \
320 esac; \
321 dest=$$outdir/$$(dirname -- "$$rel"); \
322 mkdir -p "$$dest"; \
323 $(FAUST) -lang cpp -I $(FAUSTLIBS1) -I $(FAUSTLIBS2) -json "$$file" -O "$$dest" > /dev/null; \
324 done
325 endef
326
327 #########################################################################
328 # rules for c/c++ compilation
329 %.o: %.cpp
330 $(eval tmp1 := $(patsubst $(version)/cpp/%, $(SAMPLESROOT)/%, $(<D)))
331 $(eval tmp := $(patsubst $(version)/ocpp/%, $(REGRESSION)/%, $(tmp1)))
332 $(CXX) -c $(CPP_OPTIONS) -I$(tmp) $< -o $@
333
334 %.o: %.c
335 $(eval tmp := $(patsubst $(version)/c/%, $(SAMPLESROOT)/%, $(<D)))
336 $(GCC) -c $(C_OPTIONS) -I$(tmp) $< -o $@