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 | # 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 | |
---|
27 | import pprint |
---|
28 | import os |
---|
29 | |
---|
30 | import check |
---|
31 | import execute |
---|
32 | |
---|
33 | def load(): |
---|
34 | uname = os.uname() |
---|
35 | sysctl = '/sbin/sysctl ' |
---|
36 | e = execute.capture_execution() |
---|
37 | exit_code, proc, output = e.shell(sysctl + 'hw.ncpu') |
---|
38 | if exit_code == 0: |
---|
39 | ncpus = output.split(' ')[1].strip() |
---|
40 | else: |
---|
41 | ncpus = '1' |
---|
42 | if uname[4] == 'amd64': |
---|
43 | cpu = 'x86_64' |
---|
44 | else: |
---|
45 | cpu = uname[4] |
---|
46 | version = uname[2] |
---|
47 | if version.find('-') > 0: |
---|
48 | version = version.split('-')[0] |
---|
49 | defines = { |
---|
50 | '_ncpus': ('none', 'none', ncpus), |
---|
51 | '_os': ('none', 'none', 'freebsd'), |
---|
52 | '_host': ('triplet', 'required', cpu + '-freebsd' + version), |
---|
53 | '_host_vendor': ('none', 'none', 'pc'), |
---|
54 | '_host_os': ('none', 'none', 'freebsd'), |
---|
55 | '_host_os_version': ('none', 'none', version), |
---|
56 | '_host_cpu': ('none', 'none', cpu), |
---|
57 | '_host_alias': ('none', 'none', '%{nil}'), |
---|
58 | '_host_arch': ('none', 'none', cpu), |
---|
59 | '_usr': ('dir', 'required', '/usr/local'), |
---|
60 | '_var': ('dir', 'optional', '/usr/local/var'), |
---|
61 | '__bash': ('exe', 'optional', '/usr/local/bin/bash'), |
---|
62 | '__bison': ('exe', 'required', '/usr/local/bin/bison'), |
---|
63 | '__git': ('exe', 'required', '/usr/local/bin/git'), |
---|
64 | '__svn': ('exe', 'required', '/usr/local/bin/svn'), |
---|
65 | '__xz': ('exe', 'optional', '/usr/bin/xz'), |
---|
66 | '__make': ('exe', 'required', 'gmake'), |
---|
67 | '__patch_opts': ('none', 'none', '-E') |
---|
68 | } |
---|
69 | |
---|
70 | defines['_build'] = defines['_host'] |
---|
71 | defines['_build_vendor'] = defines['_host_vendor'] |
---|
72 | defines['_build_os'] = defines['_host_os'] |
---|
73 | defines['_build_cpu'] = defines['_host_cpu'] |
---|
74 | defines['_build_alias'] = defines['_host_alias'] |
---|
75 | defines['_build_arch'] = defines['_host_arch'] |
---|
76 | |
---|
77 | # FreeBSD 10 and above no longer have /usr/bin/cvs, but it can (e.g.) be |
---|
78 | # installed to /usr/local/bin/cvs through the devel/cvs port |
---|
79 | if int(float(version)) >= 10: |
---|
80 | cc = '/usr/bin/cc' |
---|
81 | if check.check_exe(cc, cc): |
---|
82 | defines['__cc'] = cc |
---|
83 | cxx = '/usr/bin/c++' |
---|
84 | if check.check_exe(cxx, cxx): |
---|
85 | defines['__cxx'] = cxx |
---|
86 | cvs = 'cvs' |
---|
87 | if check.check_exe(cvs, cvs): |
---|
88 | defines['__cvs'] = cvs |
---|
89 | # |
---|
90 | # Fix the mess iconv is on FreeBSD 10.0. |
---|
91 | # |
---|
92 | defines['iconv_optincludes'] = ('none', 'none', '-I/usr/local/include -L/usr/local/lib') |
---|
93 | |
---|
94 | for gv in ['47', '48', '49']: |
---|
95 | gcc = '%s-portbld-freebsd%s-gcc%s' % (cpu, version, gv) |
---|
96 | if check.check_exe(gcc, gcc): |
---|
97 | defines['__cc'] = gcc |
---|
98 | break |
---|
99 | for gv in ['47', '48', '49']: |
---|
100 | gxx = '%s-portbld-freebsd%s-g++%s' % (cpu, version, gv) |
---|
101 | if check.check_exe(gxx, gxx): |
---|
102 | defines['__cxx'] = gxx |
---|
103 | break |
---|
104 | |
---|
105 | return defines |
---|
106 | |
---|
107 | if __name__ == '__main__': |
---|
108 | pprint.pprint(load()) |
---|