Guide to X11/Building

Building
X11, from the reference implementation to Xorg 6.9, uses its own "imake" build system. The clients, server, and libraries are in one build tree. (It is very difficult to build only one part of the tree; the entire tree must be built.) Some things, like Mesa and Freetype, are hacked to optionally be part of the tree.

Xorg 7.0 replaces this with a set of modules based around GNU autoconf build system. This creates a complex system of packages and dependencies. Problems with implementing two systems for the simultaneous Xorg 6.9rc1 and Xorg 7.0rc1 delayed release candidate 1.

Imake system
In order to build Xorg with imake, you first need to download and extract the source tarball. The tarball for Xorg 6.9rc1 was called xorg-x11-6.8.99.901.tar.bz2 and is available from here. Now that the final versions of Xorg 6.9 and 7.0 are available, you can find them using the list of mirrors here.

A rough outline of the build system:
 * 1) Create a "host.def" file (which is optional).
 * 2) Do "make World" to configure and build the tree.
 * 3) Do "make install" and "make install.man" to install everything.

You can use the "host.def" file to customize your build. If you do not create one, then you use the default settings, which should already be tuned to your operating system.

The file xc/BUILD describes the build in more detail.

Yes, you must build the entire tree to build one part. The exception is that sometimes you can do a server-only or server-less build. See our section on and xc/config/cf/xorgsite.def.

Example build
In the following example, root has given us the write access to /usr/local/src. We downloaded Xorg 6.9 release candidate 1 (/usr/local/src/xorg-x11-6.8.99.901.tar.bz2).

We already have Xorg 6.8.2 installed. We are running it during the build, so we have multiple xterms to type shell commands in.

Using an "xterm", extract the source to /usr/local/src, creating /usr/local/src/xc: $ cd /usr/local/src $ bzcat xorg-x11-6.8.99.901.tar.bz2 | pax -rv

As xc/BUILD explains, we can use lndir to create a shadow tree of symbolic links to the source. (This prevents objects from appearing in the source tree.) Because "lndir" is part of X, and we have Xorg 6.8.2 already, we can run "lndir": $ mkdir xcbuild $ cd xcbuild $ lndir ../xc

Note that the current directory is <tt>/usr/local/src/xcbuild</tt> now. We will skip creating the <tt>config/cf/host.def</tt> and use the default configuration. It is now time to call the Makefile. We must run <tt>make World</tt> because there is no other correct way to configure and start the build. If we run Bourne shell: $ make World > World.log 2>&1

The "xterm" running "make" is now busy. To watch the log, we run "tail" in a second xterm: $ cd /usr/local/src/xcbuild $ tail -f World.log

Eventually, the log announces that the build of Xorg is complete.

We install (to the default <tt>/usr/X11R6</tt>, thus overwriting most of Xorg 6.8.2): $ sudo make install $ sudo make install.man

Note:
 * 1) If we do not have "sudo" working on our system, then we would use "su".
 * 2) One can exit from X11 before doing the install. The other option is to overwrite most of X11 while it is running. This can work, but is slightly less safe.

If necessary, exit from X and run <tt>xorgcfg</tt> to make a config file.

Building a static server
One can hack the tree to build only a static X server. This is useful if you need better hardware support from an X server in the newer version of a tree. Also, this skips over building the libraries, clients, and separate server modules. (X11 protocol is very stable, so newer servers work with older libraries and clients.)

OpenBSD provides an example <tt>host.def</tt> for that. Their example <tt>host.def</tt> is the basis of the next scenario. If you have some reason to static-build an X server, you would do something similar to the next scenario.

''Scenario: We have installed Xorg 6.8.2. We need the better "ati" driver in Xorg 6.9rc0 (release candidate 0), but we need to skip most of the 6.9rc0 tree to avoid errors.''

Solution: We will static-build a 6.9rc0 server.

Create this file at <tt>config/cf/host.def</tt> in the tree. If you have a shadow tree, put it in the shadow tree. The file is: /* * you may also restrict the drivers that are built by editing and * uncommenting the line below */
 * 1) define InstallEmptyHostDef
 * 1) define BuildServersOnly       YES
 * 1) define XF86CardDrivers             wsfb ati
 * 1) define UsbMouseSupport                NO
 * 2) define DoLoadableServer               NO
 * 3) define XnestServer                    NO
 * 4) define XVirtualFramebufferServer      NO
 * 5) define XprtServer                     NO
 * 6) define BuildGlxExt                    NO
 * 7) define BuildGLXLibrary                NO
 * 8) define BuildGLULibrary                NO
 * 9) define BuildRenderLibrary             NO
 * 10) define BuildLBX                       NO
 * 11) define BuildType1                     NO
 * 12) define BuildFreeType                  NO
 * 13) define BuildXTrueType                 NO
 * 14) define BuildSpeedo                    NO
 * 15) define BuildFonts                     NO
 * 16) define BuildXFree86ConfigTools        NO

The "XF86CardDrivers" line is changed to specify only "wsfb" and "ati". Our driver is "ati". We have a second driver which avoids advanced hardware features, in case "ati" fails us. The "wsfb" driver on OpenBSD uses the kernel framebuffer instead of reconfiguring the hardware. At Linux, the framebuffer driver is "fbdev". On i386 hardware, "vga" and "vesa" might be good choices. Use one of the following lines:
 * 1) define XF86CardDrivers             wsfb ati
 * 2) define XF86CardDrivers             fbdev ati
 * 3) define XF86CardDrivers             vga ati
 * 4) define XF86CardDrivers             vesa ati

Now start the build: $ make World > World.log 2>&1

The build eventually stops with an error because some "XlibConf.h" is missing; our host.def is skipping that step. (This is a bug; Xorg 6.8.2 did not need an "XlibConf.h" file.) That file probably would have been generated by building libX11, which we skipped. For the server, we actually do not need it. Create an empty file at <tt>xc/lib/X11/XlibConf.h</tt>: $ touch lib/X11/XlibConf.h

Now resume the build: $ make Everything >> World.log 2>&1

Eventually the build finishes. The server appears at <tt>xc/programs/Xserver/Xorg</tt>. Because this file is statically linked, it is the only file to install. We install at <tt>/usr/X11R6/bin/Xorg69</tt> to complement our Xorg 6.8.2 installation at <tt>/usr/X11R6</tt>: $ cp -p programs/Xserver/Xorg /usr/X11R6/bin/Xorg69

Now we need to test the server. First, if we are running X now, exit from X to the console. Then make our new server setuid root so it can use video hardware: $ cd /usr/X11R6/bin $ chown root:wheel Xorg69 $ chmod a+xs Xorg69

Generate the new config file with Xorg69 -configure, then test it with xinit -- /usr/X11R6/bin/Xorg69. If it works, make Xorg69 the default server by changing the <tt>/usr/X11R6/bin/X</tt> symbolic link: $ cd /usr/X11R6/bin $ rm X $ ln -s Xorg69 X

We might want to chmod a-x /usr/X11R6/bin/Xorg to prevent anyone from using the old "Xorg" with the new config file that relies on a "Xorg69" driver.