3 exec ${GUILE-guile} --no-auto-compile -L . -L guile -C . -C guile -s "$0" ${1+"$@"}
6 (use-modules (srfi srfi-26)
9 ;; FIXME: .go dependencies
10 ;; workaround: always update .go before calculating hashes
11 ;;(use-modules ((mes make) #:select (sytem**)))
15 "guix/shell-utils.scm"
16 "language/c99/compiler.scm"
17 "language/c99/info.scm"
24 (define %go-files (map (compose (cut string-append <> ".go") (cut string-drop-right <> 4)) %scm-files))
26 (setenv "host" %host-type)
27 (with-directory-excursion "guile"
28 (apply system* `("guile"
33 "../build-aux/compile-all.scm"
36 (use-modules (srfi srfi-1)
37 (ice-9 curried-definitions)
41 (add-target (bin.mescc "stage0/exit-42.c" #:libc #f))
42 (add-target (check "stage0/exit-42.0-guile" #:signal 11)) ; FIXME: segfault
44 (add-target (cpp.mescc "mlibc/mini-libc-mes.c"))
45 (add-target (compile.mescc "mlibc/mini-libc-mes.c"))
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))
50 (add-target (cpp.mescc "mlibc/libc-mes.c"))
51 (add-target (compile.mescc "mlibc/libc-mes.c"))
53 (add-target (bin.mescc "stage0/exit-42.c"))
54 (add-target (check "stage0/exit-42.guile" #:exit 42))
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))
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)))
65 (add-scaffold-test "t" #:libc mini-libc-mes.E)
66 ;;(add-scaffold-test "t" #:libc libc-mes+tcc.E)
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)
77 (add-target (group "check-scaffold-tests/0" #:dependencies (filter (target-prefix? "check-scaffold/tests/0") %targets)))
79 ;; tests/10: control without libc
81 (cut add-scaffold-test <> #:libc #f)
90 (add-target (group "check-scaffold-tests/1" #:dependencies (filter (target-prefix? "check-scaffold/tests/1") %targets)))
92 ;; tests/20: loop without libc
94 (cut add-scaffold-test <> #:libc #f)
100 (add-target (group "check-scaffold-tests/2" #:dependencies (filter (target-prefix? "check-scaffold/tests/2") %targets)))
102 ;; tests/30: call, compare: mini-libc-mes.c
104 (cut add-scaffold-test <> #:libc mini-libc-mes.E)
111 "36-compare-arithmetic"
115 (add-target (group "check-scaffold-tests/3" #:dependencies (filter (target-prefix? "check-scaffold/tests/3") %targets)))
117 ;; tests/40: control: mini-libc-mes.c
119 (cut add-scaffold-test <> #:libc mini-libc-mes.E)
127 (add-target (group "check-scaffold-tests/4" #:dependencies (filter (target-prefix? "check-scaffold/tests/4") %targets)))
129 ;; tests/50: libc-mes.c
137 (add-target (group "check-scaffold-tests/5" #:dependencies (filter (target-prefix? "check-scaffold/tests/5") %targets)))
139 ;; tests/60: building up to scaffold/m.c, scaffold/micro-mes.c
148 (add-target (group "check-scaffold-tests/6" #:dependencies (filter (target-prefix? "check-scaffold/tests/6") %targets)))
150 ;; tests/70: and beyond src/mes.c -- building up to 8cc.c, pcc.c, tcc.c, libguile/eval.c
155 "72-typedef-struct-def"
157 "74-multi-line-string"
159 "76-pointer-arithmetic"
163 "7a-struct-char-array"
164 "7b-struct-int-array"
167 "7e-struct-array-access"
168 "7f-struct-pointer-arithmetic"
169 "7g-struct-byte-word-field"
173 (add-target (group "check-scaffold-tests/7" #:dependencies (filter (target-prefix? "check-scaffold/tests/7") %targets)))
175 (add-target (group "check-scaffold-tests" #:dependencies (filter (target-prefix? "check-scaffold/tests") %targets)))
177 (add-target (cpp.mescc "mlibc/libc-mes+tcc.c"))
178 (add-target (compile.mescc "mlibc/libc-mes+tcc.c"))
180 (define* (add-tcc-test name)
181 (add-target (bin.gcc (string-append "scaffold/tinycc/" name ".c") #:libc #f #:includes '("scaffold/tinycc")))
182 (add-target (check (string-append "scaffold/tinycc/" name ".mlibc-gcc") #:baseline (string-append "scaffold/tinycc/" name ".expect")))
184 (add-target (bin.mescc (string-append "scaffold/tinycc/" name ".c") #:includes '("scaffold/tinycc")))
185 (add-target (check (string-append "scaffold/tinycc/" name ".guile") #:baseline (string-append "scaffold/tinycc/" name ".expect"))))
202 "13_integer_literals"
208 "19_pointer_arithmetic"
210 "20_pointer_comparison"
212 ;;"22_floating_point" ; float
213 ;;"23_type_coercion" ; float
214 ;;"24_math_library" ; float
216 ;;"27_sizeof" ; float
217 ;;"28_strings" ; TODO: strncpy strchr strrchr memset memcpy memcmp
220 ;;"30_hanoi" ; fails with GCC
222 ;;"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"))))))
223 ;;"34_array_assignment" ; fails with GCC
226 ;;"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"))))))))
227 ;; "37_sprintf" ; integer formatting unsupported
228 ;;"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"))))))
229 ;;"39_typedef" ; unsupported: (decl (decl-spec-list (stor-spec (typedef)) (type-spec (typename "MyFunStruct"))) (init-declr-list (init-declr (ptr-declr (pointer) (ident "MoreFunThanEver")))))
231 ;;"40_stdio" ; f* functions
233 ;;"42_function_pointer" ; f* functions
235 "44_scoped_declarations"
236 ;; "45_empty_for" ; unsupported
237 ;;"46_grep" ; f* functions
240 ;;"49_bracket_evaluation" ; float
242 "50_logical_second_arg"
243 ;;"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"))))))
244 ;;"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"))))
246 ;;"55_lshift_type" ; unsigned
249 (add-target (group "check-scaffold-tinycc" #:dependencies (filter (target-prefix? "check-scaffold/tinycc") %targets)))
251 ;;(add-target (group "check-scaffold" #:dependencies (filter (target-prefix? "check-scaffold") %targets)))
253 (add-target (bin.gcc "scaffold/main.c"))
254 (add-target (check "scaffold/main.gcc" #:exit 42))
256 (add-target (bin.gcc "scaffold/main.c" #:libc #f))
257 (add-target (check "scaffold/main.mlibc-gcc" #:exit 42))
259 (add-target (bin.mescc "scaffold/main.c" #:libc mini-libc-mes.E))
260 (add-target (check "scaffold/main.mini-guile" #:exit 42))
262 (add-target (bin.mescc "scaffold/main.c"))
263 (add-target (check "scaffold/main.guile" #:exit 42))
266 (add-target (bin.gcc "scaffold/hello.c"))
267 (add-target (check "scaffold/hello.gcc" #:exit 42))
269 (add-target (bin.gcc "scaffold/hello.c" #:libc #f))
270 (add-target (check "scaffold/hello.mlibc-gcc" #:exit 42))
272 (add-target (bin.mescc "scaffold/hello.c" #:libc mini-libc-mes.E))
273 (add-target (check "scaffold/hello.mini-guile" #:exit 42))
275 (add-target (bin.mescc "scaffold/hello.c"))
276 (add-target (check "scaffold/hello.guile" #:exit 42))
279 (add-target (bin.gcc "scaffold/m.c"))
280 (add-target (check "scaffold/m.gcc" #:exit 255))
282 (add-target (bin.gcc "scaffold/m.c" #:libc #f))
283 (add-target (check "scaffold/m.mlibc-gcc" #:exit 255))
285 (add-target (bin.mescc "scaffold/m.c"))
286 (add-target (check "scaffold/m.guile" #:exit 255))
288 (add-target (bin.gcc "scaffold/micro-mes.c" #:libc #f))
289 (add-target (check "scaffold/micro-mes.mlibc-gcc" #:exit 6)) ; arg1 arg2 arg3 arg4 arg5
291 (add-target (bin.mescc "scaffold/micro-mes.c"))
292 (add-target (check "scaffold/micro-mes.guile" #:exit 6)) ; arg1 arg2 arg3 arg4 arg5
294 (add-target (group "check-scaffold" #:dependencies (filter (target-prefix? "check-scaffold") %targets)))
297 '("gc" "lib" "math" "mes" "posix" "reader" "vector"))
300 `(,@(map (cut string-append "src/" <> ".c") snarf-bases)
301 ,@(map (cut string-append "src/" <> ".mes.h") snarf-bases)
302 ,@(map (cut string-append "src/" <> ".mes.i") snarf-bases)
303 ,@(map (cut string-append "src/" <> ".mes.environment.i") snarf-bases)))
305 (define gcc-snarf-targets
307 (add-target (snarf "src/gc.c" #:mes? #f))
308 (add-target (snarf "src/lib.c" #:mes? #f))
309 (add-target (snarf "src/math.c" #:mes? #f))
310 (add-target (snarf "src/mes.c" #:mes? #f))
311 (add-target (snarf "src/posix.c" #:mes? #f))
312 (add-target (snarf "src/reader.c" #:mes? #f))
313 (add-target (snarf "src/vector.c" #:mes? #f))))
315 (define mes-snarf-targets
317 (add-target (snarf "src/gc.c"))
318 (add-target (snarf "src/lib.c" #:mes? #t))
319 (add-target (snarf "src/math.c" #:mes? #t))
320 (add-target (snarf "src/mes.c" #:mes? #t))
321 (add-target (snarf "src/posix.c" #:mes? #t))
322 (add-target (snarf "src/reader.c" #:mes? #t))
323 (add-target (snarf "src/vector.c" #:mes? #t))))
325 (add-target (bin.gcc "src/mes.c" #:dependencies gcc-snarf-targets
326 #:defines `("FIXED_PRIMITIVES=1"
329 ,(string-append "VERSION=\"" %version "\"")
330 ,(string-append "MODULEDIR=\"" (string-append %prefix (if (string-null? %prefix) "" "/") %moduledir "/") "\"")
331 ,(string-append "PREFIX=\"" %prefix "\""))
332 #:includes '("src")))
334 (add-target (bin.gcc "src/mes.c" #:libc #f
335 #:dependencies mes-snarf-targets
336 #:defines `("FIXED_PRIMITIVES=1"
338 ,(string-append "VERSION=\"" %version "\"")
339 ,(string-append "MODULEDIR=\"" (string-append %prefix (if (string-null? %prefix) "" "/") "/" %moduledir "/") "\"")
340 ,(string-append "PREFIX=\"" %prefix "\""))
341 #:includes '("src")))
343 (add-target (bin.mescc "src/mes.c" #:dependencies mes-snarf-targets
344 #:defines `("FIXED_PRIMITIVES=1"
346 ,(string-append "VERSION=\"" %version "\"")
347 ,(string-append "MODULEDIR=\"" (string-append %prefix (if (string-null? %prefix) "" "/") %moduledir "/") "\"")
348 ,(string-append "PREFIX=\"" %prefix "\""))
349 #:includes '("src")))
355 "tests/quasiquote.test"
370 "tests/let-syntax.test"
378 (define (add-mes.gcc-test o)
379 (add-target (target (file-name o)))
380 (add-target (check o #:dependencies (list (get-target "src/mes.mlibc-gcc")))))
382 (define (add-mes.guile-test o)
383 (add-target (target (file-name o)))
384 (add-target (check o #:dependencies (list (get-target "src/mes.guile")))))
386 ;; takes long, and should always pass if...
387 ;;(for-each add-mes.gcc-test mes-tests)
389 ;; ...mes.guile passes :-)
390 (for-each add-mes.guile-test mes-tests)
392 ;; FIXME: run tests/base.test
393 (setenv "MES" "src/mes.guile")
395 (add-target (install "guile/mescc.scm" #:dir "bin" #:substitutes #t))
396 (add-target (install "scripts/mescc.mes" #:dir "bin" #:substitutes #t))
397 (add-target (install "scripts/repl.mes" #:dir "bin" #:substitutes #t))
398 (define bootstrap? #f)
400 (add-target (install "src/mes.mes" #:dir "bin" #:installed-name "mes"))
401 (add-target (install "src/mes.guile" #:dir "bin" #:installed-name "mes")))
403 (define* ((install-dir #:key dir) name)
404 (add-target (install name #:dir (string-append dir "/" (dirname name)))))
406 (add-target (install "module/mes/base-0.mes" #:dir (string-append %moduledir "/mes") #:substitutes #t))
407 (add-target (install "module/language/c99/compiler.mes" #:dir (string-append %moduledir "/language/c99") #:substitutes #t))
409 (define %module-dir "share/mes")
412 ((install-dir #:dir (string-append %module-dir)) f))
413 '("module/language/c99/compiler.mes"
414 "module/language/c99/compiler.scm"
415 "module/language/c99/info.mes"
416 "module/language/c99/info.scm"
417 "module/language/paren.mes"
420 "module/mes/as-i386.mes"
421 "module/mes/as-i386.scm"
424 ;;"module/mes/base-0.mes"
425 "module/mes/base.mes"
426 "module/mes/bytevectors.mes"
427 "module/mes/bytevectors.scm"
428 "module/mes/catch.mes"
429 "module/mes/display.mes"
432 "module/mes/fluids.mes"
433 "module/mes/getopt-long.mes"
434 "module/mes/getopt-long.scm"
435 "module/mes/guile.mes"
436 "module/mes/lalr.mes"
437 "module/mes/lalr.scm"
439 "module/mes/match.mes"
440 "module/mes/match.scm"
441 "module/mes/optargs.mes"
442 "module/mes/optargs.scm"
444 "module/mes/peg/cache.scm"
445 "module/mes/peg/codegen.scm"
446 "module/mes/peg/simplify-tree.scm"
447 "module/mes/peg/string-peg.scm"
448 "module/mes/peg/using-parsers.scm"
449 "module/mes/pmatch.mes"
450 "module/mes/pmatch.scm"
451 "module/mes/posix.mes"
452 "module/mes/pretty-print.mes"
453 "module/mes/pretty-print.scm"
454 "module/mes/psyntax-0.mes"
455 "module/mes/psyntax-1.mes"
456 "module/mes/psyntax.mes"
457 "module/mes/psyntax.pp"
458 "module/mes/psyntax.ss"
459 "module/mes/quasiquote.mes"
460 "module/mes/quasisyntax.mes"
461 "module/mes/quasisyntax.scm"
462 "module/mes/read-0.mes"
463 "module/mes/record-0.mes"
464 "module/mes/record.mes"
465 "module/mes/repl.mes"
467 "module/mes/syntax.mes"
468 "module/mes/syntax.scm"
469 "module/mes/test.mes"
470 "module/mes/tiny-0.mes"
471 "module/mes/type-0.mes"
472 "module/nyacc/lalr.mes"
473 "module/nyacc/lang/c99/cpp.mes"
474 "module/nyacc/lang/c99/parser.mes"
475 "module/nyacc/lang/calc/parser.mes"
476 "module/nyacc/lang/util.mes"
477 "module/nyacc/lex.mes"
478 "module/nyacc/parse.mes"
479 "module/nyacc/util.mes"
480 "module/rnrs/arithmetic/bitwise.mes"
481 "module/srfi/srfi-0.mes"
482 "module/srfi/srfi-1.mes"
483 "module/srfi/srfi-1.scm"
484 "module/srfi/srfi-13.mes"
485 "module/srfi/srfi-14.mes"
486 "module/srfi/srfi-16.mes"
487 "module/srfi/srfi-16.scm"
488 "module/srfi/srfi-26.mes"
489 "module/srfi/srfi-26.scm"
490 "module/srfi/srfi-43.mes"
491 "module/srfi/srfi-9-psyntax.mes"
492 "module/srfi/srfi-9.mes"
493 "module/srfi/srfi-9.scm"
494 "module/sxml/xpath.mes"
495 "module/sxml/xpath.scm"))
497 (define* ((install-guile-dir #:key dir) name)
498 (add-target (install (string-append "guile/" name) #:dir (string-append dir "/" (dirname name)))))
502 ((install-guile-dir #:dir (string-append %guiledir)) f))
507 ((install-guile-dir #:dir (string-append %godir)) f))
510 (add-target (install "mlibc/libc-mes.E" #:dir "lib"))
511 (add-target (install "mlibc/libc-mes.M1" #:dir "lib"))
512 (add-target (install "mlibc/libc-mes+tcc.E" #:dir "lib"))
513 (add-target (install "mlibc/libc-mes+tcc.M1" #:dir "lib"))
514 (add-target (install "mlibc/mini-libc-mes.E" #:dir "lib"))
515 (add-target (install "mlibc/mini-libc-mes.M1" #:dir "lib"))
519 ((install-dir #:dir "share/") f))
520 '("mlibc/include/alloca.h"
521 "mlibc/include/assert.h"
522 "mlibc/include/ctype.h"
523 "mlibc/include/dlfcn.h"
524 "mlibc/include/errno.h"
525 "mlibc/include/fcntl.h"
526 "mlibc/include/features.h"
527 "mlibc/include/inttypes.h"
528 "mlibc/include/libgen.h"
529 "mlibc/include/limits.h"
530 "mlibc/include/locale.h"
531 "mlibc/include/math.h"
532 "mlibc/include/mlibc.h"
533 "mlibc/include/setjmp.h"
534 "mlibc/include/signal.h"
535 "mlibc/include/stdarg.h"
536 "mlibc/include/stdbool.h"
537 "mlibc/include/stdint.h"
538 "mlibc/include/stdio.h"
539 "mlibc/include/stdlib.h"
540 "mlibc/include/stdnoreturn.h"
541 "mlibc/include/string.h"
542 "mlibc/include/strings.h"
543 "mlibc/include/sys/cdefs.h"
544 "mlibc/include/sys/mman.h"
545 "mlibc/include/sys/stat.h"
546 "mlibc/include/sys/time.h"
547 "mlibc/include/sys/timeb.h"
548 "mlibc/include/sys/types.h"
549 "mlibc/include/sys/ucontext.h"
550 "mlibc/include/sys/wait.h"
551 "mlibc/include/time.h"
552 "mlibc/include/unistd.h"))
555 (compose add-target (cut install <> #:dir "share/doc/mes"))
565 (add-target (install "doc/fosdem/fosdem.pdf" #:dir "share/doc/mes"))
568 (cond ((member "all-go" args) #t)
569 ((member "clean-go" args) (map delete-file (filter file-exists? %go-files)))
570 ((member "clean" args) (clean))
571 ((member "list" args) (display (string-join (map target-file-name %targets) "\n" 'suffix)))
572 ((member "help" args) (format #t "Usage: ./make.scm [TARGET]...
584 (string-join (filter (negate (cut string-index <> #\/)) (map target-file-name %targets)) "\n " 'prefix)))
586 (let ((targets (match args
587 (() (filter (negate check-target?) %targets))
588 ((? (cut member "all" <>)) (filter (conjoin (negate install-target?)
589 (negate check-target?))
591 ((? (cut member "check" <>)) (filter check-target? %targets))
592 ((? (cut member "install" <>)) (filter install-target? %targets))
593 (_ (filter-map (cut get-target <>) args)))))
594 (for-each build targets)
595 ;;((@@ (mes make) store) #:print 0)
598 (main (cdr (command-line)))