~ubuntu-branches/ubuntu/quantal/enigmail/quantal-security

« back to all changes in this revision

Viewing changes to mozilla/build/unix/build-toolchain/build-gcc.py

  • Committer: Package Import Robot
  • Author(s): Chris Coulson
  • Date: 2013-09-13 16:02:15 UTC
  • mfrom: (0.12.16)
  • Revision ID: package-import@ubuntu.com-20130913160215-u3g8nmwa0pdwagwc
Tags: 2:1.5.2-0ubuntu0.12.10.1
* New upstream release v1.5.2 for Thunderbird 24

* Build enigmail using a stripped down Thunderbird 17 build system, as it's
  now quite difficult to build the way we were doing previously, with the
  latest Firefox build system
* Add debian/patches/no_libxpcom.patch - Don't link against libxpcom, as it
  doesn't exist anymore (but exists in the build system)
* Add debian/patches/use_sdk.patch - Use the SDK version of xpt.py and
  friends
* Drop debian/patches/ipc-pipe_rename.diff (not needed anymore)
* Drop debian/patches/makefile_depth.diff (not needed anymore)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/python
 
2
# This Source Code Form is subject to the terms of the Mozilla Public
 
3
# License, v. 2.0. If a copy of the MPL was not distributed with this
 
4
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
5
 
 
6
 
 
7
# The directories end up in the debug info, so the easy way of getting
 
8
# a reproducible build is to run it in a know absolute directory.
 
9
# We use a directory in /builds/slave because the mozilla infrastructure
 
10
# cleans it up automatically.
 
11
base_dir = "/builds/slave/moz-toolchain"
 
12
 
 
13
source_dir = base_dir + "/src"
 
14
build_dir  = base_dir + "/build"
 
15
aux_inst_dir = build_dir + '/aux_inst'
 
16
old_make = aux_inst_dir + '/bin/make'
 
17
 
 
18
##############################################
 
19
 
 
20
import urllib
 
21
import os
 
22
import os.path
 
23
import shutil
 
24
import tarfile
 
25
import subprocess
 
26
 
 
27
def download_uri(uri):
 
28
    fname = uri.split('/')[-1]
 
29
    if (os.path.exists(fname)):
 
30
        return fname
 
31
    urllib.urlretrieve(uri, fname)
 
32
    return fname
 
33
 
 
34
def extract(tar, path):
 
35
    t = tarfile.open(tar)
 
36
    t.extractall(path)
 
37
 
 
38
def check_run(args):
 
39
    r = subprocess.call(args)
 
40
    assert r == 0
 
41
 
 
42
def run_in(path, args):
 
43
    d = os.getcwd()
 
44
    os.chdir(path)
 
45
    check_run(args)
 
46
    os.chdir(d)
 
47
 
 
48
def patch(patch, plevel, srcdir):
 
49
    patch = os.path.realpath(patch)
 
50
    check_run(['patch', '-d', srcdir, '-p%s' % plevel, '-i', patch, '--fuzz=0',
 
51
               '-s'])
 
52
 
 
53
def build_package(package_source_dir, package_build_dir, configure_args,
 
54
                   make = old_make):
 
55
    if not os.path.exists(package_build_dir):
 
56
        os.mkdir(package_build_dir)
 
57
    run_in(package_build_dir,
 
58
           ["%s/configure" % package_source_dir] + configure_args)
 
59
    run_in(package_build_dir, [make, "-j8"])
 
60
    run_in(package_build_dir, [make, "install"])
 
61
 
 
62
def build_aux_tools(base_dir):
 
63
    make_build_dir = base_dir + '/make_build'
 
64
    build_package(make_source_dir, make_build_dir,
 
65
                  ["--prefix=%s" % aux_inst_dir], "make")
 
66
 
 
67
    run_in(unifdef_source_dir, ["make"])
 
68
    run_in(unifdef_source_dir, ["make", "prefix=%s" % aux_inst_dir, "install"])
 
69
 
 
70
    tar_build_dir = base_dir + '/tar_build'
 
71
    build_package(tar_source_dir, tar_build_dir,
 
72
                  ["--prefix=%s" % aux_inst_dir])
 
73
 
 
74
    gawk_build_dir = base_dir + '/gawk_build'
 
75
    build_package(gawk_source_dir, gawk_build_dir,
 
76
                  ["--prefix=%s" % aux_inst_dir])
 
77
 
 
78
def with_env(env, f):
 
79
    old_env = os.environ.copy()
 
80
    os.environ.update(env)
 
81
    f()
 
82
    os.environ.clear()
 
83
    os.environ.update(old_env)
 
