test: Split-up Mescc scaffold test.
[mes.git] / make.scm
1 #! /usr/bin/env guile
2 !#
3
4 (set! %load-path (cons "guile" %load-path))
5 (set! %load-path (cons "../guix" %load-path))
6 (set! %load-compiled-path (cons "guile" %load-compiled-path))
7 (set! %load-compiled-path (cons "../guix" %load-compiled-path))
8
9 (use-modules (guix shell-utils))
10
11 ;; FIXME: .go dependencies
12 ;; workaround: always update .go before calculating hashes
13 ;;(use-modules ((mes make) #:select (sytem**)))
14 (let* ((scm-files '("guix/make.scm"
15                     "guix/records.scm"
16                     "guix/shell-utils.scm"
17                     "language/c99/compiler.scm"
18                     "mes/as-i386.scm"
19                     "mes/as.scm"
20                     "mes/elf.scm"
21                     "mes/M1.scm")))
22   (setenv "srcdir" "guile")
23   (setenv "host" %host-type)
24   (with-directory-excursion "guile"
25     (apply system* `("guile"
26                      "--no-auto-compile"
27                      "-L" "."
28                      "-C" "."
29                      "-s"
30                      "../build-aux/compile-all.scm"
31                      ,@scm-files))))
32
33 (use-modules (srfi srfi-1)
34              (srfi srfi-26)
35              (ice-9 curried-definitions)
36              (ice-9 match)
37              (guix make))
38
39 (add-target (bin.mescc "stage0/exit-42.c" #:libc #f))
40 (add-target (check "stage0/exit-42.0-guile" #:signal 11))  ; FIXME: segfault
41
42 (add-target (bin.mescc "stage0/exit-42.c" #:libc mini-libc-mes.E))
43 (add-target (check "stage0/exit-42.mini-guile" #:exit 42))
44
45 (add-target (bin.mescc "stage0/exit-42.c"))
46 (add-target (check "stage0/exit-42.guile" #:exit 42))
47
48 (define* (add-scaffold-test name #:key (exit 0) (libc libc-mes.E))
49   (add-target (bin.gcc (string-append "scaffold/tests/" name ".c") #:libc #f))
50   (add-target (check (string-append "scaffold/tests/" name ".mlibc-gcc") #:exit exit))
51
52   (add-target (bin.mescc (string-append "scaffold/tests/" name ".c") #:libc libc))
53   (add-target (check (string-append "scaffold/tests/" name "." (cond ((not libc) "0-")
54                                                                      ((eq? libc mini-libc-mes.E) "mini-")
55                                                                      (else "")) "guile") #:exit exit)))
56
57 ;; tests/00: exit, functions without libc
58 (add-scaffold-test "00-exit-0" #:libc #f)
59 (add-scaffold-test "01-return-0" #:libc #f)
60 (add-scaffold-test "02-return-1" #:libc #f #:exit 1)
61 (add-scaffold-test "03-call" #:libc #f)
62 (add-scaffold-test "04-call-0" #:libc #f)
63 (add-scaffold-test "05-call-1" #:libc #f #:exit 1)
64 (add-scaffold-test "06-call-!1" #:libc #f)
65
66 (add-target (group "check-scaffold-tests/0" #:dependencies (filter (target-prefix? "check-scaffold/tests/0") %targets)))
67
68 ;; tests/10: control without libc
69 (for-each
70  (cut add-scaffold-test <> #:libc #f)
71  '("10-if-0"
72    "11-if-1"
73    "12-if-=="
74    "13-if-!="
75    "14-if-goto"
76    "15-if-!f"
77    "16-if-t"))
78
79 (add-target (group "check-scaffold-tests/1" #:dependencies (filter (target-prefix? "check-scaffold/tests/1") %targets)))
80
81 ;; tests/20: loop without libc
82 (for-each
83  (cut add-scaffold-test <> #:libc #f)
84  '("20-while"
85    "21-char[]"
86    "22-while-char[]"))
87
88 (add-target (group "check-scaffold-tests/2" #:dependencies (filter (target-prefix? "check-scaffold/tests/2") %targets)))
89
90 ;; tests/30: call, compare: mini-libc-mes.c
91 (for-each
92  (cut add-scaffold-test <> #:libc mini-libc-mes.E)
93  '("30-strlen"
94    "31-eputs"
95    "32-compare"
96    "33-and-or"
97    "34-pre-post"
98    "35-compare-char"
99    "36-compare-arithmetic"
100    "37-compare-assign"
101    "38-compare-call"))
102
103 (add-target (group "check-scaffold-tests/3" #:dependencies (filter (target-prefix? "check-scaffold/tests/3") %targets)))
104
105 ;; tests/40: control: mini-libc-mes.c
106 (for-each
107  (cut add-scaffold-test <> #:libc mini-libc-mes.E)
108  '("40-if-else"
109    "41-?"
110    "42-goto-label"
111    "43-for-do-while"
112    "44-switch"
113    "45-void-call"))
114
115 (add-target (group "check-scaffold-tests/4" #:dependencies (filter (target-prefix? "check-scaffold/tests/4") %targets)))
116
117 ;; tests/50: libc-mes.c
118 (for-each
119  add-scaffold-test
120  '("50-assert"
121    "51-strcmp"
122    "52-itoa"
123    "54-argv"))
124
125 (add-target (group "check-scaffold-tests/5" #:dependencies (filter (target-prefix? "check-scaffold/tests/5") %targets)))
126
127 ;; tests/60: building up to scaffold/m.c, scaffold/micro-mes.c
128 (for-each
129  add-scaffold-test
130  '("60-math"
131    "61-array"
132    "63-struct-cell"
133    "64-make-cell"
134    "65-read"))
135
136 (add-target (group "check-scaffold-tests/6" #:dependencies (filter (target-prefix? "check-scaffold/tests/6") %targets)))
137
138 ;; tests/70: and beyond src/mes.c -- building up to 8cc.c, pcc.c, tcc.c, libguile/eval.c
139 (for-each
140  add-scaffold-test
141  '("70-printf"
142    "71-struct-array"))
143
144 (add-target (group "check-scaffold-tests/7" #:dependencies (filter (target-prefix? "check-scaffold/tests/7") %targets)))
145
146 (add-target (group "check-scaffold-tests" #:dependencies (filter (target-prefix? "check-scaffold/tests") %targets)))
147
148 (add-target (group "check-scaffold" #:dependencies (filter (target-prefix? "check-scaffold") %targets)))
149
150 (add-target (bin.gcc "scaffold/hello.c"))
151 (add-target (check "scaffold/hello.gcc" #:exit 42))
152
153 (add-target (bin.gcc "scaffold/hello.c" #:libc #f))
154 (add-target (check "scaffold/hello.mlibc-gcc" #:exit 42))
155
156 (add-target (bin.mescc "scaffold/hello.c" #:libc mini-libc-mes.E))
157 (add-target (check "scaffold/hello.mini-guile" #:exit 42))
158
159 (add-target (bin.mescc "scaffold/hello.c"))
160 (add-target (check "scaffold/hello.guile" #:exit 42))
161
162
163 (add-target (bin.gcc "scaffold/m.c"))
164 (add-target (check "scaffold/m.gcc" #:exit 255))
165
166 (add-target (bin.gcc "scaffold/m.c" #:libc #f))
167 (add-target (check "scaffold/m.mlibc-gcc" #:exit 255))
168
169 (add-target (bin.mescc "scaffold/m.c"))
170 (add-target (check "scaffold/m.guile" #:exit 255))
171
172 (add-target (bin.gcc "scaffold/micro-mes.c" #:libc #f))
173 (add-target (check "scaffold/micro-mes.mlibc-gcc" #:exit 1))
174
175 (add-target (bin.mescc "scaffold/micro-mes.c"))
176 (add-target (check "scaffold/micro-mes.guile" #:exit 1))
177
178 (define snarf-bases
179   '("gc" "lib" "math" "mes" "posix" "reader" "vector"))
180
181 (define bla
182   `(,@(map (cut string-append "src/" <> ".c") snarf-bases)
183     ,@(map (cut string-append "src/" <> ".mes.h") snarf-bases)
184     ,@(map (cut string-append "src/" <> ".mes.i") snarf-bases)
185     ,@(map (cut string-append "src/" <> ".mes.environment.i") snarf-bases)))
186
187 (define gcc-snarf-targets
188   (list
189    (add-target (snarf "src/gc.c" #:mes? #f))
190    (add-target (snarf "src/lib.c" #:mes? #f))
191    (add-target (snarf "src/math.c" #:mes? #f))
192    (add-target (snarf "src/mes.c" #:mes? #f))
193    (add-target (snarf "src/posix.c" #:mes? #f))
194    (add-target (snarf "src/reader.c" #:mes? #f))
195    (add-target (snarf "src/vector.c" #:mes? #f))))
196
197 (define mes-snarf-targets
198   (list
199    (add-target (snarf "src/gc.c" #:mes? #t))
200    (add-target (snarf "src/lib.c" #:mes? #t))
201    (add-target (snarf "src/math.c" #:mes? #t))
202    (add-target (snarf "src/mes.c" #:mes? #t))
203    (add-target (snarf "src/posix.c" #:mes? #t))
204    (add-target (snarf "src/reader.c" #:mes? #t))
205    (add-target (snarf "src/vector.c" #:mes? #t))))
206
207 (define VERSION "0.8")
208 (define PREFIX (or (getenv "PREFIX") "/usr/local"))
209 (define DATADIR (or (getenv "DATADIR") (string-append PREFIX " /share")))
210 (define MODULEDIR (or (getenv "MODULEDIR") (string-append DATADIR "/module/")))
211
212 (add-target (bin.gcc "src/mes.c" #:dependencies gcc-snarf-targets
213                      #:defines `("FIXED_PRIMITIVES=1"
214                                  "MES_FULL=1"
215                                  "POSIX=1"
216                                  ,(string-append "VERSION=\"" VERSION "\"")
217                                  ,(string-append "MODULEDIR=\"" MODULEDIR "\"")
218                                  ,(string-append "PREFIX=\"" PREFIX "\""))))
219
220 (add-target (bin.gcc "src/mes.c" #:libc #f
221                      #:dependencies mes-snarf-targets
222                      #:defines `("FIXED_PRIMITIVES=1"
223                                  "MES_FULL=1"
224                                  ,(string-append "VERSION=\"" VERSION "\"")
225                                  ,(string-append "MODULEDIR=\"" MODULEDIR "\"")
226                                  ,(string-append "PREFIX=\"" PREFIX "\""))))
227
228 (add-target (bin.mescc "src/mes.c" #:dependencies mes-snarf-targets
229                        #:defines `("FIXED_PRIMITIVES=1"
230                                    "MES_FULL=1"
231                                  ,(string-append "VERSION=\"" VERSION "\"")
232                                  ,(string-append "MODULEDIR=\"" MODULEDIR "\"")
233                                  ,(string-append "PREFIX=\"" PREFIX "\""))))
234
235 (define mes-tests
236   '("tests/read.test"
237     "tests/base.test"
238     "tests/closure.test"
239     "tests/quasiquote.test"
240     "tests/let.test"
241     "tests/scm.test"
242     "tests/display.test"
243     "tests/cwv.test"
244     "tests/math.test"
245     "tests/vector.test"
246     "tests/srfi-1.test"
247     "tests/srfi-13.test"
248     "tests/srfi-14.test"
249     "tests/optargs.test"
250     "tests/fluids.test"
251     "tests/catch.test"
252     "tests/psyntax.test"
253     "tests/pmatch.test"
254     "tests/let-syntax.test"
255     "tests/guile.test"
256     "tests/record.test"
257     ;;sloooowwww
258     ;;"tests/match.test"
259     ;;"tests/peg.test"
260     ))
261
262 (define (add-mes.gcc-test o)
263   (add-target (target (file-name o)))
264   (add-target (check o #:dependencies (list (get-target "src/mes.mlibc-gcc")))))
265
266 (define (add-mes.guile-test o)
267   (add-target (target (file-name o)))
268   (add-target (check o #:dependencies (list (get-target "src/mes.guile")))))
269
270 ;; takes long, and should always pass if...
271 ;;(for-each add-mes.gcc-test mes-tests)
272
273 ;; ...mes.guile passes :-)
274 (for-each add-mes.guile-test mes-tests)
275
276 ;; FIXME: run tests/base.test
277 (setenv "MES" "src/mes.guile")
278
279 (define (main args)
280   (cond ((member "clean" args) (clean))
281         ((member "help" args) (format #t "Usage: ./make.scm [TARGET]...
282
283 Targets:
284     all
285     check
286     clean
287     help~a
288 "
289                                       ;;(string-join (map target-file-name %targets) "\n    " 'prefix)
290                                       (string-join (filter (negate (cut string-index <> #\/)) (map target-file-name %targets)) "\n    " 'prefix)))
291         (else
292          (let ((targets (match args
293                           (() (filter (negate check-target?) %targets))
294                           ((? (cut member "all" <>)) (filter (negate check-target?) %targets))
295                           ((? (cut member "check" <>)) (filter check-target? %targets))
296                           (_ (filter-map (cut get-target <>) args)))))
297            (for-each build targets)
298            ;;((@@ (mes make) store) #:print 0)
299            (exit %status)))))
300
301 (main (cdr (command-line)))