Makefiles for Elisp

Chris Wellons has another great post over at Null Program. This post discusses how he uses makefiles to build his Emacs packages. If you’re like most Elisp programmers, you probably write only small bits of Elisp to add to your init.el and, of course, that doesn’t require a makefile.

Wellons, on the other hand, is writing Emacs packages for others to use. The majority of those consist of a single file but there’s still a good reason to use a makefile. In the first place, Wellons has tests for his packages and he has rules to run those tests in the package’s makefile. That makes it easy to run the tests after every update. The other issue is subtler but still important. As Wellons says, the Elisp compiler may be dumb but it does do static analysis and it’s a useful way of finding problems before they manifest themselves at run time. Therefore, the default rule in his makefiles is to compile the Elisp files.

Most of the post documents the conventions that he uses in his makefiles. He shows the Makefile for each of his projects so you can see real examples of what he does. The other important point is that Wellons makes a point of writing portable makefiles. That means they will work with any make adhering to the POSIX make standard, not just GNU make. If you’re writing software that will be used in a variety of Unix/Linux systems, this can make your life a lot easier because you can use the system make rather than installing GNU make.

Besides serving as a good example of using makefiles for Elisp projects, Wellons’ post is also a nice tutorial on makefiles. If you don’t know anything about make, it won’t help you much but if you’re an occasional user, it’s an excellent reminder of the important points. If you’re a beginner, you should check out his make tutorial.

If you’re writing Emacs packages or you’re just in need of a booster shot for your make-foo, this post is definitely worth your time. As usual, Wellons presents useful information in an interesting way.

Update [2020-01-24 Fri 14:26]: find → finding

This entry was posted in General and tagged , . Bookmark the permalink.