annotate Lib/distutils/emxccompiler.py @ 54294:dba767bc3155 legacy-trunk

remove mention of old ctypes version
author Benjamin Peterson <benjamin@python.org>
date Sat, 23 May 2009 20:59:09 +0000
parents 9314be0bbb64
children 386452b2d9d5 6b18a095c2e7
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
21885
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
1 """distutils.emxccompiler
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
2
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
3 Provides the EMXCCompiler class, a subclass of UnixCCompiler that
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
4 handles the EMX port of the GNU C compiler to OS/2.
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
5 """
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
6
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
7 # issues:
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
8 #
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
9 # * OS/2 insists that DLLs can have names no longer than 8 characters
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
10 # We put export_symbols in a def-file, as though the DLL can have
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
11 # an arbitrary length name, but truncate the output filename.
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
12 #
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
13 # * only use OMF objects and use LINK386 as the linker (-Zomf)
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
14 #
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
15 # * always build for multithreading (-Zmt) as the accompanying OS/2 port
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
16 # of Python is only distributed with threads enabled.
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
17 #
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
18 # tested configurations:
25479
bbf8cf5ee9f9 Whitespace normalization (get rid of tabs).
Guido van Rossum <guido@python.org>
parents: 24528
diff changeset
19 #
21885
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
20 # * EMX gcc 2.81/EMX 0.9d fix03
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
21
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
22 __revision__ = "$Id$"
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
23
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
24 import os,sys,copy
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
25 from distutils.ccompiler import gen_preprocess_options, gen_lib_options
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
26 from distutils.unixccompiler import UnixCCompiler
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
27 from distutils.file_util import write_file
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
28 from distutils.errors import DistutilsExecError, CompileError, UnknownFileError
23668
ca87119255eb Make setup.py less chatty by default.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 21885
diff changeset
29 from distutils import log
21885
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
30
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
31 class EMXCCompiler (UnixCCompiler):
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
32
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
33 compiler_type = 'emx'
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
34 obj_extension = ".obj"
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
35 static_lib_extension = ".lib"
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
36 shared_lib_extension = ".dll"
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
37 static_lib_format = "%s%s"
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
38 shared_lib_format = "%s%s"
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
39 res_extension = ".res" # compiled resource file
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
40 exe_extension = ".exe"
25479
bbf8cf5ee9f9 Whitespace normalization (get rid of tabs).
Guido van Rossum <guido@python.org>
parents: 24528
diff changeset
41
21885
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
42 def __init__ (self,
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
43 verbose=0,
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
44 dry_run=0,
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
45 force=0):
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
46
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
47 UnixCCompiler.__init__ (self, verbose, dry_run, force)
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
48
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
49 (status, details) = check_config_h()
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
50 self.debug_print("Python's GCC status: %s (details: %s)" %
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
51 (status, details))
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
52 if status is not CONFIG_H_OK:
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
53 self.warn(
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
54 "Python's pyconfig.h doesn't seem to support your compiler. " +
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
55 ("Reason: %s." % details) +
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
56 "Compiling may fail because of undefined preprocessor macros.")
25479
bbf8cf5ee9f9 Whitespace normalization (get rid of tabs).
Guido van Rossum <guido@python.org>
parents: 24528
diff changeset
57
21885
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
58 (self.gcc_version, self.ld_version) = \
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
59 get_versions()
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
60 self.debug_print(self.compiler_type + ": gcc %s, ld %s\n" %
25479
bbf8cf5ee9f9 Whitespace normalization (get rid of tabs).
Guido van Rossum <guido@python.org>
parents: 24528
diff changeset
61 (self.gcc_version,
21885
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
62 self.ld_version) )
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
63
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
64 # Hard-code GCC because that's what this is all about.
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
65 # XXX optimization, warnings etc. should be customizable.
31068
9314be0bbb64 use same compiler switches as core for extensions
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 26210
diff changeset
66 self.set_executables(compiler='gcc -Zomf -Zmt -O3 -fomit-frame-pointer -mprobe -Wall',
9314be0bbb64 use same compiler switches as core for extensions
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 26210
diff changeset
67 compiler_so='gcc -Zomf -Zmt -O3 -fomit-frame-pointer -mprobe -Wall',
21885
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
68 linker_exe='gcc -Zomf -Zmt -Zcrtdll',
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
69 linker_so='gcc -Zomf -Zmt -Zcrtdll -Zdll')
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
70
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
71 # want the gcc library statically linked (so that we don't have
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
72 # to distribute a version dependent on the compiler we have)
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
73 self.dll_libraries=["gcc"]
25479
bbf8cf5ee9f9 Whitespace normalization (get rid of tabs).
Guido van Rossum <guido@python.org>
parents: 24528
diff changeset
74
21885
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
75 # __init__ ()
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
76
24527
32f92d766b81 add parameter missing following Jeremy's compiler class refactoring
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 23913
diff changeset
77 def _compile(self, obj, src, ext, cc_args, extra_postargs, pp_opts):
23913
1298e97fb343 Add implementation of _compile() and use default compile() method.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 23823
diff changeset
78 if ext == '.rc':
1298e97fb343 Add implementation of _compile() and use default compile() method.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 23823
diff changeset
79 # gcc requires '.rc' compiled to binary ('.res') files !!!
1298e97fb343 Add implementation of _compile() and use default compile() method.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 23823
diff changeset
80 try:
1298e97fb343 Add implementation of _compile() and use default compile() method.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 23823
diff changeset
81 self.spawn(["rc", "-r", src])
1298e97fb343 Add implementation of _compile() and use default compile() method.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 23823
diff changeset
82 except DistutilsExecError, msg:
1298e97fb343 Add implementation of _compile() and use default compile() method.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 23823
diff changeset
83 raise CompileError, msg
25479
bbf8cf5ee9f9 Whitespace normalization (get rid of tabs).
Guido van Rossum <guido@python.org>
parents: 24528
diff changeset
84 else: # for other files use the C-compiler
23913
1298e97fb343 Add implementation of _compile() and use default compile() method.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 23823
diff changeset
85 try:
1298e97fb343 Add implementation of _compile() and use default compile() method.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 23823
diff changeset
86 self.spawn(self.compiler_so + cc_args + [src, '-o', obj] +
1298e97fb343 Add implementation of _compile() and use default compile() method.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 23823
diff changeset
87 extra_postargs)
1298e97fb343 Add implementation of _compile() and use default compile() method.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 23823
diff changeset
88 except DistutilsExecError, msg:
1298e97fb343 Add implementation of _compile() and use default compile() method.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 23823
diff changeset
89 raise CompileError, msg
21885
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
90
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
91 def link (self,
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
92 target_desc,
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
93 objects,
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
94 output_filename,
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
95 output_dir=None,
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
96 libraries=None,
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
97 library_dirs=None,
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
98 runtime_library_dirs=None,
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
99 export_symbols=None,
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
100 debug=0,
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
101 extra_preargs=None,
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
102 extra_postargs=None,
26036
771b6f521b95 This patch fixes the following bugs:
Gustavo Niemeyer <gustavo@niemeyer.net>
parents: 25479
diff changeset
103 build_temp=None,
771b6f521b95 This patch fixes the following bugs:
Gustavo Niemeyer <gustavo@niemeyer.net>
parents: 25479
diff changeset
104 target_lang=None):
25479
bbf8cf5ee9f9 Whitespace normalization (get rid of tabs).
Guido van Rossum <guido@python.org>
parents: 24528
diff changeset
105
21885
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
106 # use separate copies, so we can modify the lists
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
107 extra_preargs = copy.copy(extra_preargs or [])
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
108 libraries = copy.copy(libraries or [])
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
109 objects = copy.copy(objects or [])
25479
bbf8cf5ee9f9 Whitespace normalization (get rid of tabs).
Guido van Rossum <guido@python.org>
parents: 24528
diff changeset
110
21885
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
111 # Additional libraries
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
112 libraries.extend(self.dll_libraries)
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
113
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
114 # handle export symbols by creating a def-file
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
115 # with executables this only works with gcc/ld as linker
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
116 if ((export_symbols is not None) and
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
117 (target_desc != self.EXECUTABLE)):
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
118 # (The linker doesn't do anything if output is up-to-date.
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
119 # So it would probably better to check if we really need this,
25479
bbf8cf5ee9f9 Whitespace normalization (get rid of tabs).
Guido van Rossum <guido@python.org>
parents: 24528
diff changeset
120 # but for this we had to insert some unchanged parts of
bbf8cf5ee9f9 Whitespace normalization (get rid of tabs).
Guido van Rossum <guido@python.org>
parents: 24528
diff changeset
121 # UnixCCompiler, and this is not what we want.)
21885
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
122
25479
bbf8cf5ee9f9 Whitespace normalization (get rid of tabs).
Guido van Rossum <guido@python.org>
parents: 24528
diff changeset
123 # we want to put some files in the same directory as the
21885
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
124 # object files are, build_temp doesn't help much
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
125 # where are the object files
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
126 temp_dir = os.path.dirname(objects[0])
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
127 # name of dll to give the helper files the same base name
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
128 (dll_name, dll_extension) = os.path.splitext(
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
129 os.path.basename(output_filename))
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
130
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
131 # generate the filenames for these files
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
132 def_file = os.path.join(temp_dir, dll_name + ".def")
25479
bbf8cf5ee9f9 Whitespace normalization (get rid of tabs).
Guido van Rossum <guido@python.org>
parents: 24528
diff changeset
133
21885
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
134 # Generate .def file
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
135 contents = [
23671
8efa52e0a844 Fix unused local variables caught by pychecker.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 23668
diff changeset
136 "LIBRARY %s INITINSTANCE TERMINSTANCE" % \
8efa52e0a844 Fix unused local variables caught by pychecker.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 23668
diff changeset
137 os.path.splitext(os.path.basename(output_filename))[0],
21885
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
138 "DATA MULTIPLE NONSHARED",
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
139 "EXPORTS"]
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
140 for sym in export_symbols:
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
141 contents.append(' "%s"' % sym)
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
142 self.execute(write_file, (def_file, contents),
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
143 "writing %s" % def_file)
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
144
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
145 # next add options for def-file and to creating import libraries
25479
bbf8cf5ee9f9 Whitespace normalization (get rid of tabs).
Guido van Rossum <guido@python.org>
parents: 24528
diff changeset
146 # for gcc/ld the def-file is specified as any other object files
21885
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
147 objects.append(def_file)
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
148
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
149 #end: if ((export_symbols is not None) and
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
150 # (target_desc != self.EXECUTABLE or self.linker_dll == "gcc")):
25479
bbf8cf5ee9f9 Whitespace normalization (get rid of tabs).
Guido van Rossum <guido@python.org>
parents: 24528
diff changeset
151
21885
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
152 # who wants symbols and a many times larger output file
25479
bbf8cf5ee9f9 Whitespace normalization (get rid of tabs).
Guido van Rossum <guido@python.org>
parents: 24528
diff changeset
153 # should explicitly switch the debug mode on
21885
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
154 # otherwise we let dllwrap/ld strip the output file
25479
bbf8cf5ee9f9 Whitespace normalization (get rid of tabs).
Guido van Rossum <guido@python.org>
parents: 24528
diff changeset
155 # (On my machine: 10KB < stripped_file < ??100KB
21885
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
156 # unstripped_file = stripped_file + XXX KB
25479
bbf8cf5ee9f9 Whitespace normalization (get rid of tabs).
Guido van Rossum <guido@python.org>
parents: 24528
diff changeset
157 # ( XXX=254 for a typical python extension))
bbf8cf5ee9f9 Whitespace normalization (get rid of tabs).
Guido van Rossum <guido@python.org>
parents: 24528
diff changeset
158 if not debug:
bbf8cf5ee9f9 Whitespace normalization (get rid of tabs).
Guido van Rossum <guido@python.org>
parents: 24528
diff changeset
159 extra_preargs.append("-s")
bbf8cf5ee9f9 Whitespace normalization (get rid of tabs).
Guido van Rossum <guido@python.org>
parents: 24528
diff changeset
160
21885
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
161 UnixCCompiler.link(self,
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
162 target_desc,
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
163 objects,
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
164 output_filename,
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
165 output_dir,
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
166 libraries,
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
167 library_dirs,
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
168 runtime_library_dirs,
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
169 None, # export_symbols, we do this in our def-file
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
170 debug,
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
171 extra_preargs,
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
172 extra_postargs,
26036
771b6f521b95 This patch fixes the following bugs:
Gustavo Niemeyer <gustavo@niemeyer.net>
parents: 25479
diff changeset
173 build_temp,
771b6f521b95 This patch fixes the following bugs:
Gustavo Niemeyer <gustavo@niemeyer.net>
parents: 25479
diff changeset
174 target_lang)
25479
bbf8cf5ee9f9 Whitespace normalization (get rid of tabs).
Guido van Rossum <guido@python.org>
parents: 24528
diff changeset
175
21885
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
176 # link ()
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
177
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
178 # -- Miscellaneous methods -----------------------------------------
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
179
24528
62f6babece1f - comment improvement
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 24527
diff changeset
180 # override the object_filenames method from CCompiler to
62f6babece1f - comment improvement
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 24527
diff changeset
181 # support rc and res-files
21885
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
182 def object_filenames (self,
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
183 source_filenames,
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
184 strip_dir=0,
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
185 output_dir=''):
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
186 if output_dir is None: output_dir = ''
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
187 obj_names = []
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
188 for src_name in source_filenames:
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
189 # use normcase to make sure '.rc' is really '.rc' and not '.RC'
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
190 (base, ext) = os.path.splitext (os.path.normcase(src_name))
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
191 if ext not in (self.src_extensions + ['.rc']):
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
192 raise UnknownFileError, \
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
193 "unknown file type '%s' (from '%s')" % \
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
194 (ext, src_name)
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
195 if strip_dir:
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
196 base = os.path.basename (base)
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
197 if ext == '.rc':
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
198 # these need to be compiled to object files
25479
bbf8cf5ee9f9 Whitespace normalization (get rid of tabs).
Guido van Rossum <guido@python.org>
parents: 24528
diff changeset
199 obj_names.append (os.path.join (output_dir,
21885
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
200 base + self.res_extension))
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
201 else:
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
202 obj_names.append (os.path.join (output_dir,
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
203 base + self.obj_extension))
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
204 return obj_names
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
205
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
206 # object_filenames ()
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
207
24528
62f6babece1f - comment improvement
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 24527
diff changeset
208 # override the find_library_file method from UnixCCompiler
62f6babece1f - comment improvement
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 24527
diff changeset
209 # to deal with file naming/searching differences
62f6babece1f - comment improvement
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 24527
diff changeset
210 def find_library_file(self, dirs, lib, debug=0):
62f6babece1f - comment improvement
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 24527
diff changeset
211 shortlib = '%s.lib' % lib
62f6babece1f - comment improvement
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 24527
diff changeset
212 longlib = 'lib%s.lib' % lib # this form very rare
62f6babece1f - comment improvement
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 24527
diff changeset
213
62f6babece1f - comment improvement
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 24527
diff changeset
214 # get EMX's default library directory search path
62f6babece1f - comment improvement
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 24527
diff changeset
215 try:
62f6babece1f - comment improvement
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 24527
diff changeset
216 emx_dirs = os.environ['LIBRARY_PATH'].split(';')
62f6babece1f - comment improvement
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 24527
diff changeset
217 except KeyError:
62f6babece1f - comment improvement
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 24527
diff changeset
218 emx_dirs = []
25479
bbf8cf5ee9f9 Whitespace normalization (get rid of tabs).
Guido van Rossum <guido@python.org>
parents: 24528
diff changeset
219
24528
62f6babece1f - comment improvement
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 24527
diff changeset
220 for dir in dirs + emx_dirs:
62f6babece1f - comment improvement
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 24527
diff changeset
221 shortlibp = os.path.join(dir, shortlib)
62f6babece1f - comment improvement
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 24527
diff changeset
222 longlibp = os.path.join(dir, longlib)
62f6babece1f - comment improvement
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 24527
diff changeset
223 if os.path.exists(shortlibp):
62f6babece1f - comment improvement
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 24527
diff changeset
224 return shortlibp
62f6babece1f - comment improvement
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 24527
diff changeset
225 elif os.path.exists(longlibp):
62f6babece1f - comment improvement
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 24527
diff changeset
226 return longlibp
25479
bbf8cf5ee9f9 Whitespace normalization (get rid of tabs).
Guido van Rossum <guido@python.org>
parents: 24528
diff changeset
227
24528
62f6babece1f - comment improvement
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 24527
diff changeset
228 # Oops, didn't find it in *any* of 'dirs'
62f6babece1f - comment improvement
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 24527
diff changeset
229 return None
62f6babece1f - comment improvement
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 24527
diff changeset
230
21885
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
231 # class EMXCCompiler
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
232
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
233
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
234 # Because these compilers aren't configured in Python's pyconfig.h file by
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
235 # default, we should at least warn the user if he is using a unmodified
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
236 # version.
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
237
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
238 CONFIG_H_OK = "ok"
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
239 CONFIG_H_NOTOK = "not ok"
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
240 CONFIG_H_UNCERTAIN = "uncertain"
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
241
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
242 def check_config_h():
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
243
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
244 """Check if the current Python installation (specifically, pyconfig.h)
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
245 appears amenable to building extensions with GCC. Returns a tuple
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
246 (status, details), where 'status' is one of the following constants:
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
247 CONFIG_H_OK
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
248 all is well, go ahead and compile
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
249 CONFIG_H_NOTOK
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
250 doesn't look good
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
251 CONFIG_H_UNCERTAIN
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
252 not sure -- unable to read pyconfig.h
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
253 'details' is a human-readable string explaining the situation.
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
254
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
255 Note there are two ways to conclude "OK": either 'sys.version' contains
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
256 the string "GCC" (implying that this Python was built with GCC), or the
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
257 installed "pyconfig.h" contains the string "__GNUC__".
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
258 """
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
259
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
260 # XXX since this function also checks sys.version, it's not strictly a
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
261 # "pyconfig.h" check -- should probably be renamed...
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
262
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
263 from distutils import sysconfig
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
264 import string
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
265 # if sys.version contains GCC then python was compiled with
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
266 # GCC, and the pyconfig.h file should be OK
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
267 if string.find(sys.version,"GCC") >= 0:
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
268 return (CONFIG_H_OK, "sys.version mentions 'GCC'")
25479
bbf8cf5ee9f9 Whitespace normalization (get rid of tabs).
Guido van Rossum <guido@python.org>
parents: 24528
diff changeset
269
21885
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
270 fn = sysconfig.get_config_h_filename()
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
271 try:
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
272 # It would probably better to read single lines to search.
25479
bbf8cf5ee9f9 Whitespace normalization (get rid of tabs).
Guido van Rossum <guido@python.org>
parents: 24528
diff changeset
273 # But we do this only once, and it is fast enough
21885
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
274 f = open(fn)
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
275 s = f.read()
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
276 f.close()
25479
bbf8cf5ee9f9 Whitespace normalization (get rid of tabs).
Guido van Rossum <guido@python.org>
parents: 24528
diff changeset
277
21885
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
278 except IOError, exc:
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
279 # if we can't read this file, we cannot say it is wrong
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
280 # the compiler will complain later about this file as missing
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
281 return (CONFIG_H_UNCERTAIN,
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
282 "couldn't read '%s': %s" % (fn, exc.strerror))
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
283
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
284 else:
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
285 # "pyconfig.h" contains an "#ifdef __GNUC__" or something similar
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
286 if string.find(s,"__GNUC__") >= 0:
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
287 return (CONFIG_H_OK, "'%s' mentions '__GNUC__'" % fn)
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
288 else:
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
289 return (CONFIG_H_NOTOK, "'%s' does not mention '__GNUC__'" % fn)
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
290
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
291
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
292 def get_versions():
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
293 """ Try to find out the versions of gcc and ld.
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
294 If not possible it returns None for it.
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
295 """
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
296 from distutils.version import StrictVersion
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
297 from distutils.spawn import find_executable
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
298 import re
25479
bbf8cf5ee9f9 Whitespace normalization (get rid of tabs).
Guido van Rossum <guido@python.org>
parents: 24528
diff changeset
299
21885
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
300 gcc_exe = find_executable('gcc')
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
301 if gcc_exe:
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
302 out = os.popen(gcc_exe + ' -dumpversion','r')
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
303 out_string = out.read()
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
304 out.close()
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
305 result = re.search('(\d+\.\d+\.\d+)',out_string)
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
306 if result:
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
307 gcc_version = StrictVersion(result.group(1))
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
308 else:
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
309 gcc_version = None
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
310 else:
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
311 gcc_version = None
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
312 # EMX ld has no way of reporting version number, and we use GCC
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
313 # anyway - so we can link OMF DLLs
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
314 ld_version = None
c8286cc702c9 Forgot to add the new emxccompiler.py from Andrew I. MacIntyre's
Marc-André Lemburg <mal@egenix.com>
parents:
diff changeset
315 return (gcc_version, ld_version)