source: project/build/base.scm @ 2934

Last change on this file since 2934 was 2934, checked in by felix winkelmann, 14 years ago

metafile fixes

File size: 7.5 KB
Line 
1;;;; base.scm
2
3
4#+(not csi)
5(declare
6  (export CC C++ OPTIM LINK LINKFLAGS LINKLIBS CSC AR SUFSHR CSCFLAGS SHAREDFLAGS
7          CSCOPTIM RANLIB CSCLIBS SHELLMODE FILEMODE EXEMODE CCFLAGS C++FLAGS
8          SCANHEADERS BUILD_VERSION SUFDLSHR CSCLINKFLAGS SUFEXE SUFOBJ SUFLIB HDRSCAN INCLUDEDIRS
9          link main-from-objects main cc c++ library object objects link-library scheme-extension
10          link-shared-library csc user-object scheme-main scheme-link clean install-file
11          install-bin install-man install-shell shared-library install-lib) )
12
13
14(define BUILD_VERSION +version+)
15(define CC "cc")
16(define C++ "c++")
17(define OPTIM "-g")
18(define CSCOPTIM "-O2 -d1")
19(define CSC "csc")
20(define AR "ar ru")
21(define RANLIB "ranlib")
22(define SUFSHR (if (eq? (software-version) 'macosx) ".dylib" ".so"))
23(define SHAREDFLAGS (if (eq? (software-version) 'macosx) "-dynamiclib" "-shared"))
24(define SHELLMODE #o755)
25(define FILEMODE #o644)
26(define EXEMODE #o755)
27(define LINKLIBS "")
28(define CSCLIBS "")
29(define LINKFLAGS "")
30(define C++FLAGS "")
31(define CCFLAGS "")
32(define CSCFLAGS "")
33(define CSCLINKFLAGS "")
34(define SCANHEADERS #t)
35(define LINK #f)
36(define SUFDLSHR "so")
37(define SUFEXE "")
38(define SUFOBJ "o")
39(define SUFLIB "a")
40(define HDRSCAN "(^|\n)[ \t]*#[ \t]*include[ \t]*[\"]([^\"]+)[\"]")
41(define INCLUDEDIRS '())
42(define DESTDIR "
43
44
45(define (link image . objs)
46  (actions
47   "link"
48   image
49   (lambda _
50     (run (,($ LINK CC) -o ,image ,@(normalize objs) ,($ LINKFLAGS) ,($ LINKLIBS))))))
51
52(define (scheme-link image . objs)
53  (actions
54   "link Scheme"
55   image
56   (lambda _
57     (run (,($ CSC) -o ,image ,@(normalize objs) ,($ CSCLINKFLAGS) ,($ CSCLIBS))))))
58
59(define (link-shared-library image . objs)
60  (let ((image (suffix ($ SUFSHR) image))
61        (objs (normalize objs)) )
62    (depends "all" image)
63    (depends image objs)
64    (clean image)
65    (actions
66     "link" image
67     (lambda _ (run (,($ LINK CC) ,($ SHAREDFLAGS) -o ,image ,@objs ,($ LINKFLAGS) ,($ LINKLIBS) )))) ) )
68
69(define (scheme-extension ext . srcs)
70  (let* ((ext (suffix ($ SUFDLSHR) ext))
71         (srcs (normalize srcs))
72         (os (map (cut suffix SUFOBJ <>) (normalize srcs))))
73    (objects srcs)
74    (for-each (lambda (o) (set! (on o 'CSCFLAGS) (conc (on o 'CSCFLAGS ($ CSCFLAGS)) " -s "))) os)
75    (depends "all" ext)
76    (depends ext os)
77    (clean ext)
78    (actions
79     "link scheme extension" ext
80     ^{,($ CSC) -s -o ,ext ,@os ,($ CSCLINKFLAGS) ,($ CSCLIBS)} ) ) )
81
82(define (link-library lib . objs)
83  (let ((lib (suffix SUFLIB lib))
84        (objs (normalize objs)) )
85    (depends "all" lib)
86    (depends lib objs)
87    (clean lib)
88    (actions
89     "link library" lib
90     (lambda _
91       (run (,($ AR) ,lib ,@objs))
92       (run (,($ RANLIB) ,lib)) ) ) ) )
93
94(define (main-from-objects image . objs)
95  (let ((objs (normalize objs)))
96    (depends "all" image)
97    (clean image objs)
98    (depends image objs)
99    (apply link image objs) ) )
100
101(define (main image . srcs)
102  (objects srcs)
103  (let ((os (map (cut suffix SUFOBJ <>) (normalize srcs))))
104    (apply main-from-objects image os) ) )
105
106(define (shared-library image . srcs)
107  (objects srcs)
108  (let ((os (map (cut suffix SUFOBJ <>) (normalize srcs))))
109    (apply link-shared-library image os) ) )
110
111(define (scheme-main image . srcs)
112  (let ((objs (suffix SUFOBJ srcs)))
113    (objects srcs)
114    (depends "all" image)
115    (clean image objs)
116    (depends image objs)
117    (apply scheme-link image objs) ) )
118
119(define (library lib . srcs)
120  (let ((srcs (normalize srcs)))
121    (let ((os (map (cut suffix SUFOBJ <>) srcs)))
122      (apply link-library lib os)
123      (for-each cc os srcs) ) ) )
124
125(define (c-headers obj src)
126  (when (->boolean SCANHEADERS)
127    (when (file-exists? src)
128      (depends obj (scan-headers src *VERBOSE* INCLUDEDIRS HDRSCAN))) ) )
129
130(define (cc obj src)
131  (let ((obj (suffix SUFOBJ obj)))
132    (depends obj src)
133    (clean obj)
134    (c-headers obj src)
135    (actions
136     "cc" obj
137     (lambda _
138       (run (,($ CC) ,($ CCFLAGS) ,($ OPTIM) -c ,src -o ,obj) ) ) ) ) )
139
140(define (c++ obj src)
141  (let ((obj (suffix SUFOBJ obj)))
142    (depends obj src)
143    (clean obj)
144    (c-headers obj src)
145    (actions
146     "c++" obj
147     (lambda _
148       (run (,($ C++) ,($ C++FLAGS) ,($ OPTIM) -c ,src -o ,obj) ) ) ) ) )
149
150(define (csc obj src)
151  (let ((obj (suffix SUFOBJ obj)))
152    (depends obj src)
153    (clean obj)
154    (actions
155     "csc" obj
156     (lambda _
157       (run (,($ CSC) ,($ CSCFLAGS) ,($ CSCOPTIM) -c ,src -o ,obj) ) ) ) ) )
158
159(define (object t s)
160  (let ((ext (suffix s)))
161    (cond ((not ext) (user-object t s))
162          ((member ext '("cc" "cpp" "c++" "cxx" "C")) (c++ t s))
163          ((string=? ext "c") (cc t s))
164          ((member ext '("scm" "ss")) (csc t s))
165          (else (user-object t s)) )
166    (depends t s) ) )
167
168(define (objects . srcs)
169  (for-each
170   (lambda (s)
171     (object (suffix SUFOBJ s) s) )
172   (normalize srcs)) )
173
174(define clean
175  (let ((cleaned '()))
176    (lambda targets
177      (set! cleaned (lset-union string=? cleaned (normalize targets)))
178      (actions
179       "clean"
180       "clean"
181       (lambda _ (run (rm -f ,@cleaned))) ) ) ) )
182
183(define (user-object t s)
184  (quit "unable to infer source type of ~a for target ~a" s t) )
185
186(define (ensuredir dir)
187  (unless (file-exists? dir) (run (mkdir -p ,dir))))
188
189(define *installed-bins* '())
190(define *installed-mans* '())
191(define *installed-scripts* '())
192(define *installed-files* '())
193(define *installed-libs* '())
194
195(notfile
196 "all" "clean" "install" "install-bin" "install-lib" "install-file"
197 "install-man" "install-shell")
198
199(actions
200 "install-bin"
201 (lambda _
202   (for-each
203    (lambda (i)
204      (let ((dir (car i))
205            (f (cdr i)) )
206        (ensuredir dir)
207        (run (install -m ,(->mode ($ EXEMODE)) ,f ,dir)) ) )
208    *installed-bins*) ) )   
209
210(actions
211 "install-file"
212 (lambda _
213   (for-each
214    (lambda (i)
215      (let ((dir (car i))
216            (f (cdr i)) )
217        (ensuredir dir)
218        (run (install -m ,(->mode ($ FILEMODE)) ,f ,dir)) ) )
219    *installed-files*) ) )   
220
221(actions
222 "install-lib"
223 (lambda _
224   (for-each
225    (lambda (i)
226      (let ((dir (car i))
227            (f (cdr i)) )
228        (ensuredir dir)
229        (run (install -m ,(->mode ($ FILEMODE)) ,f ,dir))
230        (when (eq? 'macosx (software-version)) (run (,RANLIB ,(prefix dir f))) ) ) )
231    *installed-libs*) ) )   
232
233(actions
234 "install-man"
235 (lambda _
236   (for-each
237    (lambda (i)
238      (let ((dir (car i))
239            (f (cdr i)) )
240        (let ((dir2 (make-pathname dir (conc "man" (suffix f)))))
241          (ensuredir dir2)
242          (run (install -m ,(->mode ($ FILEMODE)) ,f ,dir2))) ) )
243    *installed-mans*) ) )   
244
245(actions
246 "install-shell"
247 (lambda _
248   (for-each
249    (lambda (i)
250      (let ((dir (car i))
251            (f (cdr i)) )
252        (ensuredir dir)
253        (run (install -m ,(->mode ($ SHELLMODE)) ,f ,dir)) ) )
254    *installed-scripts*) ) )
255
256(define (install-bin dir . srcs)
257  (depends "install-bin" srcs)
258  (set! *installed-bins* (lset-union equal? *installed-bins* (map (cut cons dir <>) (normalize srcs)))) )
259
260(define (install-file dir . srcs)
261  (depends "install-file" srcs)
262  (set! *installed-files* (lset-union equal? *installed-files* (map (cut cons dir <>) (normalize srcs))) ) )
263
264(define (install-lib dir . srcs)
265  (depends "install-lib" srcs)
266  (set! *installed-libs* (lset-union equal? *installed-libs* (map (cut cons dir <>) (normalize srcs))) ) )
267
268(define (install-man dir . srcs)
269  (depends "install-man" srcs)
270  (set! *installed-mans* (lset-union equal? *installed-mans* (map (cut cons dir <>) (normalize srcs)))))
271
272(define (install-shell dir . srcs)
273  (depends "install-shell" srcs)
274  (set! *installed-scripts* (lset-union equal? *installed-scripts* (map (cut cons dir <>) (normalize srcs)))))
275
276(depends "install" "install-bin" "install-lib" "install-file" "install-man" "install-shell")
Note: See TracBrowser for help on using the repository browser.