52e57cdb089b08f0de6bc7523dc09a873b1f7c64
[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 match)
36              (guix make))
37
38 (add-target (bin.mescc "stage0/exit-42.c" #:libc #f))
39 (add-target (check "stage0/exit-42.0-guile" #:signal 11))  ; FIXME: segfault
40
41 (add-target (bin.mescc "stage0/exit-42.c" #:libc mini-libc-mes.E))
42 (add-target (check "stage0/exit-42.mini-guile" #:exit 42))
43
44 (add-target (bin.mescc "stage0/exit-42.c"))
45 (add-target (check "stage0/exit-42.guile" #:exit 42))
46
47
48 (add-target (bin.gcc "scaffold/hello.c"))
49 (add-target (check "scaffold/hello.gcc" #:exit 42))
50
51 (add-target (bin.gcc "scaffold/hello.c" #:libc #f))
52 (add-target (check "scaffold/hello.mlibc-gcc" #:exit 42))
53
54 (add-target (bin.mescc "scaffold/hello.c" #:libc mini-libc-mes.E))
55 (add-target (check "scaffold/hello.mini-guile" #:exit 42))
56
57 (add-target (bin.mescc "scaffold/hello.c"))
58 (add-target (check "scaffold/hello.guile" #:exit 42))
59
60
61 (add-target (bin.gcc "scaffold/m.c"))
62 (add-target (check "scaffold/m.gcc" #:exit 255))
63
64 (add-target (bin.gcc "scaffold/m.c" #:libc #f))
65 (add-target (check "scaffold/m.mlibc-gcc" #:exit 255))
66
67 (add-target (bin.mescc "scaffold/m.c"))
68 (add-target (check "scaffold/m.guile" #:exit 255))
69
70
71 (add-target (bin.gcc "scaffold/t-tcc.c"))
72 (add-target (check "scaffold/t-tcc.gcc"))
73
74 (add-target (bin.gcc "scaffold/t-tcc.c" #:libc #f))
75 (add-target (check "scaffold/t-tcc.mlibc-gcc"))
76
77 (add-target (bin.mescc "scaffold/t-tcc.c"))
78 (add-target (check "scaffold/t-tcc.guile"))
79
80
81 (add-target (bin.gcc "scaffold/micro-mes.c" #:libc #f))
82 (add-target (check "scaffold/micro-mes.mlibc-gcc" #:exit 1))
83
84 (add-target (bin.mescc "scaffold/micro-mes.c"))
85 (add-target (check "scaffold/micro-mes.guile" #:exit 1))
86
87
88 (add-target (bin.gcc "scaffold/t.c"))
89 (add-target (check "scaffold/t.gcc"))
90
91 (add-target (bin.gcc "scaffold/t.c" #:libc #f))
92 (add-target (check "scaffold/t.mlibc-gcc"))
93
94 (add-target (bin.mescc "scaffold/t.c"))
95 (add-target (check "scaffold/t.guile"))
96
97 (define snarf-bases
98   '("gc" "lib" "math" "mes" "posix" "reader" "vector"))
99
100 (define bla
101   `(,@(map (cut string-append "src/" <> ".c") snarf-bases)
102     ,@(map (cut string-append "src/" <> ".mes.h") snarf-bases)
103     ,@(map (cut string-append "src/" <> ".mes.i") snarf-bases)
104     ,@(map (cut string-append "src/" <> ".mes.environment.i") snarf-bases)))
105
106 (define gcc-snarf-targets
107   (list
108    (add-target (snarf "src/gc.c" #:mes? #f))
109    (add-target (snarf "src/lib.c" #:mes? #f))
110    (add-target (snarf "src/math.c" #:mes? #f))
111    (add-target (snarf "src/mes.c" #:mes? #f))
112    (add-target (snarf "src/posix.c" #:mes? #f))
113    (add-target (snarf "src/reader.c" #:mes? #f))
114    (add-target (snarf "src/vector.c" #:mes? #f))))
115
116 (define mes-snarf-targets
117   (list
118    (add-target (snarf "src/gc.c" #:mes? #t))
119    (add-target (snarf "src/lib.c" #:mes? #t))
120    (add-target (snarf "src/math.c" #:mes? #t))
121    (add-target (snarf "src/mes.c" #:mes? #t))
122    (add-target (snarf "src/posix.c" #:mes? #t))
123    (add-target (snarf "src/reader.c" #:mes? #t))
124    (add-target (snarf "src/vector.c" #:mes? #t))))
125
126 (define VERSION "0.8")
127 (define PREFIX (or (getenv "PREFIX") "/usr/local"))
128 (define DATADIR (or (getenv "DATADIR") (string-append PREFIX " /share")))
129 (define MODULEDIR (or (getenv "MODULEDIR") (string-append DATADIR "/module/")))
130
131 (add-target (bin.gcc "src/mes.c" #:dependencies gcc-snarf-targets
132                      #:defines `("FIXED_PRIMITIVES=1"
133                                  "MES_FULL=1"
134                                  "POSIX=1"
135                                  ,(string-append "VERSION=\"" VERSION "\"")
136                                  ,(string-append "MODULEDIR=\"" MODULEDIR "\"")
137                                  ,(string-append "PREFIX=\"" PREFIX "\""))))
138
139 (add-target (bin.gcc "src/mes.c" #:libc #f
140                      #:dependencies mes-snarf-targets
141                      #:defines `("FIXED_PRIMITIVES=1"
142                                  "MES_FULL=1"
143                                  ,(string-append "VERSION=\"" VERSION "\"")
144                                  ,(string-append "MODULEDIR=\"" MODULEDIR "\"")
145                                  ,(string-append "PREFIX=\"" PREFIX "\""))))
146
147 (add-target (bin.mescc "src/mes.c" #:dependencies mes-snarf-targets
148                        #:defines `("FIXED_PRIMITIVES=1"
149                                    "MES_FULL=1"
150                                  ,(string-append "VERSION=\"" VERSION "\"")
151                                  ,(string-append "MODULEDIR=\"" MODULEDIR "\"")
152                                  ,(string-append "PREFIX=\"" PREFIX "\""))))
153
154 (define mes-tests
155   '("tests/read.test"
156     "tests/base.test"
157     "tests/closure.test"
158     "tests/quasiquote.test"
159     "tests/let.test"
160     "tests/scm.test"
161     "tests/display.test"
162     "tests/cwv.test"
163     "tests/math.test"
164     "tests/vector.test"
165     "tests/srfi-1.test"
166     "tests/srfi-13.test"
167     "tests/srfi-14.test"
168     "tests/optargs.test"
169     "tests/fluids.test"
170     "tests/catch.test"
171     "tests/psyntax.test"
172     "tests/pmatch.test"
173     "tests/let-syntax.test"
174     "tests/guile.test"
175     "tests/record.test"
176     ;;sloooowwww
177     ;;"tests/match.test"
178     ;;"tests/peg.test"
179     ))
180
181 (define (add-mes.gcc-test o)
182   (add-target (target (file-name o)))
183   (add-target (check o #:dependencies (list (get-target "src/mes.mlibc-gcc")))))
184
185 (define (add-mes.guile-test o)
186   (add-target (target (file-name o)))
187   (add-target (check o #:dependencies (list (get-target "src/mes.guile")))))
188
189 ;; takes long, and should always pass if...
190 ;;(for-each add-mes.gcc-test mes-tests)
191
192 ;; ...mes.guile passes :-)
193 (for-each add-mes.guile-test mes-tests)
194
195 ;; FIXME: run tests/base.test
196 (setenv "MES" "src/mes.guile")
197
198 (define (check-target? o)
199   (string-prefix? "check-" (target-file-name o)))
200
201 (define (main args)
202   (cond ((member "clean" args) (clean))
203         ((member "help" args) (display "Usage: ./make.scm [TARGET]...
204
205 Targets:
206     all
207     check
208     clean
209
210     stage0/exit42.mini-guile
211     scaffold/hello.guile
212     src/mes.guile
213 "))
214         (else
215          (let ((targets (match args
216                           (() (filter (negate check-target?) %targets))
217                           ((? (cut member "all" <>)) (filter (negate check-target?) %targets))
218                           ((? (cut member "check" <>)) (filter check-target? %targets))
219                           (_ (filter-map (cut get-target <>) args)))))
220            (for-each build targets)
221            ;;((@@ (mes make) store) #:print 0)
222            (exit %status)))))
223
224 (main (cdr (command-line)))