Building emacs22 on Mac OS X
by Chris Adamson
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?
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 -d:pserver:email@example.com:/sources/emacs 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
makefor 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
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
configure. In fact, that's the only thing you need to do special. Here's the steps:
sudo make install
The last step installs the
Emacs.app 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 Emacs.app from the command-line, you can use the path
/Applications/Emacs.app/Contents/MacOS/Emacs . 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
.profile (depending on whether your shell is
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
alias emacs "/Applications/Emacs.app/Contents/MacOS/Emacs"
setenv EDITOR /Applications/Emacs.app/Contents/MacOS/Emacs
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...
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
.profile as described above.
So here's the deal:
./configure --without-carbon --with-x --prefix=/usr/local
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.
Have you tried emacs22 on OS X? Anything interesting to share?
Yeah, so regarding the "no step 3" bit. That only works if I numbered the X11 step correctly.
If you don't want to complie your own then why not try aquamacs emacs (http://aquamacs.org/). It's a fully native (cocoa) application. It supports native osx keyboard short cuts as well as the normal emacs ones.
It's activly being devloped and is very stable (it based on v22 of emacs), I use it every day.
It does feel slightly odd being a hybred between two systems, but then any emacs on the mac is going to feel that way!
New Intel Macs and Linux
This may not be directly related but reading this did give me this thought I am about to share.
Checking to see which architectures your binary can run on
Checking to see which architectures your binary can run on
Ah, well that settles it:
|For those on later G4s and G5s, you can enable better optimization in gcc by defining CFLAGS to be "-O3 -mcpu=7450 -faltivec -ftree-vectorize" (G4) or "-O3 -mcpu=970 -faltivec -ftree-vectorize" (G5) before the ".configure". (If you're using tcsh, a 'setenv CFLAGS ""' before the ".configure" is sufficient.) By default, you only get "-O2" without any processor-specific optimizations.|
The 'make bootstrap' give me these errors :
ld: Undefined symbols:
_HICopyAccessibilityActionDescription referenced from QuickTime expected to be defined in Carbon
_HICopyAccessibilityRoleDescription referenced from QuickTime expected to be defined in Carbon
_LLCStyleInfoCheckForOpenTypeTables referenced from QuickTime expected to be defined in ApplicationServices
_LLCStyleInfoGetUserRunFeatures referenced from QuickTime expected to be defined in ApplicationServices
make: *** [temacs] Error 1
make: *** [bootstrap-build] Error 2
make: *** [bootstrap] Error 2
No idea off-hand... have you installed the developer (XCode) tools, including the X11 SDK, from the Tiger DVD?
I get similar errors when building emacs. But I have been building emacs from CVS now and then for several years now. This seems to be a recent problem. I tried checking out old versions back to Oct 1. But the error persists. I now belive that something has changed in my build environment.
I also get errors like:
I have fink installed and the linking uses libncurses from /sw/lib. Don't know it that is significant.
Another suspect is QuickTime. I have recently ugraded QuickTime to 7.0.4
|I just pulled from source again and it worked (building the Carbon .app). But with multiple people having problems building from CVS, maybe you should file a bug with the emacs team?|
1) Building a Carbon app that can be copied around can be done with "cd mac; ./make-package --self-contained"; that puts the executables, lisp files, etc, all in the resources of the .app package, and modifies the paths at startup time. So you can click on the Emacs.app icon and drag it around, copy it to other machines, etc., and it'll Just Work.
|It works in intel mac. Thanks!|
concerning the compilation, I hear it may come from a bad quicktime (i have not tested yet)
I've been using AquaMacs which m_kneightley already mentions. So far, it's been very nice. Probably the best thing is that it remaps a lot of they keys to more standard Mac ones i.e Apple+S for save. Might not suit a fanatical Emacs user but it's great for me!
RE building emacs (I tried 21.2 and 21.4) on an intel mac: doesn't work, ./configure doesn't recognize the architecture:
I have built emacs as described in this article on my INTEL macbook pro. It works like a dream. The only thing to be careful about is that you get the latest version from CVS (Not one of the tar.gz files on the gnu site).
A few notes:
1. Aquamacs isn't a Cocoa app. It's basically the same with the Carbon app shown here, but with Mac-style customizations such as short cuts, additional third-party elisp packages, fancy icons, and the fancy name.
2. "ld: Undefined symbols" occurs on Panther with QuickTime 7.0.4, but not on Tiger.
As built from CVS on a MacBook Pro
I just compiled for X11 on my MacBook Pro: