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

4.10
Last change on this file since ce33364 was ce33364, checked in by Sebastian Huber <sebastian.huber@…>, on 01/17/19 at 10:29:50

sb: Change Linux default prefix to "/opt"

http://refspecs.linuxbase.org/FHS_3.0/fhs/ch03s13.html#purpose14

Update #3680.

  • 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        '_prefix':          ('dir',     'optional', '/opt'),
67        '__bzip2':          ('exe',     'required', '/usr/bin/bzip2'),
68        '__gzip':           ('exe',     'required', '/bin/gzip'),
69        '__tar':            ('exe',     'required', '/bin/tar')
70        }
71
72    # Works for LSB distros
73    try:
74        distro = platform.dist()[0]
75        distro_ver = float(platform.dist()[1])
76    except ValueError:
77        # Non LSB distro found, use failover"
78        pass
79
80    # Non LSB - fail over to issue
81    if distro == '':
82        try:
83            issue = open('/etc/issue').read()
84            distro = issue.split(' ')[0]
85            distro_ver = float(issue.split(' ')[2])
86        except:
87            pass
88
89    # Manage distro aliases
90    if distro in ['centos']:
91        distro = 'redhat'
92    elif distro in ['fedora']:
93        if distro_ver < 17:
94            distro = 'redhat'
95    elif distro in ['centos', 'fedora']:
96        distro = 'redhat'
97    elif distro in ['Ubuntu', 'ubuntu', 'LinuxMint', 'linuxmint']:
98        distro = 'debian'
99    elif distro in ['Arch']:
100        distro = 'arch'
101    elif distro in ['SuSE']:
102        distro = 'suse'
103
104    variations = {
105        'debian' : { '__bzip2':        ('exe',     'required', '/bin/bzip2'),
106                     '__chgrp':        ('exe',     'required', '/bin/chgrp'),
107                     '__chown':        ('exe',     'required', '/bin/chown'),
108                     '__grep':         ('exe',     'required', '/bin/grep'),
109                     '__sed':          ('exe',     'required', '/bin/sed') },
110        'redhat' : { '__bzip2':        ('exe',     'required', '/bin/bzip2'),
111                     '__chgrp':        ('exe',     'required', '/bin/chgrp'),
112                     '__chown':        ('exe',     'required', '/bin/chown'),
113                     '__install_info': ('exe',     'required', '/sbin/install-info'),
114                     '__grep':         ('exe',     'required', '/bin/grep'),
115                     '__sed':          ('exe',     'required', '/bin/sed'),
116                     '__touch':        ('exe',     'required', '/bin/touch') },
117        'fedora' : { '__chown':        ('exe',     'required', '/usr/bin/chown'),
118                     '__install_info': ('exe',     'required', '/usr/sbin/install-info') },
119        'arch'   : { '__gzip':         ('exe',     'required', '/usr/bin/gzip'),
120                     '__chown':        ('exe',     'required', '/usr/bin/chown') },
121        'suse'   : { '__chgrp':        ('exe',     'required', '/usr/bin/chgrp'),
122                     '__chown':        ('exe',     'required', '/usr/sbin/chown') },
123        }
124
125    if distro in variations:
126        for v in variations[distro]:
127            if path.exists(variations[distro][v][2]):
128                defines[v] = variations[distro][v]
129
130    defines['_build']        = defines['_host']
131    defines['_build_vendor'] = defines['_host_vendor']
132    defines['_build_os']     = defines['_host_os']
133    defines['_build_cpu']    = defines['_host_cpu']
134    defines['_build_alias']  = defines['_host_alias']
135    defines['_build_arch']   = defines['_host_arch']
136
137    return defines
138
139if __name__ == '__main__':
140    pprint.pprint(load())
Note: See TracBrowser for help on using the repository browser.