Skip to content

Instantly share code, notes, and snippets.

@cellularmitosis
Last active December 12, 2021 18:38
Show Gist options
  • Save cellularmitosis/7c3a6d5cbd2505f25ac2e9ba788fdad2 to your computer and use it in GitHub Desktop.
Save cellularmitosis/7c3a6d5cbd2505f25ac2e9ba788fdad2 to your computer and use it in GitHub Desktop.
Installing clisp on OS X Leopard / PowerPC

Blog 2021/12/11

<- previous | index | next ->

Installing clisp on OS X Leopard / PowerPC

IMG_7373 copy

Note: these scripts assume you already have Xcode installed, see https://macintoshgarden.org/apps/apple-xcode and install Xcode 3.1.4.

It appears 2.39 was the last version of clisp which shipped a binary release for OS X / PowerPC:

It doesn't work out of the box

A bit of fiddling revealed that this binary release appears to:

  • rely on being placed in /usr/local/lib/clisp
  • rely on the presence of /sw/lib/libreadline.4.dylib
  • have been built against readline 4.3 (4.2 will fail with dyld: Symbol not found: _rl_insert_mode)
$ cd clisp-2.39
$ ./clisp
./clisp: /usr/local/lib/clisp/base/lisp.run: No such file or directory
$ sudo mv clisp-2.39 /usr/local/lib/clisp
$ cd /usr/local/lib/clisp
$ ./clisp
dyld: Library not loaded: /sw/lib/libreadline.4.dylib
  Referenced from: /usr/local/lib/clisp/base/lisp.run
  Reason: image not found
Trace/BPT trap
$ DYLD_PRINT_LIBRARIES=1 ./clisp
dyld: loaded: /usr/local/lib/clisp/./clisp
dyld: loaded: /usr/lib/libSystem.B.dylib
dyld: loaded: /usr/lib/system/libmathCommon.A.dylib
dyld: loaded: /usr/local/lib/clisp/base/lisp.run
dyld: Library not loaded: /sw/lib/libreadline.4.dylib
  Referenced from: /usr/local/lib/clisp/base/lisp.run
  Reason: image not found
Trace/BPT trap
$ otool -l clisp | grep ' name'
         name /usr/lib/dyld (offset 12)
         name /usr/lib/libSystem.B.dylib (offset 24)

Note: /sw/ appears to be the Fink installation root.

Building readline 4.3

I was unable to find any downloadable libreadline.4.dylib files, so I ended up writing a script which builds it from source.

readline 4.3 will build, but needs a small patch to its shlib/Makefile to:

  • link against ncurses
  • fix the version provided by the dylib (4.3, not 4)

Download or copy readline-4.3.tar.gz into ~/Downloads/, then run the attached script install-readline-4.3-leopard-powerpc.sh.

Installing clisp

Download or copy clisp-2.39-powerpc-apple-darwin8.7.0-8.7.0.tar.gz into ~/Downloads/, then run the attached script install-clisp-2.39-leopard-powerpc.sh.

clisp should now run:

