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:
- kernel
- Dependencies
DRM (both libdrm & the DRM modules for non-intel)
- 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.
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:
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
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:
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. Don't bother for intel.
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.
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
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
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
You possibly will want the evdev driver, especially if your distro uses the evdev system
xf86-input-evdev
git clone git://git.freedesktop.org/git/xorg/driver/xf86-input-evdev
cd xf86-input-evdev
./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).
This first 4 steps are no longer need, for the drives which use new drm gem, which is the case of Intel.
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"
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"
REPOS="\
git://git.freedesktop.org/git/xorg/util/macros \
git://git.freedesktop.org/git/xorg/proto/x11proto \
git://git.freedesktop.org/git/xorg/proto/damageproto \
git://git.freedesktop.org/git/xorg/proto/xextproto \
git://git.freedesktop.org/git/xorg/proto/fontsproto \
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/proto/xf86vidmodeproto \
git://git.freedesktop.org/git/xorg/proto/xf86dgaproto \
git://git.freedesktop.org/git/xorg/proto/xf86driproto \
git://git.freedesktop.org/git/xorg/proto/xcmiscproto \
git://git.freedesktop.org/git/xorg/proto/scrnsaverproto \
git://git.freedesktop.org/git/xorg/proto/bigreqsproto \
git://git.freedesktop.org/git/xorg/proto/resourceproto \
git://git.freedesktop.org/git/xorg/proto/compositeproto \
git://git.freedesktop.org/git/xorg/proto/fixesproto \
git://git.freedesktop.org/git/xorg/proto/evieproto \
git://git.freedesktop.org/git/xorg/proto/kbproto \
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/libXv \
git://git.freedesktop.org/git/xorg/lib/libXvMC \
git://git.freedesktop.org/git/xorg/lib/libXxf86vm \
git://git.freedesktop.org/git/xorg/lib/libXinerama \
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="\
fontsproto \
x11proto \
xextproto \
videoproto \
renderproto \
inputproto \
damageproto \
xf86vidmodeproto \
xf86dgaproto \
xf86driproto \
xcmiscproto \
scrnsaverproto \
bigreqsproto \
resourceproto \
compositeproto \
resourceproto \
evieproto \
kbproto \
fixesproto \
libxtrans \
proto \
pthread-stubs \
libxcb \
libX11 \
libXext \
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)
make install
cd ..
}
update_modules()
{
for module in $modules; do
echo "Updating $module"
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 ======================
echo configuring $i
echo ======================
./autogen.sh --prefix="$PREFIX"
echo ======================
echo building $i
echo ======================
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 --with-state-trackers="egl dri2"
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

