#  Re: Build SBCL on Termux (fail)
vit01 (mira, 1) → vit01  –  11:49:43 2016-07-03

// translation of my "progress"

Attempt to build SBCL on Termux device. Now this crashes at "make-genesis-2.sh" part because of "double defun" error.

====
# Open Termux
# Emacs is required for etags, Clang - for build, GCC - for nm and alternative build.

apt install gcc clang make emacs proot
git clone https://github.com/sbcl/sbcl
cd sbcl
find ./ -name "*.sh" | xargs termux-fix-shebang
termux-fix-shebang src/runtime/linux-nm
====


Create file lisp.sh:

====
#!/system/xbin/bash

dir=/path/to/other/rootfs

proot -R $dir $dir/usr/bin/sbcl ${@}
====


"Other rootfs" is a chroot environment having sbcl-arm already installed inside. I used archlinux-arm for this (see my previous post); you can take sbcl not only from native archlinux repositories, but also from debian armhf package (unpack .deb and place binaries by hand).

====
chmod +x *.sh # yes, for all .sh

cd src/runtime
====


Edit two files: Config.arm-linux and Config.arm-android. Build scripts use the first one on Termux. We need to put in order these configs.

In the file Config.arm-linux change

OS_SRC = linux-os.c arm-linux-os.c

to

OS_SRC = linux-os.c arm-linux-os.c android-os.c arm-android-os.c

taken from Config.arm-android

====
cd ../../
# start build

./make.sh --prefix=/data/data/com.termux/files/usr --arch=arm --with-android --xc-host='./lisp.sh'
====


If you build using Clang, you can skip next stages. GCC generates incorrect code, so we have nothing to do with that. You'd better use clang.

#### Proceed to alternative GCC reality...

Wait previous command to fail with "undefined reference to call_into_lisp". It's "alright", continue.

Copy all files from output/ and src/runtime/genesis/ to the host machine (having already git cloned sbcl sources). Also move src/runtime/arm-assem.S, src/runtime/ldso-stubs.S and compile both of them using NDK. You should pass -c parameter to GCC for ldso-stubs.S proper compilation.

Move arm-assem.o and ldso-stubs.o back to the phone. Finish one of the first build stages.

====
cd src/runtime

gcc -g -o sbcl arm-assem.o ldso-stubs.o alloc.o backtrace.o breakpoint.o coreparse.o dynbind.o funcall.o gc-common.o globals.o interr.o interrupt.o largefile.o monitor.o os-common.o parse.o print.o purify.o pthread-futex.o regnames.o run-program.o runtime.o safepoint.o save.o search.o thread.o time.o util.o validate.o vars.o wrap.o arm-arch.o linux-os.o arm-linux-os.o android-os.o arm-android-os.o gencgc.o -ldl -lm

# If you have android-os.o and arm-android-os.o files missing, you should compile them by hand too.
====


Initial sbcl binary is ready, cast additional magic spells...

====
nm -gp sbcl | grep -v " [FUw] " > sbcl.nm

cd ../../

make CFLAGS="-fPIE" -C tools-for-build -I./src/runtime grovel-headers
tools-for-build/grovel-headers > output/stuff-groveled-from-headers.lisp
make -C src/runtime after-grovel-headers
====


Start Lisp stage of compilation

./make-host-2.sh

#### End of alternative GCC reality

Wait some time...
Lisp compiler prints a double defun error during the parsing of lisp-obj files for cold sbcl.core generation.

Clang won't help with that too.