Compile Chez Scheme On Android ARM

September 15, 2017

In a recent exercise I described my new tablet computer, and talked about installing Guile Scheme because I could not get Chez Scheme to compile. I have finally been able to compile my preferred Scheme interpreter, Chez Scheme, on my Android ARM tablet. This note describes how I did it.

Chez Scheme is written partly in C and partly in Scheme; as a consequence, it requires a working Scheme compiler to be compiled. For popular platforms, such as Linux, Chez Scheme is distributed with the Scheme portion of the compiler already compiled, but for the Android ARM platform, we have to compile the Scheme portion of the compiler ourselves. The procedure is to compile Chez Scheme on some available platform (we will use Linux), cross-compile the Scheme portion of the compiler for the Android ARM platform, compile the C portion of the compiler on Android ARM, and then complete the build on Android ARM. It’s easier than it sounds. First, if you don’t already have Chez Scheme running on your Linux platform, perform the following steps to obtain and compile Chez Scheme (similar instructions apply on other platforms, go to the Chez Scheme Project Page for assistance):

cd /usr/local/src
sudo wget https://github.com/cisco/ChezScheme/archive/v9.4.tar.gz
gunzip v9.4.tar.gz
tar -xvf v9.4.tar
sudo rm v9.4.tar
cd ChezScheme-9.4
sudo ./configure
sudo make install

At this point you should have a working Chez Scheme system on the Linux computer. You might want to stop and play with it to make sure it works. Assuming that you compiled on an Intel system, the machine type was a6le, so perform the following steps to cross-compile to machine type arm32le for the Android ARM:

sudo mkdir boot/arm32le
cd a6le
sudo make -f Mf-boot arm32le.boot
cd ..
sudo ./configure -m=arm32le
sudo ./configure --workarea=arm32le
cd arm32le/s
sudo make -f Mf-cross m=a6le xm=arm32le base=../../a6le

Now the cross-compilation is complete and you are ready to work on the Android ARM system. Still on the desktop, pack up the complete Chez Scheme system:

cd /usr/local/src
sudo tar -czvf ChezScheme-9.4.tar.gz ChezScheme-9.4

We look next at the Android ARM tablet. We will be running under GnuRoot, so that must first be installed and configured. On the tablet, go to the Google Play Store and install program GnuRoot Debian; it should take only a few minutes. The environment installed by GnuRoot is minimal, so perform the following steps to install some useful software on your system:

apt-get update && apt-get -y upgrade
apt-get install build-essential ed vim m4 gawk
apt-get install ssh guile-2.0 python wget curl

Depending on your aspirations, you might want to install some other packages, or omit some of those shown above. Next, copy the .gz file to directory /usr/local/src on an Android tablet running GnuRoot; I did it by performing the following commands on the tablet, which was connected to my local network, but they are unlikely to work unmodified on your machine:

cd /usr/local/src
sftp phil@192.168.1.65
     cd /usr/local/src
     get ChezScheme-9.4.tar.gz
     quit

Once you have copied the .gz file to the tablet, perform the following steps there. It is odd to install and then uninstall X-windows, but Chez Scheme requires X-windows to compile, and doesn’t require it to run, so this sequence is correct (that was the trick that took me so long to figure out, delaying the compilation by several weeks):

apt-get install libncurses5-dev libncursesw5-dev
gunzip ChezScheme-9.4.tar.gz
tar -xvf ChezScheme-9.4.tar
rm ChezScheme-9.4.tar
cd ChezScheme-9.4
apt-get x11-common libx11-dev
cd arm32le/c
make
apt-get purge x11-common libx11-dev
cd ../s
make allx
cd ../..

At this point the program is compiled and ready to use. However, the install script doesn’t work properly, for some reason, so the program must be installed manually with the following commands:

cp arm32le/bin/scheme /usr/local/bin
cp arm32le/bin/petite /usr/local/bin
chmod +x /usr/local/bin/scheme
chmod +x /usr/local/bin/petite
mkdir /usr/local/csv9.4/arm32le
cp boot/arm32le/scheme.boot /usr/local/csv9.4/arm32le
cp boot/arm32le/petite.boot /usr/local/csv9.4/arm32le

And that’s it. To test your installation, type scheme at the command-line prompt; you should be rewarded with the Chez Scheme welcome text followed by a Scheme prompt:

Chez Scheme Version 9.4
Copyright 1984-2016 Cisco Systems, Inc.

>

Your task is to get your preferred programming environment working on your mobile device, and let us know how it works. If anyone installs Chez Scheme, I would appreciate your feedback on the instructions given above, particularly if you find any errors.

4 Responses to “Compile Chez Scheme On Android ARM”

  1. John Cowan said

    There is way too much “sudo” here: it’s a very bad policy to build as root. Build in one’s home directory or some other non-system place and then install as root. If you want to move the sources to /usr/bin/src afterwards, then do so.

  2. Vincent Manis said

    This article arrived at a very fortunate time for me, as I had an urgent need for an Android Scheme system. Some comments.

    I echo John Cowan, don’t use sudo. I keep my source trees elsewhere, and used sudo nowhere in my version of this.
    You might be tempted to do the Android side of this in your /home directory. Don’t. /home corresponds to a directory on the internal “SD card” (which is nothing of the sort). I don’t understand Android’s notion of file permissions, but pretty much, the SD directory is formatted with the FAT file system, and is mounted noexec. I created a /chez directory at the top of the hierarchy, and everything went flawlessly. (Google is my friend, I knew none of this till this morning).
    If you’re using the head of the git repository, get rid of the git history (nuke everything at the top level whose name starts with .git). I copied my ChezScheme directory to a chez-arm directory, nuked the history, and then downloaded chez-arm. Your battery charge probably won’t last long enough to download the history, and you don’t want it on the tablet anyway.
    I did the install the way it’s shown here, but you may have to adjust it slightly, depending on which version of Chez Scheme you’re using. I’m using the head of the Git repository, which shows up as version 9.4.1. Hint: note the version before downloading things to the tablet. So for me, the last stage was to copy the .boot files to /usr/lib/csv9.4.1/arm32le.
    I haven’t finished the job. I have Chez Scheme working just fine on my tablet, but I haven’t yet automated the setup by writing a shell script that does it automatically. So, chances are that I’ll forget all of this by the time I have to do it again in the absence of an automated, properly documented script.

    Thanks again for this article, it helped me a lot.

  3. programmingpraxis said

    @Vincent: You’re welcome. And thank you for your book, many years ago. It is still in my library.

    You and John are correct: I should not have used sudo. I copied the commands from an email from someone who had done the process previously, and didn’t stop to think about what I was doing. I know better than that, dammit.

    You are correct that Android file system permissions are mysterious, and that /home is mounted noexec. I stumbled over that, too. I did all of my work in /usr/local/src/ChezScheme-9.4.

    I did not use the git version of the program, instead I downloaded the 9.4 tarball on the main Chez Scheme page.

    I didn’t mention it in the exercise text, but I did a simple comparison of Chez and Guile, which I had been using until I could get Chez compiled. I used a simple Pollard-rho factoring program to factor (10**34-1)/9; it took 52 seconds for Chez and an astonishing 23 minutes for Guile (yes, I know that Pollard-rho is not the algorithm of choice for that factorization, but I wanted something that would take a while). In fact, I twice interrupted the Guile computation, thinking something was wrong, before letting it run to completion the third time. I’ve long thought that Chez is the best available implementation of Scheme, and this is once again confirmation of that.

    Thank you for your comments.

    Phil

Leave a comment