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

4.104.114.95
Last change on this file since a14171f was a14171f, checked in by Chris Johns <chrisj@…>, on 04/10/14 at 08:26:42

sb: Add _host_os_version to all supported hosts.

  • Property mode set to 100644
File size: 5.4 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    version = uname[2]
54    defines = {
55        '_ncpus':           ('none',    'none',     ncpus),
56        '_os':              ('none',    'none',     'linux'),
57        '_host':            ('triplet', 'required', cpu + '-linux-gnu'),
58        '_host_vendor':     ('none',    'none',     'gnu'),
59        '_host_os':         ('none',    'none',     'linux'),
60        '_host_os_version': ('none',    'none',     version),
61        '_host_cpu':        ('none',    'none',     cpu),
62        '_host_alias':      ('none',    'none',     '%{nil}'),
63        '_host_arch':       ('none',    'none',     cpu),
64        '_usr':             ('dir',     'required', '/usr'),
65        '_var':             ('dir',     'required', '/var'),
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    try:
73        distro = platform.dist()[0]
74        distro_ver = float(platform.dist()[1])
75    except ValueError:
76        # Non LSB distro found, use failover"
77        pass
78
79    # Non LSB - fail over to issue
80    if distro == '':
81        try:
82            issue = open('/etc/issue').read()
83            distro = issue.split(' ')[0]
84            distro_ver = float(issue.split(' ')[2])
85        except:
86            pass
87
88    # Manage distro aliases
89    if distro in ['centos']:
90        distro = 'redhat'
91    elif distro in ['fedora']:
92        if distro_ver < 17:
93            distro = 'redhat'
94    elif distro in ['centos', 'fedora']:
95        distro = 'redhat'
96    elif distro in ['Ubuntu', 'ubuntu']:
97        distro = 'debian'
98    elif distro in ['Arch']:
99        distro = 'arch'
100    elif distro in ['SuSE']:
101        distro = 'suse'
102
103    variations = {
104        'debian' : { '__bzip2':        ('exe',     'required', '/bin/bzip2'),
105                     '__chgrp':        ('exe',     'required', '/bin/chgrp'),
106                     '__chown':        ('exe',     'required', '/bin/chown'),
107                     '__grep':         ('exe',     'required', '/bin/grep'),
108                     '__sed':          ('exe',     'required', '/bin/sed') },
109        'redhat' : { '__bzip2':        ('exe',     'required', '/bin/bzip2'),
110                     '__chgrp':        ('exe',     'required', '/bin/chgrp'),
111                     '__chown':        ('exe',     'required', '/bin/chown'),
112                     '__install_info': ('exe',     'required', '/sbin/install-info'),
113                     '__grep':         ('exe',     'required', '/bin/grep'),
114                     '__sed':          ('exe',     'required', '/bin/sed'),
115                     '__touch':        ('exe',     'required', '/bin/touch') },
116        'fedora' : { '__chown':        ('exe',     'required', '/usr/bin/chown'),
117                     '__install_info': ('exe',     'required', '/usr/sbin/install-info') },
118        'arch'   : { '__gzip':         ('exe',     'required', '/usr/bin/gzip'),
119                     '__chown':        ('exe',     'required', '/usr/bin/chown') },
120        'suse'   : { '__chgrp':        ('exe',     'required', '/usr/bin/chgrp'),
121                     '__chown':        ('exe',     'required', '/usr/sbin/chown') },
122        }
123
124    if variations.has_key(distro):
125        for v in variations[distro]:
126            if path.exists(variations[distro][v][2]):
127                defines[v] = variations[distro][v]
128
129    defines['_build']        = defines['_host']
130    defines['_build_vendor'] = defines['_host_vendor']
131    defines['_build_os']     = defines['_host_os']
132    defines['_build_cpu']    = defines['_host_cpu']
133    defines['_build_alias']  = defines['_host_alias']
134    defines['_build_arch']   = defines['_host_arch']
135
136    return defines
137
138if __name__ == '__main__':
139    pprint.pprint(load())
Note: See TracBrowser for help on using the repository browser.