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?



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 -d:pserver:anonymous@cvs.sv.gnu.org:/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




  • 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 Emacs.app into the Applciations folder. You're ready to go -- double click it to launch it.



image



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 .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/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.



image



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:



image



And hey, check out the version number:



image



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?


20 Comments

ShrinkyNutsMcAngryPants
2006-01-21 21:07:00
DarwinPorts
My steps:


1) Install DarwinPorts (http://www.darwinports.org)


For Carbon:
2) sudo port install emacs-devel +carbon


For X11:
3) sudo port install emacs-devel +x11


There is no step 3. :-)

ShrinkyNutsMcAngryPants
2006-01-21 21:09:48
DarwinPorts
Yeah, so regarding the "no step 3" bit. That only works if I numbered the X11 step correctly.
m_keightley
2006-01-22 01:30:20
aquamacs
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!
MactOSiX
2006-01-22 18:17:43
New Intel Macs and Linux
This may not be directly related but reading this did give me this thought I am about to share.


One of the issues with software compiled for unix/linux based operating systems is that they offer the most support to x86 chips (Intel, AMD). This is due, I presume, to more people using those chips.


What will having an Intel chip inside of a Mac do for support of apps such as emacs? What will it do for the support of linux distributions on a Mac? Apple switching to an Intel chip may break open new levels of support for unix apps on the Mac.


Of course this doesn't help the current discussion, but it might help the situation down the road.

kip
2006-01-23 08:57:53
Checking to see which architectures your binary can run on
lipo -info
invalidname
2006-01-23 10:05:57
Checking to see which architectures your binary can run on
Ah, well that settles it:


[chrisg5:~] cadamson% lipo -info /usr/local/bin/emacs
Non-fat file: /usr/local/bin/emacs is architecture: ppc


[chrisg5:~] cadamson% lipo -info /Applications/Emacs.app/Contents/MacOS/Emacs
Non-fat file: /Applications/Emacs.app/Contents/MacOS/Emacs is architecture: ppc

ddp
2006-01-28 17:55:47
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.
narberd
2006-01-29 22:28:13
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[2]: *** [temacs] Error 1
make[1]: *** [bootstrap-build] Error 2
make: *** [bootstrap] Error 2


Can you help me ?


thank you.

Chris Adamson
2006-01-30 15:35:56
narberd writes:

The 'make bootstrap' give me these errors :


No idea off-hand... have you installed the developer (XCode) tools, including the X11 SDK, from the Tiger DVD?
Lennart Staflin
2006-01-31 16:59:37
narberd:
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:


ld: warning multiple definitions of symbol _PC
terminfo.o definition of _PC in section (__DATA,__common)
symbol _acosl used from dynamic library /usr/lib/libstdc++.6.dylib(single module) not from earlier dynamic library /usr/lib/libSystem.B.dylib(ld64.o)

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

Chris Adamson
2006-01-31 19:56:21
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?
Ken Raeburn
2006-02-01 05:47:14
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.


2) Universal binaries for Emacs are Hard. The file mac/INSTALL mentions describes why Emacs binaries aren't universal. First, the normal Emacs build process uses an "unexec" step that runs Emacs, loads some Lisp code, and dumps out an image of Emacs-plus-loaded-Lisp-code; obviously that's going to be per-architecture. Second, apparently Rosetta doesn't work properly on Emacs. So, theoretically, you could probably construct a build procedure that involves doing the "unexec" on one machine of each architecture and then find some way to "edit" the resulting binaries together, but I don't think that's going to get into the standard build process...

Seunghan
2006-02-02 19:07:29
It works in intel mac. Thanks!
xav'
2006-02-20 03:01:16
concerning the compilation, I hear it may come from a bad quicktime (i have not tested yet)


the suggested way was to go back to quicktime 7.0.1
http://www.apple.com/support/downloads/quicktime701reinstallerforquicktime704.html

Steve George
2006-03-21 11:10:24
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!


Steve

Mike
2006-03-26 00:11:32
RE building emacs (I tried 21.2 and 21.4) on an intel mac: doesn't work, ./configure doesn't recognize the architecture:


pico:~/downloads/emacs-21.4 mep$ ./configure --without-carbon --with-x
loading cache ./config.cache
checking host system type... i386-apple-darwin8.5.3
configure: error: Emacs hasn't been ported to `i386-apple-darwin8.5.3' systems.
Check `etc/MACHINES' for recognized configuration names.


I notice that "Seunghan" posted that he did get it to work on an intel mac... not sure how to explain our opposite outcomes.


I just tried DarwinPorts, and it worked (both X11 and Carbon, separately).


Cheers,


Mike

Caius
2006-03-26 17:38:26
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).
Tad
2006-03-27 14:59:48
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.
Brian Choate
2006-03-27 18:36:53
As built from CVS on a MacBook Pro


@uriel $ lipo -info /usr/local/bin/emacs
Non-fat file: /usr/local/bin/emacs is architecture: i386


@uriel $ lipo -info /Applications/Emacs.app/Contents/MacOS/Emacs
Non-fat file: /Applications/Emacs.app/Contents/MacOS/Emacs is architecture: i386

Andrew
2006-06-01 22:42:46
I just compiled for X11 on my MacBook Pro:


Intel compilation works!