Documentation: Making CMUCL-compiled files executable

On GNU/Linux systems running kernel 2.2 or greater, CMUCL-compiled FASL files can be made directly executable by the kernel by registering them with the binfmt_misc module. This mechanism requires the user to have root access, and obviously to have compiled binfmt_misc support in the kernel (you can check for this in /proc/filesystems).

     # mount -t binfmt_misc none /proc/sys/fs/binfmt_misc
     # echo ':lisp:E::x86f::/usr/local/bin/lisp-start:' > /proc/sys/fs/binfmt_misc/register

These steps require root privileges; you may wish to add those lines to your boot files (for instance in a file in the directory /etc/rc.local), so that they are executed automatically each time your machine boots. [The first step (mounting the binfmt_misc filesystem) is only required for kernel versions after 2.4.13 or 2.4.2-ac.]

You must also create an executable shell script /usr/local/bin/lisp-start containing the following (you may need to adjust paths, depending on where you installed CMUCL):

   #!/bin/sh

   CMUCLLIB=/opt/cmucl/lib/cmucl/lib
   export CMUCLLIB

   exec /opt/cmucl/bin/lisp -quiet -noinit -batch -load ${1+"$@"}

The next step is to generate a FASL file for your application. The FASL file, which has a platform-dependent filename extension such as x86f or sparcf, contains a fast-loading, compiled representation of your CL source code. A FASL file can be obtained by using the COMPILE-FILE function. If the application comprises more than a single source file, compile each one individually, then concatenate all the FASL files into a single one, in the same order as you would have loaded them. You then need to make the FASL file executable, using the chmod command.

     % chmod a+x whatever.x86f
     % ./whatever.x86f

Any commandline arguments can be accessed at the end of the list EXT:*COMMAND-LINE-STRINGS*. See Paul Foley's extended solution to this problem, that also allows you to make CL source files executable.

by Paul Foley and Eric Marsden