~ chicken-core (chicken-5) 15f900e4404e2a4cd7faf9b8073184c0620d7b90
commit 15f900e4404e2a4cd7faf9b8073184c0620d7b90 Author: felix <felix@call-with-current-continuation.org> AuthorDate: Sat Nov 25 16:03:00 2017 +0100 Commit: Peter Bex <peter@more-magic.net> CommitDate: Sat Dec 2 15:34:40 2017 +0100 Improve using custom build scripts Refactored common "recursive" egg properties; custom build commands are made executable and are prefixed with the source directory. Also add bindir to the PATH. In build scripts CHICKEN_CC and CHICKEN_CXX are set to point to the required C/C++ compilers. Signed-off-by: Peter Bex <peter@more-magic.net> diff --git a/chicken-install.scm b/chicken-install.scm index 09580d35..17af8116 100644 --- a/chicken-install.scm +++ b/chicken-install.scm @@ -201,6 +201,7 @@ (data #f #t #t) (modules #f #f #f) (c-include #f #f #t) + (only #f #t #t) (scheme-include #f #f #t))) (define (validate-egg-info info) @@ -886,17 +887,17 @@ (exec (if (eq? platform 'windows) script (string-append - (if sudo - (string-append sudo-program " ") - "") - (let ((dyld (and (eq? (software-version) 'macosx) - (get-environment-variable "DYLD_LIBRARY_PATH")))) - (if dyld - (string-append "/usr/bin/env DYLD_LIBRARY_PATH=" - (qs dyld) - " ") - "")) - "sh " script)) + (if sudo + (string-append sudo-program " ") + "") + (let ((dyld (and (eq? (software-version) 'macosx) + (get-environment-variable "DYLD_LIBRARY_PATH")))) + (if dyld + (string-append "/usr/bin/env DYLD_LIBRARY_PATH=" + (qs dyld) + " ") + "")) + "sh " script)) stop)) (define (write-info name info mode) diff --git a/egg-compile.scm b/egg-compile.scm index 55b19b20..a6e0f571 100644 --- a/egg-compile.scm +++ b/egg-compile.scm @@ -151,8 +151,6 @@ files) (define (compile-component info) (case (car info) - ((target) (when (eq? mode 'target) (for-each compile-component (cdr info)))) - ((host) (when (eq? mode 'host) (for-each compile-component (cdr info)))) ((extension) (fluid-let ((target (check-target (cadr info) exts)) (deps '()) @@ -269,13 +267,10 @@ (cons (list target dependencies: deps source: src options: opts link-options: lopts linkage: link custom: cbuild mode: mode output-file: rtarget) - prgs))))))) + prgs))))) + (else (compile-common info compile-component)))) (define (compile-extension/program info) (case (car info) - ((target) - (when (eq? mode 'target) (for-each compile-extension/program (cdr info)))) - ((host) - (when (eq? mode 'host) (for-each compile-extension/program (cdr info)))) ((linkage) (set! link (cdr info))) ((types-file) @@ -303,22 +298,29 @@ ((modules) (set! mods (map ->string (cdr info)))) ((dependencies) - (set! deps (append deps (map ->dep (cdr info))))))) + (set! deps (append deps (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)))))) (define (compile-data/include info) (case (car info) - ((target) (when (eq? mode 'target) (for-each compile-data/include (cdr info)))) - ((host) (when (eq? mode 'host) (for-each compile-data/include (cdr info)))) ((destination) (set! dest (->string (arg info 1 name?)))) ((files) - (set! files (append files (map ->string (cdr info))))))) + (set! files (append files (map ->string (cdr info))))) + (else (compile-common info compile-data/include)))) (define (->dep x) (if (name? x) x (error "invalid dependency" x))) (define (compile info) (case (car info) - ((target) (when (eq? mode 'target) (for-each compile (cdr info)))) - ((host) (when (eq? mode 'host) (for-each compile (cdr info)))) - ((components) (for-each compile-component (cdr info))))) + ((components) (for-each compile-component (cdr info))) + (else (compile-common info compile)))) (define (arg info n #!optional (pred (constantly #t))) (when (< (length info) n) (error "missing argument" info n)) @@ -440,7 +442,7 @@ predefined-types custom types-file inline-file) srcdir platform) - (let* ((cmd (or (and custom (prefix-custom-command custom)) + (let* ((cmd (or (and custom (prefix srcdir custom)) default-csc)) (sname (prefix srcdir name)) (ssname (and source (prefix srcdir source))) @@ -461,6 +463,8 @@ (object-extension platform)) mode))) (src (quotearg (or ssname (conc sname ".scm"))))) + (when custom + (prepare-custom-command cmd platform)) (print "\n" (slashify default-builder platform) " " out " " cmd (if keep-generated-files " -k" "") " -setup-mode -static -I " srcdir @@ -478,7 +482,7 @@ predefined-types custom types-file inline-file) srcdir platform) - (let* ((cmd (or (and custom (prefix-custom-command custom)) + (let* ((cmd (or (and custom (prefix srcdir custom)) default-csc)) (sname (prefix srcdir name)) (opts (append (if (null? options) @@ -496,6 +500,8 @@ (ssname (and source (prefix srcdir source))) (out (quotearg (target-file (conc sname ".so") mode))) (src (quotearg (or ssname (conc sname ".scm"))))) + (when custom + (prepare-custom-command cmd platform)) (print "\n" (slashify default-builder platform) " " out " " cmd (if keep-generated-files " -k" "") (if (eq? mode 'host) " -host" "") @@ -508,7 +514,7 @@ (options '()) (link-options '()) custom) srcdir platform) - (let* ((cmd (or (and custom (prefix-custom-command custom)) + (let* ((cmd (or (and custom (prefix srcdir custom)) default-csc)) (sname (prefix srcdir name)) (opts (if (null? options) @@ -516,6 +522,8 @@ options)) (out (quotearg (target-file (conc sname ".import.so") mode))) (src (quotearg (conc sname ".import.scm")))) + (when custom + (prepare-custom-command cmd platform)) (print "\n" (slashify default-builder platform) " " out " " cmd (if keep-generated-files " -k" "") " -setup-mode -s" @@ -528,7 +536,7 @@ (options '()) (link-options '()) custom) srcdir platform) - (let* ((cmd (or (and custom (prefix-custom-command custom)) + (let* ((cmd (or (and custom (prefix srcdir custom)) default-csc)) (sname (prefix srcdir name)) (ssname (and source (prefix srcdir source))) @@ -539,6 +547,8 @@ (executable-extension platform)) mode))) (src (quotearg (or ssname (conc sname ".scm"))))) + (when custom + (prepare-custom-command cmd platform)) (print "\n" (slashify default-builder platform) " " out " " cmd (if keep-generated-files " -k" "") " -setup-mode" @@ -551,7 +561,7 @@ (options '()) (link-options '()) custom mode) srcdir platform) - (let* ((cmd (or (and custom (prefix-custom-command custom)) + (let* ((cmd (or (and custom (prefix srcdir custom)) default-csc)) (sname (prefix srcdir name)) (ssname (and source (prefix srcdir source))) @@ -562,6 +572,8 @@ (executable-extension platform)) mode))) (src (quotearg (or ssname (conc sname ".scm"))))) + (when custom + (prepare-custom-command cmd platform)) (print "\n" (slashify default-builder platform) " " out " " cmd (if keep-generated-files " -k" "") (if (eq? mode 'host) " -host" "") @@ -572,10 +584,12 @@ (define ((compile-generated-file name #!key dependencies source custom) srcdir platform) - (let* ((cmd (prefix-custom-command custom)) + (let* ((cmd (prefix srcdir custom)) (sname (prefix srcdir name)) (ssname (and source (prefix srcdir source))) (out (quotearg (or ssname sname)))) + (when custom + (prepare-custom-command cmd platform)) (print "\n" (slashify default-builder platform) " " out " " cmd " : " #;(arglist dependencies)))) @@ -739,14 +753,20 @@ (printf #<<EOF #!/bin/sh~% set -e +PATH="~a":$PATH +CHICKEN_CC="~a" +CHICKEN_CXX="~a" EOF - )) + default-bindir default-cc default-cxx)) ((windows) (printf #<<EOF @echo off~% +set PATH=~a;%PATH% +set CHICKEN_CC=~a +set CHICKEN_CXX=~a EOF - )))) + default-bindir default-cc default-cxx)))) (define ((build-suffix mode name info) platform) (case platform @@ -841,13 +861,6 @@ EOF ((unix) (string-append "${" var "}")) ((windows) (string-append "%" var "%")))) -(define (prefix-custom-command cmd) - (cond ((irregex-match "^csi( .+)$" cmd) => - (lambda (m) (string-append default-csi (irregex-match-substring m 1)))) - ((irregex-match "^csc( .+)$" cmd) => - (lambda (m) (string-append default-csc (irregex-match-substring m 1)))) - ((irregex-match "^cc( .+)$" cmd) => - (lambda (m) (string-append default-cc (irregex-match-substring m 1)))) - ((irregex-match "^c\\+\\+( .+)$" cmd) => - (lambda (m) (string-append default-cxx (irregex-match-substring m 1)))) - (else cmd))) +(define (prepare-custom-command cmd platform) + (unless (eq? 'windows platform) + (print "chmod +x " (quotearg cmd)))) diff --git a/manual/Extensions b/manual/Extensions index c73b5c4a..0ad06287 100644 --- a/manual/Extensions +++ b/manual/Extensions @@ -77,6 +77,9 @@ can also be used to override include- and linker-paths. Each of these variables may contain one or more directory names, separated by {{:}} or {{;}} and will be passed using {{-I}} and {{-L}} to the C compiler. +Finally, you can use the {{custom-build}} egg file property to use a +custom script to compile your extension's code. See below for more information. + === Creating eggs An egg can be created by placing its code and some special @@ -319,6 +322,14 @@ instead of the default build operations. This property is mandatory for components of type {{generated-source-file}}. {{STRING}} usually contains a shell command and thus may be platform sensitive. +The script will be made executable on UNIX systems, if necessary, +and will be invoked like the {{csc}} program and +is executed with the location of the CHICKEN +binaries in the {{PATH}}. Also, tjhe environment variables +{{CHICKEN_CC}} and {{CHICKEN_CXX}} are set to the +names of the C and C++ compiler that were used for building the +system. + ====== csc-options [egg property] (csc-options OPTION ...)Trap