Wanna build GNU Emacs on macOS from source?

It’s really easy to build GNU Emacs on macOS from source. However it comes with some catches.

Basically you only need the Xcode Command Line Tools (CLT) installed and you are good to go. If you don’t have it already, simply run the following to install.

sudo xcode-select --install

Now you download the tarball from the official GNU site. After extracting, you want to configure and make it. Now you face the problem of dependent dynamic libraries like gnutls and jannson.

You realize that it’s easy to get them installed, provided you have Homebrew. You simply run

brew install gnutls
brew install jansson

respectively. That’s nice! Now you can build Emacs by issuing

./configure
make
make install

Perfect! This leaves you with a freshly built Emacs.app in the nextstep sub-directory. You probably want to stage it to your local Applications directory for further inspection and try.

cp -a nextstep/Emacs.app ~/Applications

Now comes the catch! Since the app depends on extra libraries which are not present on macOS systems by default, you cannot simply add your freshly built app to your friend to use, unless he/she has these extra libraries pre-installed on their system. This is bad. You want an app to simply work on any of those macOS systems, without the hustle installing dependent libraries first, right? What can we do?

Well, one solution can be to use a tool which puts all the dependent dynamic libraries inside the application bundle and fixes their dynamic-linking configuration to refer to them inside the bundle.

Is there such a tool? Well, neither Apple nor GNU offers such a command line tool to my knowledge. However there are several solutions floating around the internet. Some of them are written in C++, Ruby, Python and Shell. What’s common in them is that they invoke the commands, otool and install_name_tool from the CLT to get the job done. Also due to the nature of the dependency-tree, they do it recursively on all the dependent extra libraries.

Inspired by these, and my drive to learn about macOS bundles, dynamic libraries and tools, I created a command line tool in Shell which makes it super easy to process the Emacs.app after building it to make it truly standalone.

Tip: place the script bundle-dylibs in ~/bin and make sure that it’s executable and ~/bin is on the PATH!

curl -s -O https://raw.githubusercontent.com/imrehorvath/bundle-dylibs/main/bundle-dylibs
chmod +x bundle-dylibs

The final step is to invoke the tool, to do the magic. Simply run:

bundle-dylibs ~/Applications/Emacs.app

Of course, the tool can be applied to other application bundles as well. However it is highly recommended to apply it to a COPY of the app and not the original! Also keep in mind that there are no liabilities! Use it at your own risk!

Check the tool out on GitHub!

Wanna build GNU Emacs on macOS from source?