$ /usr/local/lib/clisp/clisp
  i i i i i i i       ooooo    o        ooooooo   ooooo   ooooo
  I I I I I I I      8     8   8           8     8     o  8    8
  I  \ `+' /  I      8         8           8     8        8    8
   \  `-+-'  /       8         8           8      ooooo   8oooo
    `-__|__-'        8         8           8           8  8
        |            8     o   8           8     o     8  8
  ------+------       ooooo    8oooooo  ooo8ooo   ooooo   8

Copyright (c) Bruno Haible, Michael Stoll 1992, 1993
Copyright (c) Bruno Haible, Marcus Daniels 1994-1997
Copyright (c) Bruno Haible, Pierpaolo Bernardi, Sam Steingold 1998
Copyright (c) Bruno Haible, Sam Steingold 1999-2000
Copyright (c) Sam Steingold, Bruno Haible 2001-2006

[1]> (+ 1 1)
2
[2]> 

Thanks to:

#!/bin/bash
# Install (prebuilt) clisp into /usr/local/lib/clisp.
# This script was written for OS X Leopard / PowerPC.
set -e
set -x
if test -e /usr/local/lib/clisp ; then
echo "/usr/local/lib/clisp already exists, exiting."
exit 0
fi
if ! test -e ~/Downloads/clisp-2.39-powerpc-apple-darwin8.7.0-8.7.0.tar.gz ; then
echo "Error: clisp tarball missing." >&2
echo "See https://sourceforge.net/projects/clisp/files/clisp/2.39/clisp-2.39-powerpc-apple-darwin8.7.0-8.7.0.tar.gz/download" >&2
exit 1
fi
if ! test -e ~/opt/readline-4.3 ; then
echo "Error: ~/opt/readline-4.3 is missing." >&2
echo "See install-readline-4.3-leopard-powerpc.sh." >&2
exit 1
fi
cd /tmp
rm -rf clisp-2.39
cat ~/Downloads/clisp-2.39-powerpc-apple-darwin8.7.0-8.7.0.tar.gz | gunzip | tar x
mkdir -p /usr/local/lib
sudo mv clisp-2.39 /usr/local/lib/clisp
if ! test -e /sw/lib/libreadline.4.dylib ; then
sudo mkdir -p /sw/lib
sudo ln -sf ~/opt/readline-4.3/lib/libreadline.4.dylib /sw/lib/
fi
#!/bin/bash
# Install readline 4.3 on OS X Leopard / PowerPC.
set -e
set -x
if test -e ~/opt/readline-4.3 ; then
echo "readline-4.3 already installed, exiting."
exit 0
fi
if ! test -e ~/Downloads/readline-4.3.tar.gz ; then
echo "~/Downloads/readline-4.3.tar.gz missing, exiting." >&2
echo "See https://ftp.gnu.org/gnu/readline/readline-4.3.tar.gz" >&2
exit 1
fi
cd /tmp
rm -rf readline-4.3
cat ~/Downloads/readline-4.3.tar.gz | gunzip | tar x
cd readline-4.3
./configure --prefix=$HOME/opt/readline-4.3
cd shlib
patch Makefile << "EOF"
--- Makefile 2021-12-12 00:42:01.000000000 -0600
+++ Makefile.patched 2021-12-12 00:42:46.000000000 -0600
@@ -72,8 +72,8 @@
SHOBJ_XLDFLAGS =
SHOBJ_LIBS =
-SHLIB_XLDFLAGS = -arch_only `/usr/bin/arch` -install_name $(libdir)/$@ -current_version $(SHLIB_MAJOR)$(SHLIB_MINOR) -compatibility_version $(SHLIB_MAJOR) -v
-SHLIB_LIBS = -lSystem
+SHLIB_XLDFLAGS = -arch_only `/usr/bin/arch` -install_name $(libdir)/$@ -current_version $(SHLIB_MAJOR)$(SHLIB_MINOR) -compatibility_version $(SHLIB_MAJOR)$(SHLIB_MINOR) -v
+SHLIB_LIBS = -lSystem -lncurses
SHLIB_LIBSUFF = dylib
SHLIB_LIBVERSION = $(SHLIB_MAJOR)$(SHLIB_MINOR).$(SHLIB_LIBSUFF)
EOF
cd ..
make
make install
@cellularmitosis
Copy link
Author

A trivial performance benchmark:

$ cat fib-bench.cl 
(defun fib (n) (if (< n 2) n (+ (fib (- n 1)) (fib (- n 2)))))
(fib 30)

11 seconds on my 1.25 GHz eMac:

cell@emac3$ time clisp fib-bench.cl 

real	0m11.638s
user	0m11.578s
sys	0m0.042s

Less than one second on my M1 Mac mini 🤯:

$ time clisp fib-bench.cl 

real	0m0.742s
user	0m0.733s
sys	0m0.007s

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment