From 71f6e79532e3de86b98580036c3bd45096a6f646 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Daniel=20Kochma=C5=84ski?= <daniel@turtleware.eu>
Date: Tue, 11 Aug 2015 09:23:54 +0200
Subject: [PATCH] ecl: add test of ld-flags usage
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Signed-off-by: Daniel Kochmański <daniel@turtleware.eu>
---
 test/ecl-make-image.script      |  8 +++
 test/ecl-make-image/hello.lisp  |  8 +++
 test/ecl-make-image/hello_aux.c |  1 +
 test/ecl-make-image/hellow.asd  |  3 ++
 test/ecl-make-image/readme.lisp | 86 +++++++++++++++++++++++++++++++++
 5 files changed, 106 insertions(+)
 create mode 100644 test/ecl-make-image.script
 create mode 100644 test/ecl-make-image/hello.lisp
 create mode 100644 test/ecl-make-image/hello_aux.c
 create mode 100644 test/ecl-make-image/hellow.asd
 create mode 100644 test/ecl-make-image/readme.lisp

diff --git a/test/ecl-make-image.script b/test/ecl-make-image.script
new file mode 100644
index 000000000..ba8bea80e
--- /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 000000000..ee28f5d1c
--- /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 000000000..7b8580f60
--- /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 000000000..7e2a49814
--- /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 000000000..01a0d4a8b
--- /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+)
-- 
GitLab