3
Read this file if you are a Debian Developer or would like to become
4
one, or if you would like to create your own binary packages of GCC.
8
From the GCC sources, Debian currently builds 3 source packages and
9
almost 100 binary packages, using a single set of build scripts. The
10
3 source packages are:
12
gcc-4.3: C, C++, Fortran, Objective-C and Objective-C++, plus many
13
common libraries like libssp and libgcc.
17
The way we do this is quite peculiar, so listen up :)
19
When we build from the gcc-4.3 source package, we produce, among many
20
others, a gcc-4.3-source binary package that contains the pristine
21
upstream tarball and some Debian-specific patches. Any user can then
22
install this package on their Debian system, and will have the full
23
souces in /usr/src/gcc-4.3/gcc-<timestamp>.tar.bz2, along with the
24
Makefile snippets that unpack and patch them.
26
The intended use for this package is twofold: (a) allow users to build
27
their own cross-compilers, and (b) build the other two packages,
30
For gcj-4.3 and gnat-4.3, the "source tarball" just contains an empty
33
$ tar tzf gnat-4.3_4.3-20070609.orig.tar.gz
34
gnat-4.3-4.3-20070609.orig/
36
The build scripts for all source packages are the same, and they are
37
included, as usual, in the .diff.gz file.
41
As for all other Debian packages, you build GCC by calling
44
The first thing debian/rules does it to look at the top-most entry in
45
debian/changelog: this tells it which source package it is building.
46
For example, if the first entry in debian/changelog reads:
48
gcj-4.3 (4.3-20070609-1) unstable; urgency=low
52
-- Ludovic Brenta <lbrenta@debian.org> Tue, 26 Jun 2007 00:26:42 +0200
54
then, debian/rules will build only the Java binary packages.
56
The second step is to unpack the GCC source tarball. This tarball is
57
either in the build directory (when building gcc-4.3), or in
58
/usr/src/gcc-4.3/gcc-<timestamp>.tar.bz2 (when building the other
61
The third step is to build debian/control from debian/control.m4 and a
62
complex set of rules specified in debian/rules.conf. The resulting
63
control file contains only the binary packages to be built.
65
The fourth step is to select which patches to apply (this is done in
66
debian/rules.defs), and then to apply the selected patches (see
69
The fifth step is to create a "build" directory, cd into it, call
70
../src/configure, and bootstrap the compiler and libraries selected.
71
This is in debian/rules2.
73
The sixth step is to call "make install" in the build directory: this
74
installs the compiler and libraries into debian/tmp
75
(i.e. debian/tmp/usr/bin/gcc, etc.)
77
The seventh step is to run the GCC test suite (this actually takes at
78
least as much time as bootstrapping, and you can disable it by setting
79
WITHOUT_CHECK to "yes" in the environment).
81
The eighth step is to build the binary packages, i.e. the .debs. This
82
is done by a set of language- and architecture-dependent Makefile
83
snippets in the debian/rules.d/ directory, which move files from the
84
debian/tmp tree to the debian/<package> trees.
86
* Making your own packages
88
In this example, we will build our own gnat-4.3 package.
90
1) Create a .orig.tar.gz tarball containing a single, empty directory.
92
$ mkdir gnat-4.3-4.3-20070609.orig
93
$ tar czf gnat-4.3_4.3-20070609.orig.tar.gz gnat-4.3-4.3-20070609.orig
95
2) Install gcc-4.3-source, which contains the real sources:
97
# apt-get install gcc-4.3-source
99
3) Create a build directory:
101
$ mkdir gnat-4.3-4.3-20070609; cd gnat-4.3-4.3-20070609
103
4) Checkout from Subversion:
105
$ svn checkout svn://svn.debian.org/gcccvs/branches/sid/gcc-4.3/debian
107
5) Edit the debian/changelog file, adding a new entry at the top that
108
starts with "gnat-4.3" instead of "gcc-4.3".
110
6) Generate the debian/control file, adjusted for gnat:
112
$ debian/rules control
116
$ dpkg-buildpackage -rfakeroot
120
You need a powerful machine to build GCC. The larger, the better.
121
The build scripts take advantage of as many CPU threads as are
122
available in your box (for example: 2 threads on a dual-core amd64; 4
123
threads on a dual-core POWER5; 32 threads on an 8-core UltraSPARC T1,
126
If you have 2 GB or more of physical RAM, you can achieve maximum
127
performance by building in a tmpfs, like this:
129
1) as root, create the new tmpfs:
131
# mount -t tmpfs -o size=1280m none /home/lbrenta/src/debian/ram
133
By default, the tmpfs will be limited to half your physical RAM. The
134
beauty of it is that it only consumes as much physical RAM as
135
necessary to hold the files in it; deleting files frees up RAM.
137
2) As your regular user, create the working directory in the tmpfs
139
$ cp --archive ~/src/debian/gcc-4.3-4.3-20070901 ~/src/debian/ram
141
3) Build in there. On my dual-core, 2 GHz amd64, it takes 34 minutes
142
to build gnat, and the tmpfs takes 992 MiB of physical RAM but
143
exceeds 1 GiB during the build.
145
Note that the build process uses a lot of temporary files. Your $TEMP
146
directory should therefore also be in a ram disk. You can achieve
147
that either by mounting it as tmpfs, or by setting TEMP to point to
150
Also note that each thread in your processor(s) will run a compiler in
151
it and use up RAM. Therefore your physical memory should be:
153
Physical_RAM >= 1.2 + 0.4 * Threads (in GiB)
155
(this is an estimate; your mileage may vary). If you have less
156
physical RAM than recommended, reduce the number of threads allocated
157
to the build process, or do not use a tmpfs to build.
161
Debian applies a large number of patches to GCC as part of the build
162
process. The patches are shell scripts located in debian/patches.
163
The file debian/rules.defs selects the language front-ends and
164
libraries to build. Then, based on that, debian/rules.patch selects
165
which patches to apply and in which order, then applies them and
166
produces a file listing the applied patches in order in
167
stamps/02-patch-stamp.
169
There is currently no tool to help modify patches; you have to do it
170
by hand. Here is one possible way to do it:
172
1) Apply all patches up to and EXCLUDING the patch you intend to
175
2) Make a deep copy of the src directory, e.g.
176
$ cp --archive src src.bak
178
3) Apply the patch you intend to modify.
180
4) Open the .dpatch file in your editor and remove the entire patch
181
section; leave alone the shell script part at the top.
183
5) Change the files you want in the src directory. After making
184
changes, you can experiment with
186
(where K is the number of processor threads you have)
188
6) $ diff -rNu src.bak src >> debian/patches/<file>.dpatch
190
7) Apply all remaining patches, to see if your change broke any of
193
8) $ svn commit debian/patches/<file>.dpatch
195
If you want to add a new patch, the procedure is similar. You must
196
first choose where in the list of patches you want to insert your new
197
patch. Then, apply all patches up to that point and start editing.
198
Do not forget to add a reference to your patch at the proper place in
201
** Patching GCC with Quilt
203
The above method uses an entire copy of the source tree, which is
204
currently 474 megabytes in size. If you are in a one-gigabyte ram
205
disk (see Hints above), this may be a problem. One solution to this
206
problem is to use quilt, which will only keep copies of the files
207
touched by patches, not all files. It also automates the updating of
208
a patch after you change the sources.
210
Quilt however does not take into account the selection of patches made
211
in debian/rules.defs; instead it has a static list of patches. After
212
calling "debian/rules patch", you can generate such a list like this:
214
$ egrep '^[^ ]+:' stamps/02-patch-stamp | \
215
sed 's!:!.dpatch -p0!' > debian/patches/series
217
Unfortunately, not all patches are applied with -p0; you must then
218
edit debian/patches/series by hand to replace -p0 with -p1 for a few
221
Once you have your debian/patches/series:
223
$ debian/rules unpatch
224
$ export QUILT_PATCHES=$PWD/debian/patches
226
$ quilt push -a (or quilt push <patch_name>)
227
edit files at will; quilt add <file_name> to add a new file to the patch
230
$ quilt push -a # check that no patch is broken
233
$ debian/rules clean build
237
Ludovic Brenta, 2007-12-05.