From ef585e8435ebd7b26f1adbc846095f50d5b9a0d3 Mon Sep 17 00:00:00 2001 From: "Tarn W. Burton" Date: Sat, 7 Dec 2024 09:02:20 -0500 Subject: [PATCH] Add static linking option --- src/gctools/snapshotSaveLoad.cc | 10 ++++++- src/koga/config-header.lisp | 1 + src/koga/configure.lisp | 13 +++++++++ src/koga/ninja.lisp | 50 ++++++++++++++++++--------------- src/koga/setup.lisp | 1 + 5 files changed, 52 insertions(+), 23 deletions(-) diff --git a/src/gctools/snapshotSaveLoad.cc b/src/gctools/snapshotSaveLoad.cc index ebe2d4bad6..3faeac00ea 100644 --- a/src/gctools/snapshotSaveLoad.cc +++ b/src/gctools/snapshotSaveLoad.cc @@ -2727,7 +2727,15 @@ void* snapshot_save_impl(void* data) { } cmd = CXX_BINARY " " BUILD_LINKFLAGS " -L" + snapshot_data->_LibDir + " -o" + snapshot_data->_FileName + " " + obj_filename + - " -Wl,-whole-archive -liclasp -Wl,-no-whole-archive -lclasp " BUILD_LIB; + " -Wl,-whole-archive -liclasp" +#ifndef CLASP_STATIC_LINKING + " -Wl,-no-whole-archive" +#endif + " -lclasp " +#ifdef CLASP_STATIC_LINKING + " -Wl,-no-whole-archive" +#endif + BUILD_LIB; #endif #ifdef _TARGET_OS_DARWIN cmd = CXX_BINARY " " BUILD_LINKFLAGS " -o" + snapshot_data->_FileName + diff --git a/src/koga/config-header.lisp b/src/koga/config-header.lisp index d254f0ddf5..ff695aa842 100644 --- a/src/koga/config-header.lisp +++ b/src/koga/config-header.lisp @@ -132,6 +132,7 @@ "CLASP_DEV_GENERATED_PATH" (namestring (merge-pathnames (root :variant-generated) (build-path configuration))) "CLASP_DEV_INCLUDE_PATH" "include" + "CLASP_STATIC_LINKING" (static-linking-p configuration) "CLASP_INSTALL_SYS_PATH" (namestring (root :install-share)) "CLASP_INSTALL_LIB_PATH" (namestring (root :install-lib)) "CLASP_INSTALL_GENERATED_PATH" (namestring (root :install-generated)) diff --git a/src/koga/configure.lisp b/src/koga/configure.lisp index 0b126c3927..6fa2f7af40 100644 --- a/src/koga/configure.lisp +++ b/src/koga/configure.lisp @@ -141,6 +141,11 @@ :initarg :lib-path :type pathname :documentation "The directory under which to install the Clasp libraries.") + (syslib-path :accessor syslib-path + :initform #P"/usr/local/lib/" + :initarg :syslib-path + :type pathname + :documentation "The directory under which to install the Clasp libraries.") (share-path :accessor share-path :initform #P"/usr/local/share/clasp/" :initarg :share-path @@ -778,6 +783,14 @@ is not compatible with snapshots.") (not (member feature +core-features+))) *features*)))) +(defun lib-filename (configuration name &key (dynamic nil dynamicp)) + (make-pathname :name name + :type (if (or (static-linking-p configuration) + (not dynamicp)) + "a" + #+darwin "dylib" + #-darwin "so"))) + (defun build-name (name &key common (gc *variant-gc* gc-p) diff --git a/src/koga/ninja.lisp b/src/koga/ninja.lisp index 78b89997b6..98b14c15b6 100644 --- a/src/koga/ninja.lisp +++ b/src/koga/ninja.lisp @@ -388,11 +388,11 @@ (products (mapcar (lambda (source) (make-source (source-path source) :package-share)) generated)) - (lib-name (if (static-linking-p configuration) - "libclasp.a" - #+darwin "libclasp.dylib" #-darwin "libclasp.so")) - (lib (make-source lib-name :variant-lib)) - (lib-installed (make-source lib-name :package-lib)) + (libclasp-name (lib-filename configuration "libclasp" :dynamic t)) + (libclasp (make-source libclasp-name :variant-lib)) + (libclasp-installed (make-source libclasp-name (if (static-linking-p configuration) + :package-lib + :package-syslib))) (filtered-sifs (if *variant-precise* (sort sifs (lambda (x y) @@ -413,15 +413,15 @@ (if (static-linking-p configuration) (ninja:write-build output-stream :ar :inputs objects - :outputs (list lib)) + :outputs (list libclasp)) (ninja:write-build output-stream :link-lib :variant-ldflags *variant-ldflags* :variant-ldlibs *variant-ldlibs* - :libname lib-name + :libname libclasp-name :inputs objects - :outputs (list lib))) + :outputs (list libclasp))) (ninja:write-build output-stream :phony - :inputs (list lib) + :inputs (list libclasp) :outputs (list (build-name target))) (when *variant-default* (loop for input in generated @@ -430,10 +430,10 @@ :inputs (list input) :outputs (list output))) (ninja:write-build output-stream :install-file - :inputs (list lib) - :outputs (list lib-installed)) + :inputs (list libclasp) + :outputs (list libclasp-installed)) (ninja:write-build output-stream :phony - :inputs (list* lib-installed + :inputs (list* libclasp-installed products) :outputs (list "install_lib")))) @@ -442,9 +442,10 @@ &key objects sifs &allow-other-keys &aux (exe (make-source "iclasp" :variant)) (exe-installed (make-source "iclasp" :package-bin)) - (ilib (make-source "libiclasp.a" :variant-lib)) - (ilib-installed (make-source "libiclasp.a" :package-lib)) - (lib (make-source #+darwin "libclasp.dylib" #-darwin "libclasp.so" :variant-lib)) + (libiclasp-name (lib-filename configuration "libiclasp")) + (libiclasp (make-source libiclasp-name :variant-lib)) + (libiclasp-installed (make-source libiclasp-name :package-lib)) + (libclasp (make-source (lib-filename configuration "libclasp" :dynamic t) :variant-lib)) (symlink (make-source (if (member :cando (extensions configuration)) "cando" "clasp") @@ -459,12 +460,17 @@ (cleap-symlink-installed (make-source "cleap" :package-bin))) (ninja:write-build output-stream :ar :inputs objects - :outputs (list ilib)) + :outputs (list libiclasp)) (ninja:write-build output-stream :link :variant-ldflags *variant-ldflags* - :variant-ldlibs (format nil "-lclasp ~a" *variant-ldlibs*) + :variant-ldlibs (concatenate 'string + (if (static-linking-p configuration) + #+darwin "-Wl,-all_load -lclasp -Wl,-noall_load " + #-darwin "-Wl,-whole-archive -lclasp -Wl,-no-whole-archive" + "-lclasp ") + *variant-ldlibs*) :inputs objects - :order-only-inputs (list lib) + :order-only-inputs (list libclasp) :outputs (list exe)) (ninja:write-build output-stream :symbolic-link :inputs (list exe) @@ -476,7 +482,7 @@ :target (file-namestring (source-path exe)) :outputs (list cleap-symlink))) (ninja:write-build output-stream :phony - :inputs (append (list exe symlink ilib) + :inputs (append (list exe symlink libiclasp) (when (member :cando (extensions configuration)) (list cleap-symlink)) (when (and *variant-default* @@ -490,8 +496,8 @@ :inputs (list exe) :outputs (list exe-installed)) (ninja:write-build output-stream :install-file - :inputs (list ilib) - :outputs (list ilib-installed)) + :inputs (list libiclasp) + :outputs (list libiclasp-installed)) (ninja:write-build output-stream :symbolic-link :inputs (list exe-installed) :target (file-namestring (source-path exe-installed)) @@ -509,7 +515,7 @@ "install_extension_code" "install_bin" "install_lib" - ilib-installed + libiclasp-installed exe-installed symlink-installed) (when (member :cando (extensions configuration)) diff --git a/src/koga/setup.lisp b/src/koga/setup.lisp index de1d5fcc65..efd76138d4 100644 --- a/src/koga/setup.lisp +++ b/src/koga/setup.lisp @@ -239,6 +239,7 @@ writing the build and variant outputs." :install-generated install-generated :package-bin (resolve-package-path (bin-path *configuration*)) :package-share (resolve-package-path (share-path *configuration*)) + :package-syslib (resolve-package-path (syslib-path *configuration*)) :package-lib (resolve-package-path (lib-path *configuration*)) :package-generated (resolve-package-path install-generated) *root-paths*))