This page contains some outdated information. To get an up-to-date description of how to build the packages, please take a look at Building the X Window System.

  • Modular X development using the git trees *

Since it's fairly common to do development that touches several layers of the graphics stack, this guide will cover building the whole thing, from the DRM up through the X server and drivers. We'll install the whole stack into a separate directory, just to keep things separated from the distribution packages we (presumably) want to keep working as we break things in our sandbox.

On a basic level, you'll need to build things in roughly this order:

An alternate method of building the packages in a more automated fashion using the jhbuild utility can be found in the JhBuildInstructions.

Everything described underneath is also available as a pre made script, located at the bottom of this page.

Minimum requirements

Basically, Linux 2.6.x, Free/Net/OpenBSD, OpenSolaris/Solaris 10, Hurd, OS X 10.5, and Cygwin systems should work fine on any architecture these are likely to run on. Compiler-wise, gcc 3.x, Intel icc, Sun Studio, and llvm-clang are generally known to work. See below if you're looking at a port:

So, here's the assumptions I've been working from:

The X server core and software DDXes should build and work on basically
all of the free BSDs (not counting Darwin), Solaris 10+ and OpenSolaris,
Linux, Hurd, and some versions of SCO, on any CPU architecture they
support.  Kdrive's hardware servers - basically just Xfbdev at this
point - is Linux-only; the rest should work anywhere.  The Xorg DDX
could probably be built for just about any architecture, but it doesn't
really make sense to do so in all cases; s390 doesn't have a PCI bus, so
it'd be a bit silly.  But the bus support code is in some sense
optional, an arm port wouldn't necessarily need PCI support, etc.  The
Xorg DDX does assume a vaguely ELF-like linking environment and a
libdl-like interface to it; this isn't a problem for any of the
currently supported ports, but anyone trying to port it to OSX, AIX, or
ancient HP/UX would probably have issues.

Obviously, the xwin and quartz DDXes are platform-specific.

The server's compiler needs to be C89 plus a few common C99 extensions.
Don't say "requires C99"; no compiler completely supports C99 yet, as
far as I'm aware.  Yes, even gcc:

http://gcc.gnu.org/c99status.html

Most of the client libs and apps should work on pretty much any vaguely
modern unix; there's generally no compelling need to break them, and
indeed most of the apps should be left the hell alone because they're
not things we want to encourage people to use.  xtrans is sort of a
special case because it's so deeply tied to the X server, it should be
considered as portable as the server is.

Non-server compiler pretty much just needs to be C89 or better.

- ajax

Kernel

As of linux 2.6.28, the canonical upstream for the Intel DRM (direct rendering manager) code is the linux kernel, and replaces the linux-core build below for other chipsets. There are plenty of instructions on building your own kernel out there, but the quick summary is:

git clone git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6.git
cd linux-2.6
make menuconfig
# Choose CONFIG_AGP=y
# Choose CONFIG_AGP_INTEL=y
# Choose CONFIG_DRM=m
# Choose CONFIG_DRM_I915=m
make
sudo make install modules_install
sudo update-grub
sudo reboot

Building Dependencies

Autoconf (part of the autotools system X uses for its build system) likely needs macros defined by X. These are included in the util/macros package:

  • macros - git://git.freedesktop.org/git/xorg/util/macros Once you've installed the macros, you need to let the other packages use them:

    1. export ACLOCAL="aclocal -I /opt/gfx-test/share/aclocal" Mesa and the X server proper have several dependencies, and depending on your distribution you may need to update some of the libraries, headers, and prototypes it depends on before configuring the build. Common examples include:
  • libx11proto - git://git.freedesktop.org/git/xorg/proto/x11proto

  • libxtrans - git://git.freedesktop.org/git/xorg/lib/libxtrans
  • libX11 - git://git.freedesktop.org/git/xorg/lib/libX11
  • libXext - git://git.freedesktop.org/git/xorg/lib/libXext
  • dri2proto - git://git.freedesktop.org/git/xorg/proto/dri2proto
  • glproto - git://git.freedesktop.org/git/xorg/proto/glproto
  • pciaccess - git://git.freedesktop.org/git/xorg/lib/libpciaccess
  • pixman - git://git.freedesktop.org/git/pixman

The usual git clone path; cd package; ./autogen.sh --prefix=/opt/gfx-test; make; make install sequence should build these modules.

Once the build & install has completed, you'll need to set your PKG_CONFIG_PATH environment variable, so subsequent configurations will pick up your new bits.

  1. export PKG_CONFIG_PATH=/opt/gfx-test/lib/pkgconfig

Building DRM

See http://dri.freedesktop.org/wiki/Building. In short:

The DRM (Direct Rendering Manager) provides kernel and library interfaces to clients wanting access to kernel managed resources like interrupts, buffer swaps, DMA memory mapping and graphics memory management. Building it is fairly straightforward:

  1. git clone git://git.freedesktop.org/git/mesa/drm
  2. cd drm
  3. ./autogen.sh --prefix=/opt/gfx-test # or wherever you want to install it.
  4. make
  5. make -C linux-core # assuming you're on Linux, otherwise use bsd-core. Don't bother for intel.
  6. make install _# with new drm gem, like Intel. On make install try don't overwrite drm kernel headers with this drm headers of libdrm. _

Building Mesa

See http://dri.freedesktop.org/wiki/Building. In short:

The Mesa package contains the GL stack and its associated chip specific drivers, which provide direct and indirect rendering acceleration. Note that to build some of the test programs there is a dependency on the development packages for GLUT. You'll have to ensure those development packages have been installed, or you can disable building the GLUT programs by adding_ --disable-glut_ to the autogen line below. You will still be able to build the common demo programs such as glxgears without GLUT, though.

  1. git clone git://git.freedesktop.org/git/mesa/mesa
  2. cd mesa
  3. ./autogen.sh --prefix=/opt/gfx-test --with-driver=dri --disable-glut
  4. make
  5. make install
  6. mkdir -p /opt/gfx-test/bin
  7. install -m755 progs/xdemos/{glxinfo,glxgears} /opt/gfx-test/bin/

Gallium build instructions

Gallium is an alternative architecture for hardware acceleration in mesa. It is currently a branch in the official mesa tree.

  1. git clone git://git.freedesktop.org/git/mesa/mesa
  2. cd mesa
  3. git checkout origin/gallium-0.1
  4. make with whatever target you want (the list of targets is in mesa/configs/, common targets are linux, linux-dri, linux-dri-x86 and linux-dri-x86-64)

Building the X Server

  • Here we build the X server with builtin fonts so we don't have to do too much configuration later. Note if you're building DMX or Xgl for example you need the --with-mesa-source option.
  • git clone git://git.freedesktop.org/git/xorg/xserver
  • cd xserver
  • ./autogen.sh --prefix=/opt/gfx-test --enable-builtin-fonts
  • make
  • make install
  • chown root /opt/gfx-test/bin/Xorg; chmod +s /opt/gfx-test/bin/Xorg # assuming you don't run as root

Making the keyboard work

Using disto setup

If you have a non qwerty keyboard, and don't want to install XKeyboardConfig, you might want to add the following flag to the autogen.sh script, when building the X server :

  • --with-xkb-path=/usr/share/X11/xkb (You may need to adjust the path depending on your distribution).

Also the X server will search for the xkbcomp program in /opt/gfx-test/bin. So you will need to create a symbolic link to your distribution xkbcomp :

  • cd /opt/gfx-test/bin
  • ln -s /usr/bin/xkbcomp xkbcomp

From scratch

Or you can install the XKeyboardConfig definitations

  • git clone git://anongit.freedesktop.org/git/xkeyboard-config
  • cd xkeyboard-config/
  • ./autogen.sh --prefix=$PREFIX
  • make
  • make install And the xkbcomp tool
  • git clone git://git.freedesktop.org/git/xorg/app/xkbcomp
  • cd xkbcomp/
  • ./autogen.sh --prefix=$PREFIX
  • make
  • make install

Building X drivers

Presumably you'll want a video driver and a couple of input drivers at a minimum. We'll do xf86-input-mouse, xf86-input-keyboard, and xf86-video-intel here.

xf86-input-mouse

  1. git clone git://git.freedesktop.org/git/xorg/driver/xf86-input-mouse
  2. cd xf86-input-mouse
  3. ./autogen.sh --prefix=/opt/gfx-test
  4. make
  5. make install

xf86-input-keyboard

  1. git clone git://git.freedesktop.org/git/xorg/driver/xf86-input-keyboard
  2. cd xf86-input-keyboard
  3. ./autogen.sh --prefix=/opt/gfx-test
  4. make
  5. make install

You possibly will want the evdev driver, especially if your distro uses the evdev system

