~ chicken-core (chicken-5) a86b071f49ae86d76336aed162147eb573c3af72


commit a86b071f49ae86d76336aed162147eb573c3af72
Author:     Kooda <kooda@upyum.com>
AuthorDate: Tue Aug 14 09:40:52 2018 +0200
Commit:     Evan Hanson <evhan@foldling.org>
CommitDate: Sat Aug 25 05:25:56 2018 +1200

    Make static linking work on Windows
    
    Signed-off-by: Evan Hanson <evhan@foldling.org>

diff --git a/csc.scm b/csc.scm
index 2c3c4ce6..75074ee8 100644
--- a/csc.scm
+++ b/csc.scm
@@ -63,6 +63,7 @@
 
 ;;; Parameters:
 
+(define windows (eq? (software-type) 'windows))
 (define mingw (eq? (software-version) 'mingw32))
 (define osx (eq? (software-version) 'macosx))
 (define cygwin (eq? (software-version) 'cygwin))
@@ -101,7 +102,7 @@
 (define rc-compiler (quotewrap (if host-mode INSTALL_RC_COMPILER TARGET_RC_COMPILER)))
 (define linker (quotewrap (if host-mode host-cc default-cc)))
 (define c++-linker (quotewrap (if host-mode host-cxx default-cxx)))
-(define object-extension "o")
+(define object-extension (if windows "obj" "o"))
 (define library-extension "a")
 (define link-output-flag "-o ")
 (define executable-extension "")
diff --git a/distribution/manifest b/distribution/manifest
index fd108087..4a5ca459 100644
--- a/distribution/manifest
+++ b/distribution/manifest
@@ -159,6 +159,7 @@ tests/test-glob.scm
 tests/matchable.scm
 tests/module-tests.scm
 tests/module-static-eval-compiled.scm
+tests/module-static-link.scm
 tests/module-tests-2.scm
 tests/multiple-values.scm
 tests/test-finalizers.scm
diff --git a/tests/csc-tests.scm b/tests/csc-tests.scm
index 6eba87b7..0bb8a11a 100644
--- a/tests/csc-tests.scm
+++ b/tests/csc-tests.scm
@@ -2,6 +2,7 @@
 
 (import (chicken file)
         (chicken pathname)
+        (chicken platform)
         (chicken process)
         (chicken process-context)
         (chicken string))
@@ -20,8 +21,10 @@
 (csc "null.scm" "-t")
 (assert (file-exists? "null.c"))
 
+(define obj-file (if (eq? (software-type) 'windows) "null.obj" "null.o"))
+
 (csc "null.c" "-c")
-(assert (file-exists? "null.o"))
+(assert (file-exists? obj-file))
 
-(csc "null.o")
+(csc obj-file)
 (run "null")
diff --git a/tests/module-static-link.scm b/tests/module-static-link.scm
new file mode 100644
index 00000000..84b89bea
--- /dev/null
+++ b/tests/module-static-link.scm
@@ -0,0 +1,3 @@
+(module main ()
+(import scheme chicken.base sample-module)
+(assert (= foo 42)))
diff --git a/tests/runtests.bat b/tests/runtests.bat
index abacfeb1..e5cd60ae 100644
--- a/tests/runtests.bat
+++ b/tests/runtests.bat
@@ -22,7 +22,7 @@ set compile_r=..\%PROGRAM_PREFIX%csc%PROGRAM_SUFFIX% %COMPILE_OPTIONS% -o a.out
 set compile_s=..\%PROGRAM_PREFIX%csc%PROGRAM_SUFFIX% %COMPILE_OPTIONS% -s -types %TYPESDB% -ignore-repository
 set interpret=..\%PROGRAM_PREFIX%csi%PROGRAM_SUFFIX% -n -include-path %TEST_DIR%/..
 
-del /f /q /s *.exe *.so *.o *.out *.import.* ..\foo.import.* %CHICKEN_INSTALL_REPOSITORY%
+del /f /q /s *.exe *.so *.o *.obj *.out *.import.* ..\foo.import.* %CHICKEN_INSTALL_REPOSITORY%
 rmdir /q /s %CHICKEN_INSTALL_REPOSITORY%
 mkdir %CHICKEN_INSTALL_REPOSITORY%
 copy %TYPESDB% %CHICKEN_INSTALL_REPOSITORY%
@@ -425,6 +425,17 @@ if errorlevel 1 exit /b 1
 rem %compile% ec-tests.scm
 rem a.out        # takes ages to compile
 
+echo ======================================== module tests (static link) ...
+%compile_r% -static -unit sample-module -J -c sample-module.scm -o sample-module.obj
+if errorlevel 1 exit /b 1
+move sample-module.link %CHICKEN_INSTALL_REPOSITORY%
+move sample-module.import.scm %CHICKEN_INSTALL_REPOSITORY%
+move sample-module.obj %CHICKEN_INSTALL_REPOSITORY%
+%compile_r% -static module-static-link.scm
+if errorlevel 1 exit /b 1
+a.out
+if errorlevel 1 exit /b 1
+
 echo ======================================== port tests ...
 %interpret% -s port-tests.scm
 if errorlevel 1 exit /b 1
@@ -613,7 +624,7 @@ a.out
 if errorlevel 1 exit /b 1
 
 echo ======================================== linking tests ...
-%compile_r% -unit reverser reverser\tags\1.0\reverser.scm -J -c -o reverser.o
+%compile_r% -unit reverser reverser\tags\1.0\reverser.scm -J -c -o reverser.obj
 %compile_r% -link reverser linking-tests.scm
 if errorlevel 1 exit /b 1
 a.out
@@ -622,7 +633,7 @@ if errorlevel 1 exit /b 1
 if errorlevel 1 exit /b 1
 a.out
 if errorlevel 1 exit /b 1
-move reverser.o %CHICKEN_INSTALL_REPOSITORY%
+move reverser.obj %CHICKEN_INSTALL_REPOSITORY%
 move reverser.import.scm %CHICKEN_INSTALL_REPOSITORY%
 %compile_r% -link reverser linking-tests.scm
 if errorlevel 1 exit /b 1
diff --git a/tests/runtests.sh b/tests/runtests.sh
index 0232e7bd..74768407 100755
--- a/tests/runtests.sh
+++ b/tests/runtests.sh
@@ -45,7 +45,7 @@ TYPESDB=../types.db
 COMPILE_OPTIONS="-v -compiler ${CHICKEN} -I${TEST_DIR}/.. -L${TEST_DIR}/.. -include-path ${TEST_DIR}/.. -libdir ${TEST_DIR}/.. -rpath ${TEST_DIR}/.."
 
 compile="../${PROGRAM_PREFIX}csc${PROGRAM_SUFFIX} ${COMPILE_OPTIONS} -o a.out -types ${TYPESDB} -ignore-repository"
-compile_r="../${PROGRAM_PREFIX}csc${PROGRAM_SUFFIX} ${COMPILE_OPTIONS} -o a.out"
+compile_r="../${PROGRAM_PREFIX}csc${PROGRAM_SUFFIX} ${COMPILE_OPTIONS}"
 compile_s="../${PROGRAM_PREFIX}csc${PROGRAM_SUFFIX} ${COMPILE_OPTIONS} -s -types ${TYPESDB} -ignore-repository"
 interpret="../${PROGRAM_PREFIX}csi${PROGRAM_SUFFIX} -n -include-path ${TEST_DIR}/.."
 time=time
@@ -58,7 +58,7 @@ $time true >/dev/null 2>/dev/null
 test $? -eq 127 && time=
 set -e
 
-rm -fr *.exe *.so *.o *.out *.import.* ../foo.import.* test-repository
+rm -fr *.exe *.so *.o *.obj *.out *.import.* ../foo.import.* test-repository
 mkdir -p test-repository
 cp $TYPESDB test-repository/types.db
 
@@ -338,6 +338,12 @@ $interpret -bnq ec.so ec-tests.scm
 # $compile ec-tests.scm
 # ./a.out        # takes ages to compile
 
+echo "======================================== module tests (static link) ..."
+$compile_r -static -unit sample-module -J -c sample-module.scm
+mv sample-module.link sample-module.import.scm sample-module.o* "$CHICKEN_INSTALL_REPOSITORY"
+$compile_r -static module-static-link.scm -o a.out
+./a.out
+
 echo "======================================== port tests ..."
 $interpret -s port-tests.scm
 
@@ -474,15 +480,16 @@ $compile -e embedded3.c embedded4.scm
 ./a.out
 
 echo "======================================== linking tests ..."
-$compile_r -unit reverser reverser/tags/1.0/reverser.scm -J -c -o reverser.o
-$compile_r -link reverser linking-tests.scm
+$compile_r -unit reverser reverser/tags/1.0/reverser.scm -J -c
+mv reverser/tags/1.0/reverser.o* ./
+$compile_r -link reverser linking-tests.scm -o a.out
 ./a.out
-$compile_r -link reverser linking-tests.scm -static
+$compile_r -link reverser linking-tests.scm -o a.out -static
 ./a.out
-mv reverser.o reverser.import.scm "$CHICKEN_INSTALL_REPOSITORY"
-$compile_r -link reverser linking-tests.scm
+mv reverser.o* reverser.import.scm "$CHICKEN_INSTALL_REPOSITORY"
+$compile_r -link reverser linking-tests.scm -o a.out
 ./a.out
-$compile_r -link reverser linking-tests.scm -static
+$compile_r -link reverser linking-tests.scm -o a.out -static
 ./a.out
 
 echo "======================================== private repository test ..."
Trap