diff --git a/test/ecl-make-image.script b/test/ecl-make-image.script new file mode 100644 index 0000000000000000000000000000000000000000..ba8bea80e35f87c416842d227e519dc27b26d343 --- /dev/null +++ b/test/ecl-make-image.script @@ -0,0 +1,8 @@ +;;; -*- Lisp -*- + +(DBG "Test ld-flags in make-image. Should load from ecl-make-image/") + +#+ecl +(progn + (chdir #P"ecl-make-image/") + (load "readme.lisp")) diff --git a/test/ecl-make-image/hello.lisp b/test/ecl-make-image/hello.lisp new file mode 100644 index 0000000000000000000000000000000000000000..ee28f5d1cc9670e0638be958aea2a0c9e34a73f9 --- /dev/null +++ b/test/ecl-make-image/hello.lisp @@ -0,0 +1,8 @@ +(in-package #:cl-user) + +(ffi::clines "extern const char *hello_string;") + +(ffi::def-foreign-var ("hello_string" +hello-string+) (* :char) nil) + +(print (ffi:convert-from-foreign-string +hello-string+)) + diff --git a/test/ecl-make-image/hello_aux.c b/test/ecl-make-image/hello_aux.c new file mode 100644 index 0000000000000000000000000000000000000000..7b8580f6016da14bffdf2d6b48edcc4be3ae43da --- /dev/null +++ b/test/ecl-make-image/hello_aux.c @@ -0,0 +1 @@ +const char *hello_string = "Hello world!"; diff --git a/test/ecl-make-image/hellow.asd b/test/ecl-make-image/hellow.asd new file mode 100644 index 0000000000000000000000000000000000000000..7e2a49814ec614fd06363823896934c43347522e --- /dev/null +++ b/test/ecl-make-image/hellow.asd @@ -0,0 +1,3 @@ +(defsystem #:hellow + :serial t + :components ((:file "hello"))) diff --git a/test/ecl-make-image/readme.lisp b/test/ecl-make-image/readme.lisp new file mode 100644 index 0000000000000000000000000000000000000000..01a0d4a8bc1ff1051f56b307694d06d42413547d --- /dev/null +++ b/test/ecl-make-image/readme.lisp @@ -0,0 +1,86 @@ +;;; +;;; DESCRIPTION: +;;; +;;; This file uses a "Hellow world!" string which is in an another C +;;; file called hello_aux.c. Both hello.lisp and hello_aux.c are +;;; compiled and linked into either +;;; +;;; 1) a FASL file (see build_fasl.lisp) +;;; 2) a shared library (see build_dll.lisp) +;;; 3) or a standalone executable file. (build_exe.lisp) +;;; +;;; USE: +;;; +;;; Launch a copy of ECL and load this file in it +;;; +;;; (load "readme.lisp") +;;; +(require 'asdf) + +(format t " +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;;; +;;; BUILDING hello_aux.o FILE +;;; +") + +;;; +;;; * We compile hello.lisp and hello_aux.c separately. +;;; +;; (compile-file "hello.lisp" :system-p t) + +(c::compiler-cc "hello_aux.c" (compile-file-pathname "hello_aux.c" :type :object)) + +(format t " +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;;; +;;; BUILDING A STANDALONE EXECUTABLE +;;; +") + +;; +;; * Combine files in a standalone executable. We reuse the files +;; from the previous example +;; + +(defconstant +standalone-exe+ (compile-file-pathname "hellow" :type :program)) + +(push (make-pathname :name nil :type nil :version nil + :defaults *load-truename*) + asdf:*central-registry*) + +(asdf:make-build :hellow + :type :program + :move-here "./" + :prologue-code "printf(\"Good morning sunshine!\");" + :epilogue-code '(progn + (format t "~%Good bye sunshine.~%") + (ext:quit 0)) + :ld-flags + (list (namestring (compile-file-pathname "hello_aux.c" :type :object)))) + +;; This doesnt seem to work +;; (asdf:operate 'asdf:program-op :hellow +;; :ld-flags +;; (list (namestring (compile-file-pathname "hello_aux.c" :type :object)))) + +;; +;; * Test the program +;; +(format t " +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;;; +;;; TESTING A STANDALONE EXECUTABLE +;;; + +") +(uiop:run-program (format nil "./~A" +standalone-exe+) :output *standard-output*) + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;;; +;;; CLEAN UP +;;; + +;; (delete-file (compile-file-pathname "hello.lisp" :type :object)) +(delete-file (compile-file-pathname "hello_aux.c" :type :object)) +(delete-file +standalone-exe+)