xf86-input-evdev

  1. git clone git://git.freedesktop.org/git/xorg/driver/xf86-input-evdev
  2. cd xf86-input-evdev
  3. ./autogen.sh --prefix=/opt/gfx-test
  4. make
  5. make install

xf86-video-intel

  1. git clone git://git.freedesktop.org/git/xorg/driver/xf86-video-intel
  2. cd xf86-video-intel
  3. ./autogen.sh --prefix=/opt/gfx-test
  4. make
  5. make install

Running your new stack

Now that your development environment is set up, you can try running it (as root).

This first 4 steps are no longer need, for the drives which use new drm gem, which is the case of Intel.

  1. rmmod i915 # assuming you're using Intel
  2. rmmod drm
  3. insmod/linux-core/drm.ko
  4. insmod/linux-core/i915.ko
  5. export LD_LIBRARY_PATH=/opt/gfx-test/lib
  6. startx -- /opt/gfx-test/bin/Xorg -verbose # make sure you have a ~/.xinitrc with what you want to run

And there you have it, a fresh stack ready for tracking & doing upstream development. Enjoy!

Troubleshooting

If you can't install the drm kernel module with the message (can't allocate memory), you perhaps set the virtual size in xorg.conf higher than your graphic memory size.

Quick and easy way to install a development build

on debian/ubuntu this script depends on the following packages: build-essential git-core autoconf automake sudo libtool pkg-config xsltproc xcb-proto libfreetype6-dev libexpat1-dev libssl-dev

# !/bin/bash

## X.org development build script
## @author Łukasz Jernaś - original version
## @author legolas558 - some improvements
#

PREFIX="/opt/gfx-test"
PKG_CONFIG_PATH=/opt/gfx-test/lib/pkgconfig

# Attempt to detect proper concurrency level
CPU_CORES=`cat /proc/cpuinfo | grep -m1 "cpu cores" | sed s/".*: "//`
CONCURRENCY_LEVEL=$(( $CPU_CORES + 1 ))

MAKE="make"
MAKEINST="sudo make install"

## the freedesktop git server
GFDR="git://git.freedesktop.org/git"

REPOS="\
$GFDR/xorg/util/macros \
$GFDR/xorg/proto/x11proto \
$GFDR/xorg/proto/damageproto \
$GFDR/xorg/proto/xextproto \
$GFDR/xorg/proto/fontsproto \
$GFDR/xorg/proto/videoproto \
$GFDR/xorg/proto/renderproto \
$GFDR/xorg/proto/inputproto \
$GFDR/xorg/proto/xf86vidmodeproto \
$GFDR/xorg/proto/xf86dgaproto \
$GFDR/xorg/proto/xf86driproto \
$GFDR/xorg/proto/xcmiscproto \
$GFDR/xorg/proto/scrnsaverproto \
$GFDR/xorg/proto/bigreqsproto \
$GFDR/xorg/proto/resourceproto \
$GFDR/xorg/proto/compositeproto \
$GFDR/xorg/proto/fixesproto \
$GFDR/xorg/proto/evieproto \
$GFDR/xorg/proto/kbproto \
$GFDR/xorg/lib/libxtrans \
$GFDR/xorg/lib/libX11 \
$GFDR/xorg/lib/libXext \
$GFDR/xorg/lib/libXi \
$GFDR/xorg/lib/libxkbfile \
$GFDR/xorg/lib/libfontenc \
$GFDR/xorg/lib/libXfont \
$GFDR/xorg/lib/libXfixes \
$GFDR/xorg/lib/libXdamage \
$GFDR/xorg/lib/libXv \
$GFDR/xorg/lib/libXvMC \
$GFDR/xorg/lib/libXxf86vm \
$GFDR/xorg/lib/libXinerama \
$GFDR/xorg/proto/dri2proto \
$GFDR/xorg/proto/glproto \
$GFDR/xorg/lib/libpciaccess \
$GFDR/pixman \
$GFDR/xcb/proto \
$GFDR/xcb/pthread-stubs \
$GFDR/xorg/lib/libXau \
$GFDR/xcb/libxcb \
$GFDR/xorg/proto/randrproto \
$GFDR/mesa/drm \
$GFDR/mesa/mesa \
$GFDR/xorg/xserver \
$GFDR/xorg/driver/xf86-input-mouse \
$GFDR/xorg/driver/xf86-input-keyboard \
$GFDR/xorg/driver/xf86-video-intel"