84
 
 
85
def build_glibc(env, stage_dir, inst_dir):
 
86
    def f():
 
87
        build_glibc_aux(stage_dir, inst_dir)
 
88
    with_env(env, f)
 
89
 
 
90
def build_glibc_aux(stage_dir, inst_dir):
 
91
    glibc_build_dir = stage_dir + '/glibc'
 
92
    build_package(glibc_source_dir, glibc_build_dir,
 
93
                  ["--disable-profile",
 
94
                   "--enable-add-ons=nptl",
 
95
                   "--without-selinux",
 
96
                   "--enable-kernel=%s" % linux_version,
 
97
                   "--libdir=%s/lib64" % inst_dir,
 
98
                   "--prefix=%s" % inst_dir])
 
99
 
 
100
def build_linux_headers_aux(inst_dir):
 
101
    run_in(linux_source_dir, [old_make, "headers_check"])
 
102
    run_in(linux_source_dir, [old_make, "INSTALL_HDR_PATH=dest",
 
103
                               "headers_install"])
 
104
    shutil.move(linux_source_dir + "/dest/include", inst_dir + '/include')
 
105
 
 
106
def build_linux_headers(inst_dir):
 
107
    def f():
 
108
        build_linux_headers_aux(inst_dir)
 
109
    with_env({"PATH" : aux_inst_dir + "/bin:%s" % os.environ["PATH"]}, f)
 
110
 
 
111
def build_gcc(stage_dir, is_stage_one):
 
112
    gcc_build_dir = stage_dir + '/gcc'
 
113
    tool_inst_dir = stage_dir + '/inst'
 
114
    lib_inst_dir = stage_dir + '/libinst'
 
115
    gcc_configure_args = ["--prefix=%s" % tool_inst_dir,
 
116
                          "--enable-__cxa_atexit",
 
117
                          "--with-gmp=%s" % lib_inst_dir,
 
118
                          "--with-mpfr=%s" % lib_inst_dir,
 
119
                          "--with-mpc=%s" % lib_inst_dir,
 
120
                          "--enable-languages=c,c++",
 
121
                          "--disable-lto",
 
122
                          "--disable-multilib",
 
123
                          "--disable-bootstrap"]
 
124
    if is_stage_one:
 
125
        # We build the stage1 gcc without shared libraries. Otherwise its
 
126
        # libgcc.so would depend on the system libc.so, which causes problems
 
127
        # when it tries to use that libgcc.so and the libc we are about to
 
128
        # build.
 
129
        gcc_configure_args.append("--disable-shared")
 
130
 
 
131
    build_package(gcc_source_dir, gcc_build_dir, gcc_configure_args)
 
132
 
 
133
    if is_stage_one:
 
134
        # The glibc build system uses -lgcc_eh, but at least in this setup
 
135
        # libgcc.a has all it needs.
 
136
        d = tool_inst_dir + "/lib/gcc/x86_64-unknown-linux-gnu/4.5.2/"
 
137
        os.symlink(d + "libgcc.a", d + "libgcc_eh.a")
 
138
 
 
139
def build_one_stage(env, stage_dir, is_stage_one):
 
140
    def f():
 
141
        build_one_stage_aux(stage_dir, is_stage_one)
 
142
    with_env(env, f)
 
143
 
 
144
def build_one_stage_aux(stage_dir, is_stage_one):
 
145
    os.mkdir(stage_dir)
 
146
 
 
147
    lib_inst_dir = stage_dir + '/libinst'
 
148
 
 
149
    gmp_build_dir = stage_dir + '/gmp'
 
150
    build_package(gmp_source_dir, gmp_build_dir,
 
151
                  ["--prefix=%s" % lib_inst_dir, "--disable-shared"])
 
152
    mpfr_build_dir = stage_dir + '/mpfr'
 
153
    build_package(mpfr_source_dir, mpfr_build_dir,
 
154
                  ["--prefix=%s" % lib_inst_dir, "--disable-shared",
 
155
                   "--with-gmp=%s" % lib_inst_dir])
 
156
    mpc_build_dir = stage_dir + '/mpc'
 
157
    build_package(mpc_source_dir, mpc_build_dir,
 
158
                  ["--prefix=%s" % lib_inst_dir, "--disable-shared",
 
159
                   "--with-gmp=%s" % lib_inst_dir,
 
160
                   "--with-mpfr=%s" % lib_inst_dir])
 
161
 
 
162
    tool_inst_dir = stage_dir + '/inst'
 
163
    os.mkdir(tool_inst_dir)
 
164
    os.mkdir(tool_inst_dir + '/lib64')
 
