source: rtems-tools/rtemstoolkit/netbsd.py @ 3618a62

5
Last change on this file since 3618a62 was 7d3350d, checked in by Chris Johns <chrisj@…>, on 04/24/17 at 14:31:44

rtemstoolkit: Move host support access into a separate module.

Moving the host support into a module lets it get used where options
is not being used.

  • Property mode set to 100644
File size: 3.6 KB
Line 
1#
2# RTEMS Tools Project (http://www.rtems.org/)
3# Copyright 2010-2017 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# RTEMS Tools is free software: you can redistribute it and/or modify
9# it under the terms of the GNU General Public License as published by
10# the Free Software Foundation, either version 3 of the License, or
11# (at your option) any later version.
12#
13# RTEMS Tools is distributed in the hope that it will be useful,
14# but WITHOUT ANY WARRANTY; without even the implied warranty of
15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16# GNU General Public License for more details.
17#
18# You should have received a copy of the GNU General Public License
19# along with RTEMS Tools.  If not, see <http://www.gnu.org/licenses/>.
20#
21
22#
23# This code is based on what ever doco about spec files I could find and
24# RTEMS project's spec files.
25#
26
27import os
28
29try:
30    from . import check
31    from . import execute
32except (ValueError, SystemError):
33    import check
34    import execute
35
36def cpus():
37    sysctl = '/sbin/sysctl '
38    e = execute.capture_execution()
39    exit_code, proc, output = e.shell(sysctl + 'hw.ncpu')
40    if exit_code == 0:
41        ncpus = int(output.split(' ')[1].strip())
42    else:
43        ncpus = 1
44    return ncpus
45
46def overrides():
47    uname = os.uname()
48    ncpus = '%d' % (cpus())
49    if uname[4] == 'amd64':
50        cpu = 'x86_64'
51    else:
52        cpu = uname[4]
53    version = uname[2]
54    if version.find('-') > 0:
55        version = version.split('-')[0]
56    defines = {
57        '_ncpus':            ('none',    'none',    '1'),
58        '_os':               ('none',    'none',     'netbsd'),
59        '_host':             ('triplet', 'required', cpu + '-netbsd' + version),
60        '_host_vendor':      ('none',    'none',     'pc'),
61        '_host_os':          ('none',    'none',     'netbsd'),
62        '_host_os_version':  ('none',    'none',     version),
63        '_host_cpu':         ('none',    'none',     cpu),
64        '_host_alias':       ('none',    'none',     '%{nil}'),
65        '_host_arch':        ('none',    'none',     cpu),
66        '_usr':              ('dir',     'required', '/usr'),
67        '_var':              ('dir',     'optional', '/var'),
68        'optincludes_build': ('none',    'none',     '-I/usr/pkg/include -L/usr/pkg/lib'),
69        '__bash':            ('exe',     'optional', '/usr/pkg/bin/bash'),
70        '__bison':           ('exe',     'required', '/usr/pkg/bin/bison'),
71        '__git':             ('exe',     'required', '/usr/pkg/bin/git'),
72        '__svn':             ('exe',     'required', '/usr/pkg/bin/svn'),
73        '__xz':              ('exe',     'optional', '/usr/pkg/bin/xz'),
74        '__make':            ('exe',     'required', 'gmake'),
75        '__patch_opts':      ('none',     'none',    '-E')
76        }
77
78    defines['_build']        = defines['_host']
79    defines['_build_vendor'] = defines['_host_vendor']
80    defines['_build_os']     = defines['_host_os']
81    defines['_build_cpu']    = defines['_host_cpu']
82    defines['_build_alias']  = defines['_host_alias']
83    defines['_build_arch']   = defines['_host_arch']
84
85    for gv in ['47', '48', '49']:
86        gcc = '%s-portbld-netbsd%s-gcc%s' % (cpu, version, gv)
87        if check.check_exe(gcc, gcc):
88            defines['__cc'] = gcc
89            break
90    for gv in ['47', '48', '49']:
91        gxx = '%s-portbld-netbsd%s-g++%s' % (cpu, version, gv)
92        if check.check_exe(gxx, gxx):
93            defines['__cxx'] = gxx
94            break
95
96    return defines
97
98if __name__ == '__main__':
99    import pprint
100    pprint.pprint(cpus())
101    pprint.pprint(overrides())
Note: See TracBrowser for help on using the repository browser.