modules="\
fontsproto \
x11proto \
xextproto \
videoproto \
renderproto \
inputproto \
damageproto \
xf86vidmodeproto \
xf86dgaproto \
xf86driproto \
xcmiscproto \
scrnsaverproto \
bigreqsproto \
resourceproto \
compositeproto \
resourceproto \
evieproto \
kbproto \
fixesproto \
proto \
pthread-stubs \
libxcb \
libXext \
libxtrans \
libX11 \
libXau \
libXi \
libxkbfile \
libfontenc \
libXfont \
libXv \
libXvMC \
libXxf86vm \
libXinerama \
libXfixes \
libXdamage \
dri2proto \
glproto \
libpciaccess \
pixman \
randrproto"

init()
{
        for repo in $REPOS; do
                echo "Cloning $repo"
                git clone $repo
        done
        cd macros
        echo "Building macros"
        ./autogen.sh --prefix="$PREFIX"
        ($MAKE) && \
        $($MAKEINST)
        cd ..
}

update_modules()
{
        for module in $modules; do
                echo "Updating $module"
                cd $module
                git pull || return $?
                cd ..
        done
}

configure ()
{
        export ACLOCAL="aclocal -I $PREFIX/share/aclocal"
        export PKG_CONFIG_PATH="$PREFIX/lib/pkgconfig"
        ## configure all modules
        for i in $modules; do
                cd $i
                echo ======================
                echo configuring $i
                echo ======================
                ./autogen.sh --prefix="$PREFIX"
                if [ $? -ne 0 ]; then
                        echo "Failed to configure $i."
                        if [[ "$i" == "libX11" ]]; then
                                echo "If you are getting a libX11 error related to xtrans, install xtrans package into your system"
                        fi
                        exit -1
                fi
                cd ..

        done
        # build drm
        cd drm
        ./autogen.sh --prefix="$PREFIX"
        if [ $? -ne 0 ]; then
                echo "Failed to configure DRM."
                exit -2
        fi
        # assuming you're on Linux, otherwise use bsd-core
        cd ..
## configure mesa
        cd mesa
        ./autogen.sh --prefix=$PREFIX --with-driver=dri --disable-glut --with-state-trackers="egl dri"
        if [ $? -ne 0 ]; then
                echo "Failed to configure Mesa."
                exit -3
        fi
        cd ..
## configure xserver
        cd xserver
        ./autogen.sh --prefix=$PREFIX --enable-builtin-fonts
        if [ $? -ne 0 ]; then
                echo "Failed to configure X server."
                exit -4
        fi
        cd ..
## mouse, keyboard and intel video
        for MYM in "xf86-input-mouse xf86-input-keyboard xf86-video-intel"; do
                cd $MYM && \
                ./autogen.sh --prefix=$PREFIX
                if [ $? -ne 0 ]; then
                        echo "Failed to configure $MYM."
                        exit -5
                fi
                cd ..
        done
}

build ()
{
        export ACLOCAL="aclocal -I $PREFIX/share/aclocal"
        export PKG_CONFIG_PATH="$PREFIX/lib/pkgconfig"
        for i in $modules; do
                cd $i
                echo ======================
                echo building $i
                echo ======================
                ($MAKE) && \
                ($MAKEINST) || return $?
                cd ..

        done
        # build drm
        cd drm
        ## commented because not working - legolas558
        # assuming you're on Linux, otherwise use bsd-core
##        make -C linux-core
        ($MAKE) && \
        ($MAKEINST) || return $?
        cd ..
## build mesa
        cd mesa
        ($MAKE) && \
        ($MAKEINST) && \
        mkdir -p $PREFIX/bin && \
        sudo install -m755 progs/xdemos/{glxinfo,glxgears} $PREFIX/bin/ || return $?
        cd ..
## build xserver
        cd xserver
        ($MAKE) && \
        ($MAKEINST) && \
        sudo chown root $PREFIX/bin/Xorg && \
        sudo chmod +s $PREFIX/bin/Xorg || return $?
        cd ..
## build mouse, keyboard and intel video driver
        for MYM in "xf86-input-mouse xf86-input-keyboard xf86-video-intel"; do
                cd $MYM && \
                ($MAKE) && \
                ($MAKEINST)
                if [ $? -ne 0 ]; then
                        echo "Failed to build&install $MYM."
                        return -5
                fi
                cd ..
        done && \
        echo "All OK"
}

case "$1" in
        init)
                init
                ;;
        configure)
                configure
                ;;
        build)
                build
                ;;
        update)
                update_modules
                ;;
        *)
                echo "Usage: $0 init | update | configure | build "
                exit 3
esac