blob: e6bc676461e88477e0cf3d9649a4fecf33f47dda [file] [log] [blame]
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00001# To be fixed:
2# Implement --disable-modules setting
Fredrik Lundhade711a2001-01-24 08:00:28 +00003
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00004import sys, os, string, getopt
5from distutils import sysconfig
Marc-André Lemburg7c6fcda2001-01-26 18:03:24 +00006from distutils.errors import *
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00007from distutils.core import Extension, setup
8from distutils.command.build_ext import build_ext
9
10# This global variable is used to hold the list of modules to be disabled.
11disabled_module_list = []
12
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +000013def find_file(filename, std_dirs, paths):
14 """Searches for the directory where a given file is located,
15 and returns a possibly-empty list of additional directories, or None
16 if the file couldn't be found at all.
Fredrik Lundhade711a2001-01-24 08:00:28 +000017
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +000018 'filename' is the name of a file, such as readline.h or libcrypto.a.
19 'std_dirs' is the list of standard system directories; if the
20 file is found in one of them, no additional directives are needed.
21 'paths' is a list of additional locations to check; if the file is
22 found in one of them, the resulting list will contain the directory.
23 """
24
25 # Check the standard locations
26 for dir in std_dirs:
27 f = os.path.join(dir, filename)
28 if os.path.exists(f): return []
29
30 # Check the additional directories
31 for dir in paths:
32 f = os.path.join(dir, filename)
33 if os.path.exists(f):
34 return [dir]
35
36 # Not found anywhere
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +000037 return None
38
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +000039def find_library_file(compiler, libname, std_dirs, paths):
40 filename = compiler.library_filename(libname, lib_type='shared')
41 result = find_file(filename, std_dirs, paths)
42 if result is not None: return result
Fredrik Lundhade711a2001-01-24 08:00:28 +000043
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +000044 filename = compiler.library_filename(libname, lib_type='static')
45 result = find_file(filename, std_dirs, paths)
46 return result
47
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +000048def module_enabled(extlist, modname):
49 """Returns whether the module 'modname' is present in the list
50 of extensions 'extlist'."""
51 extlist = [ext for ext in extlist if ext.name == modname]
52 return len(extlist)
Fredrik Lundhade711a2001-01-24 08:00:28 +000053
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +000054class PyBuildExt(build_ext):
Fredrik Lundhade711a2001-01-24 08:00:28 +000055
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +000056 def build_extensions(self):
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +000057
58 # Detect which modules should be compiled
59 self.detect_modules()
60
61 # Remove modules that are present on the disabled list
62 self.extensions = [ext for ext in self.extensions
63 if ext.name not in disabled_module_list]
Fredrik Lundhade711a2001-01-24 08:00:28 +000064
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +000065 # Fix up the autodetected modules, prefixing all the source files
66 # with Modules/ and adding Python's include directory to the path.
67 (srcdir,) = sysconfig.get_config_vars('srcdir')
68
Neil Schemenauer726b78e2001-01-24 17:18:21 +000069 # Figure out the location of the source code for extension modules
70 moddir = os.path.join(os.getcwd(), srcdir, 'Modules')
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +000071 moddir = os.path.normpath(moddir)
72 srcdir, tail = os.path.split(moddir)
73 srcdir = os.path.normpath(srcdir)
74 moddir = os.path.normpath(moddir)
75
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +000076 for ext in self.extensions[:]:
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +000077 ext.sources = [ os.path.join(moddir, filename)
78 for filename in ext.sources ]
79 ext.include_dirs.append( '.' ) # to get config.h
Andrew M. Kuchlinge3d6e412001-01-19 02:50:34 +000080 ext.include_dirs.append( os.path.join(srcdir, './Include') )
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +000081
Andrew M. Kuchlinge7c87322001-01-19 16:58:21 +000082 # If a module has already been built statically,
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +000083 # don't build it here
Andrew M. Kuchlinge7c87322001-01-19 16:58:21 +000084 if ext.name in sys.builtin_module_names:
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +000085 self.extensions.remove(ext)
Andrew M. Kuchling5bbc7b92001-01-18 20:39:34 +000086
87 # When you run "make CC=altcc" or something similar, you really want
88 # those environment variables passed into the setup.py phase. Here's
89 # a small set of useful ones.
90 compiler = os.environ.get('CC')
91 linker_so = os.environ.get('LDSHARED')
92 args = {}
93 # unfortunately, distutils doesn't let us provide separate C and C++
94 # compilers
95 if compiler is not None:
96 args['compiler_so'] = compiler
97 if linker_so is not None:
98 args['linker_so'] = linker_so + ' -shared'
99 self.compiler.set_executables(**args)
100
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000101 build_ext.build_extensions(self)
102
Marc-André Lemburg7c6fcda2001-01-26 18:03:24 +0000103 def build_extension(self, ext):
104
105 try:
106 build_ext.build_extension(self, ext)
107 except (CCompilerError, DistutilsError), why:
108 self.announce('WARNING: building of extension "%s" failed: %s' %
109 (ext.name, sys.exc_info()[1]))
110
Andrew M. Kuchling34febf52001-01-24 03:31:07 +0000111 def get_platform (self):
Fredrik Lundhade711a2001-01-24 08:00:28 +0000112 # Get value of sys.platform
113 platform = sys.platform
114 if platform[:6] =='cygwin':
115 platform = 'cygwin'
Andrew M. Kuchling34febf52001-01-24 03:31:07 +0000116
Fredrik Lundhade711a2001-01-24 08:00:28 +0000117 return platform
Andrew M. Kuchling34febf52001-01-24 03:31:07 +0000118
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000119 def detect_modules(self):
Fredrik Lundhade711a2001-01-24 08:00:28 +0000120 # Ensure that /usr/local is always used
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000121 if '/usr/local/lib' not in self.compiler.library_dirs:
122 self.compiler.library_dirs.append('/usr/local/lib')
123 if '/usr/local/include' not in self.compiler.include_dirs:
124 self.compiler.include_dirs.append( '/usr/local/include' )
125
126 # lib_dirs and inc_dirs are used to search for files;
127 # if a file is found in one of those directories, it can
128 # be assumed that no additional -I,-L directives are needed.
129 lib_dirs = self.compiler.library_dirs + ['/lib', '/usr/lib']
130 inc_dirs = ['/usr/include'] + self.compiler.include_dirs
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000131 exts = []
132
Fredrik Lundhade711a2001-01-24 08:00:28 +0000133 platform = self.get_platform()
Andrew M. Kuchling34febf52001-01-24 03:31:07 +0000134
Fredrik Lundhade711a2001-01-24 08:00:28 +0000135 # Check for MacOS X, which doesn't need libm.a at all
136 math_libs = ['m']
137 if platform == 'Darwin1.2':
138 math_libs = []
Andrew M. Kuchling5ddb25f2001-01-23 22:21:11 +0000139
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000140 # XXX Omitted modules: gl, pure, dl, SGI-specific modules
141
142 #
143 # The following modules are all pretty straightforward, and compile
144 # on pretty much any POSIXish platform.
145 #
Fredrik Lundhade711a2001-01-24 08:00:28 +0000146
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000147 # Some modules that are normally always on:
148 exts.append( Extension('regex', ['regexmodule.c', 'regexpr.c']) )
149 exts.append( Extension('pcre', ['pcremodule.c', 'pypcre.c']) )
Fredrik Lundhade711a2001-01-24 08:00:28 +0000150
Andrew M. Kuchlingd5c43062001-01-17 15:59:25 +0000151 exts.append( Extension('xreadlines', ['xreadlinesmodule.c']) )
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000152
153 # array objects
154 exts.append( Extension('array', ['arraymodule.c']) )
155 # complex math library functions
Andrew M. Kuchling5ddb25f2001-01-23 22:21:11 +0000156 exts.append( Extension('cmath', ['cmathmodule.c'],
157 libraries=math_libs) )
Fredrik Lundhade711a2001-01-24 08:00:28 +0000158
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000159 # math library functions, e.g. sin()
Andrew M. Kuchling5ddb25f2001-01-23 22:21:11 +0000160 exts.append( Extension('math', ['mathmodule.c'],
161 libraries=math_libs) )
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000162 # fast string operations implemented in C
163 exts.append( Extension('strop', ['stropmodule.c']) )
164 # time operations and variables
Andrew M. Kuchling5ddb25f2001-01-23 22:21:11 +0000165 exts.append( Extension('time', ['timemodule.c'],
166 libraries=math_libs) )
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000167 # operator.add() and similar goodies
168 exts.append( Extension('operator', ['operator.c']) )
169 # access to the builtin codecs and codec registry
170 exts.append( Extension('_codecs', ['_codecsmodule.c']) )
171 # static Unicode character database
Marc-André Lemburg14970be2001-01-22 10:38:27 +0000172 exts.append( Extension('unicodedata', ['unicodedata.c']) )
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000173 # access to ISO C locale support
174 exts.append( Extension('_locale', ['_localemodule.c']) )
175
176 # Modules with some UNIX dependencies -- on by default:
177 # (If you have a really backward UNIX, select and socket may not be
178 # supported...)
179
180 # fcntl(2) and ioctl(2)
181 exts.append( Extension('fcntl', ['fcntlmodule.c']) )
182 # pwd(3)
183 exts.append( Extension('pwd', ['pwdmodule.c']) )
184 # grp(3)
185 exts.append( Extension('grp', ['grpmodule.c']) )
186 # posix (UNIX) errno values
187 exts.append( Extension('errno', ['errnomodule.c']) )
188 # select(2); not on ancient System V
189 exts.append( Extension('select', ['selectmodule.c']) )
190
191 # The md5 module implements the RSA Data Security, Inc. MD5
192 # Message-Digest Algorithm, described in RFC 1321. The necessary files
193 # md5c.c and md5.h are included here.
194 exts.append( Extension('md5', ['md5module.c', 'md5c.c']) )
195
196 # The sha module implements the SHA checksum algorithm.
197 # (NIST's Secure Hash Algorithm.)
198 exts.append( Extension('sha', ['shamodule.c']) )
199
Andrew M. Kuchling5bbc7b92001-01-18 20:39:34 +0000200 # Tommy Burnette's 'new' module (creates new empty objects of certain
201 # kinds):
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000202 exts.append( Extension('new', ['newmodule.c']) )
203
204 # Helper module for various ascii-encoders
205 exts.append( Extension('binascii', ['binascii.c']) )
206
207 # Fred Drake's interface to the Python parser
208 exts.append( Extension('parser', ['parsermodule.c']) )
209
210 # Digital Creations' cStringIO and cPickle
211 exts.append( Extension('cStringIO', ['cStringIO.c']) )
212 exts.append( Extension('cPickle', ['cPickle.c']) )
213
214 # Memory-mapped files (also works on Win32).
215 exts.append( Extension('mmap', ['mmapmodule.c']) )
216
217 # Lance Ellinghaus's modules:
218 # enigma-inspired encryption
219 exts.append( Extension('rotor', ['rotormodule.c']) )
220 # syslog daemon interface
221 exts.append( Extension('syslog', ['syslogmodule.c']) )
222
223 # George Neville-Neil's timing module:
224 exts.append( Extension('timing', ['timingmodule.c']) )
225
226 #
Andrew M. Kuchling5bbc7b92001-01-18 20:39:34 +0000227 # Here ends the simple stuff. From here on, modules need certain
228 # libraries, are platform-specific, or present other surprises.
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000229 #
230
231 # Multimedia modules
232 # These don't work for 64-bit platforms!!!
233 # These represent audio samples or images as strings:
234
Fredrik Lundhade711a2001-01-24 08:00:28 +0000235 # Disabled on 64-bit platforms
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000236 if sys.maxint != 9223372036854775807L:
237 # Operations on audio samples
238 exts.append( Extension('audioop', ['audioop.c']) )
239 # Operations on images
240 exts.append( Extension('imageop', ['imageop.c']) )
241 # Read SGI RGB image files (but coded portably)
242 exts.append( Extension('rgbimg', ['rgbimgmodule.c']) )
243
244 # readline
Andrew M. Kuchling4f9e9432001-01-17 20:20:44 +0000245 if (self.compiler.find_library_file(lib_dirs, 'readline')):
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000246 exts.append( Extension('readline', ['readline.c'],
Marc-André Lemburg7c6fcda2001-01-26 18:03:24 +0000247 library_dirs=['/usr/lib/termcap'],
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000248 libraries=['readline', 'termcap']) )
249
250 # The crypt module is now disabled by default because it breaks builds
251 # on many systems (where -lcrypt is needed), e.g. Linux (I believe).
252
253 if self.compiler.find_library_file(lib_dirs, 'crypt'):
254 libs = ['crypt']
255 else:
256 libs = []
257 exts.append( Extension('crypt', ['cryptmodule.c'], libraries=libs) )
258
259 # socket(2)
260 # Detect SSL support for the socket module
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000261 ssl_incs = find_file('openssl/ssl.h', inc_dirs,
Andrew M. Kuchlinge7c87322001-01-19 16:58:21 +0000262 ['/usr/local/ssl/include',
263 '/usr/contrib/ssl/include/'
264 ]
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000265 )
266 ssl_libs = find_library_file(self.compiler, 'ssl',lib_dirs,
Andrew M. Kuchlinge7c87322001-01-19 16:58:21 +0000267 ['/usr/local/ssl/lib',
268 '/usr/contrib/ssl/lib/'
269 ] )
Fredrik Lundhade711a2001-01-24 08:00:28 +0000270
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000271 if (ssl_incs is not None and
272 ssl_libs is not None):
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000273 exts.append( Extension('_socket', ['socketmodule.c'],
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000274 include_dirs = ssl_incs,
Fredrik Lundhade711a2001-01-24 08:00:28 +0000275 library_dirs = ssl_libs,
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000276 libraries = ['ssl', 'crypto'],
277 define_macros = [('USE_SSL',1)] ) )
278 else:
279 exts.append( Extension('_socket', ['socketmodule.c']) )
280
281 # Modules that provide persistent dictionary-like semantics. You will
282 # probably want to arrange for at least one of them to be available on
283 # your machine, though none are defined by default because of library
284 # dependencies. The Python module anydbm.py provides an
285 # implementation independent wrapper for these; dumbdbm.py provides
286 # similar functionality (but slower of course) implemented in Python.
287
288 # The standard Unix dbm module:
Andrew M. Kuchling34febf52001-01-24 03:31:07 +0000289 if platform not in ['cygwin']:
290 if (self.compiler.find_library_file(lib_dirs, 'ndbm')):
291 exts.append( Extension('dbm', ['dbmmodule.c'],
292 libraries = ['ndbm'] ) )
293 else:
294 exts.append( Extension('dbm', ['dbmmodule.c']) )
Fredrik Lundhade711a2001-01-24 08:00:28 +0000295
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000296 # Anthony Baxter's gdbm module. GNU dbm(3) will require -lgdbm:
297 if (self.compiler.find_library_file(lib_dirs, 'gdbm')):
298 exts.append( Extension('gdbm', ['gdbmmodule.c'],
299 libraries = ['gdbm'] ) )
300
301 # Berkeley DB interface.
302 #
303 # This requires the Berkeley DB code, see
304 # ftp://ftp.cs.berkeley.edu/pub/4bsd/db.1.85.tar.gz
305 #
306 # Edit the variables DB and DBPORT to point to the db top directory
307 # and the subdirectory of PORT where you built it.
308 #
309 # (See http://electricrain.com/greg/python/bsddb3/ for an interface to
310 # BSD DB 3.x.)
311
312 # Note: If a db.h file is found by configure, bsddb will be enabled
313 # automatically via Setup.config.in. It only needs to be enabled here
314 # if it is not automatically enabled there; check the generated
315 # Setup.config before enabling it here.
316
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000317 db_incs = find_file('db_185.h', inc_dirs, [])
318 if (db_incs is not None and
319 self.compiler.find_library_file(lib_dirs, 'db') ):
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000320 exts.append( Extension('bsddb', ['bsddbmodule.c'],
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000321 include_dirs = db_incs,
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000322 libraries = ['db'] ) )
323
324 # The mpz module interfaces to the GNU Multiple Precision library.
Fredrik Lundhade711a2001-01-24 08:00:28 +0000325 # You need to ftp the GNU MP library.
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000326 # This was originally written and tested against GMP 1.2 and 1.3.2.
327 # It has been modified by Rob Hooft to work with 2.0.2 as well, but I
328 # haven't tested it recently. For a more complete module,
329 # refer to pympz.sourceforge.net.
330
331 # A compatible MP library unencombered by the GPL also exists. It was
332 # posted to comp.sources.misc in volume 40 and is widely available from
333 # FTP archive sites. One URL for it is:
334 # ftp://gatekeeper.dec.com/.b/usenet/comp.sources.misc/volume40/fgmp/part01.Z
335
336 # Anthony Baxter's gdbm module. GNU dbm(3) will require -lgdbm:
337 if (self.compiler.find_library_file(lib_dirs, 'gmp')):
338 exts.append( Extension('mpz', ['mpzmodule.c'],
339 libraries = ['gmp'] ) )
340
341
342 # Unix-only modules
Andrew M. Kuchling34febf52001-01-24 03:31:07 +0000343 if platform not in ['mac', 'win32']:
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000344 # Steen Lumholt's termios module
345 exts.append( Extension('termios', ['termios.c']) )
346 # Jeremy Hylton's rlimit interface
Andrew M. Kuchling34febf52001-01-24 03:31:07 +0000347 if platform not in ['cygwin']:
348 exts.append( Extension('resource', ['resource.c']) )
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000349
350 if (self.compiler.find_library_file(lib_dirs, 'nsl')):
351 exts.append( Extension('nis', ['nismodule.c'],
352 libraries = ['nsl']) )
353
354 # Curses support, requring the System V version of curses, often
Fredrik Lundhade711a2001-01-24 08:00:28 +0000355 # provided by the ncurses library.
Andrew M. Kuchling34febf52001-01-24 03:31:07 +0000356 if platform == 'sunos4':
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000357 include_dirs += ['/usr/5include']
358 lib_dirs += ['/usr/5lib']
359
360 if (self.compiler.find_library_file(lib_dirs, 'ncurses')):
361 curses_libs = ['ncurses']
362 exts.append( Extension('_curses', ['_cursesmodule.c'],
363 libraries = curses_libs) )
364 elif (self.compiler.find_library_file(lib_dirs, 'curses')):
365 if (self.compiler.find_library_file(lib_dirs, 'terminfo')):
366 curses_libs = ['curses', 'terminfo']
367 else:
368 curses_libs = ['curses', 'termcap']
Fredrik Lundhade711a2001-01-24 08:00:28 +0000369
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000370 exts.append( Extension('_curses', ['_cursesmodule.c'],
371 libraries = curses_libs) )
Fredrik Lundhade711a2001-01-24 08:00:28 +0000372
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000373 # If the curses module is enabled, check for the panel module
374 if (os.path.exists('Modules/_curses_panel.c') and
375 module_enabled(exts, '_curses') and
376 self.compiler.find_library_file(lib_dirs, 'panel')):
377 exts.append( Extension('_curses_panel', ['_curses_panel.c'],
378 libraries = ['panel'] + curses_libs) )
Fredrik Lundhade711a2001-01-24 08:00:28 +0000379
380
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000381
382 # Lee Busby's SIGFPE modules.
383 # The library to link fpectl with is platform specific.
384 # Choose *one* of the options below for fpectl:
385
Andrew M. Kuchling34febf52001-01-24 03:31:07 +0000386 if platform == 'irix5':
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000387 # For SGI IRIX (tested on 5.3):
388 exts.append( Extension('fpectl', ['fpectlmodule.c'],
389 libraries=['fpe']) )
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000390 elif 0: # XXX how to detect SunPro?
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000391 # For Solaris with SunPro compiler (tested on Solaris 2.5 with SunPro C 4.2):
392 # (Without the compiler you don't have -lsunmath.)
393 #fpectl fpectlmodule.c -R/opt/SUNWspro/lib -lsunmath -lm
394 pass
395 else:
396 # For other systems: see instructions in fpectlmodule.c.
397 #fpectl fpectlmodule.c ...
398 exts.append( Extension('fpectl', ['fpectlmodule.c']) )
399
400
401 # Andrew Kuchling's zlib module.
402 # This require zlib 1.1.3 (or later).
403 # See http://www.cdrom.com/pub/infozip/zlib/
404 if (self.compiler.find_library_file(lib_dirs, 'z')):
405 exts.append( Extension('zlib', ['zlibmodule.c'],
406 libraries = ['z']) )
407
408 # Interface to the Expat XML parser
409 #
410 # Expat is written by James Clark and must be downloaded separately
411 # (see below). The pyexpat module was written by Paul Prescod after a
412 # prototype by Jack Jansen.
413 #
Andrew M. Kuchling5bbc7b92001-01-18 20:39:34 +0000414 # The Expat dist includes Windows .lib and .dll files. Home page is
415 # at http://www.jclark.com/xml/expat.html, the current production
416 # release is always ftp://ftp.jclark.com/pub/xml/expat.zip.
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000417 #
418 # EXPAT_DIR, below, should point to the expat/ directory created by
419 # unpacking the Expat source distribution.
420 #
Andrew M. Kuchling5bbc7b92001-01-18 20:39:34 +0000421 # Note: the expat build process doesn't yet build a libexpat.a; you
422 # can do this manually while we try convince the author to add it. To
423 # do so, cd to EXPAT_DIR, run "make" if you have not done so, then
424 # run:
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000425 #
426 # ar cr libexpat.a xmltok/*.o xmlparse/*.o
427 #
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000428 expat_defs = []
429 expat_incs = find_file('expat.h', inc_dirs, [])
430 if expat_incs is not None:
431 # expat.h was found
432 expat_defs = [('HAVE_EXPAT_H', 1)]
433 else:
434 expat_incs = find_file('xmlparse.h', inc_dirs, [])
Fredrik Lundhade711a2001-01-24 08:00:28 +0000435
Martin v. Löwis1ab29b22001-01-21 10:54:52 +0000436 if (expat_incs is not None and
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000437 self.compiler.find_library_file(lib_dirs, 'expat')):
438 exts.append( Extension('pyexpat', ['pyexpat.c'],
439 define_macros = expat_defs,
440 libraries = ['expat']) )
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000441
442 # Platform-specific libraries
Andrew M. Kuchling34febf52001-01-24 03:31:07 +0000443 if platform == 'linux2':
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000444 # Linux-specific modules
445 exts.append( Extension('linuxaudiodev', ['linuxaudiodev.c']) )
446
Andrew M. Kuchling34febf52001-01-24 03:31:07 +0000447 if platform == 'sunos5':
Fredrik Lundhade711a2001-01-24 08:00:28 +0000448 # SunOS specific modules
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000449 exts.append( Extension('sunaudiodev', ['sunaudiodev.c']) )
450
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000451 self.extensions.extend(exts)
452
453 # Call the method for detecting whether _tkinter can be compiled
454 self.detect_tkinter(inc_dirs, lib_dirs)
Fredrik Lundhade711a2001-01-24 08:00:28 +0000455
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000456
457 def detect_tkinter(self, inc_dirs, lib_dirs):
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000458 # The _tkinter module.
459 #
460 # The command for _tkinter is long and site specific. Please
461 # uncomment and/or edit those parts as indicated. If you don't have a
462 # specific extension (e.g. Tix or BLT), leave the corresponding line
463 # commented out. (Leave the trailing backslashes in! If you
464 # experience strange errors, you may want to join all uncommented
465 # lines and remove the backslashes -- the backslash interpretation is
466 # done by the shell's "read" command and it may not be implemented on
467 # every system.
468
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000469 # Assume we haven't found any of the libraries or include files
470 tcllib = tklib = tcl_includes = tk_includes = None
Andrew M. Kuchlingd5c43062001-01-17 15:59:25 +0000471 for version in ['8.4', '8.3', '8.2', '8.1', '8.0']:
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000472 tklib = self.compiler.find_library_file(lib_dirs,
473 'tk' + version )
474 tcllib = self.compiler.find_library_file(lib_dirs,
475 'tcl' + version )
Fredrik Lundhade711a2001-01-24 08:00:28 +0000476 if tklib and tcllib:
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000477 # Exit the loop when we've found the Tcl/Tk libraries
478 break
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000479
Fredrik Lundhade711a2001-01-24 08:00:28 +0000480 # Now check for the header files
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000481 if tklib and tcllib:
482 # Check for the include files on Debian, where
483 # they're put in /usr/include/{tcl,tk}X.Y
484 debian_tcl_include = ( '/usr/include/tcl' + version )
485 debian_tk_include = ( '/usr/include/tk' + version )
486 tcl_includes = find_file('tcl.h', inc_dirs,
487 [debian_tcl_include]
488 )
489 tk_includes = find_file('tk.h', inc_dirs,
490 [debian_tk_include]
491 )
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000492
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000493 if (tcllib is None or tklib is None and
494 tcl_includes is None or tk_includes is None):
495 # Something's missing, so give up
496 return
Fredrik Lundhade711a2001-01-24 08:00:28 +0000497
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000498 # OK... everything seems to be present for Tcl/Tk.
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000499
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000500 include_dirs = [] ; libs = [] ; defs = [] ; added_lib_dirs = []
501 for dir in tcl_includes + tk_includes:
502 if dir not in include_dirs:
503 include_dirs.append(dir)
Fredrik Lundhade711a2001-01-24 08:00:28 +0000504
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000505 # Check for various platform-specific directories
Andrew M. Kuchling34febf52001-01-24 03:31:07 +0000506 platform = self.get_platform()
507 if platform == 'sunos5':
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000508 include_dirs.append('/usr/openwin/include')
509 added_lib_dirs.append('/usr/openwin/lib')
510 elif os.path.exists('/usr/X11R6/include'):
511 include_dirs.append('/usr/X11R6/include')
512 added_lib_dirs.append('/usr/X11R6/lib')
513 elif os.path.exists('/usr/X11R5/include'):
514 include_dirs.append('/usr/X11R5/include')
515 added_lib_dirs.append('/usr/X11R5/lib')
516 else:
Fredrik Lundhade711a2001-01-24 08:00:28 +0000517 # Assume default location for X11
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000518 include_dirs.append('/usr/X11/include')
519 added_lib_dirs.append('/usr/X11/lib')
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000520
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000521 # Check for Tix extension
522 if self.compiler.find_library_file(lib_dirs + added_lib_dirs, 'tix4.1.8.0'):
523 defs.append( ('WITH_TIX', 1) )
524 libs.append('tix4.1.8.0')
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000525
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000526 # Check for BLT extension
527 if self.compiler.find_library_file(lib_dirs + added_lib_dirs, 'BLT8.0'):
528 defs.append( ('WITH_BLT', 1) )
529 libs.append('BLT8.0')
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000530
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000531 # Add the Tcl/Tk libraries
Fredrik Lundhade711a2001-01-24 08:00:28 +0000532 libs.append('tk'+version)
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000533 libs.append('tcl'+version)
Fredrik Lundhade711a2001-01-24 08:00:28 +0000534
Andrew M. Kuchling34febf52001-01-24 03:31:07 +0000535 if platform in ['aix3', 'aix4']:
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000536 libs.append('ld')
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000537
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000538 # Finally, link with the X11 libraries
539 libs.append('X11')
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000540
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000541 ext = Extension('_tkinter', ['_tkinter.c', 'tkappinit.c'],
542 define_macros=[('WITH_APPINIT', 1)] + defs,
543 include_dirs = include_dirs,
544 libraries = libs,
545 library_dirs = added_lib_dirs,
546 )
547 self.extensions.append(ext)
Fredrik Lundhade711a2001-01-24 08:00:28 +0000548
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000549 # XXX handle these, but how to detect?
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000550 # *** Uncomment and edit for PIL (TkImaging) extension only:
Fredrik Lundhade711a2001-01-24 08:00:28 +0000551 # -DWITH_PIL -I../Extensions/Imaging/libImaging tkImaging.c \
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000552 # *** Uncomment and edit for TOGL extension only:
Fredrik Lundhade711a2001-01-24 08:00:28 +0000553 # -DWITH_TOGL togl.c \
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000554 # *** Uncomment these for TOGL extension only:
Fredrik Lundhade711a2001-01-24 08:00:28 +0000555 # -lGL -lGLU -lXext -lXmu \
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000556
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000557def main():
558 setup(name = 'Python standard library',
Neil Schemenauere7e2ece2001-01-17 21:58:00 +0000559 version = '%d.%d' % sys.version_info[:2],
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000560 cmdclass = {'build_ext':PyBuildExt},
561 # The struct module is defined here, because build_ext won't be
562 # called unless there's at least one extension module defined.
563 ext_modules=[Extension('struct', ['structmodule.c'])]
564 )
Fredrik Lundhade711a2001-01-24 08:00:28 +0000565
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000566# --install-platlib
567if __name__ == '__main__':
568 sysconfig.set_python_build()
569 main()