Getting started with asdf, Common Lisp and BKNR

Setting up a Lisp based environment that depends on many external libraries can be a time consuming task. For BKNR, we have decided to set up a private repository of thirdparty libraries and import upstream versions whenever we see upgrading them beneficial. This makes setting up Common Lisp and BKNR on new systems rather easy, and these instructions may help you get going even if you are not interested in BKNR.

We use Subversion as version control system. In our repository, we have a thirdparty/ directory into which we import libraries that we need for our deployments.

Prerequisites

A Unix shell

You need to have basic familarity with command lines to follow these instructions. If you don't feel comfortable with working in the Unix shell, these instructions are not for you.

A Common Lisp compiler

BKNR itself supports Clozure CL and SBCL, but these instructions should be good for other compilers, too.

Emacs

Install a recent version of Emacs. It should be installable using your operating systems' packaging mechanism. Carbon Emacs works well on Mac OS X.

Subversion

You need the Subversion client to actually download the software from our repository. Check if the svn command is available on your system. If not, either install it using your package manager or download it from the Subversion Web Site.

Getting started

Check out software

Choose a place where you want to keep the BKNR checkout. We are going to assume that you will use the bknr-svn/ subdirectory in your home directory.

$ cd
$ svn co http://bknr.net/svn/trunk bknr-svn
A    bknr-svn/build.lisp
A    bknr-svn/xhtmlgen
A    bknr-svn/xhtmlgen/package.lisp
A    bknr-svn/xhtmlgen/xhtmlgen.asd
A    bknr-svn/xhtmlgen/xhtmlgen.lisp
...

If you are not interested in BKNR and want to save some disk space:

$ cd
$ svn co http://bknr.net/svn/trunk/thirdparty bknr-svn
A    bknr-svn/usocket-svn
A    bknr-svn/usocket-svn/test
A    bknr-svn/usocket-svn/test/test-usocket.lisp
A    bknr-svn/usocket-svn/test/usocket-test.asd
A    bknr-svn/usocket-svn/test/package.lisp

Either way, this will take a moment.

Set up ASDF so that it finds the libraries

Loading libraries in Common Lisp is commonly done with ASDF. In order for ASDF to be able to find the libraries that you have installed, your ASDF:*CENTRAL-REGISTRY* variable needs to be properly set up. One way to do this is to scan the file system for libraries at Lisp startup and add all directories that contain libraries to that the ASDF:*CENTRAL-REGISTRY* variable. This can be accomplished by the function SETUP-REGISTRY, which needs to be defined in the startup file of your Common Lisp implementation.

Every Common Lisp implementation has its own startup file, located in the user's home directory:

ImplementationStartup file name
Clozure CLccl-init.lisp
CMUCL.cmucl-init
SBCL.sbclrc
CLISP.clisprc

Place the following code in the startup file for your implementation:

(require 'asdf)

(defun setup-registry (directory-path)
  (format t "; adding components under ~A to asdf registry~%" directory-path)
  (mapc (lambda (asd-pathname)
          (pushnew (make-pathname :name nil
                                  :type nil
                                  :version nil 
                                  :defaults asd-pathname)
                   asdf:*central-registry*
                   :test #'equal))
        (directory (merge-pathnames #p"**/*.asd" directory-path))))

(setup-registry (merge-pathnames #p"bknr-svn/" (user-homedir-pathname)))

When you start your lisp, it will now scan the bknr-svn/ tree for libraries and make them available for ASDF to load.

Set up Emacs to load Slime

Slime is the most popular Emacs extension to do Common Lisp development at the moment, and it is available in the BKNR thirdparty tree, too. To make your Emacs find Slime, add the following to the .emacs file in your home directory:

(push "~/bknr-svn/thirdparty/slime/" load-path)
(require 'slime)
(slime-setup '(slime-presentations slime-fancy slime-asdf slime-banner slime-fancy-inspector))

(setq inferior-lisp-program "openmcl")

Depending on the Lisp you use, replace the "openmcl" by the name of your your Lisp executable:

ImplementationExecutable NameNotes
Clozure CLopenmcl(or whatever you copied the scripts/openmcl file to)
CMUCLlisp
SBCLsbcl
CLISPclisp

Now start Emacs. If you have never used emacs before, press Control-H and t to enter the Emacs tutorial and work through it (it does not take a long time). To start Slime (and Lisp), use M-x slime - It will take a moment to compile some Slime components and then scan your library directory. Once you see the CL-USER> prompt, you'll be all set. Type

(asdf:oos 'asdf:load-op :cl-who)

to the Slime buffer to check whether ASDF has been properly set up. It should load the CL-WHO HTML generation library and not produce any errors.