Last active
April 30, 2020 14:05
-
-
Save YasuakiHonda/98b2496f10642cdc080666b02b3db001 to your computer and use it in GitHub Desktop.
How to cross-compile Maxima for Android using ECL20.4.24 (Embeddable Common Lisp)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Tested environment: Debian 10 Linux, ecl-20.4.24.tgz, android-ndk-r21-linux-x86_64.zip, maxima-5.43.2.tar.gz. | |
Shell is bash. | |
Save NDK-setup.sh and maxima-cross.lisp in ~ directory. Both are available in this Gist. | |
Expand ecl-20.4.24.tgz into ~/ecl-20.4.24 directory. | |
Expand android-ndk-r21-linux-x86_64.zip into ~/android-ndk-r21 directory. | |
1. Build the host ECL, as specified in ~/ecl-20.4.24/INSTALL file. | |
2. Configure the toolchain, by using NDK-setup.sh saved in ~ downloaded from this Gist: | |
% source ~/NDK-setup.sh | |
3. Build and install the target library, as specified in ~/ecl-20.4.24/INSTALL file. | |
~/ecl-20.4.24/ecl-android-host is created and binary and libraries are installed there. | |
We need to keep cmpdefs.lsp created during the build of target library, with slight modification. | |
% sed s/defvar/defparameter/g ~/ecl-20.4.24/build/cmp/cmpdefs.lsp > ~/ecl-20.4.24/ecl-android-host/cmpdefs.lsp | |
Expand maxima-5.43.2.tar.gz into ~/maxima-5.43.2 directory. | |
We need two files to be modified to compile maxima smoothly. | |
1) In ~/maxima-5.43.2/lisp-utils/defsystem.lisp, line 4155, "lisp:require" -> "cl:require" | |
2) In ~/maxima-5.43.2/src/maxima.system, line 83, "'(progn (require :defsystem)" -> "'(progn" | |
% cd ~/maxima-5.43.2/src | |
% mkdir binary-ecl; mkdir binary-ecl/numerical/; mkdir binary-ecl/numerical/slatec | |
% source ~/NDK-setup.sh | |
% ~/ecl-20.4.24/ecl-android-host/bin/ecl | |
> (load "~/maxima-cross.lisp") | |
> (quit) | |
% file binary-ecl/maxima | |
binary-ecl/maxima: ELF 32-bit LSB shared object, ARM, EABI5 version 1 (SYSV), dynamically linked, interpreter /system/bin/linker, with debug_info, not stripped | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;;; Copyright 2020, Yasuaki Honda, yasuaki.honda@gmail.com | |
;;; GPL v2 | |
;;; host ecl needs to run in ~/maxima-5.43.2/src directory | |
(load "maxima-package.lisp") | |
(compile (intern "MAKE-UNSPECIAL" :maxima) | |
'(lambda (s) | |
(when (symbolp s) | |
(format t "~%;;; Declaring ~A as NOT SPECIAL" s) | |
(ffi::c-inline (s) (:object) :object | |
"((#0)->symbol.stype = stp_ordinary, #0)" | |
:one-liner t)))) | |
(load "~/ecl-20.4.24/ecl-android-host/cmpdefs.lsp") | |
(load "../lisp-utils/defsystem.lisp") | |
(load "maxima.system") | |
(funcall (find-symbol "OPERATE-ON-SYSTEM" :make) | |
"maxima" :compile :load-source-instead-of-binary t) | |
(setf (symbol-value (find-symbol "*AUTOCONF-LD-FLAGS*" :maxima)) "") | |
(build-maxima-lib) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Copyright 2020, Yasuaki Honda, yasuaki.honda@gmail.com | |
# GPL v2 | |
export ECL_TO_RUN=~/ecl-20.4.24/ecl-android-host/bin/ecl | |
export NDK_PATH=~/android-ndk-r21 | |
export ANDROID_API=28 | |
export TOOLCHAIN_PATH=$NDK_PATH/toolchains/llvm/prebuilt/linux-x86_64 | |
export PATH=$TOOLCHAIN_PATH/bin:$PATH | |
export SYSROOT=$TOOLCHAIN_PATH/sysroot | |
export LDFLAGS="--sysroot=${SYSROOT} -D__ANDROID_API__=${ANDROID_API} -fuse-ld=bfd" | |
export CPPFLAGS="--sysroot=${SYSROOT} -D__ANDROID_API__=${ANDROID_API} -isystem ${SYSROOT}/usr/include/arm-linux-androideabi" | |
export CC=armv7a-linux-androideabi28-clang | |
export CXX=armv7a-linux-androideabi28-clang++ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
It was necessary to modify two source files in Maxima-5.43.2. They are lisp-utils/defsystem.lisp and src/maxima.system. | |
The auther has reported these two as bugs to the maxima mailing list, then we concluded to fix them. | |
As one of maintainers of Maxima, I have already committed the fixes to the main source tree. | |
The later versions (either 5.43.3 if any, or 5.44.0) will already include these modifications, so manual fixing can be skipped. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment