7c5d28839b642a51a9d1aca9e79262cbdd1a0891
[mes.git] / make.scm
1 #! /bin/sh
2 # -*- scheme -*-
3 exec ${GUILE-guile} --no-auto-compile -L . -L guile -C . -C guile -s "$0" ${1+"$@"}
4 !#
5
6 (use-modules (srfi srfi-26)
7              (guix shell-utils))
8
9 ;; FIXME: .go dependencies
10 ;; workaround: always update .go before calculating hashes
11 ;;(use-modules ((mes make) #:select (sytem**)))
12 (define %scm-files
13   '("guix/make.scm"
14     "guix/records.scm"
15     "guix/shell-utils.scm"
16     "language/c99/compiler.scm"
17     "language/c99/info.scm"
18     "mes/as-i386.scm"
19     "mes/as.scm"
20     "mes/bytevectors.scm"
21     "mes/elf.scm"
22     "mes/guile.scm"
23     "mes/M1.scm"))
24 (define %go-files (map (compose (cut string-append <> ".go") (cut string-drop-right <> 4)) %scm-files))
25 (setenv "srcdir" ".")
26 (setenv "host" %host-type)
27 (with-directory-excursion "guile"
28   (apply system* `("guile"
29                    "--no-auto-compile"
30                    "-L" "."
31                    "-C" "."
32                    "-s"
33                    "../build-aux/compile-all.scm"
34                    ,@%scm-files)))
35
36 (use-modules (srfi srfi-1)
37              (ice-9 curried-definitions)
38              (ice-9 match)
39              (guix make))
40
41 (add-target (bin.mescc "stage0/exit-42.c" #:libc #f))
42 (add-target (check "stage0/exit-42.0-guile" #:signal 11))  ; FIXME: segfault
43
44 (add-target (cpp.mescc "mlibc/mini-libc-mes.c"))
45 (add-target (compile.mescc "mlibc/mini-libc-mes.c"))
46
47 (add-target (bin.mescc "stage0/exit-42.c" #:libc mini-libc-mes.E))
48 (add-target (check "stage0/exit-42.mini-guile" #:exit 42))
49
50 (add-target (cpp.mescc "mlibc/libc-mes.c"))
51 (add-target (compile.mescc "mlibc/libc-mes.c"))
52
53 (add-target (bin.mescc "stage0/exit-42.c"))
54 (add-target (check "stage0/exit-42.guile" #:exit 42))
55
56 (define* (add-scaffold-test name #:key (exit 0) (libc libc-mes.E))
57   (add-target (bin.gcc (string-append "scaffold/tests/" name ".c") #:libc #f))
58   (add-target (check (string-append "scaffold/tests/" name ".mlibc-gcc") #:exit exit))
59
60   (add-target (bin.mescc (string-append "scaffold/tests/" name ".c") #:libc libc))
61   (add-target (check (string-append "scaffold/tests/" name "." (cond ((not libc) "0-")
62                                                                      ((eq? libc mini-libc-mes.E) "mini-")
63                                                                      (else "")) "guile") #:exit exit)))
64
65 (add-scaffold-test "t" #:libc mini-libc-mes.E)
66 ;;(add-scaffold-test "t" #:libc libc-mes+tcc.E)
67
68 ;; tests/00: exit, functions without libc
69 (add-scaffold-test "00-exit-0" #:libc #f)
70 (add-scaffold-test "01-return-0" #:libc #f)
71 (add-scaffold-test "02-return-1" #:libc #f #:exit 1)
72 (add-scaffold-test "03-call" #:libc #f)
73 (add-scaffold-test "04-call-0" #:libc #f)
74 (add-scaffold-test "05-call-1" #:libc #f #:exit 1)
75 (add-scaffold-test "06-call-!1" #:libc #f)
76
77 (add-target (group "check-scaffold-tests/0" #:dependencies (filter (target-prefix? "check-scaffold/tests/0") %targets)))
78
79 ;; tests/10: control without libc
80 (for-each
81  (cut add-scaffold-test <> #:libc #f)
82  '("10-if-0"
83    "11-if-1"
84    "12-if-=="
85    "13-if-!="
86    "14-if-goto"
87    "15-if-!f"
88    "16-if-t"))
89
90 (add-target (group "check-scaffold-tests/1" #:dependencies (filter (target-prefix? "check-scaffold/tests/1") %targets)))
91
92 ;; tests/20: loop without libc
93 (for-each
94  (cut add-scaffold-test <> #:libc #f)
95  '("20-while"
96    "21-char[]"
97    "22-while-char[]"
98    "23-pointer"))
99
100 (add-target (group "check-scaffold-tests/2" #:dependencies (filter (target-prefix? "check-scaffold/tests/2") %targets)))
101
102 ;; tests/30: call, compare: mini-libc-mes.c
103 (for-each
104  (cut add-scaffold-test <> #:libc mini-libc-mes.E)
105  '("30-strlen"
106    "31-eputs"
107    "32-compare"
108    "33-and-or"
109    "34-pre-post"
110    "35-compare-char"
111    "36-compare-arithmetic"
112    "37-compare-assign"
113    "38-compare-call"))
114
115 (add-target (group "check-scaffold-tests/3" #:dependencies (filter (target-prefix? "check-scaffold/tests/3") %targets)))
116
117 ;; tests/40: control: mini-libc-mes.c
118 (for-each
119  (cut add-scaffold-test <> #:libc mini-libc-mes.E)
120  '("40-if-else"
121    "41-?"
122    "42-goto-label"
123    "43-for-do-while"
124    "44-switch"
125    "45-void-call"))
126
127 (add-target (group "check-scaffold-tests/4" #:dependencies (filter (target-prefix? "check-scaffold/tests/4") %targets)))
128
129 ;; tests/50: libc-mes.c
130 (for-each
131  add-scaffold-test
132  '("50-assert"
133    "51-strcmp"
134    "52-itoa"
135    "54-argv"))
136
137 (add-target (group "check-scaffold-tests/5" #:dependencies (filter (target-prefix? "check-scaffold/tests/5") %targets)))
138
139 ;; tests/60: building up to scaffold/m.c, scaffold/micro-mes.c
140 (for-each
141  add-scaffold-test
142  '("60-math"
143    "61-array"
144    "63-struct-cell"
145    "64-make-cell"
146    "65-read"))
147
148 (add-target (group "check-scaffold-tests/6" #:dependencies (filter (target-prefix? "check-scaffold/tests/6") %targets)))
149
150 ;; tests/70: and beyond src/mes.c -- building up to 8cc.c, pcc.c, tcc.c, libguile/eval.c
151 (for-each
152  add-scaffold-test
153  '("70-printf"
154    "71-struct-array"
155    "72-typedef-struct-def"
156    "73-union"
157    "74-multi-line-string"
158    "75-struct-union"
159    "76-pointer-arithmetic"
160    "77-pointer-assign"
161    "78-union-struct"
162    "79-int-array"
163    "7a-struct-char-array"
164    "7b-struct-int-array"
165    "7c-dynarray"))
166
167 (add-target (group "check-scaffold-tests/7" #:dependencies (filter (target-prefix? "check-scaffold/tests/7") %targets)))
168
169 (add-target (group "check-scaffold-tests" #:dependencies (filter (target-prefix? "check-scaffold/tests") %targets)))
170
171 (add-target (cpp.mescc "mlibc/libc-mes+tcc.c"))
172 (add-target (compile.mescc "mlibc/libc-mes+tcc.c"))
173
174 (define* (add-tcc-test name)
175   (add-target (bin.gcc (string-append "scaffold/tinycc/" name ".c") #:libc #f #:includes '("scaffold/tinycc")))
176   (add-target (check (string-append "scaffold/tinycc/" name ".mlibc-gcc") #:baseline (string-append "scaffold/tinycc/" name ".expect")))
177
178   (add-target (bin.mescc (string-append "scaffold/tinycc/" name ".c") #:includes '("scaffold/tinycc")))
179   (add-target (check (string-append "scaffold/tinycc/" name ".guile") #:baseline (string-append "scaffold/tinycc/" name ".expect"))))
180 (map
181  add-tcc-test
182  '("00_assignment"
183    "01_comment"
184    "02_printf"
185    "03_struct"
186    "04_for"
187    "05_array"
188    "06_case"
189    "07_function"
190    "08_while"
191    "09_do_while"
192
193    "10_pointer"
194    "11_precedence"
195    "12_hashdefine"
196    "13_integer_literals"
197    "14_if"
198    "15_recursion"
199    "16_nesting"
200    "17_enum"
201    "18_include"
202    "19_pointer_arithmetic"
203
204    "20_pointer_comparison"
205    "21_char_array"
206    ;;"22_floating_point"       ; float
207    ;;"23_type_coercion"        ; float
208    ;;"24_math_library"         ; float
209    "25_quicksort"
210    ;;"27_sizeof"               ; float
211    ;;"28_strings"              ; TODO: strncpy strchr strrchr memset memcpy memcmp
212    "29_array_address"
213
214    ;;"30_hanoi"                ; fails with GCC
215    "31_args"
216    ;;"32_led"                  ; unsupported: (decl (decl-spec-list (stor-spec (static)) (type-spec (fixed-type "int"))) (init-declr-list (init-declr (array-of (ident "d") (p-expr (fixed "32"))))))
217    ;;"34_array_assignment"     ; fails with GCC
218    "33_ternary_op"
219    "35_sizeof"
220    ;;"36_array_initialisers"   ; unspported: (decl (decl-spec-list (type-spec (fixed-type "int"))) (init-declr-list (init-declr (array-of (ident "Array") (p-expr (fixed "10"))) (initzer (initzer-list (initzer (p-expr (fixed "12"))) (initzer (p-expr (fixed "34"))) (initzer (p-expr (fixed "56"))) (initzer (p-expr (fixed "78"))) (initzer (p-expr (fixed "90"))) (initzer (p-expr (fixed "123"))) (initzer (p-expr (fixed "456"))) (initzer (p-expr (fixed "789"))) (initzer (p-expr (fixed "8642"))) (initzer (p-expr (fixed "9753"))))))))
221    ;; "37_sprintf"             ; integer formatting unsupported
222    ;;"38_multiple_array_index" ; unspported: (decl (decl-spec-list (type-spec (fixed-type "int"))) (init-declr-list (init-declr (array-of (array-of (ident "a") (p-expr (fixed "4"))) (p-expr (fixed "4"))))))
223    ;;"39_typedef"              ; unsupported: (decl (decl-spec-list (stor-spec (typedef)) (type-spec (typename "MyFunStruct"))) (init-declr-list (init-declr (ptr-declr (pointer) (ident "MoreFunThanEver")))))
224
225    ;;"40_stdio"                ; f* functions
226    "41_hashif"
227    ;;"42_function_pointer"     ; f* functions
228    "43_void_param"
229    "44_scoped_declarations"
230    ;; "45_empty_for"           ; unsupported
231    ;;"46_grep"                 ; f* functions
232    "47_switch_return"
233    "48_nested_break"
234    ;;"49_bracket_evaluation"   ; float
235
236    "50_logical_second_arg"
237    ;;"51_static"               ; unsupported: (decl (decl-spec-list (stor-spec (static)) (type-spec (fixed-type "int"))) (init-declr-list (init-declr (ident "fred") (initzer (p-expr (fixed "1234"))))))
238    ;;"52_unnamed_enum"         ; unsupported: (decl (decl-spec-list (stor-spec (typedef)) (type-spec (enum-def (enum-def-list (enum-defn (ident "e")) (enum-defn (ident "f")) (enum-defn (ident "g")))))) (init-declr-list (init-declr (ident "h"))))
239    "54_goto"
240    ;;"55_lshift_type"          ; unsigned
241    ))
242
243 (add-target (group "check-scaffold-tinycc" #:dependencies (filter (target-prefix? "check-scaffold/tinycc") %targets)))
244
245 ;;(add-target (group "check-scaffold" #:dependencies (filter (target-prefix? "check-scaffold") %targets)))
246
247 (add-target (bin.gcc "scaffold/hello.c"))
248 (add-target (check "scaffold/hello.gcc" #:exit 42))
249
250 (add-target (bin.gcc "scaffold/hello.c" #:libc #f))
251 (add-target (check "scaffold/hello.mlibc-gcc" #:exit 42))
252
253 (add-target (bin.mescc "scaffold/hello.c" #:libc mini-libc-mes.E))
254 (add-target (check "scaffold/hello.mini-guile" #:exit 42))
255
256 (add-target (bin.mescc "scaffold/hello.c"))
257 (add-target (check "scaffold/hello.guile" #:exit 42))
258
259
260 (add-target (bin.gcc "scaffold/m.c"))
261 (add-target (check "scaffold/m.gcc" #:exit 255))
262
263 (add-target (bin.gcc "scaffold/m.c" #:libc #f))
264 (add-target (check "scaffold/m.mlibc-gcc" #:exit 255))
265
266 (add-target (bin.mescc "scaffold/m.c"))
267 (add-target (check "scaffold/m.guile" #:exit 255))
268
269 (add-target (bin.gcc "scaffold/micro-mes.c" #:libc #f))
270 (add-target (check "scaffold/micro-mes.mlibc-gcc" #:exit 6)) ; arg1 arg2 arg3 arg4 arg5
271
272 (add-target (bin.mescc "scaffold/micro-mes.c"))
273 (add-target (check "scaffold/micro-mes.guile" #:exit 6)) ; arg1 arg2 arg3 arg4 arg5
274
275 (add-target (group "check-scaffold" #:dependencies (filter (target-prefix? "check-scaffold") %targets)))
276
277 (define snarf-bases
278   '("gc" "lib" "math" "mes" "posix" "reader" "vector"))
279
280 (define bla
281   `(,@(map (cut string-append "src/" <> ".c") snarf-bases)
282     ,@(map (cut string-append "src/" <> ".mes.h") snarf-bases)
283     ,@(map (cut string-append "src/" <> ".mes.i") snarf-bases)
284     ,@(map (cut string-append "src/" <> ".mes.environment.i") snarf-bases)))
285
286 (define gcc-snarf-targets
287   (list
288    (add-target (snarf "src/gc.c" #:mes? #f))
289    (add-target (snarf "src/lib.c" #:mes? #f))
290    (add-target (snarf "src/math.c" #:mes? #f))
291    (add-target (snarf "src/mes.c" #:mes? #f))
292    (add-target (snarf "src/posix.c" #:mes? #f))
293    (add-target (snarf "src/reader.c" #:mes? #f))
294    (add-target (snarf "src/vector.c" #:mes? #f))))
295
296 (define mes-snarf-targets
297   (list
298    (add-target (snarf "src/gc.c"))
299    (add-target (snarf "src/lib.c" #:mes? #t))
300    (add-target (snarf "src/math.c" #:mes? #t))
301    (add-target (snarf "src/mes.c" #:mes? #t))
302    (add-target (snarf "src/posix.c" #:mes? #t))
303    (add-target (snarf "src/reader.c" #:mes? #t))
304    (add-target (snarf "src/vector.c" #:mes? #t))))
305
306 (add-target (bin.gcc "src/mes.c" #:dependencies gcc-snarf-targets
307                      #:defines `("FIXED_PRIMITIVES=1"
308                                  "MES_FULL=1"
309                                  "POSIX=1"
310                                  ,(string-append "VERSION=\"" %version "\"")
311                                  ,(string-append "MODULEDIR=\"" (string-append %prefix (if (string-null? %prefix) "" "/") %moduledir "/") "\"")
312                                  ,(string-append "PREFIX=\"" %prefix "\""))
313                      #:includes '("src")))
314
315 (add-target (bin.gcc "src/mes.c" #:libc #f
316                      #:dependencies mes-snarf-targets
317                      #:defines `("FIXED_PRIMITIVES=1"
318                                  "MES_FULL=1"
319                                  ,(string-append "VERSION=\"" %version "\"")
320                                  ,(string-append "MODULEDIR=\"" (string-append %prefix (if (string-null? %prefix) "" "/") "/" %moduledir "/") "\"")
321                                  ,(string-append "PREFIX=\"" %prefix "\""))
322                      #:includes '("src")))
323
324 (add-target (bin.mescc "src/mes.c" #:dependencies mes-snarf-targets
325                        #:defines `("FIXED_PRIMITIVES=1"
326                                    "MES_FULL=1"
327                                    ,(string-append "VERSION=\"" %version "\"")
328                                    ,(string-append "MODULEDIR=\"" (string-append %prefix (if (string-null? %prefix) "" "/") %moduledir "/") "\"")
329                                    ,(string-append "PREFIX=\"" %prefix "\""))
330                        #:includes '("src")))
331
332 (define mes-tests
333   '("tests/read.test"
334     "tests/base.test"
335     "tests/closure.test"
336     "tests/quasiquote.test"
337     "tests/let.test"
338     "tests/scm.test"
339     "tests/display.test"
340     "tests/cwv.test"
341     "tests/math.test"
342     "tests/vector.test"
343     "tests/srfi-1.test"
344     "tests/srfi-13.test"
345     "tests/srfi-14.test"
346     "tests/optargs.test"
347     "tests/fluids.test"
348     "tests/catch.test"
349     "tests/psyntax.test"
350     "tests/pmatch.test"
351     "tests/let-syntax.test"
352     "tests/guile.test"
353     "tests/record.test"
354     ;;sloooowwww
355     ;;"tests/match.test"
356     ;;"tests/peg.test"
357     ))
358
359 (define (add-mes.gcc-test o)
360   (add-target (target (file-name o)))
361   (add-target (check o #:dependencies (list (get-target "src/mes.mlibc-gcc")))))
362
363 (define (add-mes.guile-test o)
364   (add-target (target (file-name o)))
365   (add-target (check o #:dependencies (list (get-target "src/mes.guile")))))
366
367 ;; takes long, and should always pass if...
368 ;;(for-each add-mes.gcc-test mes-tests)
369
370 ;; ...mes.guile passes :-)
371 (for-each add-mes.guile-test mes-tests)
372
373 ;; FIXME: run tests/base.test
374 (setenv "MES" "src/mes.guile")
375
376 (add-target (install "guile/mescc.scm" #:dir "bin" #:substitutes #t))
377 (add-target (install "scripts/mescc.mes" #:dir "bin" #:substitutes #t))
378 (add-target (install "scripts/repl.mes" #:dir "bin" #:substitutes #t))
379 (define bootstrap? #f)
380 (if bootstrap?
381     (add-target (install "src/mes.mes" #:dir "bin" #:installed-name "mes"))
382     (add-target (install "src/mes.guile" #:dir "bin" #:installed-name "mes")))
383
384 (define* ((install-dir #:key dir) name)
385   (add-target (install name  #:dir (string-append dir "/" (dirname name)))))
386
387 (add-target (install "module/mes/base-0.mes" #:dir (string-append %moduledir "/mes") #:substitutes #t))
388 (add-target (install "module/language/c99/compiler.mes" #:dir (string-append %moduledir "/language/c99") #:substitutes #t))
389
390 (define %module-dir "share/mes")
391 (for-each
392  (lambda (f)
393    ((install-dir #:dir (string-append %module-dir)) f))
394  '("module/language/c99/compiler.mes"
395    "module/language/c99/compiler.scm"
396    "module/language/c99/info.mes"
397    "module/language/c99/info.scm"
398    "module/language/paren.mes"
399    "module/mes/M1.mes"
400    "module/mes/M1.scm"
401    "module/mes/as-i386.mes"
402    "module/mes/as-i386.scm"
403    "module/mes/as.mes"
404    "module/mes/as.scm"
405    ;;"module/mes/base-0.mes"
406    "module/mes/base.mes"
407    "module/mes/bytevectors.mes"
408    "module/mes/bytevectors.scm"
409    "module/mes/catch.mes"
410    "module/mes/display.mes"
411    "module/mes/elf.mes"
412    "module/mes/elf.scm"
413    "module/mes/fluids.mes"
414    "module/mes/getopt-long.mes"
415    "module/mes/getopt-long.scm"
416    "module/mes/guile.mes"
417    "module/mes/lalr.mes"
418    "module/mes/lalr.scm"
419    "module/mes/let.mes"
420    "module/mes/match.mes"
421    "module/mes/match.scm"
422    "module/mes/optargs.mes"
423    "module/mes/optargs.scm"
424    "module/mes/peg.mes"
425    "module/mes/peg/cache.scm"
426    "module/mes/peg/codegen.scm"
427    "module/mes/peg/simplify-tree.scm"
428    "module/mes/peg/string-peg.scm"
429    "module/mes/peg/using-parsers.scm"
430    "module/mes/pmatch.mes"
431    "module/mes/pmatch.scm"
432    "module/mes/posix.mes"
433    "module/mes/pretty-print.mes"
434    "module/mes/pretty-print.scm"
435    "module/mes/psyntax-0.mes"
436    "module/mes/psyntax-1.mes"
437    "module/mes/psyntax.mes"
438    "module/mes/psyntax.pp"
439    "module/mes/psyntax.ss"
440    "module/mes/quasiquote.mes"
441    "module/mes/quasisyntax.mes"
442    "module/mes/quasisyntax.scm"
443    "module/mes/read-0.mes"
444    "module/mes/record-0.mes"
445    "module/mes/record.mes"
446    "module/mes/repl.mes"
447    "module/mes/scm.mes"
448    "module/mes/syntax.mes"
449    "module/mes/syntax.scm"
450    "module/mes/test.mes"
451    "module/mes/tiny-0.mes"
452    "module/mes/type-0.mes"
453    "module/nyacc/lalr.mes"
454    "module/nyacc/lang/c99/cpp.mes"
455    "module/nyacc/lang/c99/parser.mes"
456    "module/nyacc/lang/calc/parser.mes"
457    "module/nyacc/lang/util.mes"
458    "module/nyacc/lex.mes"
459    "module/nyacc/parse.mes"
460    "module/nyacc/util.mes"
461    "module/rnrs/arithmetic/bitwise.mes"
462    "module/srfi/srfi-0.mes"
463    "module/srfi/srfi-1.mes"
464    "module/srfi/srfi-1.scm"
465    "module/srfi/srfi-13.mes"
466    "module/srfi/srfi-14.mes"
467    "module/srfi/srfi-16.mes"
468    "module/srfi/srfi-16.scm"
469    "module/srfi/srfi-26.mes"
470    "module/srfi/srfi-26.scm"
471    "module/srfi/srfi-43.mes"
472    "module/srfi/srfi-9-psyntax.mes"
473    "module/srfi/srfi-9.mes"
474    "module/srfi/srfi-9.scm"
475    "module/sxml/xpath.mes"
476    "module/sxml/xpath.scm"))
477
478 (define* ((install-guile-dir #:key dir) name)
479   (add-target (install (string-append "guile/" name) #:dir (string-append dir "/" (dirname name)))))
480
481 (for-each
482  (lambda (f)
483    ((install-guile-dir #:dir (string-append %guiledir)) f))
484  %scm-files)
485
486 (for-each
487  (lambda (f)
488    ((install-guile-dir #:dir (string-append %godir)) f))
489  %go-files)
490
491 (add-target (install "mlibc/libc-mes.E" #:dir "lib"))
492 (add-target (install "mlibc/libc-mes.M1" #:dir "lib"))
493 (add-target (install "mlibc/libc-mes+tcc.E" #:dir "lib"))
494 (add-target (install "mlibc/libc-mes+tcc.M1" #:dir "lib"))
495 (add-target (install "mlibc/mini-libc-mes.E" #:dir "lib"))
496 (add-target (install "mlibc/mini-libc-mes.M1" #:dir "lib"))
497
498 (for-each
499  (lambda (f)
500    ((install-dir #:dir "share/") f))
501  '("mlibc/include/alloca.h"
502    "mlibc/include/assert.h"
503    "mlibc/include/ctype.h"
504    "mlibc/include/dlfcn.h"
505    "mlibc/include/errno.h"
506    "mlibc/include/fcntl.h"
507    "mlibc/include/features.h"
508    "mlibc/include/inttypes.h"
509    "mlibc/include/libgen.h"
510    "mlibc/include/limits.h"
511    "mlibc/include/locale.h"
512    "mlibc/include/math.h"
513    "mlibc/include/mlibc.h"
514    "mlibc/include/setjmp.h"
515    "mlibc/include/signal.h"
516    "mlibc/include/stdarg.h"
517    "mlibc/include/stdbool.h"
518    "mlibc/include/stdint.h"
519    "mlibc/include/stdio.h"
520    "mlibc/include/stdlib.h"
521    "mlibc/include/stdnoreturn.h"
522    "mlibc/include/string.h"
523    "mlibc/include/strings.h"
524    "mlibc/include/sys/cdefs.h"
525    "mlibc/include/sys/mman.h"
526    "mlibc/include/sys/stat.h"
527    "mlibc/include/sys/time.h"
528    "mlibc/include/sys/timeb.h"
529    "mlibc/include/sys/types.h"
530    "mlibc/include/sys/ucontext.h"
531    "mlibc/include/sys/wait.h"
532    "mlibc/include/time.h"
533    "mlibc/include/unistd.h"))
534
535 (for-each
536  (compose add-target (cut install <> #:dir "share/doc/mes"))
537  '("AUTHORS"
538    ;;"ChangeLog"
539    "COPYING"
540    "HACKING"
541    "INSTALL"
542    "NEWS"
543    "README"
544    "doc/ANNOUNCE-0.9"))
545
546 (add-target (install "doc/fosdem/fosdem.pdf" #:dir "share/doc/mes"))
547
548 (define (main args)
549   (cond ((member "all-go" args) #t)
550         ((member "clean-go" args) (map delete-file (filter file-exists? %go-files)))
551         ((member "clean" args) (clean))
552         ((member "list" args) (display (string-join (map target-file-name %targets) "\n" 'suffix)))
553         ((member "help" args) (format #t "Usage: ./make.scm [TARGET]...
554
555 Targets:
556     all
557     all-go
558     check
559     clean
560     clean-go
561     help~a
562     install
563     list
564 "
565                                       (string-join (filter (negate (cut string-index <> #\/)) (map target-file-name %targets)) "\n    " 'prefix)))
566         (else
567          (let ((targets (match args
568                           (() (filter (negate check-target?) %targets))
569                           ((? (cut member "all" <>)) (filter (conjoin (negate install-target?)
570                                                                       (negate check-target?))
571                                                              %targets))
572                           ((? (cut member "check" <>)) (filter check-target? %targets))
573                           ((? (cut member "install" <>)) (filter install-target? %targets))
574                           (_ (filter-map (cut get-target <>) args)))))
575            (for-each build targets)
576            ;;((@@ (mes make) store) #:print 0)
577            (exit %status)))))
578
579 (main (cdr (command-line)))