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