Changeset 12052 in project
- Timestamp:
- 10/01/08 00:53:27 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
chicken/trunk/scripts/chicken-bundle.scm
r12050 r12052 17 17 (define chicken-include-dir (foreign-value "C_INSTALL_INCLUDE_HOME" c-string) ) 18 18 19 (define s+ string-append) 19 (define (s+ . lst) (apply string-append (map ->string lst))) 20 20 21 (define (sl\ p lst) (string-intersperse (map ->string lst) p)) 21 22 … … 28 29 ,(args:make-option (chicken-dir) (required: "DIR") 29 30 (s+ "directory where Chicken C files can be found")) 30 ,(args:make-option (chicken-units) (required: " DIR")31 ,(args:make-option (chicken-units) (required: "LIST") 31 32 (s+ "Chicken units to be included with the bundle (comma-separated list)")) 33 ,(args:make-option (exclude) (required: "LIST") 34 (s+ "libraries to be excluded from bundling (comma-separated list)")) 32 35 ,(args:make-option (repo-dir) (required: "DIR") 33 36 (s+ "install eggs in directory DIR")) 37 ,(args:make-option (suffix) (required: "STRING") 38 (s+ "use given suffix for archive name and top-level directory (default is -bundle)")) 34 39 ,(args:make-option (verbose) #:none 35 40 (s+ "enable verbose mode") … … 65 70 (define (read-c-files path) 66 71 (find-files path ".*.c" cons (list) 0)) 72 (define (read-h-files path) 73 (find-files path ".*.h" cons (list) 0)) 67 74 68 75 (define tmpdir-prefix … … 86 93 (if (file-exists? path) (loop (random 10000)) path)))) 87 94 88 (define (fnxp flst) 89 (concatenate (map (lambda (p) (map (lambda (f) (s+ (second p) "/" f)) (third p))) flst))) 95 (define (chxp flst) 96 (concatenate (map (lambda (p) (append (map (lambda (f) (s+ (second p) dirsep f)) (third p)) 97 (map (lambda (f) (s+ (second p) dirsep f)) (fourth p)))) 98 flst))) 99 100 (define (cxp flst) 101 (concatenate (map (lambda (p) (map (lambda (f) (s+ (second p) dirsep f)) (fourth p))) flst))) 90 102 91 103 (define (build-makefile egg-name flst units cc-options) 104 (message "Creating Makefile" ) 92 105 (call-with-output-file "Makefile" 93 106 (lambda (out) 94 107 (let ((text #<#EOF 95 ## This file was generated by chicken-bundle , do not edit or your changes might be lost108 ## This file was generated by chicken-bundle 96 109 ## 97 #(s+ egg-name ": ") runtime.c library.c #(sl\ " " (map (lambda (u) (s+ u ".c")) units)) #(sl\ " " ( fnxp flst))98 #(list->string (list #\tab)) $(CC) #(identity cc-options) -o #(s+ egg-name)$^110 #(s+ egg-name ": ") runtime.c library.c #(sl\ " " (map (lambda (u) (s+ u ".c")) units)) #(sl\ " " (cxp flst)) 111 #(list->string (list #\tab)) $(CC) #(identity cc-options) -o $@ $^ 99 112 EOF 100 113 )) 101 114 (display text out))))) 102 115 103 (define (build-bundle egg-name repo-dir build-dir chicken-dir chicken-units cc-options) 104 (let ((cwd (current-directory))) 105 (run (rm -rf ,(s+ build-dir "/*"))) 106 (run (rm -rf ,(s+ repo-dir "/*"))) 107 (run (chicken-setup -d ,(if *verbose* "-v" "") -k -build-prefix ,build-dir -repository ,repo-dir ,egg-name)) 108 (let ((bundle-name (s+ egg-name "-bundle.tar.gz") ) 109 (flst 110 (let loop ((subdirs (read-subdirs build-dir)) (flst (list))) 111 (if (null? subdirs) flst 112 (let* ((subdir (car subdirs)) 113 (c-files (read-c-files subdir)) 114 (subdir-name (pathname-strip-directory subdir)) 115 (c-file-names (map pathname-strip-directory c-files)) 116 (bundle-subdir-name (third (string-split subdir-name ".")))) 117 (loop (cdr subdirs) (cons (list subdir-name bundle-subdir-name c-file-names) flst))))))) 116 (define (build-bundle egg-name suffix repo-dir build-dir chicken-dir 117 chicken-units cc-options exclude) 118 (let ((cwd (current-directory)) 119 (bundle-dir (s+ build-dir dirsep egg-name suffix)) 120 (bundle-name (s+ egg-name suffix ".tar.gz") )) 121 (run (rm -rf ,(s+ build-dir dirsep "*"))) 122 (run (rm -rf ,(s+ repo-dir dirsep "*"))) 123 (run (chicken-setup ,(if *verbose* "-v" "") -d -k -build-prefix ,build-dir -repository ,repo-dir ,egg-name)) 124 (let ((flst 125 (let loop ((subdirs (read-subdirs build-dir)) (flst (list))) 126 (if (null? subdirs) flst 127 (let* ((subdir (car subdirs)) 128 (c-files (read-c-files subdir)) 129 (h-files (read-h-files subdir)) 130 (subdir-name (pathname-strip-directory subdir)) 131 (subdir-eggname (third (string-split subdir-name "."))) 132 (bundle-subdir-name (s+ subdir-eggname ".dir")) 133 (c-file-names (map pathname-strip-directory c-files)) 134 (h-file-names (map pathname-strip-directory h-files))) 135 (if (member subdir-eggname exclude) 136 (loop (cdr subdirs) flst) 137 (loop (cdr subdirs) (cons (list subdir-name bundle-subdir-name h-file-names 138 c-file-names) flst)))))))) 118 139 (if (null? flst) (error 'build-bundle "no C files found")) 119 (run (cp ,(s+ chicken-include-dir "/chicken.h") ,build-dir)) 120 (run (cp ,(s+ chicken-dir "/runtime.c") ,build-dir)) 121 (run (cp ,(s+ chicken-dir "/library.c") ,build-dir)) 122 (for-each (lambda (u) (run (cp ,(s+ chicken-dir "/" u ".c") ,build-dir))) chicken-units) 140 (if (not (file-exists? bundle-dir)) 141 (begin 142 (message "Creating directory ~a" bundle-dir) 143 (create-directory bundle-dir))) 144 (run (rm -rf ,(s+ bundle-dir dirsep "*"))) 145 (change-directory bundle-dir) 146 (build-makefile egg-name flst chicken-units cc-options) 147 (run (cp ,(s+ chicken-include-dir dirsep "chicken.h") ,bundle-dir)) 148 (run (cp ,(s+ chicken-dir dirsep "runtime.c") ,bundle-dir)) 149 (run (cp ,(s+ chicken-dir dirsep "library.c") ,bundle-dir)) 150 (for-each (lambda (u) (run (cp ,(s+ chicken-dir dirsep u ".c") ,bundle-dir))) chicken-units) 123 151 (change-directory build-dir) 124 (build-makefile egg-name flst chicken-units cc-options) 125 (for-each (lambda (p) (run (mv ,(first p) ,(second p)))) flst) 126 (run (tar zcf ,bundle-name Makefile chicken.h runtime.c library.c 127 ,@(map (lambda (u) (s+ u ".c")) chicken-units) 128 ,@(fnxp flst))) 129 (run (mv ,(s+ build-dir "/" bundle-name) ,cwd)) 152 (for-each (lambda (p) (run (mv ,(first p) ,(s+ bundle-dir dirsep (second p))))) flst) 153 (let* ((bundle-dir-name (pathname-strip-directory bundle-dir)) 154 (mkbp (lambda (x) (s+ bundle-dir-name dirsep x))) 155 (mkbpu (lambda (x) (s+ bundle-dir-name dirsep x ".c")))) 156 (run (tar zcf ,bundle-name 157 ,@(map mkbp `(Makefile chicken.h runtime.c library.c )) 158 ,@(map mkbp (chxp flst)) ,@(map mkbpu chicken-units)))) 159 (run (mv ,(s+ build-dir dirsep bundle-name) ,cwd)) 130 160 (change-directory cwd) 131 161 ))) … … 134 164 135 165 (define (main options operands) 136 (let ((opt_cc-options (or (alist-ref 'cc-options options) "")) 166 (let ((opt_exclude (or ((lambda (x) (and x (string-split x ","))) (alist-ref 'exclude options)) 167 (list))) 168 (opt_suffix (or (alist-ref 'suffix options) "-bundle")) 169 (opt_cc-options (or (alist-ref 'cc-options options) "-g -O2")) 137 170 (opt_chicken-dir (or (alist-ref 'chicken-dir options) ".")) 138 171 (opt_chicken-units (or ((lambda (x) (and x (string-split x ","))) (alist-ref 'chicken-units options)) 139 (list " utils" "extras" "srfi-1" "srfi-13" "srfi-14")))172 (list "data-structures" "utils" "extras" "srfi-1" "srfi-4" "srfi-13" "srfi-14"))) 140 173 (opt_build-dir (or (alist-ref 'build-dir options) (compute-unique-path "build"))) 141 174 (opt_repo-dir (or (alist-ref 'repo-dir options) (compute-unique-path "repo")))) … … 151 184 (message "Creating directory ~a" opt_repo-dir) 152 185 (create-directory opt_repo-dir))) 153 (for-each (lambda (x) (build-bundle x opt_repo-dir opt_build-dir opt_chicken-dir opt_chicken-units opt_cc-options )) 186 (for-each (lambda (x) (build-bundle x opt_suffix opt_repo-dir opt_build-dir opt_chicken-dir 187 opt_chicken-units opt_cc-options opt_exclude )) 154 188 operands))) 155 189
Note: See TracChangeset
for help on using the changeset viewer.