Development/git

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:

  1. Dependencies
  2. DRM (both libdrm & the DRM modules)

  3. Mesa
  4. X server
  5. X drivers

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.

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:

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:

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

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

  6. make install

Building Mesa

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

Making the keyboard work

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 :

(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 :

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

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).

  1. rmmod i915 # assuming you're using Intel

  2. rmmod drm

  3. insmod <path_to_drm_tree_above>/linux-core/drm.ko

  4. insmod <path_to_drm_tree_above>/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

PREFIX="/opt/gfx-test"

MAKE="make -j3" 

REPOS="\
git://git.freedesktop.org/git/xorg/util/macros \
git://git.freedesktop.org/git/xorg/proto/x11proto \
git://git.freedesktop.org/git/xorg/proto/xextproto \
git://git.freedesktop.org/git/xorg/proto/videoproto \
git://git.freedesktop.org/git/xorg/proto/renderproto \
git://git.freedesktop.org/git/xorg/proto/inputproto \
git://git.freedesktop.org/git/xorg/lib/libxtrans \
git://git.freedesktop.org/git/xorg/lib/libX11 \
git://git.freedesktop.org/git/xorg/lib/libXext \
git://git.freedesktop.org/git/xorg/lib/libxkbfile \
git://git.freedesktop.org/git/xorg/lib/libfontenc \
git://git.freedesktop.org/git/xorg/lib/libXfont \
git://git.freedesktop.org/git/xorg/lib/libXfixes \
git://git.freedesktop.org/git/xorg/lib/libXdamage \
git://git.freedesktop.org/git/xorg/lib/libXvMC \
git://git.freedesktop.org/git/xorg/lib/libXxf86vm \
git://git.freedesktop.org/git/xorg/proto/dri2proto \
git://git.freedesktop.org/git/xorg/proto/glproto \
git://git.freedesktop.org/git/xorg/lib/libpciaccess \
git://git.freedesktop.org/git/pixman \
git://git.freedesktop.org/git/xcb/proto \
git://git.freedesktop.org/git/xcb/pthread-stubs \
git://git.freedesktop.org/git/xcb/libxcb \
git://git.freedesktop.org/git/xorg/proto/randrproto \
git://git.freedesktop.org/git/mesa/drm \
git://git.freedesktop.org/git/mesa/mesa \
git://git.freedesktop.org/git/xorg/xserver \
git://git.freedesktop.org/git/xorg/driver/xf86-input-mouse \
git://git.freedesktop.org/git/xorg/driver/xf86-input-keyboard \
git://git.freedesktop.org/git/xorg/driver/xf86-video-intel"

modules="\
x11proto \
xextproto \
videoproto \
renderproto \
inputproto \
libxtrans \
proto \
pthread-stubs \
libxcb \
libX11 \
libXext \
libxkbfile \
libfontenc \
libXfont \
libXvMC \
libXxf86vm \
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);
        make install
        cd ..
}

update_modules()
{
        for module in $modules; do
                cd $module
                git pull
                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 "Building $i"
                ./autogen.sh --prefix="$PREFIX";
                if [ $? -ne 0 ]; then
                        echo "Failed to configure $i."
                        exit
                fi
                ($MAKE);
                make install
                cd ..
        done
        # build drm
        cd drm
        ./autogen.sh --prefix="$PREFIX"
        ($MAKE)
        make -C linux-core
        # assuming you're on Linux, otherwise use bsd-core
        make install
        cd ..
#build mesa
        cd mesa
        ./autogen.sh --prefix=$PREFIX --with-driver=dri --disable-glut
        if [ $? -ne 0 ]; then
                echo "Failed to configure Mesa."
                exit
        fi
        ($MAKE)
        make install
        mkdir -p $PREFIX/bin
        install -m755 progs/xdemos/{glxinfo,glxgears} $PREFIX/bin/
        cd ..
#buildxserver
        cd xserver
        ./autogen.sh --prefix=$PREFIX --enable-builtin-fonts
        if [ $? -ne 0 ]; then
                echo "Failed to configure X server."
                exit
        fi
        ($MAKE)
        make install
        chown root $PREFIX/bin/Xorg;
        chmod +s $PREFIX/bin/Xorg
        cd ..
#mouse
        cd xf86-input-mouse
        ./autogen.sh --prefix=$PREFIX
        ($MAKE)
        make install
        cd ..
#keyboard
         
        cd xf86-input-keyboard
        ./autogen.sh --prefix=$PREFIX
        ($MAKE)
        make install
        cd ..
#intel
        cd xf86-video-intel
        ./autogen.sh --prefix=$PREFIX
        ($MAKE)
        make install
        cd ..
}

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