165
    os.symlink('lib64', tool_inst_dir + '/lib')
 
166
 
 
167
    build_linux_headers(tool_inst_dir)
 
168
 
 
169
    # zlib's configure only works if run from the source dir, copy the source
 
170
    zlib_build_dir = stage_dir + '/zlib'
 
171
    shutil.copytree(zlib_source_dir, zlib_build_dir)
 
172
    build_package(zlib_build_dir, zlib_build_dir,
 
173
                  ["--prefix=%s" % tool_inst_dir])
 
174
 
 
175
    binutils_build_dir = stage_dir + '/binutils'
 
176
    build_package(binutils_source_dir, binutils_build_dir,
 
177
                  ["--prefix=%s" % tool_inst_dir,
 
178
                   "--without-zlib"])
 
179
 
 
180
    # During stage one we have to build gcc first, this glibc doesn't even
 
181
    # build with gcc 4.6. During stage two, we have to build glibc first.
 
182
    # The problem is that libstdc++ is built with xgcc and if glibc has
 
183
    # not been built yet xgcc will use the system one.
 
184
    if is_stage_one:
 
185
        build_gcc(stage_dir, is_stage_one)
 
186
        build_glibc({"CC"  : tool_inst_dir + "/bin/gcc",
 
187
                     "CXX" : tool_inst_dir + "/bin/g++"},
 
188
                    stage_dir, tool_inst_dir)
 
189
    else:
 
190
        build_glibc({}, stage_dir, tool_inst_dir)
 
191
        build_gcc(stage_dir, is_stage_one)
 
192
 
 
193
def build_tar_package(tar, name, base, directory):
 
194
    name = os.path.realpath(name)
 
195
    run_in(base, [tar, "-cf", name, "--mtime=2012-01-01", "--owner=root",
 
196
                  directory])
 
197
 
 
198
##############################################
 
199
 
 
200
def build_source_dir(prefix, version):
 
201
    return source_dir + '/' + prefix + version
 
202
 
 
203
binutils_version = "2.21.1"
 
204
glibc_version = "2.5.1"
 
205
linux_version = "2.6.18"
 
206
tar_version = "1.26"
 
207
gawk_version = "3.1.5"
 
208
make_version = "3.81"
 
209
gcc_version = "4.5.2"
 
210
mpfr_version = "2.4.2"
 
211
zlib_version = "1.2.3"
 
212
gmp_version = "5.0.1"
 
213
mpc_version = "0.8.1"
 
214
unifdef_version = "2.6"
 
215
 
 
216
binutils_source_uri = "http://ftp.gnu.org/gnu/binutils/binutils-%sa.tar.bz2" % \
 
217
    binutils_version
 
218
glibc_source_uri = "http://ftp.gnu.org/gnu/glibc/glibc-%s.tar.bz2" % \
 
219
    glibc_version
 
220
linux_source_uri = "http://www.kernel.org/pub/linux/kernel/v2.6/linux-%s.tar.bz2" % \
 
221
    linux_version
 
222
tar_source_uri = "http://ftp.gnu.org/gnu/tar/tar-%s.tar.bz2" % \
 
223
    tar_version
 
224
gawk_source_uri = "http://ftp.gnu.org/gnu/gawk/gawk-%s.tar.bz2" % \
 
225
    gawk_version
 
226
make_source_uri = "http://ftp.gnu.org/gnu/make/make-%s.tar.bz2" % \
 
227
    make_version
 
228
unifdef_source_uri = "http://dotat.at/prog/unifdef/unifdef-%s.tar.gz" % \
 
229
    unifdef_version
 
230
gcc_source_uri = "http://ftp.gnu.org/gnu/gcc/gcc-%s/gcc-%s.tar.bz2" % \
 
231
    (gcc_version, gcc_version)
 
232
mpfr_source_uri = "http://www.mpfr.org/mpfr-%s/mpfr-%s.tar.bz2" % \
 
233
    (mpfr_version, mpfr_version)
 
234
zlib_source_uri = "http://iweb.dl.sourceforge.net/project/libpng/zlib/%s/zlib-%s.tar.bz2" % (zlib_version, zlib_version)
 
235
gmp_source_uri = "http://ftp.gnu.org/gnu/gmp/gmp-%s.tar.bz2" % gmp_version
 
236
mpc_source_uri = "http://www.multiprecision.org/mpc/download/mpc-%s.tar.gz" % \
 
237
    mpc_version
 
238
 
 
239
binutils_source_tar = download_uri(binutils_source_uri)
 
240
glibc_source_tar = download_uri(glibc_source_uri)
 
241
linux_source_tar = download_uri(linux_source_uri)
 
