1 | # |
---|
2 | # RTEMS Tools Project (http://www.rtems.org/) |
---|
3 | # Copyright 2010-2013 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 | # Windows specific support and overrides. |
---|
22 | # |
---|
23 | |
---|
24 | import error |
---|
25 | import pprint |
---|
26 | import os |
---|
27 | import sys |
---|
28 | |
---|
29 | import execute |
---|
30 | |
---|
31 | def load(): |
---|
32 | # Default to the native Windows Python. |
---|
33 | uname = 'win32' |
---|
34 | if 'PROCESSOR_ARCHITECTURE' in os.environ: |
---|
35 | if os.environ['PROCESSOR_ARCHITECTURE'] == 'AMD64': |
---|
36 | hosttype = 'x86_64' |
---|
37 | machsize = '64' |
---|
38 | else: |
---|
39 | hosttype = 'i686' |
---|
40 | machsize = '32' |
---|
41 | else: |
---|
42 | hosttype = 'x86_64' |
---|
43 | machsize = '32' |
---|
44 | |
---|
45 | uname = 'mingw32' |
---|
46 | machine = 'w%s' % (machsize) |
---|
47 | |
---|
48 | # See if this is actually MSYS2/Cygwin Python |
---|
49 | if os.name == 'posix': |
---|
50 | _uname = os.uname() |
---|
51 | if _uname[0].startswith('MINGW'): |
---|
52 | pass |
---|
53 | elif _uname[0].startswith('CYGWIN'): |
---|
54 | hosttype = _uname[4] |
---|
55 | uname = 'cygwin' |
---|
56 | machine = 'pc' |
---|
57 | else: |
---|
58 | raise error.general('invalid POSIX python for Windows') |
---|
59 | |
---|
60 | host_triple = '%s-%s-%s' % (hosttype, machine, uname) |
---|
61 | build_triple = '%s-%s-%s' % (hosttype, machine, uname) |
---|
62 | |
---|
63 | if 'NUMBER_OF_PROCESSORS' in os.environ: |
---|
64 | ncpus = os.environ['NUMBER_OF_PROCESSORS'] |
---|
65 | else: |
---|
66 | ncpus = '1' |
---|
67 | |
---|
68 | if 'MSYSTEM' in os.environ: |
---|
69 | os.environ.pop('NUMBER_OF_PROCESSORS') |
---|
70 | |
---|
71 | version = uname[2] |
---|
72 | defines = { |
---|
73 | '_ncpus': ('none', 'none', ncpus), |
---|
74 | '_os': ('none', 'none', 'win32'), |
---|
75 | '_build': ('triplet', 'required', build_triple), |
---|
76 | '_build_vendor': ('none', 'none', 'microsoft'), |
---|
77 | '_build_os': ('none', 'none', 'win32'), |
---|
78 | '_build_os_version': ('none', 'none', version), |
---|
79 | '_build_cpu': ('none', 'none', hosttype), |
---|
80 | '_build_alias': ('none', 'none', '%{nil}'), |
---|
81 | '_build_arch': ('none', 'none', hosttype), |
---|
82 | '_host': ('triplet', 'required', host_triple), |
---|
83 | '_host_vendor': ('none', 'none', 'microsoft'), |
---|
84 | '_host_os': ('none', 'none', 'win32'), |
---|
85 | '_host_cpu': ('none', 'none', hosttype), |
---|
86 | '_host_alias': ('none', 'none', '%{nil}'), |
---|
87 | '_host_arch': ('none', 'none', hosttype), |
---|
88 | '_usr': ('dir', 'optional', '/opt/local'), |
---|
89 | '_var': ('dir', 'optional', '/opt/local/var'), |
---|
90 | '__bash': ('exe', 'required', 'bash'), |
---|
91 | '__bzip2': ('exe', 'required', 'bzip2'), |
---|
92 | '__bison': ('exe', 'required', 'bison'), |
---|
93 | '__cat': ('exe', 'required', 'cat'), |
---|
94 | '__cc': ('exe', 'required', 'gcc'), |
---|
95 | '__chgrp': ('exe', 'required', 'chgrp'), |
---|
96 | '__chmod': ('exe', 'required', 'chmod'), |
---|
97 | '__chown': ('exe', 'required', 'chown'), |
---|
98 | '__cp': ('exe', 'required', 'cp'), |
---|
99 | '__cvs': ('exe', 'required', 'cvs'), |
---|
100 | '__cxx': ('exe', 'required', 'g++'), |
---|
101 | '__flex': ('exe', 'required', 'flex'), |
---|
102 | '__git': ('exe', 'required', 'git'), |
---|
103 | '__grep': ('exe', 'required', 'grep'), |
---|
104 | '__gzip': ('exe', 'required', 'gzip'), |
---|
105 | '__id': ('exe', 'required', 'id'), |
---|
106 | '__install': ('exe', 'required', 'install'), |
---|
107 | '__install_info': ('exe', 'required', 'install-info'), |
---|
108 | '__ld': ('exe', 'required', 'ld'), |
---|
109 | '__ldconfig': ('exe', 'none', ''), |
---|
110 | '__makeinfo': ('exe', 'required', 'makeinfo'), |
---|
111 | '__mkdir': ('exe', 'required', 'mkdir'), |
---|
112 | '__mv': ('exe', 'required', 'mv'), |
---|
113 | '__nm': ('exe', 'required', 'nm'), |
---|
114 | '__nm': ('exe', 'required', 'nm'), |
---|
115 | '__objcopy': ('exe', 'required', 'objcopy'), |
---|
116 | '__objdump': ('exe', 'required', 'objdump'), |
---|
117 | '__patch': ('exe', 'required', 'patch'), |
---|
118 | '__patch_bin': ('exe', 'required', 'patch'), |
---|
119 | '__rm': ('exe', 'required', 'rm'), |
---|
120 | '__sed': ('exe', 'required', 'sed'), |
---|
121 | '__sh': ('exe', 'required', 'sh'), |
---|
122 | '__tar': ('exe', 'required', 'bsdtar'), |
---|
123 | '__touch': ('exe', 'required', 'touch'), |
---|
124 | '__unzip': ('exe', 'required', 'unzip'), |
---|
125 | '__xz': ('exe', 'required', 'xz'), |
---|
126 | '_buildshell': ('exe', 'required', '%{__sh}'), |
---|
127 | '___setup_shell': ('exe', 'required', '%{__sh}') |
---|
128 | } |
---|
129 | |
---|
130 | # |
---|
131 | # Locate a suitable python to use with GDB. Python Windows is more |
---|
132 | # complicated than most hosts. There are 7 possible pythons on Windows and |
---|
133 | # we can use only 4 which are split on machine size. The types are: |
---|
134 | # |
---|
135 | # 1. Python27 - python.org, cannot use cause built with MSVC. |
---|
136 | # 2. Python35 - python.org, cannot use cause built with MSVC. |
---|
137 | # 3. MSYS/Python - MSYS2, cannot use cause it is a MSYS executable. |
---|
138 | # 4. W64/Python2 - Ok if machsize is 64 |
---|
139 | # 5. W64/Python3 - gdb-7.9 needs python2. |
---|
140 | # 6. W64/Python2 - Ok if machsize is 32 |
---|
141 | # 7. W64/Python3 - gdb-7.9 needs python2. |
---|
142 | # |
---|
143 | if sys.platform == 'win32' and 'MSC' in sys.version: |
---|
144 | raise error.general('python.org Pythons are built with MSC and cannot be linked with GDB') |
---|
145 | |
---|
146 | # |
---|
147 | # Search the MSYS2 install tree for a suitable python. |
---|
148 | # |
---|
149 | if sys.platform == 'msys': |
---|
150 | e = execute.capture_execution() |
---|
151 | exit_code, proc, output = e.shell("sh -c mount") |
---|
152 | if exit_code != 0: |
---|
153 | raise error.general('cannot get MSYS mount points') |
---|
154 | install_point = None |
---|
155 | for l in output.split('\n'): |
---|
156 | if ' on / ' in l: |
---|
157 | install_point = l.split()[0] |
---|
158 | break |
---|
159 | if install_point is None: |
---|
160 | raise error.general('cannot locate MSYS root mount point') |
---|
161 | if install_point[1] != ':': |
---|
162 | raise error.general('invalid MSYS root mount point: %s' % install_point) |
---|
163 | install_point = '/%s%s' % (install_point[0], install_point[2:]) |
---|
164 | bin = '/mingw%s/bin' % (machsize) |
---|
165 | bin_list = os.listdir(bin) |
---|
166 | exe = None |
---|
167 | for python in ['python2.exe']: |
---|
168 | for f in bin_list: |
---|
169 | if f == python: |
---|
170 | exe = install_point + os.path.join(bin, f) |
---|
171 | break; |
---|
172 | if exe is not None: |
---|
173 | break |
---|
174 | if exe is None: |
---|
175 | raise error.general('no valid python found; you need a mingw%s python2 installed' % (machsize)) |
---|
176 | defines['with_python_path'] = exe |
---|
177 | |
---|
178 | |
---|
179 | return defines |
---|
180 | |
---|
181 | if __name__ == '__main__': |
---|
182 | pprint.pprint(load()) |
---|