Building emacs22 on Mac OS X

Email.Email weblog link
Blog this.Blog this

Chris Adamson
Jan. 21, 2006 07:24 PM

Atom feed for this author. RSS 1.0 feed for this author. RSS 2.0 feed for this author.

A Slashdot blurb from a while back, The Future of Emacs said that "Emacs 22 will have many new features such as support for Mac OS X and Cygwin; mouse wheel support and many new modes and packages."

Woo hoo! Mac OS X support. This is a big deal, because Emacs has been somewhat notorious in terms of its Mac maintainability. Here's what I mean: a few laptops ago, I had a Rev/A iBook which didn't get any hardware acceleration from OS X (we're talking 10.0 and maybe 10.1 here), so I found myself using X11 and xterm instead of Terminal, since X11 wasn't bogging my sad little iPurse down with fancy Quartz rendering in software. Given that I was in X11, I wanted a more X-aware Emacs than ships with OS X, so I was glad to see that fink's emacs build left the X11 stuff in.

But things change. Two computers later, I now prefer the Terminal, since it supports UTF-8 text (i.e., two-byte character sets), and is easier to do copy-and-paste with. But I still wanted to be able to do Emacs in separate windows, since my typical Java development environment is to have one or two terminals and 2-5 editor windows open. Mixing Terminal and X11 didn't seem like a great idea, so I needed a real Mac OS X app. There are a couple projects to do this listed in Version Tracker, but they seemed a little fragile.

Speaking of fragile, back in the fink world, every time a major version of OS X came out, they'd be broken for a few months, so when I was on X11, I'd be broken. I checked out Darwin Ports, but their emacs port crashed if you tried to build it with X11 support. So I filed a bug in November, 2002. And it defied fixing, because when Darwin Ports' Landon Fuller looked at how Fink got it to work, he reported "The fink hacks are pretty ugly" and opted to wait for "upstream fixes".

Long wait, because I started getting mail about this last fall, three years after filing it. It had become one of the longest-open bugs in Darwin Ports.

So, I need my own Emacs .app, which various projects provide in a fairly fragile form, and also want an X11 version, which the major port projects have had problems building (Darwin Ports) or maintaining (Fink). And since I'm rapidly falling out of love with Fink because of what seems to be an abandoned port problem with them, I decided that I'm finally going to just start building my own stuff and give up on package managers.

So, um, how do we build this thing?

Getting emacs22

First, you need the source. When I went googling after reading the Slashdot post, I found a blog on building emacs22 for Tiger (in Japanese). It's mostly right, but the checkout information has changed.

To check out emacs, drop into the command line and create a temporary folder... mkdir ~/tmp will do nicely. cd into and do:

cvs -z3 co emacs

This will create an emacs folder in your current folder. Now we're ready to build.

Reminder: If you proceed from this point, you will be building the code of a work-in-progress. As in "not even alpha". So if you have problems, don't be surprised, and file a bug report. That said, I've had nothing to complain about. This is a very old, very stable piece of software, after all...

The basics of building

You have two choices: building a double-clickable .app, or building the usual command-line-launched binary, presumably with X11 support. These choices are mutually incompatible: you can't create both with one build. Moreover, I've found that installing the Carbon app will deploy pieces that break the X11 support, so if you're going to do both, do the Carbon app first, then the X11 binary.

The build uses the following basic steps

  • configure - prepares make for the build, discovers information about your system needed by compilers and other parts of the build
  • make bootstrap - apparently only needed because you're building from CVS (see INSTALL.CVS).
  • make - do stuff
  • make install - put the pieces in their appropriate places on the system. You generally need admin privileges to do this, so plan on running sudo make install

Each build tweaks these steps, so read on...

Building the Carbon app

To build the double-clickable app, you pass the flag --enable-carbon-app to configure. In fact, that's the only thing you need to do special. Here's the steps:

  • ./configure --enable-carbon-app
  • make bootstrap
  • make
  • sudo make install

The last step installs the into the Applciations folder. You're ready to go -- double click it to launch it.


Two interesting things to note: if you want to launch the from the command-line, you can use the path /Applications/ . You can, in fact, set this as your EDITOR, meaning it'll be used for typing in CVS or Subversion comments. You can edit your .cshrc or .profile (depending on whether your shell is tcsh or bash respectively) to pick this up. For example, I still use tcsh (yeah, on OS X since DP3, back when they didn't include bash) and I use the following in my .cshrc:

alias emacs "/Applications/"
setenv EDITOR /Applications/

Also, this is interesting: emacs -nw (for "no window") will keep you in the Terminal, instead of bouncing Emacs into the Dock.

Speaking of the Dock, double-clicking the app icon after an instance is running, or kicking off a second one from the command-line, will cause multiple Emacs applications to appear in the Dock, as pictured below. Not very Mac-like of course: a proper Mac application would open a new window in the already-running instance.


Building for X11

OK, if you want an X11 version (instead | also), do the following.

First, the docs advocate a make distclean so you don't pick up anything from your earlier build -- if you skipped ahead to this point and didn't build the Carbon version, you can skip this.

Also, you generally need to have installed not only Apple's X11, but also the X11 SDK (an option in Apple's installer), to compile X11 stuff on OS X. No, I didn't try uninstalling mine just to see if it breaks... seriously, folks...

Next, tell configure that you're building the X11 version and not the Carbon version. The docs also advocate explicitly targeting an install directory other than /usr, since that will get clobbered by future system updates. /usr/local/ is a pretty typical choice for this purpose (obviously, you'll need to explicitly run /usr/local/bin/emacs to pick up this version, and/or change your .cshrc or .profile as described above.

So here's the deal:

  • ./configure --without-carbon --with-x --prefix=/usr/local
  • make bootstrap
  • make
  • sudo make install

Get X11 running and kick off a /usr/local/bin/emacs and you're in Happy X11 Emacs Town:


And hey, check out the version number:


So does it work on the Intel Macs?

Good question. I don't see a -arch argument in the gccs, so I don't think this is a Universal Binary. Then again, if it's only to be used on the machine it's compiled on, it seems to me like it should work -- that's the point of configure after all. If you have a shiny fast Intel iMac, try it and post a comment here.

Your mileage may vary

This has worked for me for a month or so, and I'm really happy with it, and looking forward to Emacs 22 being final someday. Hats off to the development team for making the Mac build so painless.

...and if it doesn't work for you, I'm not tech support and I'm not your mom. Attempt to deal.

Chris Adamson is an author, editor, and developer specializing in iPhone and Mac.