Skip to content

Commit

Permalink
Add static linking option
Browse files Browse the repository at this point in the history
  • Loading branch information
yitzchak committed Dec 7, 2024
1 parent b2f2dbb commit ef585e8
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 23 deletions.
10 changes: 9 additions & 1 deletion src/gctools/snapshotSaveLoad.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 +
Expand Down
1 change: 1 addition & 0 deletions src/koga/config-header.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
13 changes: 13 additions & 0 deletions src/koga/configure.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
50 changes: 28 additions & 22 deletions src/koga/ninja.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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"))))

Expand All @@ -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")
Expand All @@ -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)
Expand All @@ -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*
Expand All @@ -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))
Expand All @@ -509,7 +515,7 @@
"install_extension_code"
"install_bin"
"install_lib"
ilib-installed
libiclasp-installed
exe-installed
symlink-installed)
(when (member :cando (extensions configuration))
Expand Down
1 change: 1 addition & 0 deletions src/koga/setup.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -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*))
Expand Down

0 comments on commit ef585e8

Please sign in to comment.