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"
23 (define %go-files (map (compose (cut string-append <> ".go") (cut string-drop-right <> 4)) %scm-files))
25 (setenv "host" %host-type)
26 (with-directory-excursion "guile"
27 (apply system* `("guile"
32 "../build-aux/compile-all.scm"
35 (use-modules (srfi srfi-1)
36 (ice-9 curried-definitions)
40 (add-target (bin.mescc "stage0/exit-42.c" #:libc #f))
41 (add-target (check "stage0/exit-42.0-guile" #:signal 11)) ; FIXME: segfault
43 (add-target (cpp.mescc "mlibc/mini-libc-mes.c"))
44 (add-target (compile.mescc "mlibc/mini-libc-mes.c"))
46 (add-target (bin.mescc "stage0/exit-42.c" #:libc mini-libc-mes.E))
47 (add-target (check "stage0/exit-42.mini-guile" #:exit 42))
49 (add-target (cpp.mescc "mlibc/libc-mes.c"))
50 (add-target (compile.mescc "mlibc/libc-mes.c"))
52 (add-target (bin.mescc "stage0/exit-42.c"))
53 (add-target (check "stage0/exit-42.guile" #:exit 42))
55 (define* (add-scaffold-test name #:key (exit 0) (libc libc-mes.E))
56 (add-target (bin.gcc (string-append "scaffold/tests/" name ".c") #:libc #f))
57 (add-target (check (string-append "scaffold/tests/" name ".mlibc-gcc") #:exit exit))
59 (add-target (bin.mescc (string-append "scaffold/tests/" name ".c") #:libc libc))
60 (add-target (check (string-append "scaffold/tests/" name "." (cond ((not libc) "0-")
61 ((eq? libc mini-libc-mes.E) "mini-")
62 (else "")) "guile") #:exit exit)))
65 (add-scaffold-test "t" #:libc mini-libc-mes.E)
67 ;; tests/00: exit, functions without libc
68 (add-scaffold-test "00-exit-0" #:libc #f)
69 (add-scaffold-test "01-return-0" #:libc #f)
70 (add-scaffold-test "02-return-1" #:libc #f #:exit 1)
71 (add-scaffold-test "03-call" #:libc #f)
72 (add-scaffold-test "04-call-0" #:libc #f)
73 (add-scaffold-test "05-call-1" #:libc #f #:exit 1)
74 (add-scaffold-test "06-call-!1" #:libc #f)
76 (add-target (group "check-scaffold-tests/0" #:dependencies (filter (target-prefix? "check-scaffold/tests/0") %targets)))
78 ;; tests/10: control without libc
80 (cut add-scaffold-test <> #:libc #f)
89 (add-target (group "check-scaffold-tests/1" #:dependencies (filter (target-prefix? "check-scaffold/tests/1") %targets)))
91 ;; tests/20: loop without libc
93 (cut add-scaffold-test <> #:libc #f)
99 (add-target (group "check-scaffold-tests/2" #:dependencies (filter (target-prefix? "check-scaffold/tests/2") %targets)))
101 ;; tests/30: call, compare: mini-libc-mes.c
103 (cut add-scaffold-test <> #:libc mini-libc-mes.E)
110 "36-compare-arithmetic"
114 (add-target (group "check-scaffold-tests/3" #:dependencies (filter (target-prefix? "check-scaffold/tests/3") %targets)))
116 ;; tests/40: control: mini-libc-mes.c
118 (cut add-scaffold-test <> #:libc mini-libc-mes.E)
126 (add-target (group "check-scaffold-tests/4" #:dependencies (filter (target-prefix? "check-scaffold/tests/4") %targets)))
128 ;; tests/50: libc-mes.c
136 (add-target (group "check-scaffold-tests/5" #:dependencies (filter (target-prefix? "check-scaffold/tests/5") %targets)))
138 ;; tests/60: building up to scaffold/m.c, scaffold/micro-mes.c
147 (add-target (group "check-scaffold-tests/6" #:dependencies (filter (target-prefix? "check-scaffold/tests/6") %targets)))
149 ;; tests/70: and beyond src/mes.c -- building up to 8cc.c, pcc.c, tcc.c, libguile/eval.c
154 "72-typedef-struct-def"
156 "74-multi-line-string"
159 (add-target (group "check-scaffold-tests/7" #:dependencies (filter (target-prefix? "check-scaffold/tests/7") %targets)))
161 (add-target (group "check-scaffold-tests" #:dependencies (filter (target-prefix? "check-scaffold/tests") %targets)))
163 (add-target (cpp.mescc "mlibc/libc-mes+tcc.c"))
164 (add-target (compile.mescc "mlibc/libc-mes+tcc.c"))
166 (define* (add-tcc-test name)
167 (add-target (bin.gcc (string-append "scaffold/tinycc/" name ".c") #:libc #f #:includes '("scaffold/tinycc")))
168 (add-target (check (string-append "scaffold/tinycc/" name ".mlibc-gcc") #:baseline (string-append "scaffold/tinycc/" name ".expect")))
170 (add-target (bin.mescc (string-append "scaffold/tinycc/" name ".c") #:includes '("scaffold/tinycc")))
171 (add-target (check (string-append "scaffold/tinycc/" name ".guile") #:baseline (string-append "scaffold/tinycc/" name ".expect"))))
188 "13_integer_literals"
194 "19_pointer_arithmetic"
196 "20_pointer_comparison"
198 ;;"22_floating_point" ; float
199 ;;"23_type_coercion" ; float
200 ;;"24_math_library" ; float
202 ;;"27_sizeof" ; float
203 ;;"28_strings" ; TODO: strncpy strchr strrchr memset memcpy memcmp
206 ;;"30_hanoi" ; fails with GCC
208 ;;"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"))))))
209 ;;"34_array_assignment" ; fails with GCC
212 ;;"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"))))))))
213 ;; "37_sprintf" ; integer formatting unsupported
214 ;;"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"))))))
215 ;;"39_typedef" ; unsupported: (decl (decl-spec-list (stor-spec (typedef)) (type-spec (typename "MyFunStruct"))) (init-declr-list (init-declr (ptr-declr (pointer) (ident "MoreFunThanEver")))))
217 ;;"40_stdio" ; f* functions
219 ;;"42_function_pointer" ; f* functions
221 "44_scoped_declarations"
222 ;; "45_empty_for" ; unsupported
223 ;;"46_grep" ; f* functions
226 ;;"49_bracket_evaluation" ; float
228 "50_logical_second_arg"
229 ;;"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"))))))
230 ;;"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"))))
232 ;;"55_lshift_type" ; unsigned
235 (add-target (group "check-scaffold-tinycc" #:dependencies (filter (target-prefix? "check-scaffold/tinycc") %targets)))
237 ;;(add-target (group "check-scaffold" #:dependencies (filter (target-prefix? "check-scaffold") %targets)))
239 (add-target (bin.gcc "scaffold/hello.c"))
240 (add-target (check "scaffold/hello.gcc" #:exit 42))
242 (add-target (bin.gcc "scaffold/hello.c" #:libc #f))
243 (add-target (check "scaffold/hello.mlibc-gcc" #:exit 42))
245 (add-target (bin.mescc "scaffold/hello.c" #:libc mini-libc-mes.E))
246 (add-target (check "scaffold/hello.mini-guile" #:exit 42))
248 (add-target (bin.mescc "scaffold/hello.c"))
249 (add-target (check "scaffold/hello.guile" #:exit 42))
252 (add-target (bin.gcc "scaffold/m.c"))
253 (add-target (check "scaffold/m.gcc" #:exit 255))
255 (add-target (bin.gcc "scaffold/m.c" #:libc #f))
256 (add-target (check "scaffold/m.mlibc-gcc" #:exit 255))
258 (add-target (bin.mescc "scaffold/m.c"))
259 (add-target (check "scaffold/m.guile" #:exit 255))
261 (add-target (bin.gcc "scaffold/micro-mes.c" #:libc #f))
262 (add-target (check "scaffold/micro-mes.mlibc-gcc" #:exit 6)) ; arg1 arg2 arg3 arg4 arg5
264 (add-target (bin.mescc "scaffold/micro-mes.c"))
265 (add-target (check "scaffold/micro-mes.guile" #:exit 6)) ; arg1 arg2 arg3 arg4 arg5
267 (add-target (group "check-scaffold" #:dependencies (filter (target-prefix? "check-scaffold") %targets)))
270 '("gc" "lib" "math" "mes" "posix" "reader" "vector"))
273 `(,@(map (cut string-append "src/" <> ".c") snarf-bases)
274 ,@(map (cut string-append "src/" <> ".mes.h") snarf-bases)
275 ,@(map (cut string-append "src/" <> ".mes.i") snarf-bases)
276 ,@(map (cut string-append "src/" <> ".mes.environment.i") snarf-bases)))
278 (define gcc-snarf-targets
280 (add-target (snarf "src/gc.c" #:mes? #f))
281 (add-target (snarf "src/lib.c" #:mes? #f))
282 (add-target (snarf "src/math.c" #:mes? #f))
283 (add-target (snarf "src/mes.c" #:mes? #f))
284 (add-target (snarf "src/posix.c" #:mes? #f))
285 (add-target (snarf "src/reader.c" #:mes? #f))
286 (add-target (snarf "src/vector.c" #:mes? #f))))
288 (define mes-snarf-targets
290 (add-target (snarf "src/gc.c"))
291 (add-target (snarf "src/lib.c" #:mes? #t))
292 (add-target (snarf "src/math.c" #:mes? #t))
293 (add-target (snarf "src/mes.c" #:mes? #t))
294 (add-target (snarf "src/posix.c" #:mes? #t))
295 (add-target (snarf "src/reader.c" #:mes? #t))
296 (add-target (snarf "src/vector.c" #:mes? #t))))
298 (add-target (bin.gcc "src/mes.c" #:dependencies gcc-snarf-targets
299 #:defines `("FIXED_PRIMITIVES=1"
302 ,(string-append "VERSION=\"" %version "\"")
303 ,(string-append "MODULEDIR=\"" (string-append %moduledir "/") "\"")
304 ,(string-append "PREFIX=\"" %prefix "\""))))
306 (add-target (bin.gcc "src/mes.c" #:libc #f
307 #:dependencies mes-snarf-targets
308 #:defines `("FIXED_PRIMITIVES=1"
310 ,(string-append "VERSION=\"" %version "\"")
311 ,(string-append "MODULEDIR=\"" (string-append %moduledir "/") "\"")
312 ,(string-append "PREFIX=\"" %prefix "\""))))
314 (add-target (bin.mescc "src/mes.c" #:dependencies mes-snarf-targets
315 #:defines `("FIXED_PRIMITIVES=1"
317 ,(string-append "VERSION=\"" %version "\"")
318 ,(string-append "MODULEDIR=\"" (string-append %moduledir "/") "\"")
319 ,(string-append "PREFIX=\"" %prefix "\""))))
325 "tests/quasiquote.test"
340 "tests/let-syntax.test"
348 (define (add-mes.gcc-test o)
349 (add-target (target (file-name o)))
350 (add-target (check o #:dependencies (list (get-target "src/mes.mlibc-gcc")))))
352 (define (add-mes.guile-test o)
353 (add-target (target (file-name o)))
354 (add-target (check o #:dependencies (list (get-target "src/mes.guile")))))
356 ;; takes long, and should always pass if...
357 ;;(for-each add-mes.gcc-test mes-tests)
359 ;; ...mes.guile passes :-)
360 (for-each add-mes.guile-test mes-tests)
362 ;; FIXME: run tests/base.test
363 (setenv "MES" "src/mes.guile")
365 (add-target (install "guile/mescc.scm" #:dir "bin" #:substitutes #t))
366 (add-target (install "scripts/mescc.mes" #:dir "bin" #:substitutes #t))
367 (add-target (install "scripts/repl.mes" #:dir "bin" #:substitutes #t))
368 (define bootstrap? #f)
370 (add-target (install "src/mes.mes" #:dir "bin" #:installed-name "mes"))
371 (add-target (install "src/mes.guile" #:dir "bin" #:installed-name "mes")))
373 (define* ((install-dir #:key dir) name)
374 (add-target (install name #:dir (string-append dir "/" (dirname name)))))
376 (add-target (install "module/mes/base-0.mes" #:dir (string-append %moduledir "/mes") #:substitutes #t))
377 (add-target (install "module/language/c99/compiler.mes" #:dir (string-append %moduledir "/language/c99") #:substitutes #t))
379 (define %module-dir "share/mes")
382 ((install-dir #:dir (string-append %module-dir)) f))
383 '("module/language/c99/compiler.mes"
384 "module/language/c99/compiler.scm"
385 "module/language/c99/info.mes"
386 "module/language/c99/info.scm"
387 "module/language/paren.mes"
390 "module/mes/as-i386.mes"
391 "module/mes/as-i386.scm"
394 ;;"module/mes/base-0.mes"
395 "module/mes/base.mes"
396 "module/mes/bytevectors.mes"
397 "module/mes/bytevectors.scm"
398 "module/mes/catch.mes"
399 "module/mes/display.mes"
402 "module/mes/fluids.mes"
403 "module/mes/getopt-long.mes"
404 "module/mes/getopt-long.scm"
405 "module/mes/guile.mes"
406 "module/mes/lalr.mes"
407 "module/mes/lalr.scm"
409 "module/mes/match.mes"
410 "module/mes/match.scm"
411 "module/mes/optargs.mes"
412 "module/mes/optargs.scm"
414 "module/mes/peg/cache.scm"
415 "module/mes/peg/codegen.scm"
416 "module/mes/peg/simplify-tree.scm"
417 "module/mes/peg/string-peg.scm"
418 "module/mes/peg/using-parsers.scm"
419 "module/mes/pmatch.mes"
420 "module/mes/pmatch.scm"
421 "module/mes/posix.mes"
422 "module/mes/pretty-print.mes"
423 "module/mes/pretty-print.scm"
424 "module/mes/psyntax-0.mes"
425 "module/mes/psyntax-1.mes"
426 "module/mes/psyntax.mes"
427 "module/mes/psyntax.pp"
428 "module/mes/psyntax.ss"
429 "module/mes/quasiquote.mes"
430 "module/mes/quasisyntax.mes"
431 "module/mes/quasisyntax.scm"
432 "module/mes/read-0.mes"
433 "module/mes/record-0.mes"
434 "module/mes/record.mes"
435 "module/mes/repl.mes"
437 "module/mes/syntax.mes"
438 "module/mes/syntax.scm"
439 "module/mes/test.mes"
440 "module/mes/tiny-0.mes"
441 "module/mes/type-0.mes"
442 "module/nyacc/lalr.mes"
443 "module/nyacc/lang/c99/cpp.mes"
444 "module/nyacc/lang/c99/parser.mes"
445 "module/nyacc/lang/calc/parser.mes"
446 "module/nyacc/lang/util.mes"
447 "module/nyacc/lex.mes"
448 "module/nyacc/parse.mes"
449 "module/nyacc/util.mes"
450 "module/rnrs/arithmetic/bitwise.mes"
451 "module/srfi/srfi-0.mes"
452 "module/srfi/srfi-1.mes"
453 "module/srfi/srfi-1.scm"
454 "module/srfi/srfi-13.mes"
455 "module/srfi/srfi-14.mes"
456 "module/srfi/srfi-16.mes"
457 "module/srfi/srfi-16.scm"
458 "module/srfi/srfi-26.mes"
459 "module/srfi/srfi-26.scm"
460 "module/srfi/srfi-43.mes"
461 "module/srfi/srfi-9-psyntax.mes"
462 "module/srfi/srfi-9.mes"
463 "module/srfi/srfi-9.scm"
464 "module/sxml/xpath.mes"
465 "module/sxml/xpath.scm"))
467 (define* ((install-guile-dir #:key dir) name)
468 (add-target (install (string-append "guile/" name) #:dir (string-append dir "/" (dirname name)))))
472 ((install-guile-dir #:dir (string-append %guiledir)) f))
477 ((install-guile-dir #:dir (string-append %godir)) f))
480 (add-target (install "mlibc/libc-mes.E" #:dir "lib"))
481 (add-target (install "mlibc/libc-mes.M1" #:dir "lib"))
482 (add-target (install "mlibc/libc-mes+tcc.E" #:dir "lib"))
483 (add-target (install "mlibc/libc-mes+tcc.M1" #:dir "lib"))
484 (add-target (install "mlibc/mini-libc-mes.E" #:dir "lib"))
485 (add-target (install "mlibc/mini-libc-mes.M1" #:dir "lib"))
489 ((install-dir #:dir "share/") f))
490 '("mlibc/include/alloca.h"
491 "mlibc/include/assert.h"
492 "mlibc/include/ctype.h"
493 "mlibc/include/dlfcn.h"
494 "mlibc/include/errno.h"
495 "mlibc/include/fcntl.h"
496 "mlibc/include/features.h"
497 "mlibc/include/inttypes.h"
498 "mlibc/include/libgen.h"
499 "mlibc/include/limits.h"
500 "mlibc/include/locale.h"
501 "mlibc/include/math.h"
502 "mlibc/include/mlibc.h"
503 "mlibc/include/setjmp.h"
504 "mlibc/include/signal.h"
505 "mlibc/include/stdarg.h"
506 "mlibc/include/stdbool.h"
507 "mlibc/include/stdint.h"
508 "mlibc/include/stdio.h"
509 "mlibc/include/stdlib.h"
510 "mlibc/include/stdnoreturn.h"
511 "mlibc/include/string.h"
512 "mlibc/include/strings.h"
513 "mlibc/include/sys/cdefs.h"
514 "mlibc/include/sys/mman.h"
515 "mlibc/include/sys/stat.h"
516 "mlibc/include/sys/time.h"
517 "mlibc/include/sys/timeb.h"
518 "mlibc/include/sys/types.h"
519 "mlibc/include/sys/ucontext.h"
520 "mlibc/include/sys/wait.h"
521 "mlibc/include/time.h"
522 "mlibc/include/unistd.h"))
525 (compose add-target (cut install <> #:dir "share/doc/mes"))
534 (add-target (install "doc/fosdem/fosdem.pdf" #:dir "share/doc/mes"))
537 (cond ((member "all-go" args) #t)
538 ((member "clean-go" args) (map delete-file (filter file-exists? %go-files)))
539 ((member "clean" args) (clean))
540 ((member "list" args) (display (string-join (map target-file-name %targets) "\n" 'suffix)))
541 ((member "help" args) (format #t "Usage: ./make.scm [TARGET]...
553 (string-join (filter (negate (cut string-index <> #\/)) (map target-file-name %targets)) "\n " 'prefix)))
555 (let ((targets (match args
556 (() (filter (negate check-target?) %targets))
557 ((? (cut member "all" <>)) (filter (conjoin (negate install-target?)
558 (negate check-target?))
560 ((? (cut member "check" <>)) (filter check-target? %targets))
561 ((? (cut member "install" <>)) (filter install-target? %targets))
562 (_ (filter-map (cut get-target <>) args)))))
563 (for-each build targets)
564 ;;((@@ (mes make) store) #:print 0)
567 (main (cdr (command-line)))