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

« back to all changes in this revision

Viewing changes to build/autoconf/libstdcxx.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
 
# This script find the version of libstdc++ and prints it as single number
8
 
# with 8 bits per element. For example, GLIBCXX_3.4.10 becomes
9
 
# 3 << 16 | 4 << 8 | 10 = 197642. This format is easy to use
10
 
# in the C preprocessor.
11
 
 
12
 
# We find out both the host and target versions. Since the output
13
 
# will be used from shell, we just print the two assignments and evaluate
14
 
# them from shell.
15
 
 
16
 
import os
17
 
import subprocess
18
 
import re
19
 
import sys
20
 
 
21
 
re_for_ld = re.compile('.*\((.*)\).*')
22
 
 
23
 
def parse_readelf_line(x):
24
 
    """Return the version from a readelf line that looks like:
25
 
    0x00ec: Rev: 1  Flags: none  Index: 8  Cnt: 2  Name: GLIBCXX_3.4.6
26
 
    """
27
 
    return x.split(':')[-1].split('_')[-1].strip()
28
 
 
29
 
def parse_ld_line(x):
30
 
    """Parse a line from the output of ld -t. The output of gold is just
31
 
    the full path, gnu ld prints "-lstdc++ (path)".
32
 
    """
33
 
    t = re_for_ld.match(x)
34
 
    if t:
35
 
        return t.groups()[0].strip()
36
 
    return x.strip()
37
 
 
38
 
def split_ver(v):
39
 
    """Covert the string '1.2.3' into the list [1,2,3]
40
 
    """
41
 
    return [int(x) for x in v.split('.')]
42
 
 
43
 
def cmp_ver(a, b):
44
 
    """Compare versions in the form 'a.b.c'
45
 
    """
46
 
    for (i, j) in zip(split_ver(a), split_ver(b)):
47
 
        if i != j:
48
 
            return i - j
49
 
    return 0
50
 
 
51
 
def encode_ver(v):
52
 
    """Encode the version as a single number.
53
 
    """
54
 
    t = split_ver(v)
55
 
    return t[0] << 16 | t[1] << 8 | t[2]
56
 
 
57
 
def find_version(e):
58
 
    """Given the value of environment variable CXX or HOST_CXX, find the
59
 
    version of the libstdc++ it uses.
60
 
    """
61
 
    args = e.split()
62
 
    args +=  ['-shared', '-Wl,-t']
63
 
    p = subprocess.Popen(args, stderr=subprocess.STDOUT, stdout=subprocess.PIPE)
64
 
    candidates = [x for x in p.stdout if 'libstdc++.so' in x]
65
 
    assert len(candidates) == 1
66
 
    libstdcxx = parse_ld_line(candidates[-1])
67
 
 
68
 
    p = subprocess.Popen(['readelf', '-V', libstdcxx], stdout=subprocess.PIPE)
69
 
    versions = [parse_readelf_line(x)
70
 
                for x in p.stdout.readlines() if 'Name: GLIBCXX' in x]
71
 
    last_version = sorted(versions, cmp = cmp_ver)[-1]
72
 
    return encode_ver(last_version)
73
 
 
74
 
if __name__ == '__main__':
75
 
    if os.uname()[0] == 'Darwin':
76
 
        sdk_dir = os.environ['MACOS_SDK_DIR']
77
 
        if 'MacOSX10.5.sdk' in sdk_dir:
78
 
            target_ver = 0
79
 
            host_ver = 0
80
 
        else:
81
 
            target_ver = encode_ver('3.4.9')
82
 
            host_ver = encode_ver('3.4.9')
83
 
    else:
84
 
        cxx_env = os.environ['CXX']
85
 
        target_ver = find_version(cxx_env)
86
 
        host_cxx_env = os.environ.get('HOST_CXX', cxx_env)
87
 
        host_ver = find_version(host_cxx_env)
88
 
 
89
 
    print 'MOZ_LIBSTDCXX_TARGET_VERSION=%s' % target_ver
90
 
    print 'MOZ_LIBSTDCXX_HOST_VERSION=%s' % host_ver