Skip to content

Commit 574a36b

Browse files
committed
Add make-binary support to dump dynamic libraries together
1 parent 6dade22 commit 574a36b

File tree

1 file changed

+51
-5
lines changed

1 file changed

+51
-5
lines changed

src/make-binary.lisp

Lines changed: 51 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,60 @@
44
(in-package :starwar)
55

66
(defparameter *compression* 9)
7+
(defparameter *libprefix* "lib/")
8+
(defvar *libraries* nil)
9+
10+
(defun libpath (prefix)
11+
(merge-pathnames prefix (uiop/os:getcwd)))
12+
13+
(defun get-libraries-names (&key (loaded-only t))
14+
(remove-duplicates
15+
(mapcar #'cffi:foreign-library-pathname
16+
(cffi:list-foreign-libraries :loaded-only loaded-only))))
17+
18+
(defun get-libraries (&optional (from "/lib/"))
19+
(loop for l in (get-libraries-names)
20+
for lfrom = (merge-pathnames l from)
21+
for lpath = (probe-file lfrom)
22+
when lpath
23+
collect lfrom))
24+
25+
(defun dump-libraries (&optional (to *libprefix*))
26+
(format t "~%LIBPATH: ~a~%" (libpath to))
27+
(ensure-directories-exist (libpath to))
28+
(let ((libs (get-libraries)))
29+
(setq *libraries* (get-libraries-names))
30+
(loop for lib in (get-libraries)
31+
do (sb-ext:run-program "/bin/cp"
32+
(list "-v"
33+
(namestring lib)
34+
(namestring (libpath to)))
35+
:output *standard-output*))))
36+
37+
(defun load-library (library-name)
38+
(cffi:load-foreign-library library-name))
39+
40+
(defun import-libraries (&optional (libpath *libprefix*))
41+
(pushnew libpath
42+
cffi:*foreign-library-directories*
43+
:test #'equal)
44+
(loop for l in *libraries*
45+
do (load-library l)))
46+
47+
(defun close-libraries ()
48+
(loop for library in (cffi:list-foreign-libraries :loaded-only t)
49+
do (cffi:close-foreign-library library)))
50+
51+
(defun main-wrapper ()
52+
(import-libraries)
53+
(starwar:main))
754

8-
(defun dump-binaries ()
9-
(cffi)
10-
)
1155

1256
(defun make-binary ()
57+
(dump-libraries) ;; put all libraries into /lib
58+
(close-libraries) ;; close currently open libraries
1359
(sb-ext:save-lisp-and-die #+unix "starwar-linux"
1460
#+win32 "starwar-win32.exe"
15-
:toplevel #'starwar:main
61+
:toplevel #'main-wrapper
1662
:executable t
17-
:compression compression))
63+
:compression *compression*))

0 commit comments

Comments
 (0)