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