Next: , Up: GNU Emacs Internals

E.1 Building Emacs

This section explains the steps involved in building the Emacs executable. You don't have to know this material to build and install Emacs, since the makefiles do all these things automatically. This information is pertinent to Emacs maintenance.

Compilation of the C source files in the src directory produces an executable file called temacs, also called a bare impure Emacs. It contains the Emacs Lisp interpreter and I/O routines, but not the editing commands.

The command ‘temacs -l loadup uses temacs to create the real runnable Emacs executable. These arguments direct temacs to evaluate the Lisp files specified in the file loadup.el. These files set up the normal Emacs editing environment, resulting in an Emacs that is still impure but no longer bare.

It takes a substantial time to load the standard Lisp files. Luckily, you don't have to do this each time you run Emacs; temacs can dump out an executable program called emacs that has these files preloaded. emacs starts more quickly because it does not need to load the files. This is the Emacs executable that is normally installed.

To create emacs, use the command ‘temacs -batch -l loadup dump’. The purpose of ‘-batch’ here is to prevent temacs from trying to initialize any of its data on the terminal; this ensures that the tables of terminal information are empty in the dumped Emacs. The argument ‘dump’ tells loadup.el to dump a new executable named emacs. The variable preloaded-file-list stores a list of the Lisp files that were dumped with the emacs executable.

Some operating systems don't support dumping. On those systems, you must start Emacs with the ‘temacs -l loadup’ command each time you use it. This takes a substantial time, but since you need to start Emacs once a day at most—or once a week if you never log out—the extra time is not too severe a problem.

You can specify additional files to preload by writing a library named site-load.el that loads them. You may need to add a definition


to make n added bytes of pure space to hold the additional files. (Try adding increments of 20000 until it is big enough.) However, the advantage of preloading additional files decreases as machines get faster. On modern machines, it is usually not advisable.

After loadup.el reads site-load.el, it finds the documentation strings for primitive and preloaded functions (and variables) in the file etc/DOC where they are stored, by calling Snarf-documentation (see Accessing Documentation).

You can specify other Lisp expressions to execute just before dumping by putting them in a library named site-init.el. This file is executed after the documentation strings are found.

If you want to preload function or variable definitions, there are three ways you can do this and make their documentation strings accessible when you subsequently run Emacs:

It is not advisable to put anything in site-load.el or site-init.el that would alter any of the features that users expect in an ordinary unmodified Emacs. If you feel you must override normal features for your site, do it with default.el, so that users can override your changes if they wish. See Startup Summary.

In a package that can be preloaded, it is sometimes useful to specify a computation to be done when Emacs subsequently starts up. For this, use eval-at-startup:

— Macro: eval-at-startup body...

This evaluates the body forms, either immediately if running in an Emacs that has already started up, or later when Emacs does start up. Since the value of the body forms is not necessarily available when the eval-at-startup form is run, that form always returns nil.

— Function: dump-emacs to-file from-file

This function dumps the current state of Emacs into an executable file to-file. It takes symbols from from-file (this is normally the executable file temacs).

If you want to use this function in an Emacs that was already dumped, you must run Emacs with ‘-batch’.