Commit fb17ece8 authored by Joe Rayhawk's avatar Joe Rayhawk
Browse files

moin2iki: Importing Moin history for page CompilingMesa

parents b08783a9 0eb7011a
= This guide is an alternative guide of how to compile mesa libGL library for 3D rendering =
First of all I assume that you got at least basic 2D rendering working. If you don't you really should work on this first.
First create a directory to put all sources to it, for example say ~/software/graphics/
mkdir ~/software/
mkdir ~/software/graphics/
cd ~/software/graphics/
I hope that step is obivous to you anyway, if not, you can learn about console for example at
[[|ubuntu's console howto]]
Also make sure you have [[|git]] version control system installed, On Ubuntu systems its in 'git-core' package (beware of package 'git' which doesn't contain the git we talk about)
sudo apt-get install git-core
== Now install latest libdrm. ==
This step is usually necessarily because distributions typically lag behing libdrm that is necessarily to succesfully compile and use nouveau libGL.
Libdrm is the glue between kernel module and userspace and it is used by X driver and mesa to send
via kernel command streams to GPU.
Updating libdrm can in theory break your X as it also uses it. In practice it shouldn't happen, unless you have very old 2D nouveau driver.
First download libdrm using git from its official repostry:
git clone git://
This will create a directory named 'drm' in our current directory.
(please refer to TODO:$GIT_GUIDE to for other git related questions)
So enter it
cd drm
''note that I won't be repeating the last step as you should understand that by now for reasons I stated above''
Now configure it:
./ --enable-nouveau-experimental-api --disable-intel --disable-radeon --prefix=/usr/local
* ''--enable-nouveau-experimental-api'' - this ensures that nouveau support is compiled into libdrm. Disabled by default because..., well because interface isn't 'stable' yet..
* ''--prefix=/usr/local'' - location where to install it, this is default value but specified so you could tweak it if needed. Optional.
* ''--disable-intel'', ''--disable-radeon'' - compile time switches to disable parts of libdrm we don't need. Optional.
The former step will almost for sure fail, as usually you will be missing dependencies (that is libraries this library uses). Sadly this differs between distros.
On Ubuntu, the list of dependencies is:
* ''libx11-dev'' - several X11 related headers. don't know why needed....
* ''libpthread-stubs0-dev'' - libdrm uses this as fake replacement for pthreads. Don't know why needed. Arch linux doesn't have that package, and instead uses a [[|patch]] to stop it using these stubs. Seems only to affect intel portion of libdrm in practice.
* ''libudev-dev'' - probably uses it for hardware discovery
* ''libpciaccess-dev'' - used to get access to PCI devices for software outside the kernel.
If you have tough problem with configuring look at config.log. configure process mostly consists of compiling short test programs and testings that compile succeeded. If it fails, you'll see the log in that file. Look at it toward the end. Usually you will need the -dev package (-devel on some other distros) for a missing component.
Now compile it:
make -j2
''-j2'' says it to use 2 compile jobs and thus faster on dual core CPUs. If you have 4 core or more substitute with number of cores.
Note that this setting is purly optional.
And install it:
sudo make install
That will install the library into special directory ''/usr/local'' (thats the --prefix we specified, remember?) that exists for the purpose of overrinding distro's packages safely.
Usually you can't remove distro's libGL because too many packages depend on it, and it depends on distro's libdrm.
If you ever need to remove the installed files just go into that directory and remove files from it.
Its not that easy, but knowing that it _only_ holds files you compiled its usually small enough to find and remove everything you don't want.
'''Note''' Some braindead distros (I am looking at you Arch linux, although I am not Ubuntu fan!) don't use libraries from /usr/local/lib.
To make them see these libraries (libdrm in our case) add /usr/local/lib/ as a first line of /etc/
then run 'ldconfig' as root.
=== Compiling mesa OpenGL library ===
[[|Mesa]] [[|OpenGL]] library is the library that provides 3d acceleration on Linux.
It includes the Gallium3D, which is an modern intermediate layer between user facing API of the library and the driver code. Its included in mesa source tree.
Once again enter the main directory (~/software/graphics/)
Download mesa source the same way we did download libdrm once again from official repostry.
git clone git://
Download dependencies (these are listed in ubuntu's package, your distro will have sligtly different package names..., but overall idea is same):
* ''libdrm-dev'' - I am listing that for completeness. Mesa uses libdrm, but we just compiled it, so you '''DON'T''' need it!!
* ''libx11-dev'', ''libxfixes-dev'', ''libxdamage-dev'', ''libxext-dev'' -- X11 headers and libraies for GLX
* ''x11proto-gl-dev'' - GLX header files
* ''x11proto-dri2-dev'' - DRI2 protocol headers
* ''libxxf86vm-dev'' - X11 XFree86 video mode extension library - why the hell it needs that???
* ''xutils-dev'' - for makedepend compile helper too
* ''libexpat1-dev'' - parses driconf XML files
* ''libx11-xcb-dev'', libxcb-dri2-0-dev, libxcb-xfixes0-dev - to make it work a bit better in mulithreading environment.
* ''python2'' - yes some distros (arch for example), only bundle python3...
* ''python-libxml2'' - to parse XML api declarations bundled in source
* ''libudev-dev'' - probably to discover hardware
* ''flex'', ''bison'' - to compile shader compiler - most systems has this installed
Configure it:
./ \
--prefix=/usr/local/lib/mesa/ \
--with-dri-driverdir=/usr/local/lib/mesa/ \
--with-gallium-drivers="nouveau" \
--enable-debug \
--enable-texture-float \
--with-dri-drivers="" \
--disable-egl \
--disable-glu \
--disable-gallium-llvm \
Description of options:
* ''--prefix=/usr/local/lib/mesa/'' - we will install mesa OpenGL library into non standard location. This will help it coexist with nvidia drivers for example or allow us to disable it temporatly to avoid crashes if system uses OpenGL when desktop starts, etc...
* ''--with-dri-driverdir=/usr/local/lib/mesa/'' - this tells mesa build system to install hardware drivers to same custom dir we install mesa lib to. Note that meaning of 'hardware' driver is quite loose this day. The driver that we will compile that serves nvidia cards, named, actually contains all of Gallium3D and mesa is actually quite tiny wrapper around that. That might change in the future. FYI, Drivers are usually installed to /usr/lib/dri. This way I put them side by side with mesa is better for developer/tester.
* ''--with-gallium-drivers="nouveau"'' - self explanatory.
* ''--enable-debug'' - same as above, this enables some debug code. It will cost small fraction of FPs, but might help catch bugs.
* ''--enable-texture-float'' - this enables support for special hardware feature, so called floating point textures. This feature is patented, and thus to cover the legal a** of the developers, disabled by default. Of course if you enable it, and your country has software patents you could be sued. Use that at your own risk. Many games sadly need that feature.
* all other options are just to cut down compile time and are optional
Now compile it in same way and install (ok, last time I repeat that...) and install it.
make -j2
sudo make install
Now add /usr/local/lib/mesa/lib as first line of /etc/ and run ldconfig after that.
Run 'ldd $(which glxgears)' and hope it says that libGL from mesa is used.
We found out that on Arch linux its libGL which located in ''/usr/lib'' is always prefered over the one we install, so you have no choice but to remove it (and not rename it, as ldconfig is too smart for that...) You can instead of removing to move the libGL* files to different directory though.
And enjoy your latest mesa!
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment