-
Notifications
You must be signed in to change notification settings - Fork 115
/
build-script.ss
43 lines (39 loc) · 1.43 KB
/
build-script.ss
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
;;; -*- Gerbil -*-
;;; (C) vyzo at hackzen.org
;;; package build script template
(import :std/make
:gerbil/gambit)
(export defbuild-script)
(def (build-main args build-spec keys that-file)
(def (parse-options opts)
(let lp ((rest opts) (options []))
(match rest
([] options)
(["--release" . rest]
(lp rest (cons* build-release: #t options)))
(["--optimized" . rest]
(lp rest (cons* build-optimized: #t options)))
(["--debug" . rest]
(lp rest (cons* debug: #t options)))
(else
(error "Unexpected " rest)))))
(def srcdir
(path-normalize (path-directory that-file)))
(def (build options)
(apply make build-spec srcdir: srcdir (append options keys)))
(def (clean)
(apply make-clean build-spec srcdir: srcdir keys))
(match args
(["meta"] (write '("spec" "compile" "clean")) (newline))
(["spec"] (pretty-print build-spec))
(["compile" . options] (build (parse-options options)))
(["clean"] (clean))
([] (build []))))
(defsyntax (defbuild-script stx)
(syntax-case stx ()
((macro build-spec keys ...)
(with-syntax* ((@this-script (stx-identifier #'macro 'this-source-file))
(+this-source-file+ (syntax/loc stx (@this-script)))
(@main (stx-identifier #'macro 'main)))
#'(def (@main . args)
(build-main args build-spec [keys ...] +this-source-file+))))))