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