source: rtems-source-builder/source-builder/sb/linux.py @ fbc946c

4.104.114.95
Last change on this file since fbc946c was fbc946c, checked in by Chris Johns <chrisj@…>, on 04/02/13 at 06:54:21

Fix the CPU count on Linux.

  • Property mode set to 100644
File size: 4.2 KB
Line 
1#
2# RTEMS Tools Project (http://www.rtems.org/)
3# Copyright 2010-2012 Chris Johns (chrisj@rtems.org)
4# All rights reserved.
5#
6# This file is part of the RTEMS Tools package in 'rtems-tools'.
7#
8# Permission to use, copy, modify, and/or distribute this software for any
9# purpose with or without fee is hereby granted, provided that the above
10# copyright notice and this permission notice appear in all copies.
11#
12# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
13# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
14# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
15# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
16# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
17# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
18# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19
20#
21# This code is based on what ever doco about spec files I could find and
22# RTEMS project's spec files.
23#
24
25import pprint
26import os
27
28import platform
29import execute
30import path
31
32def load():
33    uname = os.uname()
34    smp_mflags = ''
35    processors = '/bin/grep processor /proc/cpuinfo'
36    e = execute.capture_execution()
37    exit_code, proc, output = e.shell(processors)
38    if exit_code == 0:
39        cpus = 0
40        try:
41            for l in output.split('\n'):
42                count = l.split(':')[1].strip()
43                if count > cpus:
44                    cpus = int(count)
45            if cpus > 0:
46                smp_mflags = '-j%d' % (cpus + 1)
47        except:
48            pass
49    if uname[4].startswith('arm'):
50        cpu = 'arm'
51    else:
52        cpu = uname[4]
53
54    defines = {
55        '_os':            ('none',    'none',     'linux'),
56        '_host':          ('triplet', 'required', cpu + '-linux-gnu'),
57        '_host_vendor':   ('none',    'none',     'gnu'),
58        '_host_os':       ('none',    'none',     'linux'),
59        '_host_cpu':      ('none',    'none',     cpu),
60        '_host_alias':    ('none',    'none',     '%{nil}'),
61        '_host_arch':     ('none',    'none',     cpu),
62        '_usr':           ('dir',     'required', '/usr'),
63        '_var':           ('dir',     'required', '/var'),
64        'optflags':       ('none',    'none',     '-O2 -pipe'),
65        '_smp_mflags':    ('none',    'none',     smp_mflags),
66        '__bzip2':        ('exe',     'required', '/usr/bin/bzip2'),
67        '__gzip':         ('exe',     'required', '/bin/gzip'),
68        '__tar':          ('exe',     'required', '/bin/tar')
69        }
70
71    # Works for LSB distros
72    distro = platform.dist()[0]
73
74    # Non LSB - fail over to issue
75    if distro == '':
76        try:
77            issue = open('/etc/issue').read()
78            distro = issue.split(' ')[0]
79        except:
80            pass
81
82    # Manage distro aliases
83    if distro in ['centos', 'fedora']:
84        distro = 'redhat'
85    if distro in ['Ubuntu', 'ubuntu']:
86        distro = 'debian'
87    if distro in ['Arch']:
88        distro = 'arch'
89
90    variations = {
91        'debian' : { '__bzip2':        ('exe',     'required', '/bin/bzip2'),
92                     '__chgrp':        ('exe',     'required', '/bin/chgrp'),
93                     '__chown':        ('exe',     'required', '/bin/chown'),
94                     '__grep':         ('exe',     'required', '/bin/grep'),
95                     '__sed':          ('exe',     'required', '/bin/sed') },
96        'redhat' : { '__bzip2':        ('exe',     'required', '/bin/bzip2'),
97                     '__chgrp':        ('exe',     'required', '/bin/chgrp'),
98                     '__chown':        ('exe',     'required', '/bin/chown'),
99                     '__grep':         ('exe',     'required', '/bin/grep'),
100                     '__sed':          ('exe',     'required', '/bin/sed'),
101                     '__install_info': ('exe',     'required', '/sbin/install-info') },
102        'arch'   : { '__gzip':         ('exe',     'required', '/usr/bin/gzip'),
103                     '__chown':        ('exe',     'required', '/usr/bin/chown') },
104        }
105
106    if variations.has_key(distro):
107        for v in variations[distro]:
108            if path.exists(variations[distro][v][2]):
109                defines[v] = variations[distro][v]
110    return defines
111
112if __name__ == '__main__':
113    pprint.pprint(load())
Note: See TracBrowser for help on using the repository browser.