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:
- Dependencies
DRM (both libdrm & the DRM modules)
- Mesa
- X server
- 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:
macros - git://git.freedesktop.org/git/xorg/util/macros
Once you've installed the macros, you need to let the other packages use them:
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.
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:
git clone git://git.freedesktop.org/git/mesa/drm
cd drm
./autogen.sh --prefix=/opt/gfx-test # or wherever you want to install it.
make
make -C linux-core # assuming you're on Linux, otherwise use bsd-core
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.
git clone git://git.freedesktop.org/git/mesa/mesa
cd mesa
./autogen.sh --prefix=/opt/gfx-test --with-driver=dri --disable-glut
make
make install
mkdir -p /opt/gfx-test/bin
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.
git clone git://git.freedesktop.org/git/mesa/mesa
cd mesa
git checkout origin/gallium-0.1
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
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
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
git clone git://git.freedesktop.org/git/xorg/driver/xf86-input-mouse
cd xf86-input-mouse
./autogen.sh --prefix=/opt/gfx-test
make
make install
xf86-input-keyboard
git clone git://git.freedesktop.org/git/xorg/driver/xf86-input-keyboard
cd xf86-input-keyboard
./autogen.sh --prefix=/opt/gfx-test
make
make install
xf86-video-intel
git clone git://git.freedesktop.org/git/xorg/driver/xf86-video-intel
cd xf86-video-intel
./autogen.sh --prefix=/opt/gfx-test
make
make install
Running your new stack
Now that your development environment is set up, you can try running it (as root).
rmmod i915 # assuming you're using Intel
rmmod drm
insmod <path_to_drm_tree_above>/linux-core/drm.ko
insmod <path_to_drm_tree_above>/linux-core/i915.ko
export LD_LIBRARY_PATH=/opt/gfx-test/lib
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

