| 1 |
;;; |
| 2 |
;;; DESCRIPTION: |
| 3 |
;;; |
| 4 |
;;; This file uses a "Hellow world!" string which is in an another C |
| 5 |
;;; file called hello_aux.c. Both hello.lisp and hello_aux.c are |
| 6 |
;;; compiled and linked into either |
| 7 |
;;; |
| 8 |
;;; 1) a FASL file (see build_fasl.lisp) |
| 9 |
;;; 2) a shared library (see build_dll.lisp) |
| 10 |
;;; 3) or a standalone executable file. (build_exe.lisp) |
| 11 |
;;; |
| 12 |
;;; USE: |
| 13 |
;;; |
| 14 |
;;; Launch a copy of ECL and load this file in it |
| 15 |
;;; |
| 16 |
;;; (load "readme.lisp") |
| 17 |
;;; |
| 18 |
|
| 19 |
(format t " |
| 20 |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
| 21 |
;;; |
| 22 |
;;; BUILDING A COMPOUND FASL FILE |
| 23 |
;;; |
| 24 |
") |
| 25 |
|
| 26 |
;;; |
| 27 |
;;; * We compile hello.lisp and hello_aux.c separately. |
| 28 |
;;; |
| 29 |
(compile-file "hello.lisp" :system-p t) |
| 30 |
|
| 31 |
(c::compiler-cc "hello_aux.c" (compile-file-pathname "hello_aux.c" :type :object)) |
| 32 |
|
| 33 |
;;; |
| 34 |
;;; * We combine both in a single FASL file |
| 35 |
;;; |
| 36 |
|
| 37 |
(defconstant +compound-fasl+ (compile-file-pathname "compound" :type :fasl)) |
| 38 |
|
| 39 |
(c::build-fasl +compound-fasl+ |
| 40 |
:lisp-files |
| 41 |
(list (compile-file-pathname "hello.lisp" :type :object)) |
| 42 |
:ld-flags |
| 43 |
(list (namestring (compile-file-pathname "hello_aux.c" :type :object)))) |
| 44 |
|
| 45 |
;;; |
| 46 |
;;; * We load both files |
| 47 |
;;; |
| 48 |
|
| 49 |
(load +compound-fasl+) |
| 50 |
|
| 51 |
|
| 52 |
(format t " |
| 53 |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
| 54 |
;;; |
| 55 |
;;; BUILDING A STANDALONE EXECUTABLE |
| 56 |
;;; |
| 57 |
") |
| 58 |
|
| 59 |
;; |
| 60 |
;; * Combine files in a standalone executable. We reuse the files |
| 61 |
;; from the previous example |
| 62 |
;; |
| 63 |
|
| 64 |
(defconstant +standalone-exe+ (compile-file-pathname "standalone" :type :program)) |
| 65 |
|
| 66 |
(c::build-program +standalone-exe+ |
| 67 |
:lisp-files |
| 68 |
(list (compile-file-pathname "hello.lisp" :type :object)) |
| 69 |
:ld-flags |
| 70 |
(list (namestring (compile-file-pathname "hello_aux.c" :type :object))) |
| 71 |
:epilogue-code |
| 72 |
'(si::quit)) |
| 73 |
|
| 74 |
;; |
| 75 |
;; * Test the program |
| 76 |
;; |
| 77 |
(si::system (format nil "./~A" +standalone-exe+)) |
| 78 |
|
| 79 |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
| 80 |
;;; |
| 81 |
;;; CLEAN UP |
| 82 |
;;; |
| 83 |
|
| 84 |
(delete-file (compile-file-pathname "hello.lisp" :type :object)) |
| 85 |
(delete-file (compile-file-pathname "hello_aux.c" :type :object)) |
| 86 |
(delete-file +compound-fasl+) |
| 87 |
(delete-file +standalone-exe+) |