summaryrefslogtreecommitdiff
path: root/Development/BuildingX.mdwn
blob: 441b1fe7ee5c2c87fa6db3055c84c71092e56785 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
**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|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:

[[!toc ]]

An alternate method of building the packages in a more automated fashion using the jhbuild utility can be found in the [[JhBuildInstructions|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:


[[!format txt """
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:
[[!format txt """
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|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`
1. `cd drm`
1. `./autogen.sh --prefix=/opt/gfx-test` _# or wherever you want to install it._
1. `make`
1. `make -C linux-core` _# assuming you're on Linux, otherwise use bsd-core.  Don't bother for intel._
1. `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|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`
1. `cd mesa`
1. `./autogen.sh --prefix=/opt/gfx-test --with-driver=dri --disable-glut`
1. `make`
1. `make install`
1. `mkdir -p /opt/gfx-test/bin`
1. `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`
1. `cd mesa`
1. `git checkout origin/gallium-0.1`
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

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

## xf86-input-keyboard

1. `git clone git://git.freedesktop.org/git/xorg/driver/xf86-input-keyboard`
1. `cd xf86-input-keyboard`
1. `./autogen.sh --prefix=/opt/gfx-test`
1. `make`
1. `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`
1. `cd xf86-input-evdev`
1. `./autogen.sh --prefix=/opt/gfx-test`
1. `make`
1. `make install`

## xf86-video-intel

1. `git clone git://git.freedesktop.org/git/xorg/driver/xf86-video-intel`
1. `cd xf86-video-intel`
1. `./autogen.sh --prefix=/opt/gfx-test`
1. `make`
1. `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_
1. `rmmod drm`
1. `insmod `_<path_to_drm_tree_above>_`/linux-core/drm.ko`
1. `insmod `_<path_to_drm_tree_above>_`/linux-core/i915.ko`
1. `export LD_LIBRARY_PATH=/opt/gfx-test/lib`
1. `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

[[!format txt """

# !/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

"""]]