~ chicken-core (chicken-5) 58f5296386f84162744472e68bee94738de2a5e0


commit 58f5296386f84162744472e68bee94738de2a5e0
Author:     felix <felix@call-with-current-continuation.org>
AuthorDate: Sat Dec 10 20:53:15 2016 +0100
Commit:     felix <felix@call-with-current-continuation.org>
CommitDate: Sat Dec 10 20:53:15 2016 +0100

    changed semantcis of -static option in csc, added -static to chicken

diff --git a/batch-driver.scm b/batch-driver.scm
index 327d6166..ffdbd0b1 100644
--- a/batch-driver.scm
+++ b/batch-driver.scm
@@ -327,6 +327,9 @@
       (set! explicit-use-flag #t)
       (set! cleanup-forms '())
       (set! initforms '()) )
+    (when (memq 'static options)
+      (set! static-extensions #t)
+      (register-feature! 'chicken-compile-static))
     (when (memq 'no-lambda-info options)
       (set! emit-closure-info #f) )
     (when (memq 'no-compiler-syntax options)
diff --git a/c-platform.scm b/c-platform.scm
index f77c046d..fdf4a59e 100644
--- a/c-platform.scm
+++ b/c-platform.scm
@@ -98,7 +98,7 @@
     compile-syntax tag-pointers accumulate-profile
     disable-stack-overflow-checks raw specialize
     emit-external-prototypes-first release local inline-global
-    analyze-only dynamic
+    analyze-only dynamic static
     no-argc-checks no-procedure-checks no-parentheses-synonyms
     no-procedure-checks-for-toplevel-bindings
     no-bound-checks no-procedure-checks-for-usual-bindings no-compiler-syntax
diff --git a/chicken.mdoc b/chicken.mdoc
index d9e6736b..33862c57 100644
--- a/chicken.mdoc
+++ b/chicken.mdoc
@@ -117,6 +117,8 @@ do not use units
 and
 .Sq eval
 by default
+.It Fl static
+Link extensions statically
 .It Fl check-syntax
 stop compilation after macro-expansion
 .It Fl analyze-only
diff --git a/core.scm b/core.scm
index db6337da..423da530 100644
--- a/core.scm
+++ b/core.scm
@@ -287,11 +287,13 @@
      optimize-leaf-routines standalone-executable undefine-shadowed-macros
      verbose-mode local-definitions enable-specialization block-compilation
      inline-locally inline-substitutions-enabled strict-variable-types
+     static-extensions
 
      ;; These are set by the (batch) driver, and read by the (c) backend
      disable-stack-overflow-checking emit-trace-info external-protos-first
      external-variables insert-timer-checks no-argc-checks
      no-global-procedure-checks no-procedure-checks emit-debug-info
+     linked-static-extensions
 
      ;; Other, non-boolean, flags set by (batch) driver
      profiled-procedures import-libraries inline-max-size
@@ -393,6 +395,7 @@
 (define bootstrap-mode #f)
 (define strict-variable-types #f)
 (define enable-specialization #f)
+(define static-extensions #f)
 
 ;;; Other global variables:
 
@@ -419,6 +422,7 @@
 (define toplevel-lambda-id #f)
 (define file-requirements #f)
 (define provided '())
+(define linked-static-extensions '())
 
 (define unlikely-variables '(unquote unquote-splicing))
 
@@ -677,7 +681,11 @@
 			 (let ((id         (cadr x))
 			       (alternates (cddr x)))
 			   (let-values (((exp found type)
-					 (##sys#process-require id #t alternates provided)))
+					 (##sys#process-require 
+                                           id #t 
+                                           alternates provided 
+                                           static-extensions 
+                                           register-static-extension)))
 			     (unless (not type)
 			       (##sys#hash-table-update!
 				file-requirements type
@@ -1677,6 +1685,12 @@
      '(##core#undefined) ) ) )
 
 
+;;; Register statically linked extension
+
+(define (register-static-extension id path)
+  (set! linked-static-extensions (cons path linked-static-extensions)))
+
+
 ;;; Create entry procedure:
 
 (define (build-toplevel-procedure node)
diff --git a/csc.mdoc b/csc.mdoc
index 52e26b58..6066d82b 100644
--- a/csc.mdoc
+++ b/csc.mdoc
@@ -273,9 +273,7 @@ on UNIX,
 on Windows
 .Pc
 .It Fl static-libs
-link with static CHICKEN libraries
-.It Fl static
-generate completely statically linked executable
+link with static CHICKEN libraries and extensions
 .It Fl F Ns Ar <DIR>
 pass
 .Dq -F<DIR>
diff --git a/csc.scm b/csc.scm
index e976e888..57d85bc8 100644
--- a/csc.scm
+++ b/csc.scm
@@ -305,27 +305,18 @@
 (define to-stdout #f)
 (define shared #f)
 (define static #f)
-(define static-libs #f)
 
 
 ;;; Locate object files for linking:
 
 (define (find-object-files name)
-
   (define (locate-object-file filename repo)
     (and-let* ((f (##sys#resolve-include-filename filename '() repo #f)))
       (list f)))
-
-  (define (static-extension-information name)
-    (and-let* ((info  (extension-information name))
-	       (files (alist-ref 'static info eq?)))
-      (map (lambda (f) (make-pathname (repository-path) f)) files)))
-
   (let ((f (make-pathname #f name object-extension)))
     (or (locate-object-file f #f)
 	(and (not ignore-repository)
-	     (or (static-extension-information name)
-		 (locate-object-file f #t)))
+             (locate-object-file f #t))
 	(stop "couldn't find linked extension: ~a" name))))
 
 
@@ -485,9 +476,8 @@ Usage: #{csc} FILENAME | OPTION ...
     -lLIBNAME                      link with given library
                                     (`libLIBNAME' on UNIX,
                                      `LIBNAME.lib' on Windows)
-    -static-libs                   link with static CHICKEN libraries
-    -static                        generate completely statically linked
-                                    executable
+    -static                        link with static CHICKEN libraries and
+                                    extensions (if possible)
     -F<DIR>                        pass \"-F<DIR>\" to C compiler
                                     (add framework header path on Mac OS X)
     -framework NAME                passed to linker on Mac OS X
@@ -633,12 +623,8 @@ EOF
 		(set! objc-mode #t) ]
 	       [(-static) 
 		(set! translate-options
-		  (cons* "-feature" "chicken-compile-static" translate-options))
+                  (cons "-static" translate-options))
 		(set! static #t) ]
-	       [(-static-libs) 
-		(set! translate-options
-		  (cons* "-feature" "chicken-compile-static" translate-options))
-		(set! static-libs #t) ]
 	       [(-cflags)
 		(set! inquiry-only #t) 
 		(set! show-cflags #t) ]
@@ -928,6 +914,8 @@ EOF
 	 (set! ofiles (cons fo ofiles))))
      rc-files)
     (set! object-files (append (reverse ofiles) object-files)) ; put generated object files first
+    ;; scan generated C files for mark indicating static extension files:
+    (for-each process-generated-file-marks c-files)
     (unless keep-files 
       (for-each $delete-file generated-c-files)
       (for-each $delete-file generated-rc-files))))
@@ -936,11 +924,34 @@ EOF
   (string-intersperse
    (map quote-option
 	(append
-	 (if (or static static-libs) '() nonstatic-compilation-options)
 	 compilation-optimization-options
 	 compile-options) ) ) )
 
 
+;;; Process "marks" in generated C files
+;
+; used for mapping statically linked extensions to .o files
+
+(define (process-generated-file-marks cfile)
+  (define (process-mark exp)
+    (case (car exp)
+      ((static-objects)
+       (set! object-files (append object-files (cdr exp))))
+      ;; ignore others
+      ))
+  (with-input-from-file cfile
+    (lambda ()
+      (let loop ()
+        (let ((line (read-line)))
+          (cond ((eof-object? line))
+                ((string=? "" line)) ;; scan until empty line
+                ((and (> (string-length line) 6)
+                      (string=? "/*### " (substring line 0 6)))
+                 (process-mark 
+                   (with-input-from-string (substring line 6) read)))
+                (else (loop))))))))
+              
+
 ;;; Link object files and libraries:
 
 (define (run-linking)
@@ -1007,10 +1018,10 @@ EOF
 (define (linker-libraries)
   (string-intersperse
    (append
-    (if (or static static-libs)
+    (if static
         library-files
         shared-library-files)
-    (if (or static static-libs)
+    (if static
         (list extra-libraries)
         (list extra-shared-libraries)))))
 
Trap