example 'cl-repl': add docu for cross-compiling single file or asdf lib

This commit is contained in:
pls.153 2023-02-25 12:09:43 +01:00
parent 45d6984bec
commit b5d0642812
4 changed files with 112 additions and 4 deletions

7
examples/cl-repl/lib.asd Normal file
View file

@ -0,0 +1,7 @@
;;; for cross-compiling your own library to put on the mobile device
(defsystem :lib
:serial t
:depends-on ()
:components ())

View file

@ -366,7 +366,7 @@
'(case ccase ecase ctypecase etypecase handler-bind handler-case catch
defclass defgeneric defstruct defun defmacro defmethod destructuring-bind do
do* dolist dotimes do-all-symbols do-external-symbols do-symbols flet labels
lambda let let* loop multiple-value-bind prog progn prog1 prog2 qlet
lambda let let* loop multiple-value-bind prog progn prog1 prog2 progv qlet
typecase unless when with-open-file with-output-to-string
with-input-from-string qml::do-string qml::do-with qml::when-it
qml::when-it* qml::while qml::while-it))
@ -725,6 +725,9 @@
:bold bold
:line line)))
(defun eval-expression* ()
(qlater 'eval-expression)) ; QLATER for key release event
(defun eval-expression (&optional single (history t))
(let ((text (string-trim '(#\Space #\Tab #\Newline #\Return)
(or single (q< |text| ui:*edit*)))))
@ -944,7 +947,7 @@
(let* ((edit (active-edit))
(text (q< |text| edit))
(pos (or cursor-position (q< |cursorPosition| edit)))
(start pos)
(start (max 0 (1- pos)))
ch)
(flet ((select (start end)
(setf *selection-start* start
@ -1027,7 +1030,8 @@
(defun button-pressed () ; called from QML
(flet ((hide ()
(q! |close| ui:*clipboard-menu*))
;; QLATER for key release event
(qlater (lambda () (q! |close| ui:*clipboard-menu*))))
(timer ()
(q! |restart| ui:*menu-timer*)))
(let ((button (intern (lispify (q< |objectName| *caller*))
@ -1045,7 +1049,7 @@
(:clear (clear) (timer))
(:open-file (open-file) (timer))
(:save-file (save-file) (timer))
(:eval (eval-expression) (timer))
(:eval (eval-expression*) (timer))
(:history-back (history-move "back"))
(:history-forward (history-move "forward"))
((:up :down :left :right)

View file

@ -0,0 +1,72 @@
;;; check target
(defvar *32bit* (<= most-positive-fixnum (expt 2 32)))
(let ((arg (first (ext:command-args))))
(mapc (lambda (name feature)
(when (search name arg)
(pushnew feature *features*)))
(list "/ecl-android" "/ecl-ios")
(list :android :ios)))
#+(or android ios)
(pushnew :mobile *features*)
;;; compile ASDF system
(require :asdf)
(require :cmp)
(push (merge-pathnames "../")
asdf:*central-registry*)
(setf *default-pathname-defaults*
(truename (merge-pathnames "../../../"))) ; LQML root
(defvar *current*
(let ((name (namestring *load-truename*)))
(subseq name
(length (namestring *default-pathname-defaults*))
(1+ (position #\/ name :from-end t)))))
(dolist (file (list "package" "x" "ecl-ext" "ini" "qml")) ; load LQML symbols
(load (merge-pathnames file "src/lisp/")))
(defun cc (&rest args)
(apply 'concatenate 'string args))
(progn
(defvar cl-user::*tr-path* (truename (cc *current* "i18n/")))
(load "src/lisp/tr"))
#-mobile
(progn
(require :ecl-curl)
(asdf:make-build "lib"
:monolithic t
:type :fasl
:move-here (cc *current* "build/tmp/")))
#+mobile
(progn
(pushnew :interpreter *features*)
(defvar *asdf-system* "lib")
(defvar *ql-libs* (cc *current* "ql-libs.lisp"))
(defvar *build-type* :fasl)
(defvar *library-path* (format nil "~Abuild-~A/tmp/"
*current*
#+android "android"
#+ios "ios"))
(defvar *require* (list :ecl-curl))
(load "platforms/shared/make"))
;;; rename lib
(let* ((from #-mobile (cc *current* "build/tmp/lib--all-systems.fasb")
#+mobile (cc *library-path* "lib--all-systems.fasb"))
(to "lib.fas")
(to* #-mobile (cc *current* "build/tmp/" to)
#+mobile (cc *library-path* to)))
(when (probe-file to*)
(delete-file to*))
(rename-file from to))

View file

@ -168,3 +168,28 @@ startup.
If your local web server doesn't seem to work, please check your firewall
settings.
Cross-compile a single file (or ASDF lib)
-----------------------------------------
Say you have developed something useful, and want to put a cross-compiled
version of it on your mobile device.
### Single file
```
$ECL_ANDROID/../ecl-android-host/bin/ecl --norc \
--load ~/lqml/platforms/android/cross-compile.lisp
> (compile-file "my.lisp") ; will produce 'my.fas'
```
### ASDF library
Define a system in `lib.asd`, then do:
```
cd build-android
$ECL_ANDROID/../ecl-android-host/bin/ecl --norc --shell ../make-lib.lisp ; will produce 'lib.fas'
```