summary refs log tree commit diff
path: root/pkgs/development/lisp-modules/clwrapper
diff options
context:
space:
mode:
authorMichael Raskin <7c6f434c@mail.ru>2014-11-14 15:23:29 +0300
committerMichael Raskin <7c6f434c@mail.ru>2014-11-15 15:40:45 +0300
commit82a4776bf99e1c4e2896c4fc1c3405606cc374a9 (patch)
treeba084068eaca8cceaeb6faa820b1caeb614d397d /pkgs/development/lisp-modules/clwrapper
parent128b1af2e89ae8de450be909f9fa83acb095a2ce (diff)
downloadnixlib-82a4776bf99e1c4e2896c4fc1c3405606cc374a9.tar
nixlib-82a4776bf99e1c4e2896c4fc1c3405606cc374a9.tar.gz
nixlib-82a4776bf99e1c4e2896c4fc1c3405606cc374a9.tar.bz2
nixlib-82a4776bf99e1c4e2896c4fc1c3405606cc374a9.tar.lz
nixlib-82a4776bf99e1c4e2896c4fc1c3405606cc374a9.tar.xz
nixlib-82a4776bf99e1c4e2896c4fc1c3405606cc374a9.tar.zst
nixlib-82a4776bf99e1c4e2896c4fc1c3405606cc374a9.zip
Add support for creation of executables with SBCL — hacks are for shared libraries
Diffstat (limited to 'pkgs/development/lisp-modules/clwrapper')
-rwxr-xr-xpkgs/development/lisp-modules/clwrapper/build-with-lisp.sh61
1 files changed, 61 insertions, 0 deletions
diff --git a/pkgs/development/lisp-modules/clwrapper/build-with-lisp.sh b/pkgs/development/lisp-modules/clwrapper/build-with-lisp.sh
new file mode 100755
index 000000000000..3e37cc0b8f7b
--- /dev/null
+++ b/pkgs/development/lisp-modules/clwrapper/build-with-lisp.sh
@@ -0,0 +1,61 @@
+#! /bin/sh
+# Part of NixPkgs package collection
+# This script can be used at your option under the same license as NixPkgs or
+# under MIT/X11 license
+
+lisp="$1"
+systems="$2"
+target="$3"
+code="$4"
+
+NIX_LISP_SKIP_CODE=1 NIX_LISP_COMMAND="$lisp" source "$(dirname "$0")/cl-wrapper.sh"
+
+NIX_LISP_BUILD_CODE=
+
+case "$NIX_LISP" in
+        sbcl)
+                NIX_LISP_BUILD_CODE="(progn
+                  (sb-ext:with-unlocked-packages (:sb-sys :sb-alien)
+                    (let*
+                      (
+                        (old-fn (symbol-function 'sb-alien::dlopen-or-lose))
+                        (old-ldlp #.(sb-posix:getenv \"LD_LIBRARY_PATH\"))
+                        (ldlp-merged nil)
+                        )
+                        (defun sb-alien::dlopen-or-lose (&rest args)
+                          (or
+                            (ignore-errors (progn (apply old-fn args)))
+                            (and 
+                              args
+                              (loop
+                                for path in (list $(echo "$NIX_LISP_LD_LIBRARY_PATH" | sed -e 's/:/" "/g; s/^/"; s/$/"'))
+                                for try := (apply old-fn 
+                                             (format nil "~a/~a" path (first args))
+                                             (cdr args))
+                                )
+                               )
+                            )
+                          )
+                      ))
+                  (sb-ext:save-lisp-and-die \"$target\"
+                  :toplevel (lambda ()
+                    (setf common-lisp:*standard-input* (sb-sys::make-fd-stream 0 :input t :buffering :line))
+                    (setf common-lisp:*standard-output* (sb-sys::make-fd-stream 1 :output t :buffering :line))
+                    $code)
+                    :executable t :save-runtime-options t :purify t))"
+                systems=":sb-posix $systems"
+                ;;
+        ecl)
+                NIX_LISP_BUILD_CODE="(asdf:make-build (first (list $systems)) :type :program :monolithic nil :epilogue-code '(progn (defpackage :asdf/image) $code) :move-here \"$target\")"
+                ;;
+        clisp)
+                NIX_LISP_BUILD_CODE="(ext:saveinitmem \"$target\" :norc t :init-function (lambda () $code (ext:bye)) :script nil :executable 0)"
+                ;;
+esac
+
+"$lisp" \
+  "$NIX_LISP_EXEC_CODE" "(require :asdf)" \
+  "$NIX_LISP_EXEC_CODE" "(load \"$NIX_LISP_ASDF/lib/common-lisp/asdf/build/asdf.lisp\")" \
+  "$NIX_LISP_EXEC_CODE" "(mapcar 'require (list $systems))" \
+  "$NIX_LISP_EXEC_CODE" "$NIX_LISP_BUILD_CODE" \
+  "$NIX_LISP_EXEC_CODE" "(quit)"