source: rtems-tools/rtemstoolkit/linux.py @ 3badbb0

4.104.115
Last change on this file since 3badbb0 was 50fdf12, checked in by Chris Johns <chrisj@…>, on 02/14/14 at 19:30:06

rt: Add the rtems-tester.

  • Property mode set to 100644
File size: 5.8 KB
Line 
1#
2# RTEMS Tools Project (http://www.rtems.org/)
3# Copyright 2010-2014 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# Redistribution and use in source and binary forms, with or without
9# modification, are permitted provided that the following conditions are met:
10#
11# 1. Redistributions of source code must retain the above copyright notice,
12# this list of conditions and the following disclaimer.
13#
14# 2. Redistributions in binary form must reproduce the above copyright notice,
15# this list of conditions and the following disclaimer in the documentation
16# and/or other materials provided with the distribution.
17#
18# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
22# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28# POSSIBILITY OF SUCH DAMAGE.
29#
30
31#
32# This code is based on what ever doco about spec files I could find and
33# RTEMS project's spec files.
34#
35
36import pprint
37import os
38
39import platform
40import execute
41import path
42
43def load():
44    uname = os.uname()
45    smp_mflags = ''
46    processors = '/bin/grep processor /proc/cpuinfo'
47    e = execute.capture_execution()
48    exit_code, proc, output = e.shell(processors)
49    ncpus = 0
50    if exit_code == 0:
51        try:
52            for l in output.split('\n'):
53                count = l.split(':')[1].strip()
54                if int(count) > ncpus:
55                    ncpus = int(count)
56        except:
57            pass
58    ncpus = str(ncpus + 1)
59    if uname[4].startswith('arm'):
60        cpu = 'arm'
61    else:
62        cpu = uname[4]
63
64    defines = {
65        '_ncpus':         ('none',    'none',     ncpus),
66        '_os':            ('none',    'none',     'linux'),
67        '_host':          ('triplet', 'required', cpu + '-linux-gnu'),
68        '_host_vendor':   ('none',    'none',     'gnu'),
69        '_host_os':       ('none',    'none',     'linux'),
70        '_host_cpu':      ('none',    'none',     cpu),
71        '_host_alias':    ('none',    'none',     '%{nil}'),
72        '_host_arch':     ('none',    'none',     cpu),
73        '_usr':           ('dir',     'required', '/usr'),
74        '_var':           ('dir',     'required', '/var'),
75        '__bzip2':        ('exe',     'required', '/usr/bin/bzip2'),
76        '__gzip':         ('exe',     'required', '/bin/gzip'),
77        '__tar':          ('exe',     'required', '/bin/tar')
78        }
79
80    # Works for LSB distros
81    try:
82        distro = platform.dist()[0]
83        distro_ver = float(platform.dist()[1])
84    except ValueError:
85        # Non LSB distro found, use failover"
86        pass
87
88    # Non LSB - fail over to issue
89    if distro == '':
90        try:
91            issue = open('/etc/issue').read()
92            distro = issue.split(' ')[0]
93            distro_ver = float(issue.split(' ')[2])
94        except:
95            pass
96
97    # Manage distro aliases
98    if distro in ['centos']:
99        distro = 'redhat'
100    elif distro in ['fedora']:
101        if distro_ver < 17:
102            distro = 'redhat'
103    elif distro in ['centos', 'fedora']:
104        distro = 'redhat'
105    elif distro in ['Ubuntu', 'ubuntu']:
106        distro = 'debian'
107    elif distro in ['Arch']:
108        distro = 'arch'
109    elif distro in ['SuSE']:
110        distro = 'suse'
111
112    variations = {
113        'debian' : { '__bzip2':        ('exe',     'required', '/bin/bzip2'),
114                     '__chgrp':        ('exe',     'required', '/bin/chgrp'),
115                     '__chown':        ('exe',     'required', '/bin/chown'),
116                     '__grep':         ('exe',     'required', '/bin/grep'),
117                     '__sed':          ('exe',     'required', '/bin/sed') },
118        'redhat' : { '__bzip2':        ('exe',     'required', '/bin/bzip2'),
119                     '__chgrp':        ('exe',     'required', '/bin/chgrp'),
120                     '__chown':        ('exe',     'required', '/bin/chown'),
121                     '__install_info': ('exe',     'required', '/sbin/install-info'),
122                     '__grep':         ('exe',     'required', '/bin/grep'),
123                     '__sed':          ('exe',     'required', '/bin/sed'),
124                     '__touch':        ('exe',     'required', '/bin/touch') },
125        'fedora' : { '__chown':        ('exe',     'required', '/usr/bin/chown'),
126                     '__install_info': ('exe',     'required', '/usr/sbin/install-info') },
127        'arch'   : { '__gzip':         ('exe',     'required', '/usr/bin/gzip'),
128                     '__chown':        ('exe',     'required', '/usr/bin/chown') },
129        'suse'   : { '__chgrp':        ('exe',     'required', '/usr/bin/chgrp'),
130                     '__chown':        ('exe',     'required', '/usr/sbin/chown') },
131        }
132
133    if variations.has_key(distro):
134        for v in variations[distro]:
135            if path.exists(variations[distro][v][2]):
136                defines[v] = variations[distro][v]
137
138    defines['_build']        = defines['_host']
139    defines['_build_vendor'] = defines['_host_vendor']
140    defines['_build_os']     = defines['_host_os']
141    defines['_build_cpu']    = defines['_host_cpu']
142    defines['_build_alias']  = defines['_host_alias']
143    defines['_build_arch']   = defines['_host_arch']
144
145    return defines
146
147if __name__ == '__main__':
148    pprint.pprint(load())
Note: See TracBrowser for help on using the repository browser.