242
tar_source_tar = download_uri(tar_source_uri)
 
243
gawk_source_tar = download_uri(gawk_source_uri)
 
244
make_source_tar = download_uri(make_source_uri)
 
245
unifdef_source_tar = download_uri(unifdef_source_uri)
 
246
mpc_source_tar = download_uri(mpc_source_uri)
 
247
mpfr_source_tar = download_uri(mpfr_source_uri)
 
248
zlib_source_tar = download_uri(zlib_source_uri)
 
249
gmp_source_tar = download_uri(gmp_source_uri)
 
250
gcc_source_tar = download_uri(gcc_source_uri)
 
251
 
 
252
binutils_source_dir  = build_source_dir('binutils-', binutils_version)
 
253
glibc_source_dir  = build_source_dir('glibc-', glibc_version)
 
254
linux_source_dir  = build_source_dir('linux-', linux_version)
 
255
tar_source_dir  = build_source_dir('tar-', tar_version)
 
256
gawk_source_dir  = build_source_dir('gawk-', gawk_version)
 
257
make_source_dir  = build_source_dir('make-', make_version)
 
258
unifdef_source_dir  = build_source_dir('unifdef-', unifdef_version)
 
259
mpc_source_dir  = build_source_dir('mpc-', mpc_version)
 
260
mpfr_source_dir = build_source_dir('mpfr-', mpfr_version)
 
261
zlib_source_dir = build_source_dir('zlib-', zlib_version)
 
262
gmp_source_dir  = build_source_dir('gmp-', gmp_version)
 
263
gcc_source_dir  = build_source_dir('gcc-', gcc_version)
 
264
 
 
265
if not os.path.exists(source_dir):
 
266
    os.makedirs(source_dir)
 
267
    extract(binutils_source_tar, source_dir)
 
268
    patch('binutils-deterministic.patch', 1, binutils_source_dir)
 
269
    extract(glibc_source_tar, source_dir)
 
270
    extract(linux_source_tar, source_dir)
 
271
    patch('glibc-deterministic.patch', 1, glibc_source_dir)
 
272
    run_in(glibc_source_dir, ["autoconf"])
 
273
    extract(tar_source_tar, source_dir)
 
274
    extract(gawk_source_tar, source_dir)
 
275
    extract(make_source_tar, source_dir)
 
276
    extract(unifdef_source_tar, source_dir)
 
277
    extract(mpc_source_tar, source_dir)
 
278
    extract(mpfr_source_tar, source_dir)
 
279
    extract(zlib_source_tar, source_dir)
 
280
    extract(gmp_source_tar, source_dir)
 
281
    extract(gcc_source_tar, source_dir)
 
282
    patch('plugin_finish_decl.diff', 0, gcc_source_dir)
 
283
    patch('libtool-74c8993c178a1386ea5e2363a01d919738402f30.patch', 1, gcc_source_dir)
 
284
    patch('pr49911.diff', 1, gcc_source_dir)
 
285
    patch('r159628-r163231-r171807.patch', 1, gcc_source_dir)
 
286
    patch('gcc-fixinc.patch', 1, gcc_source_dir)
 
287
    patch('gcc-include.patch', 1, gcc_source_dir)
 
288
 
 
289
if os.path.exists(build_dir):
 
290
    shutil.rmtree(build_dir)
 
291
os.makedirs(build_dir)
 
292
 
 
293
build_aux_tools(build_dir)
 
294
 
 
295
basic_path = aux_inst_dir + "/bin:/bin:/usr/bin"
 
296
 
 
297
stage1_dir = build_dir + '/stage1'
 
298
build_one_stage({"PATH"   : basic_path,
 
299
                 "CC"     : "gcc",
 
300
                 "CXX"    : "g++" },
 
301
                stage1_dir, True)
 
302
 
 
303
for stage_num in range(2, 4):
 
304
    prev_stage_dir = build_dir + '/stage' + str(stage_num - 1)
 
305
    prev_stage_inst_dir = prev_stage_dir + '/inst'
 
306
    cur_stage_dir = build_dir + '/stage' + str(stage_num)
 
307
    build_one_stage({"PATH"   : prev_stage_inst_dir + "/bin:" + basic_path,
 
308
                     "CC"     : "gcc -fgnu89-inline",
 
309
                     "CXX"    : "g++",
 
310
                     "RANLIB" : "true" },
 
311
                    cur_stage_dir, False)
 
312
 
 
313
stage3_dir = build_dir + '/stage3'
 
314
build_tar_package(aux_inst_dir + "/bin/tar",
 
315
                  "toolchain.tar", stage3_dir, "inst")