Improve handling variables, which can be either string or string array.
[build.git] / default.build
blob996c8bd6a9df6c3aa806f87b1127623ea1bcc9b9
1 default target 'default'
3 let package = 'build'
4 let version = '0.1'
6 let prefix = '/usr/local'
8 let cc = 'gcc'
10 let cppflags = [
11   '-D_POSIX_C_SOURCE=200809L'
12   '-D_DEFAULT_SOURCE=1'
13   '-DENABLE_NLS=1'
14   '-DPACKAGE="build"'
15   '-DLOCALEDIR="./po/locale"'
18 let warn_flags = [
19   '-Wabi=2'
20   '-Wall'
21   '-Warith-conversion'
22   '-Warray-bounds=1'
23   '-Wattribute-alias=2'
24   '-Wbad-function-cast'
25   '-Wconversion'
26   '-Wdate-time'
27   '-Wdisabled-optimization'
28   '-Wdouble-promotion'
29   '-Wduplicated-branches'
30   '-Wduplicated-cond'
31   '-Wduplicated-cond'
32   '-Wenum-conversion'
33   '-Wextra'
34   '-Wformat-signedness'
35   '-Wformat-truncation=2'
36   '-Wformat=2'
37   '-Wimplicit-fallthrough=2'
38   '-Winit-self'
39   '-Winvalid-pch'
40   '-Wlogical-op'
41   '-Wmissing-attributes'
42   '-Wmissing-braces'
43   '-Wmissing-declarations'
44   '-Wmissing-format-attribute'
45   '-Wmissing-include-dirs'
46   '-Wmissing-noreturn'
47   '-Wmissing-prototypes'
48   '-Wnested-externs'
49   '-Wnull-dereference'
50   '-Wold-style-definition'
51   '-Wopenmp-simd'
52   '-Wpacked'
53   '-Wpedantic'
54   '-Wpointer-arith'
55   '-Wredundant-decls'
56   '-Wrestrict'
57   '-Wshadow'
58   '-Wshift-overflow=2'
59   '-Wsign-conversion'
60   '-Wstrict-overflow=5'
61   '-Wstrict-prototypes'
62   '-Wstring-compare'
63   '-Wsuggest-attribute=cold'
64   '-Wsuggest-attribute=const'
65   '-Wsuggest-attribute=format'
66   '-Wsuggest-attribute=malloc'
67   '-Wsuggest-attribute=noreturn'
68   '-Wsuggest-attribute=pure'
69   '-Wsuggest-final-methods'
70   '-Wsuggest-final-types'
71   '-Wtrampolines'
72   '-Wundef'
73   '-Wuninitialized'
74   '-Wunknown-pragmas'
75   '-Wunreachable-code'
76   '-Wunused'
77   '-Wunused-const-variable=2'
78   '-Wunused-function'
79   '-Wunused-parameter'
80   '-Wvariadic-macros'
81   '-Wvector-operation-performance'
82   '-Wvla-larger-than=4031'
83   '-Wwrite-strings'
84   '-Wcast-qual'
85 #  '-Wpadded'
86 #  '-Wswitch-default'
87   '-Wswitch-enum'
88 #  '-Wunused-macros'
91 let warn = [
92  '-Wbool-compare'
93  '-Wbool-operation'
94  '-Wbuiltin-declaration-mismatch'
95  '-Wbuiltin-macro-redefined'
96  '-Wc11-c2x-compat'
97  '-Wcast-align'
98  '-Wcast-align=strict'
99  '-Wcast-function-type'
100  '-Wcast-qual'
101  '-Wchar-subscripts'
102  '-Wclobbered'
103  '-Wcomment'
104  '-Wconversion'
105  '-Wcoverage-mismatch'
106  '-Wcpp'
107  '-Wdangling-else'
108  '-Wdate-time'
109  '-Wdeprecated'
110  '-Wdeprecated-declarations'
111  '-Wdesignated-init'
112  '-Wdisabled-optimization'
113  '-Wdiscarded-array-qualifiers'
114  '-Wdiscarded-qualifiers'
115  '-Wdiv-by-zero'
116  '-Wdouble-promotion'
117  '-Wduplicated-branches'
118  '-Wduplicated-cond'
119  '-Wempty-body'
120  '-Wendif-labels'
121  '-Wenum-compare'
122  '-Wenum-conversion'
123  '-Wexpansion-to-defined'
124  '-Wfatal-errors'
125  '-Wfloat-conversion'
126  '-Wfloat-equal'
127  '-Wformat'
128  '-Wformat=2'
129  '-Wformat-contains-nul'
130  '-Wformat-extra-args'
131  '-Wformat-nonliteral'
132  '-Wformat-overflow=2'
133  '-Wformat-security'
134  '-Wformat-signedness'
135  '-Wformat-truncation=2'
136  '-Wformat-y2k'
137  '-Wframe-address'
138  '-Wframe-larger-than=256'
139  '-Wfree-nonheap-object'
140  '-Wif-not-aligned'
141  '-Wignored-attributes'
142  '-Wignored-qualifiers'
143  '-Wincompatible-pointer-types'
144  '-Wimplicit'
145  '-Wimplicit-fallthrough'
146  '-Wimplicit-fallthrough=2'
147  '-Wimplicit-function-declaration'
148  '-Wimplicit-int'
149  '-Winfinite-recursion'
150  '-Winit-self'
151 # '-Winline'
152  '-Wint-conversion'
153  '-Wint-in-bool-context'
154  '-Wint-to-pointer-cast'
155  '-Winvalid-memory-model'
156  '-Winvalid-pch'
157  '-Wjump-misses-init'
158  '-Wlarger-than=256'
159  '-Wlogical-not-parentheses'
160  '-Wlogical-op'
161  '-Wlong-long'
162  '-Wlto-type-mismatch'
163  '-Wmain'
164  '-Wmaybe-uninitialized'
165  '-Wmemset-elt-size'
166  '-Wmemset-transposed-args'
167  '-Wmisleading-indentation'
168  '-Wmissing-attributes'
169  '-Wmissing-braces'
170  '-Wmissing-field-initializers'
171  '-Wmissing-format-attribute'
172  '-Wmissing-include-dirs'
173  '-Wmissing-noreturn'
174  '-Wmissing-profile'
175  '-Wmultichar'
176  '-Wmultistatement-macros'
177  '-Wnonnull'
178  '-Wnonnull-compare'
179  '-Wnull-dereference'
180  '-Wodr'
181  '-Wopenacc-parallelism'
182  '-Wopenmp-simd'
183  '-Woverflow'
184  '-Woverlength-strings'
185  '-Woverride-init-side-effects'
186  '-Wpacked'
187  '-Wpacked-bitfield-compat'
188  '-Wpacked-not-aligned'
189  '-Wparentheses'
190  '-Wpointer-arith'
191  '-Wpointer-compare'
192  '-Wpointer-to-int-cast'
193  '-Wpragmas'
194  '-Wprio-ctor-dtor'
195  '-Wredundant-decls'
196  '-Wrestrict'
197  '-Wreturn-local-addr'
198  '-Wreturn-type'
199  '-Wscalar-storage-order'
200  '-Wsequence-point'
201  '-Wshadow'
202  '-Wshadow=global'
203  '-Wshadow=local'
204  '-Wshadow=compatible-local'
205  '-Wshift-count-negative'
206  '-Wshift-count-overflow'
207  '-Wshift-negative-value'
208  '-Wshift-overflow'
209  '-Wshift-overflow=2'
210  '-Wsign-compare'
211  '-Wsign-conversion'
212  '-Wsizeof-array-argument'
213  '-Wsizeof-array-div'
214  '-Wsizeof-pointer-div'
215  '-Wsizeof-pointer-memaccess'
216  '-Wstack-protector'
217 # '-Wstack-usage=256'
218  '-Wstrict-aliasing'
219  '-Wstrict-aliasing=3'
220  '-Wstrict-overflow'
221  '-Wstrict-overflow=2'
222  '-Wstring-compare'
223  '-Wstringop-overflow'
224  '-Wstringop-overread'
225  '-Wstringop-truncation'
226  '-Wswitch'
227  '-Wswitch-bool'
228  '-Wswitch-default'
229  '-Wswitch-enum'
230  '-Wswitch-outside-range'
231  '-Wswitch-unreachable'
232  '-Wsync-nand'
233 # '-Wsystem-headers'
234  '-Wtautological-compare'
235  '-Wtrampolines'
236  '-Wtrigraphs'
237  '-Wtrivial-auto-var-init'
238  '-Wtsan'
239  '-Wtype-limits'
240  '-Wundef'
241  '-Wuninitialized'
242  '-Wunknown-pragmas'
243  '-Wunsuffixed-float-constants'
244  '-Wunused'
245  '-Wunused-but-set-parameter'
246  '-Wunused-but-set-variable'
247  '-Wunused-const-variable'
248  '-Wunused-const-variable=2'
249  '-Wunused-function'
250  '-Wunused-label'
251  '-Wunused-local-typedefs'
252 # '-Wunused-macros'
253  '-Wunused-parameter'
254  '-Wunused-result'
255  '-Wunused-value'
256  '-Wunused-variable'
257  '-Wvarargs'
258  '-Wvariadic-macros'
259  '-Wvector-operation-performance'
260  '-Wvla'
261  '-Wvolatile-register-var'
262  '-Wwrite-strings'
263  '-Wzero-length-bounds'
264  '-Wconversion'
267 let sanitize = [
268   '-fsanitize=alignment'
269   '-fsanitize=bool'
270   '-fsanitize=bounds'
271   '-fsanitize=enum'
272   '-fsanitize=float-cast-overflow'
273   '-fsanitize=float-divide-by-zero'
274   '-fsanitize=integer-divide-by-zero'
275   '-fsanitize=nonnull-attribute'
276   '-fsanitize=null'
277   '-fsanitize=object-size'
278   '-fsanitize=pointer-overflow'
279   '-fsanitize=return'
280   '-fsanitize=returns-nonnull-attribute'
281   '-fsanitize=shift'
282   '-fsanitize=signed-integer-overflow'
283   '-fsanitize=thread'
284 #  '-fsanitize=leak'
285   '-fsanitize=undefined'
286   '-fsanitize=unreachable'
287   '-fsanitize=vla-bound'
288   '-fsanitize=vptr'
291 let debug_cflags = [
292   '-D_FORTIFY_SOURCE=2'
293   '-Og'
294   '-g3'
295   '-ggdb3'
296   '-pg'
297   '-Ofast'
298   '-fanalyzer'
299   @warn_flags
300   @warn
301   @sanitize
304 let release_cflags = [
305   '-DNDEBUG=1'
306   '-Ofast'
307   '-Wl,--gc-sections'
308   '-Wl,--strip-all'
309   '-flto=auto'
310   '-fno-fat-lto-objects'
311   '-fno-stack-protector'
312   '-fomit-frame-pointer'
313   '-funroll-all-loops'
316 let cflags = [
317   '-fshort-enums'
318   '-fstrict-aliasing'
319   '-fstrict-overflow'
320   '-pipe'
321   '-std=gnu11'
322   '-MMD'
323   '-pthread'
324   '-march=native'
325   @debug_cflags
326 #  @release_cflags
327   '-fdiagnostics-color=always'
330 let ldflags = [
331 #GCC  '-Wl,-lpthread'
332 #TODO  '-Wl,-lgdbm'
333 #PCC  '-Wl,-znoexecstack'
336 rule yacc {
337   description: 'YACC @in'
338   >bison -Wall \
339   > -Wdangling-alias @in
342 rule lex {
343   description: 'LEX @in'
344   >flex @in
347 rule compile {
348   description: 'CC @in'
349   >@cc @cppflags @cflags -c -o @out @in
350 #  >false
353 rule link {
354   description: 'LINK @out'
355   >@cc @ldflags @cflags -o @out @in
356   >true
359 let potfile = 'po/build.pot'
360 let pofiles = [ 'po/ru.po' ]
361 let mofiles = [ 'po/locale/ru/LC_MESSAGES/build.mo' ]
363 let xgettext_options = [
364   '--flag=N_:1:pass-c-format'
365   '--flag=S_:1:pass-c-format'
366   '--flag=S_:2:pass-c-format'
367   '--flag=_:1:pass-c-format'
368   '--flag=error:1:c-format'
369   '--flag=error_at:2:c-format'
370   '--flag=fatal:1:c-format'
371   '--flag=info:1:c-format'
372   '--flag=warning:1:c-format'
373   '--flag=warning_at:2:c-format'
374   '--from-code=UTF-8'
375   '--keyword=N_:1'
376   '--keyword=S_:1,2'
377   '--keyword=YY_:1'
378   '--keyword=YY_FATAL_ERROR:1'
379   '--keyword=_:1'
380   '--language=C'
381   '--no-wrap'
382   '-F'
385 rule msgmerge {
386   description: 'MSGMERGE @out'
387   >msgmerge -U @out @in
390 rule xgettext {
391   description: 'XGETTEXT @out'
392   >xgettext @xgettext_options --package-name @package --package-version @version --default-domain @package --output @out @in
395 rule msgfmt {
396   description: 'MSGFMT @in'
397   >msgfmt --check --statistics --verbose --output-file @out @in
400 file target [ 'src/parse.c' 'src/parse.h' ] @ 'src/parse.y' {
401   yacc @files
404 file target [ 'src/scan.c' 'src/scan.h' ] @ 'src/scan.l' {
405   lex @files
408 #file target 'src/dep-scan.c' @ 'src/dep-scan.l' {
409 #  lex @files -> @target
412 let sources = [
413   'src/build.c'
414   'src/diagnostic.c'
415   'src/cli-option-parser.c'
416   'src/graph.c'
417   'src/hash.c'
418   'src/job-server.c'
419   'src/parse.c'
420   'src/scan.c'
421   'src/thread.c'
422   'src/uniqstr.c'
423   'src/yy.c'
424   'src/utils.c'
425   'src/libquote/quotearg.c'
426   'src/libquote/localcharset.c'
427   'src/libquote/system-quote.c'
428   'src/libquote/sh-quote.c'
431 file target 'src/build.o' : 'src/scan.c' 'src/parse.c' @ 'src/build.c' { compile @files -> @target }
432 file target 'src/diagnostic.o' @ 'src/diagnostic.c' { compile @files -> @target }
433 file target 'src/graph.o'      @ 'src/graph.c'      { compile @files -> @target }
434 file target 'src/hash.o'       @ 'src/hash.c'       { compile @files -> @target }
435 file target 'src/job-server.o' @ 'src/job-server.c' { compile @files -> @target }
436 file target 'src/parse.o'      @ 'src/parse.c'      { compile @files -> @target }
437 file target 'src/scan.o'       @ 'src/scan.c'       { compile @files -> @target }
438 file target 'src/thread.o'     @ 'src/thread.c'     { compile @files -> @target }
439 file target 'src/uniqstr.o'    @ 'src/uniqstr.c'    { compile @files -> @target }
440 file target 'src/yy.o'         @ 'src/yy.c'         { compile @files -> @target }
441 file target 'src/utils.o'      @ 'src/utils.c'      { compile @files -> @target }
442 file target 'src/cli-option-parser.o'     @ 'src/cli-option-parser.c'     { compile @files -> @target }
443 file target 'src/libquote/quotearg.o'     @ 'src/libquote/quotearg.c'     { compile @files -> @target }
444 file target 'src/libquote/localcharset.o' @ 'src/libquote/localcharset.c' { compile @files -> @target }
445 file target 'src/libquote/sh-quote.o'     @ 'src/libquote/sh-quote.c'     { compile @files -> @target }
446 file target 'src/libquote/system-quote.o' @ 'src/libquote/system-quote.c' { compile @files -> @target }
448 let objects = [ @sources.map('%.c' -> '%.o') ]
450 rule graph {
451   description: 'GRAPH'
452   >./build -g | dot -Tpng -ograph.png
455 target 'graph' {
456   graph
459 file target 'build' @ @objects {
460   link @files -> @target
463 target 'default': 'build' @mofiles
465 file target 'po/ru.po': @potfile {
466   msgmerge @dependencies -> @target
469 file target 'po/build.pot' @ @sources {
470   xgettext @files -> @target
473 file target 'po/locale/ru/LC_MESSAGES/build.mo' @ 'po/ru.po' {
474   msgfmt @files -> @target
477 rule rm {
478   description: 'CLEAN'
479   >rm -f @in
482 target 'clean' {
483   rm @objects 'src/scan.h' 'src/scan.c' 'src/parse.h' 'src/parse.c'
486 rule nothing {
487    >true