-
Notifications
You must be signed in to change notification settings - Fork 0
/
egg-compile.scm
1263 lines (1178 loc) · 48.1 KB
/
egg-compile.scm
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
;;;; egg-info processing and compilation
;
; Copyright (c) 2017-2021, The CHICKEN Team
; All rights reserved.
;
; Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following
; conditions are met:
;
; Redistributions of source code must retain the above copyright notice, this list of conditions and the following
; disclaimer.
; Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following
; disclaimer in the documentation and/or other materials provided with the distribution.
; Neither the name of the author nor the names of its contributors may be used to endorse or promote
; products derived from this software without specific prior written permission.
;
; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
; OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
; AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
; CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
; CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
; SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
; THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
; OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
; POSSIBILITY OF SUCH DAMAGE.
(define default-extension-options '())
(define default-program-options '())
(define default-static-program-link-options '())
(define default-dynamic-program-link-options '())
(define default-static-extension-link-options '())
(define default-dynamic-extension-link-options '())
(define default-static-compilation-options '("-O2" "-d1"))
(define default-dynamic-compilation-options '("-O2" "-d1"))
(define default-import-library-compilation-options '("-O2" "-d0"))
(define default-program-linkage
(if staticbuild '(static) '(dynamic)))
(define default-extension-linkage
(if staticbuild '(static) '(static dynamic)))
(define +unix-executable-extension+ "")
(define +windows-executable-extension+ ".exe")
(define +unix-object-extension+ ".o")
(define +unix-archive-extension+ ".a")
(define +windows-object-extension+ ".obj")
(define +windows-archive-extension+ ".a")
(define +link-file-extension+ ".link")
(define keep-generated-files #f)
;;; some utilities
(define override-prefix
(let ((prefix (get-environment-variable "CHICKEN_INSTALL_PREFIX")))
(lambda (dir default)
(if prefix
(string-append prefix dir)
default))))
(define (object-extension platform)
(case platform
((unix) +unix-object-extension+)
((windows) +windows-object-extension+)))
(define (archive-extension platform)
(case platform
((unix) +unix-archive-extension+)
((windows) +windows-archive-extension+)))
(define (executable-extension platform)
(case platform
((unix) +unix-executable-extension+)
((windows) +windows-executable-extension+)))
(define (copy-directory-command platform)
(case platform
((unix) "cp -r")
((windows) "xcopy /y /i /e")))
(define (mkdir-command platform)
(case platform
((unix) "mkdir -p")
((windows) "mkdir")))
(define (install-executable-command platform)
(string-append default-install-program " "
default-install-program-executable-flags))
(define (install-file-command platform)
(string-append default-install-program " "
default-install-program-data-flags))
(define (remove-file-command platform)
(case platform
((unix) "rm -f")
((windows) "del /f /q")))
(define (cd-command platform)
(case platform
((unix) "cd")
((windows) "cd /d")))
(define (uses-compiled-import-library? mode)
(not (and (eq? mode 'host) staticbuild)))
;;; topological sort with cycle check
(define (sort-dependencies dag eq)
(condition-case (topological-sort dag eq)
((exn runtime cycle)
(error "cyclic dependencies" dag))))
;;; collect import libraries for all modules
(define (import-libraries mods dest rtarget mode)
(define (implib name)
(conc dest "/" name ".import."
(if (uses-compiled-import-library? mode)
"so"
"scm")))
(if mods
(map implib mods)
(list (implib rtarget))))
;;; normalize target path for "random files" (data, c-include, scheme-include)
(define (normalize-destination dest mode)
(let ((dest* (normalize-pathname dest)))
(if (irregex-search '(: bos ".." ("\\/")) dest*)
(error "destination must be relative to CHICKEN install prefix" dest)
(normalize-pathname
(make-pathname (if (eq? mode 'target)
default-prefix ; XXX wrong!
(override-prefix "/" host-prefix))
dest*)))))
;;; check condition in conditional clause
(define (check-condition tst mode link)
(define (fail x)
(error "invalid conditional expression in `cond-expand' clause"
x))
(let walk ((x tst))
(cond ((and (list? x) (pair? x))
(cond ((and (eq? (car x) 'not) (= 2 (length x)))
(not (walk (cadr x))))
((eq? 'and (car x)) (every walk (cdr x)))
((eq? 'or (car x)) (any walk (cdr x)))
(else (fail x))))
((memq x '(dynamic static)) (memq x link))
((memq x '(target host)) (memq x mode))
((symbol? x) (feature? x))
(else (fail x)))))
;;; compile an egg-information tree into abstract build/install operations
(define (compile-egg-info eggfile info version platform mode)
(let ((exts '())
(prgs '())
(objs '())
(data '())
(genfiles '())
(cinc '())
(scminc '())
(target #f)
(src #f)
(files '())
(ifiles '())
(cbuild #f)
(oname #f)
(link '())
(dest #f)
(sdeps '())
(cdeps '())
(lopts '())
(opts '())
(mods #f)
(lobjs '())
(tfile #f)
(ptfile #f)
(ifile #f)
(eggfile (locate-egg-file eggfile))
(objext (object-extension platform))
(arcext (archive-extension platform))
(exeext (executable-extension platform)))
(define (check-target t lst)
(when (member t lst)
(error "target multiply defined" t))
t)
(define (addfiles . filess)
(set! ifiles (concatenate (cons ifiles filess)))
files)
(define (compile-component info)
(case (car info)
((extension)
(fluid-let ((target (check-target (cadr info) exts))
(cdeps '())
(sdeps '())
(src #f)
(cbuild #f)
(link (if (null? link) default-extension-linkage link))
(tfile #f)
(ptfile #f)
(ifile #f)
(lopts lopts)
(lobjs '())
(oname #f)
(mods #f)
(opts opts))
(for-each compile-extension/program (cddr info))
(let ((dest (destination-repository mode #t))
;; Respect install-name if specified
(rtarget (or oname target)))
(when (eq? #t tfile) (set! tfile rtarget))
(when (eq? #t ifile) (set! ifile rtarget))
(addfiles
(if (memq 'static link)
(list (conc dest "/" rtarget
(if (null? lobjs)
objext
arcext))
(conc dest "/" rtarget +link-file-extension+))
'())
(if (memq 'dynamic link) (list (conc dest "/" rtarget ".so")) '())
(if tfile
(list (conc dest "/" tfile ".types"))
'())
(if ifile
(list (conc dest "/" ifile ".inline"))
'())
(import-libraries mods dest rtarget mode))
(set! exts
(cons (list target
dependencies: cdeps
source: src options: opts
link-options: lopts linkage: link custom: cbuild
mode: mode types-file: tfile inline-file: ifile
predefined-types: ptfile eggfile: eggfile
modules: (or mods (list rtarget))
source-dependencies: sdeps
link-objects: lobjs
output-file: rtarget)
exts)))))
((c-object)
(fluid-let ((target (check-target (cadr info) exts))
(cdeps '())
(sdeps '())
(src #f)
(cbuild #f)
(link (if (null? link) default-extension-linkage link))
(oname #f)
(mods #f)
(opts opts))
(for-each compile-extension/program (cddr info))
(let ((dest (destination-repository mode #t))
;; Respect install-name if specified
(rtarget (or oname target)))
(set! objs
(cons (list target dependencies: cdeps source: src
options: opts
linkage: link custom: cbuild
mode: mode
eggfile: eggfile
source-dependencies: sdeps
output-file: rtarget)
objs)))))
((data)
(fluid-let ((target (check-target (cadr info) data))
(dest #f)
(files '()))
(for-each compile-data/include (cddr info))
(let* ((dest (or (and dest (normalize-destination dest mode))
(if (eq? mode 'target)
default-sharedir ; XXX wrong!
(override-prefix "/share" host-sharedir))))
(dest (normalize-pathname (conc dest "/"))))
(addfiles (map (cut conc dest <>) files)))
(set! data
(cons (list target dependencies: '() files: files
destination: dest mode: mode)
data))))
((generated-source-file)
(fluid-let ((target (check-target (cadr info) data))
(src #f)
(cbuild #f)
(sdeps '())
(cdeps '()))
(for-each compile-extension/program (cddr info))
(unless cbuild
(error "generated source files need a custom build step" target))
(set! genfiles
(cons (list target dependencies: cdeps source: src
custom: cbuild source-dependencies: sdeps
eggfile: eggfile)
genfiles))))
((c-include)
(fluid-let ((target (check-target (cadr info) cinc))
(dest #f)
(files '()))
(for-each compile-data/include (cddr info))
(let* ((dest (or (and dest (normalize-destination dest mode))
(if (eq? mode 'target)
default-incdir ; XXX wrong!
(override-prefix "/include" host-incdir))))
(dest (normalize-pathname (conc dest "/"))))
(addfiles (map (cut conc dest <>) files)))
(set! cinc
(cons (list target dependencies: '() files: files
destination: dest mode: mode)
cinc))))
((scheme-include)
(fluid-let ((target (check-target (cadr info) scminc))
(dest #f)
(files '()))
(for-each compile-data/include (cddr info))
(let* ((dest (or (and dest (normalize-destination dest mode))
(if (eq? mode 'target)
default-sharedir ; XXX wrong!
(override-prefix "/share" host-sharedir))))
(dest (normalize-pathname (conc dest "/"))))
(addfiles (map (cut conc dest <>) files)))
(set! scminc
(cons (list target dependencies: '() files: files
destination: dest mode: mode)
scminc))))
((program)
(fluid-let ((target (check-target (cadr info) prgs))
(cdeps '())
(sdeps '())
(cbuild #f)
(src #f)
(link (if (null? link) default-program-linkage link))
(lobjs '())
(lopts lopts)
(oname #f)
(opts opts))
(for-each compile-extension/program (cddr info))
(let ((dest (if (eq? mode 'target)
default-bindir ; XXX wrong!
(override-prefix "/bin" host-bindir)))
;; Respect install-name if specified
(rtarget (or oname target)))
(addfiles (list (conc dest "/" rtarget exeext)))
(set! prgs
(cons (list target dependencies: cdeps
source: src options: opts
link-options: lopts linkage: link
custom: cbuild
mode: mode output-file: rtarget
source-dependencies: sdeps
link-objects: lobjs
eggfile: eggfile)
prgs)))))
(else (compile-common info compile-component))))
(define (compile-extension/program info)
(case (car info)
((linkage)
(set! link (cdr info)))
((types-file)
(set! tfile
(cond ((null? (cdr info)) #t)
((not (pair? (cadr info)))
(arg info 1 name?))
(else
(set! ptfile #t)
(set! tfile
(or (null? (cdadr info))
(arg (cadr info) 1 name?)))))))
((objects)
(let ((los (map ->string (cdr info))))
(set! lobjs (append lobjs los))
(set! cdeps (append cdeps (map ->dep los)))))
((inline-file)
(set! ifile (or (null? (cdr info)) (arg info 1 name?))))
((custom-build)
(set! cbuild (->string (arg info 1 name?))))
((csc-options)
(set! opts (append opts (cdr info))))
((link-options)
(set! lopts (append lopts (cdr info))))
((source)
(set! src (->string (arg info 1 name?))))
((install-name)
(set! oname (->string (arg info 1 name?))))
((modules)
(set! mods (map library-id (cdr info))))
((component-dependencies)
(set! cdeps (append cdeps (map ->dep (cdr info)))))
((source-dependencies)
(set! sdeps (append sdeps (map ->dep (cdr info)))))
(else (compile-common info compile-extension/program))))
(define (compile-common info walk)
(case (car info)
((target)
(when (eq? mode 'target)
(for-each walk (cdr info))))
((host)
(when (eq? mode 'host)
(for-each walk (cdr info))))
((error)
(apply error (cdr info)))
((cond-expand)
(compile-cond-expand info walk))))
(define (compile-data/include info)
(case (car info)
((destination)
(set! dest (->string (arg info 1 name?))))
((files)
(set! files (append files (map ->string (cdr info)))))
(else (compile-common info compile-data/include))))
(define (compile-options info)
(case (car info)
((csc-options) (set! opts (append opts (cdr info))))
((link-options) (set! lopts (append lopts (cdr info))))
((linkage) (set! link (append link (cdr info))))
(else (error "invalid component-options specification" info))))
(define (compile-cond-expand info walk)
(let loop ((clauses (cdr info)))
(cond ((null? clauses)
(error "no matching clause in `cond-expand' form"
info))
((or (eq? 'else (caar clauses))
(check-condition (caar clauses) mode link))
(for-each walk (cdar clauses)))
(else (loop (cdr clauses))))))
(define (->dep x)
(if (name? x)
(if (symbol? x) x (string->symbol x))
(error "invalid dependency" x)))
(define (compile info)
(case (car info)
((components) (for-each compile-component (cdr info)))
((component-options)
(for-each compile-options (cdr info)))
(else (compile-common info compile))))
(define (arg info n #!optional (pred (constantly #t)))
(when (< (length info) n)
(error "missing argument" info n))
(let ((x (list-ref info n)))
(unless (pred x)
(error "argument has invalid type" x))
x))
(define (name? x) (or (string? x) (symbol? x)))
(define dep=? equal?)
(define (filter pred lst)
(cond ((null? lst) '())
((pred (car lst)) (cons (car lst) (filter pred (cdr lst))))
(else (filter pred (cdr lst)))))
(define (filter-deps name deps)
(filter (lambda (dep)
(and (symbol? dep)
(or (assq dep exts)
(assq dep objs)
(assq dep data)
(assq dep cinc)
(assq dep scminc)
(assq dep genfiles)
(assq dep prgs)
(error "unknown component dependency" dep))))
deps))
;; collect information
(for-each compile info)
;; sort topologically, by dependencies
(let* ((all (append prgs exts objs genfiles))
(order (reverse (sort-dependencies
(map (lambda (dep)
(cons (car dep)
(filter-deps (car dep)
(get-keyword dependencies: (cdr dep)))))
all)
dep=?))))
;; generate + return build/install commands
(values
;; build commands
(append-map
(lambda (id)
(cond ((assq id exts) =>
(lambda (data)
(let ((link (get-keyword linkage: (cdr data)))
(mods (get-keyword modules: (cdr data))))
(append (if (memq 'dynamic link)
(list (apply compile-dynamic-extension data))
'())
(if (memq 'static link)
;; if compiling both static + dynamic, override
;; modules/types-file/inline-file properties to
;; avoid generating things twice:
(list (apply compile-static-extension
(if (memq 'dynamic link)
(cons (car data)
(append '(modules: #f
types-file: #f
inline-file: #f)
(cdr data)))
data)))
'())
(if (uses-compiled-import-library? mode)
(map (lambda (mod)
(apply compile-import-library
mod (cdr data))) ; override name
mods)
'())))))
((assq id prgs) =>
(lambda (data)
(let ((link (get-keyword linkage: (cdr data))))
(append (if (memq 'dynamic link)
(list (apply compile-dynamic-program data))
'())
(if (memq 'static link)
(list (apply compile-static-program data))
'())))))
((assq id objs) =>
(lambda (data)
(let ((link (get-keyword linkage: (cdr data))))
(append (if (memq 'dynamic link)
(list (apply compile-dynamic-object data))
'())
(if (memq 'static link)
(list (apply compile-static-object data))
'())))))
(else
(let ((data (assq id genfiles)))
(list (apply compile-generated-file data))))))
order)
;; installation commands
(append
(append-map
(lambda (ext)
(let ((link (get-keyword linkage: (cdr ext)))
(mods (get-keyword modules: (cdr ext))))
(append
(if (memq 'static link)
(list (apply install-static-extension ext))
'())
(if (memq 'dynamic link)
(list (apply install-dynamic-extension ext))
'())
(if (and (memq 'dynamic link)
(uses-compiled-import-library? (get-keyword mode: ext)))
(map (lambda (mod)
(apply install-import-library
mod (cdr ext))) ; override name
mods)
(map (lambda (mod)
(apply install-import-library-source
mod (cdr ext))) ; s.a.
mods))
(if (get-keyword types-file: (cdr ext))
(list (apply install-types-file ext))
'())
(if (get-keyword inline-file: (cdr ext))
(list (apply install-inline-file ext))
'()))))
exts)
(map (lambda (prg) (apply install-program prg)) prgs)
(map (lambda (data) (apply install-data data)) data)
(map (lambda (cinc) (apply install-c-include cinc)) cinc)
(map (lambda (scminc) (apply install-data scminc)) scminc))
;; augmented egg-info
(append `((installed-files ,@ifiles))
(if version `((version ,version)) '())
info)))))
;;; shell code generation - build operations
(define ((compile-static-extension name #!key mode
source-dependencies
source (options '())
predefined-types eggfile
link-objects modules
custom types-file inline-file)
srcdir platform)
(let* ((cmd (qs* (or (custom-cmd custom srcdir platform)
default-csc)
platform))
(sname (prefix srcdir name))
(tfile (qs* (prefix srcdir (conc types-file ".types"))
platform))
(ifile (qs* (prefix srcdir (conc inline-file ".inline"))
platform))
(lfile (qs* (conc sname +link-file-extension+) platform))
(opts (append (if (null? options)
default-static-compilation-options
options)
(if (and types-file
(not predefined-types))
(list "-emit-types-file" tfile)
'())
(if inline-file
(list "-emit-inline-file" ifile)
'())))
(out1 (conc sname ".static"))
(out2 (qs* (target-file (conc out1
(object-extension platform))
mode)
platform))
(out3 (if (null? link-objects)
out2
(qs* (target-file (conc out1
(archive-extension platform))
mode)
platform)))
(targets (append (list out3 lfile)
(maybe types-file tfile)
(maybe inline-file ifile)
(map (lambda (m)
(qs* (prefix srcdir (conc m ".import.scm"))
platform))
(or modules '()))))
(src (qs* (or source (conc name ".scm")) platform)))
(when custom
(prepare-custom-command cmd platform))
(print "\n" (qs* default-builder platform #t) " "
(joins targets) " : "
src " " (qs* eggfile platform) " "
(if custom cmd "") " "
(filelist srcdir source-dependencies platform)
" : " cmd
(if keep-generated-files " -k" "")
" -regenerate-import-libraries"
(if modules " -J" "") " -M"
" -setup-mode -static -I " srcdir
" -emit-link-file " lfile
(if (eq? mode 'host) " -host" "")
" -D compiling-extension -c -unit " name
" -D compiling-static-extension"
" -C -I" srcdir (arglist opts platform)
" " src " -o " out2)
(when (pair? link-objects)
(let ((lobjs (filelist srcdir
(map (cut conc <> ".static" (object-extension platform))
link-objects)
platform)))
(print (qs* default-builder platform #t) " " out3 " : "
out2 " " lobjs " : "
(qs* target-librarian platform) " "
target-librarian-options " " out3 " " out2 " "
lobjs)))
(print-end-command platform)))
(define ((compile-dynamic-extension name #!key mode mode
source (options '())
(link-options '())
predefined-types eggfile
link-objects
source-dependencies modules
custom types-file inline-file)
srcdir platform)
(let* ((cmd (qs* (or (custom-cmd custom srcdir platform)
default-csc)
platform))
(sname (prefix srcdir name))
(tfile (qs* (prefix srcdir (conc types-file ".types"))
platform))
(ifile (qs* (prefix srcdir (conc inline-file ".inline"))
platform))
(opts (append (if (null? options)
default-dynamic-compilation-options
options)
(if (and types-file
(not predefined-types))
(list "-emit-types-file" tfile)
'())
(if inline-file
(list "-emit-inline-file" ifile)
'())))
(out (qs* (target-file (conc sname ".so") mode) platform))
(src (qs* (or source (conc name ".scm")) platform))
(lobjs (map (lambda (lo)
(target-file (conc lo
(object-extension platform))
mode))
link-objects))
(targets (append (list out)
(maybe inline-file ifile)
(maybe types-file tfile)
(map (lambda (m)
(qs* (prefix srcdir (conc m ".import.scm"))
platform))
modules))))
(when custom
(prepare-custom-command cmd platform))
(print "\n" (qs* default-builder platform #t) " "
(joins targets)
" : "
src " "
(qs* eggfile platform) " "
(if custom cmd "") " "
(filelist srcdir lobjs platform) " "
(filelist srcdir source-dependencies platform)
" : "
cmd
(if keep-generated-files " -k" "")
(if (eq? mode 'host) " -host" "")
" -D compiling-extension -J -s"
" -regenerate-import-libraries"
" -setup-mode -I " srcdir
" -C -I" srcdir
(arglist opts platform)
(arglist link-options platform) " "
src " "
(filelist srcdir lobjs platform)
" -o " out)
(print-end-command platform)))
(define ((compile-import-library name #!key mode
source-dependencies
(options '()) (link-options '()))
srcdir platform)
(let* ((cmd (qs* default-csc platform))
(sname (prefix srcdir name))
(opts (if (null? options)
default-import-library-compilation-options
options))
(out (qs* (target-file (conc sname ".import.so") mode)
platform))
(src (qs* (conc name ".import.scm") platform)))
(print "\n" (qs* default-builder platform #t) " "
out
" : "
src
(filelist srcdir source-dependencies platform)
" : "
cmd
(if keep-generated-files " -k" "")
" -setup-mode -s"
(if (eq? mode 'host) " -host" "")
" -I " srcdir " -C -I" srcdir
(arglist opts platform)
(arglist link-options platform) " "
src
" -o " out)
(print-end-command platform)))
(define ((compile-static-object name #!key mode
source-dependencies
source (options '())
eggfile custom)
srcdir platform)
(let* ((cmd (qs* (or (custom-cmd custom srcdir platform)
default-csc)
platform))
(sname (prefix srcdir name))
(ssname (and source (prefix srcdir source)))
(opts (if (null? options)
default-static-compilation-options
options))
(ename (pathname-file eggfile))
(out (qs* (target-file (conc sname
".static"
(object-extension platform))
mode)
platform))
(src (qs* (or ssname (conc sname ".c")) platform)))
(when custom
(prepare-custom-command cmd platform))
(print "\n" (slashify default-builder platform) " "
out
" : "
(filelist srcdir source-dependencies platform) " "
src " "
(qs* eggfile platform) " "
(if custom cmd "")
" : "
cmd
" -setup-mode -static -I " srcdir
(if (eq? mode 'host) " -host" "")
" -c -C -I" srcdir
(arglist opts platform)
" " src
" -o " out)
(print-end-command platform)))
(define ((compile-dynamic-object name #!key mode mode
source (options '())
eggfile
source-dependencies
custom)
srcdir platform)
(let* ((cmd (qs* (or (custom-cmd custom srcdir platform)
default-csc)
platform))
(opts (if (null? options)
default-dynamic-compilation-options
options))
(sname (prefix srcdir name))
(ssname (and source (prefix srcdir source)))
(out (qs* (target-file (conc sname
(object-extension platform))
mode)
platform))
(src (qs* (or ssname (conc sname ".c")) platform)))
(when custom
(prepare-custom-command cmd platform))
(print "\n" (slashify default-builder platform) " "
out
" : "
src " "
(qs* eggfile platform) " "
(if custom cmd "") " "
(filelist srcdir source-dependencies platform)
" : "
cmd
(if (eq? mode 'host) " -host" "")
" -setup-mode -I " srcdir
" -s -c -C -I" srcdir
(arglist opts platform)
" " src
" -o " out)
(print-end-command platform)))
(define ((compile-dynamic-program name #!key source mode
(options '()) (link-options '())
source-dependencies
custom eggfile link-objects)
srcdir platform)
(let* ((cmd (qs* (or (custom-cmd custom srcdir platform)
default-csc)
platform))
(sname (prefix srcdir name))
(opts (if (null? options)
default-dynamic-compilation-options
options))
(out (qs* (target-file (conc sname
(executable-extension platform))
mode)
platform))
(lobjs (map (lambda (lo)
(target-file (conc lo
(object-extension platform))
mode))
link-objects))
(src (qs* (or source (conc name ".scm")) platform)))
(when custom
(prepare-custom-command cmd platform))
(print "\n" (qs* default-builder platform #t) " "
out
" : "
src " "
(qs* eggfile platform) " "
(if custom cmd "") " "
(filelist srcdir source-dependencies platform) " "
(filelist srcdir lobjs platform)
" : "
cmd
(if keep-generated-files " -k" "")
" -setup-mode"
(if (eq? mode 'host) " -host" "")
" -I " srcdir
" -C -I" srcdir
(arglist opts platform)
(arglist link-options platform) " "
src " "
(filelist srcdir lobjs platform)
" -o " out)
(print-end-command platform)))
(define ((compile-static-program name #!key source
(options '()) (link-options '())
source-dependencies
custom mode eggfile link-objects)
srcdir platform)
(let* ((cmd (qs* (or (custom-cmd custom srcdir platform)
default-csc)
platform))
(sname (prefix srcdir name))
(opts (if (null? options)
default-static-compilation-options
options))
(out (qs* (target-file (conc sname
(executable-extension platform))
mode)
platform))
(lobjs (map (lambda (lo)
(target-file (conc lo
(object-extension platform))
mode))
link-objects))
(src (qs* (or source (conc name ".scm")) platform)))
(when custom
(prepare-custom-command cmd platform))
(print "\n" (qs* default-builder platform #t) " "
out
" : "
src " "
(qs* eggfile platform) " "
(if custom cmd "") " "
(filelist srcdir lobjs platform) " "
(filelist srcdir source-dependencies platform)
" : "
cmd
(if keep-generated-files " -k" "")
(if (eq? mode 'host) " -host" "")
" -static -setup-mode -I " srcdir
" -C -I"
srcdir
(arglist opts platform)
(arglist link-options platform) " "
src " "
(filelist srcdir lobjs platform)
" -o " out)
(print-end-command platform)))
(define ((compile-generated-file name #!key source custom
source-dependencies eggfile)
srcdir platform)
(let ((cmd (qs* (custom-cmd custom srcdir platform) platform))
(out (qs* (or source name) platform)))
(prepare-custom-command cmd platform)
(print "\n" (qs* default-builder platform #t)
" " out " : " cmd " "
(qs* eggfile platform) " "
(filelist srcdir source-dependencies platform)
" : " cmd)
(print-end-command platform)))
;; installation operations
(define ((install-static-extension name #!key mode output-file
link-objects)
srcdir platform)
(let* ((cmd (install-file-command platform))
(mkdir (mkdir-command platform))
(ext (if (null? link-objects)
(object-extension platform)
(archive-extension platform)))
(sname (prefix srcdir name))
(out (qs* (target-file (conc sname ".static" ext) mode)
platform #t))
(outlnk (qs* (conc sname +link-file-extension+) platform #t))
(dest (destination-repository mode))
(dfile (qs* dest platform #t))
(ddir (shell-variable "DESTDIR" platform)))
(print "\n" mkdir " " ddir dfile)
(print cmd " " out " " ddir
(qs* (conc dest "/" output-file ext) platform #t))
(print cmd " " outlnk " " ddir
(qs* (conc dest "/" output-file +link-file-extension+)
platform #t))
(print-end-command platform)))
(define ((install-dynamic-extension name #!key mode (ext ".so")
output-file)
srcdir platform)
(let* ((cmd (install-executable-command platform))
(mkdir (mkdir-command platform))
(sname (prefix srcdir name))
(out (qs* (target-file (conc sname ext) mode) platform #t))
(dest (destination-repository mode))
(dfile (qs* dest platform #t))
(ddir (shell-variable "DESTDIR" platform))
(destf (qs* (conc dest "/" output-file ext) platform #t)))
(print "\n" mkdir " " ddir dfile)
(print cmd " " out " " ddir destf)
(print-end-command platform)))
(define ((install-import-library name #!key mode)
srcdir platform)
((install-dynamic-extension name mode: mode ext: ".import.so"
output-file: name)
srcdir platform))
(define ((install-import-library-source name #!key mode)
srcdir platform)
(let* ((cmd (install-file-command platform))
(mkdir (mkdir-command platform))
(sname (prefix srcdir name))
(out (qs* (target-file (conc sname ".import.scm") mode)
platform #t))
(dest (destination-repository mode))
(dfile (qs* dest platform #t))
(ddir (shell-variable "DESTDIR" platform)))
(print "\n" mkdir " " ddir dfile)
(print cmd " " out " " ddir
(qs* (conc dest "/" name ".import.scm") platform #t))
(print-end-command platform)))
(define ((install-types-file name #!key mode types-file)
srcdir platform)
(let* ((cmd (install-file-command platform))
(mkdir (mkdir-command platform))
(out (qs* (prefix srcdir (conc types-file ".types"))
platform #t))
(dest (destination-repository mode))
(dfile (qs* dest platform #t))
(ddir (shell-variable "DESTDIR" platform)))
(print "\n" mkdir " " ddir dfile)
(print cmd " " out " " ddir
(qs* (conc dest "/" types-file ".types") platform #t))
(print-end-command platform)))