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

4.104.114.95
Last change on this file since b83b596 was b83b596, checked in by Chris Johns <chrisj@…>, on 05/16/13 at 05:34:00

Fix the core detection on Linux.

  • Property mode set to 100644
File size: 5.1 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    ncpus = 0
39    if exit_code == 0:
40        try:
41            for l in output.split('\n'):
42                count = l.split(':')[1].strip()
43                if int(count) > ncpus:
44                    ncpus = int(count)
45        except:
46            pass
47    ncpus = str(ncpus + 1)
48    if uname[4].startswith('arm'):
49        cpu = 'arm'
50    else:
51        cpu = uname[4]
52
53    defines = {
54        '_ncpus':         ('none',    'none',     ncpus),
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        '__bzip2':        ('exe',     'required', '/usr/bin/bzip2'),
65        '__gzip':         ('exe',     'required', '/bin/gzip'),
66        '__tar':          ('exe',     'required', '/bin/tar')
67        }
68
69    # Works for LSB distros
70    distro = platform.dist()[0]
71    distro_ver = float(platform.dist()[1])
72
73    # Non LSB - fail over to issue
74    if distro == '':
75        try:
76            issue = open('/etc/issue').read()
77            distro = issue.split(' ')[0]
78            distro_ver = float(issue.split(' ')[2])
79        except:
80            pass
81
82    # Manage distro aliases
83    if distro in ['centos']:
84        distro = 'redhat'
85    elif distro in ['fedora']:
86        if distro_ver < 17:
87            distro = 'redhat'
88    elif distro in ['centos', 'fedora']:
89        distro = 'redhat'
90    elif distro in ['Ubuntu', 'ubuntu']:
91        distro = 'debian'
92    elif distro in ['Arch']:
93        distro = 'arch'
94    elif distro in ['SuSE']:
95        distro = 'suse'
96
97    variations = {
98        'debian' : { '__bzip2':        ('exe',     'required', '/bin/bzip2'),
99                     '__chgrp':        ('exe',     'required', '/bin/chgrp'),
100                     '__chown':        ('exe',     'required', '/bin/chown'),
101                     '__grep':         ('exe',     'required', '/bin/grep'),
102                     '__sed':          ('exe',     'required', '/bin/sed') },
103        'redhat' : { '__bzip2':        ('exe',     'required', '/bin/bzip2'),
104                     '__chgrp':        ('exe',     'required', '/bin/chgrp'),
105                     '__chown':        ('exe',     'required', '/bin/chown'),
106                     '__install_info': ('exe',     'required', '/sbin/install-info'),
107                     '__grep':         ('exe',     'required', '/bin/grep'),
108                     '__sed':          ('exe',     'required', '/bin/sed'),
109                     '__touch':        ('exe',     'required', '/bin/touch') },
110        'fedora' : { '__chown':        ('exe',     'required', '/usr/bin/chown'),
111                     '__install_info': ('exe',     'required', '/usr/sbin/install-info') },
112        'arch'   : { '__gzip':         ('exe',     'required', '/usr/bin/gzip'),
113                     '__chown':        ('exe',     'required', '/usr/bin/chown') },
114        'suse'   : { '__chgrp':        ('exe',     'required', '/usr/bin/chgrp'),
115                     '__chown':        ('exe',     'required', '/usr/sbin/chown') },
116        }
117
118    if variations.has_key(distro):
119        for v in variations[distro]:
120            if path.exists(variations[distro][v][2]):
121                defines[v] = variations[distro][v]
122
123    defines['_build']        = defines['_host']
124    defines['_build_vendor'] = defines['_host_vendor']
125    defines['_build_os']     = defines['_host_os']
126    defines['_build_cpu']    = defines['_host_cpu']
127    defines['_build_alias']  = defines['_host_alias']
128    defines['_build_arch']   = defines['_host_arch']
129
130    return defines
131
132if __name__ == '__main__':
133    pprint.pprint(load())
Note: See TracBrowser for help on using the repository browser.