Compiling Emacs from Source on MacOS Big Sur
Published: 2021-11-09
Recently I started to compile the Emacs master branch from source for daily use instead of using one of the popular formulas on Homebrew.1 It’s pretty cool to try the latest features like the native compilation and the native emoji before the stable releases. Also it’s quite a satisfying experience to be able to compile Emacs from source. It took me several tries to get it right but I think I documented everything. Here are the steps:
Install dependencies
libxml2
- Optional for native compilation
gcc
libgccjit
brew install libxml2 gcc libgccjit
Follow the post-installation instruction from libxml2
to fix the path and environment variables.
If you need to have libxml2 first in your PATH, run:
echo 'export PATH="/usr/local/opt/libxml2/bin:$PATH"' >> ~/.zshrc
For compilers to find libxml2 you may need to set:
export LDFLAGS="-L/usr/local/opt/libxml2/lib"
export CPPFLAGS="-I/usr/local/opt/libxml2/include"
For pkg-config to find libxml2 you may need to set:
export PKG_CONFIG_PATH="/usr/local/opt/libxml2/lib/pkgconfig"
Compile
I configured my Emacs with the following options. I’m not exactly sure what each meant but this combination seems to work on my machine:
--with-cairo
- enable Cairo drawing--with-imagemagick
- enable ImageMagick support--with-xwidgets
--with-native-compilation
- enable native compilation
./autogen.sh
./configure --with-cairo --with-imagemagick --with-xwidgets --with-native-compilation
# Build MacOS App bundle, `install` doesn’t actually install anything.
make clean install
The Emacs.app App bundle should now be in the nextstep/
directory. Simply copy it to the /Applications
folder to use it.
References
Footnotes
Probably the popular options are:
emacs-mac
,emacs-plus
, andemacs-head
. I was mostly usingemacs-mac
in the past.↩︎