diff --git a/examples/.android-ssl-test/.gitignore b/examples/.android-ssl-test/.gitignore new file mode 100644 index 0000000..d6b7ef3 --- /dev/null +++ b/examples/.android-ssl-test/.gitignore @@ -0,0 +1,2 @@ +* +!.gitignore diff --git a/examples/.android-ssl-test/app.asd b/examples/.android-ssl-test/app.asd new file mode 100644 index 0000000..bb8d33a --- /dev/null +++ b/examples/.android-ssl-test/app.asd @@ -0,0 +1,7 @@ +(defsystem :app + :serial t + :depends-on (#-depends-loaded :drakma) + :components ((:file "lisp/package") + (:file "lisp/ui-vars") + (:file "lisp/main"))) + diff --git a/examples/.android-ssl-test/app.pro b/examples/.android-ssl-test/app.pro new file mode 100644 index 0000000..970de5a --- /dev/null +++ b/examples/.android-ssl-test/app.pro @@ -0,0 +1,145 @@ +LISP_FILES = $$files(lisp/*) app.asd make.lisp + +android { + 32bit { + ECL = $$(ECL_ANDROID_32) + } else { + ECL = $$(ECL_ANDROID) + } + lisp.commands = $$ECL/../ecl-android-host/bin/ecl \ + -norc -shell $$PWD/make.lisp +} else:ios { + lisp.commands = $$(ECL_IOS)/../ecl-ios-host/bin/ecl \ + -norc -shell $$PWD/make.lisp +} else:unix { + lisp.commands = /usr/local/bin/ecl -shell $$PWD/make.lisp +} else:win32 { + lisp.commands = ecl.exe -shell $$PWD/make.lisp +} + +lisp.input = LISP_FILES + +win32: lisp.output = tmp/app.lib +!win32: lisp.output = tmp/libapp.a + +QMAKE_EXTRA_COMPILERS += lisp + +win32: PRE_TARGETDEPS = tmp/app.lib +!win32: PRE_TARGETDEPS = tmp/libapp.a + +QT += quick qml quickcontrols2 +TEMPLATE = app +CONFIG += c++17 no_keywords release +DEFINES += DESKTOP_APP INI_LISP INI_ASDF INI_ECL_CONTRIB +INCLUDEPATH = /usr/local/include +ECL_VERSION = $$lower($$system(ecl -v)) +ECL_VERSION = $$replace(ECL_VERSION, " ", "-") +LIBS = -L/usr/local/lib -lecl +LIBS += -L/usr/local/lib/$$ECL_VERSION +LIBS += -lasdf -lecl-help -ldeflate -lecl-cdb -lecl-curl -lql-minitar -lsockets +DESTDIR = . +TARGET = app +OBJECTS_DIR = tmp +MOC_DIR = tmp + +linux: LIBS += -L../../../platforms/linux/lib +macx: LIBS += -L../../../platforms/macos/lib +win32: LIBS += -L../../../platforms/windows/lib + +win32 { + LIBS += -lws2_32 + RC_ICONS = platforms/windows/icon.ico + + include(../../src/windows.pri) +} + +android { + DEFINES -= DESKTOP_APP + INCLUDEPATH = $$ECL/include + ECL_VERSION = $$lower($$system($$ECL/../ecl-android-host/bin/ecl -v)) + ECL_VERSION = $$replace(ECL_VERSION, " ", "-") + LIBS = -L$$ECL/lib -lecl + LIBS += -L$$ECL/lib/$$ECL_VERSION + LIBS += -lasdf -lecl-help -ldeflate -lecl-cdb -lecl-curl -lql-minitar -lsockets + LIBS += -L../../../platforms/android/lib + + equals(QT_MAJOR_VERSION, 6) { + QT += core-private + } + lessThan(QT_MAJOR_VERSION, 6) { + QT += androidextras + } + + ANDROID_MIN_SDK_VERSION = 21 + ANDROID_TARGET_SDK_VERSION = 34 + ANDROID_EXTRA_LIBS += $$ECL/lib/libecl.so + ANDROID_PACKAGE_SOURCE_DIR = ../platforms/android + + # can be downloaded from: + # https://github.com/KDAB/android_openssl/tree/master/latest + 32bit { + SSL_PATH = ../../../platforms/android/lib32 + } else { + SSL_PATH = ../../../platforms/android/lib + } + ANDROID_EXTRA_LIBS += $$SSL_PATH/libcrypto.so $$SSL_PATH/libssl.so + + 32bit { + ANDROID_ABIS = "armeabi-v7a" + } else { + ANDROID_ABIS = "arm64-v8a" + } +} + +ios { + DEFINES -= DESKTOP_APP + INCLUDEPATH = $$(ECL_IOS)/include + ECL_VERSION = $$lower($$system($ECL_IOS/../ecl-ios-host/bin/ecl -v)) + ECL_VERSION = $$replace(ECL_VERSION, " ", "-") + LIBS = -L$$(ECL_IOS)/lib -lecl + LIBS += -leclatomic -leclffi -leclgc -leclgmp + LIBS += -L$$(ECL_IOS)/lib/$$ECL_VERSION + LIBS += -lasdf -lecl-help -ldeflate -lecl-cdb -lecl-curl -lql-minitar -lsockets + LIBS += -L../../../platforms/ios/lib +} + +32bit { + android { + equals(QT_MAJOR_VERSION, 6) { + LIBS += -llqml32_armeabi-v7a + } + lessThan(QT_MAJOR_VERSION, 6) { + LIBS += -llqml32 + } + } + !android { + LIBS += -llqml32 + } + LIBS += -llisp32 +} else { + android { + equals(QT_MAJOR_VERSION, 6) { + LIBS += -llqml_arm64-v8a + } + lessThan(QT_MAJOR_VERSION, 6) { + LIBS += -llqml + } + } + !android { + LIBS += -llqml + } + LIBS += -llisp +} + +LIBS += -Ltmp -lapp +INCLUDEPATH += ../../../src/cpp + +HEADERS += ../../src/cpp/main.h +SOURCES += ../../src/cpp/main.cpp + +RESOURCES += $$files(qml/*) +RESOURCES += $$files(i18n/*.qm) + +lupdate_only { + SOURCES += i18n/tr.h +} diff --git a/examples/.android-ssl-test/build-android/install-run.sh b/examples/.android-ssl-test/build-android/install-run.sh new file mode 100755 index 0000000..a524da1 --- /dev/null +++ b/examples/.android-ssl-test/build-android/install-run.sh @@ -0,0 +1,6 @@ +# install/update (keeps app data) +adb install -r android-build/*.apk + +# try both +adb shell am start -n org.qtproject.example.app/org.qtproject.qt5.android.bindings.QtActivity # Qt5 +adb shell am start -n org.qtproject.example.app/org.qtproject.qt.android.bindings.QtActivity # Qt6 diff --git a/examples/.android-ssl-test/build-android/log.sh b/examples/.android-ssl-test/build-android/log.sh new file mode 100755 index 0000000..c532be9 --- /dev/null +++ b/examples/.android-ssl-test/build-android/log.sh @@ -0,0 +1,6 @@ +# filter for logcat to show only messages from: +# * (qlog ...) in Lisp +# * console.log(...) in QML + +adb logcat -c +adb logcat -s "[LQML]" diff --git a/examples/.android-ssl-test/build-ios/xcode.sh b/examples/.android-ssl-test/build-ios/xcode.sh new file mode 100755 index 0000000..2606894 --- /dev/null +++ b/examples/.android-ssl-test/build-ios/xcode.sh @@ -0,0 +1,3 @@ +../../../platforms/ios/cross-compile.sh ../make.lisp + +open app.xcodeproj diff --git a/examples/.android-ssl-test/build/.gitignore b/examples/.android-ssl-test/build/.gitignore new file mode 100644 index 0000000..d6b7ef3 --- /dev/null +++ b/examples/.android-ssl-test/build/.gitignore @@ -0,0 +1,2 @@ +* +!.gitignore diff --git a/examples/.android-ssl-test/i18n/readme.md b/examples/.android-ssl-test/i18n/readme.md new file mode 100644 index 0000000..acbd5fc --- /dev/null +++ b/examples/.android-ssl-test/i18n/readme.md @@ -0,0 +1,31 @@ + +Translations +------------ + +Wrap all strings which need to be translated in either `(tr "")` (Lisp files) +or `qsTr("")` (QML files). + +* compile app (either desktop or mobile, you may need `touch ../app.asd` to + force recompilation of all files); this will generate a dummy file `tr.h`, + containing all Lisp strings to translate + +* run Qt command `lupdate` (here: Spanish, French) for creating the translation + source files from both Lisp and QML strings: +``` + lupdate ../app.pro -ts es.ts fr.ts +``` +* translate all `*.ts` files using **Qt Linguist** + +* run Qt command `lrelease` to create compiled translation files: +``` + lrelease es.ts fr.ts +``` +* run respective `qmake` again (destop/mobile) in order to include all `*.qm` + files (compiled translations) + +* next time you compile the app, the translation files will be included as + resources in the executable + +Now when you launch the app, the translation file matching your system locale +setting of your platform (see `QLocale`) will be loaded, see `QTranslator` in +[main.cpp](../../../src/cpp/main.cpp). diff --git a/examples/.android-ssl-test/lisp/main.lisp b/examples/.android-ssl-test/lisp/main.lisp new file mode 100644 index 0000000..f78bd5d --- /dev/null +++ b/examples/.android-ssl-test/lisp/main.lisp @@ -0,0 +1,12 @@ +(in-package :app) + +#+android +(when (probe-file "libssl.so") + (ffi:load-foreign-library "libcrypto.so") + (ffi:load-foreign-library "libssl.so")) + +(defun ini () + (q> |text| ui:*label* + (first (last (multiple-value-list (drakma:http-request "https://duckduckgo.com")))))) + +(qlater 'ini) diff --git a/examples/.android-ssl-test/lisp/package.lisp b/examples/.android-ssl-test/lisp/package.lisp new file mode 100644 index 0000000..6689a82 --- /dev/null +++ b/examples/.android-ssl-test/lisp/package.lisp @@ -0,0 +1,4 @@ +(defpackage :app + (:use :cl :qml) + (:export)) + diff --git a/examples/.android-ssl-test/lisp/ui-vars.lisp b/examples/.android-ssl-test/lisp/ui-vars.lisp new file mode 100644 index 0000000..9a0d52e --- /dev/null +++ b/examples/.android-ssl-test/lisp/ui-vars.lisp @@ -0,0 +1,9 @@ +(defpackage ui + (:use :cl :qml) + (:export + #:*label*)) + +(in-package :ui) + +(defparameter *label* "label") + diff --git a/examples/.android-ssl-test/make.lisp b/examples/.android-ssl-test/make.lisp new file mode 100644 index 0000000..fabe425 --- /dev/null +++ b/examples/.android-ssl-test/make.lisp @@ -0,0 +1,89 @@ +;;; 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*) + +(when (probe-file "/etc/sailfish-release") + (pushnew :sfos *features*)) + +;;; copy Swank and ECL contrib files (mobile only) + +(defun cc (&rest args) + (apply 'concatenate 'string args)) + +#+mobile +(defvar *assets* #+android "../platforms/android/assets/lib/" + #+ios "../platforms/ios/assets/Library/") + +#+mobile +(defun shell (command) + (ext:run-program "sh" (list "-c" command))) + +;;; 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/"))) + +(progn + (defvar cl-user::*tr-path* (truename (cc *current* "i18n/"))) + (load "src/lisp/tr")) + +#-mobile +(progn + (require :ecl-curl) + (asdf:make-build "app" + :monolithic t + :type :static-library + :move-here (cc *current* "build/tmp/") + :init-name "ini_app")) + +#+mobile +(progn + (pushnew :interpreter *features*) + (defvar *asdf-system* "app") + (defvar *ql-libs* (cc *current* "ql-libs.lisp")) + (defvar *init-name* "ini_app") + (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* (format nil "build/tmp/app--all-systems.~A" + #+msvc "lib" + #-msvc "a")) + #+mobile (cc *library-path* "app--all-systems.a")) + (to #-msvc "libapp.a" + #+msvc "app.lib") + (to* #-mobile (cc *current* "build/tmp/" to) + #+mobile (cc *library-path* to))) + (when (probe-file to*) + (delete-file to*)) + (rename-file from to)) diff --git a/examples/.android-ssl-test/mkdirs.sh b/examples/.android-ssl-test/mkdirs.sh new file mode 100755 index 0000000..ad7c56f --- /dev/null +++ b/examples/.android-ssl-test/mkdirs.sh @@ -0,0 +1,3 @@ +mkdir build +mkdir build-android +mkdir build-ios diff --git a/examples/.android-ssl-test/platforms/android/AndroidManifest.xml b/examples/.android-ssl-test/platforms/android/AndroidManifest.xml new file mode 100644 index 0000000..1905d3f --- /dev/null +++ b/examples/.android-ssl-test/platforms/android/AndroidManifest.xml @@ -0,0 +1,86 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/examples/.android-ssl-test/ql-libs.lisp b/examples/.android-ssl-test/ql-libs.lisp new file mode 100644 index 0000000..1f08796 --- /dev/null +++ b/examples/.android-ssl-test/ql-libs.lisp @@ -0,0 +1,4 @@ +;;; define here eventual Quicklisp dependencies + +(ql:quickload :drakma) + diff --git a/examples/.android-ssl-test/qml/main.qml b/examples/.android-ssl-test/qml/main.qml new file mode 100644 index 0000000..0389dae --- /dev/null +++ b/examples/.android-ssl-test/qml/main.qml @@ -0,0 +1,15 @@ +import QtQuick 2.15 +import QtQuick.Controls 2.15 + +Item { + width: 300 + height: 500 + + Label { + objectName: "label" + text: "downloading..." + anchors.centerIn: parent + font.pixelSize: 24 + font.bold: true + } +} diff --git a/examples/.android-ssl-test/readme.md b/examples/.android-ssl-test/readme.md new file mode 100644 index 0000000..3522bfc --- /dev/null +++ b/examples/.android-ssl-test/readme.md @@ -0,0 +1,15 @@ +This is here for testing SSL on android. + +After doing `make apk`, please ensure files +``` +libssl.so +libcrypto.so +``` +are present in directory +``` +build-android/android-build/libs/arm64-v8a/ +``` + +When running the app, it should first display "downloading...", and after a few +seconds (if the android device is connected to the internet), it should display +"OK". diff --git a/examples/.android-ssl-test/run.lisp b/examples/.android-ssl-test/run.lisp new file mode 100644 index 0000000..917ac1a --- /dev/null +++ b/examples/.android-ssl-test/run.lisp @@ -0,0 +1,31 @@ +(in-package :qml-user) + +(require :asdf) + +(asdf:load-system :drakma) + +(push (merge-pathnames "./") + asdf:*central-registry*) + +(push :depends-loaded *features*) + +(asdf:operate 'asdf:load-source-op :app) + +(qset *quick-view* + |x| 0 + |y| 0) + +(defun option (name) + (find name (ext:command-args) :test 'search)) + +;;; trivial auto reload of all QML files after saving any change + +(when (option "-auto") + (load "lisp/qml-reload/auto-reload")) + +;;; for Slime after copying 'lqml-start-swank.lisp' from LQML sources +;;; to your Slime directory, which is assumed to be '~/slime/' + +(when (option "-slime") + (load "~/slime/lqml-start-swank")) ; for 'slime-connect' from Emacs +