blob: 4c3edc894979b993414b0c364aa72ac23e7dea9f [file] [log] [blame]
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00001# To be fixed:
2# Implement --disable-modules setting
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +00003
4import sys, os, string, getopt
5from distutils import sysconfig
6from distutils.core import Extension, setup
7from distutils.command.build_ext import build_ext
8
9# This global variable is used to hold the list of modules to be disabled.
10disabled_module_list = []
11
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +000012def find_file(filename, std_dirs, paths):
13 """Searches for the directory where a given file is located,
14 and returns a possibly-empty list of additional directories, or None
15 if the file couldn't be found at all.
16
17 'filename' is the name of a file, such as readline.h or libcrypto.a.
18 'std_dirs' is the list of standard system directories; if the
19 file is found in one of them, no additional directives are needed.
20 'paths' is a list of additional locations to check; if the file is
21 found in one of them, the resulting list will contain the directory.
22 """
23
24 # Check the standard locations
25 for dir in std_dirs:
26 f = os.path.join(dir, filename)
27 if os.path.exists(f): return []
28
29 # Check the additional directories
30 for dir in paths:
31 f = os.path.join(dir, filename)
32 if os.path.exists(f):
33 return [dir]
34
35 # Not found anywhere
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +000036 return None
37
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +000038def find_library_file(compiler, libname, std_dirs, paths):
39 filename = compiler.library_filename(libname, lib_type='shared')
40 result = find_file(filename, std_dirs, paths)
41 if result is not None: return result
42
43 filename = compiler.library_filename(libname, lib_type='static')
44 result = find_file(filename, std_dirs, paths)
45 return result
46
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +000047def module_enabled(extlist, modname):
48 """Returns whether the module 'modname' is present in the list
49 of extensions 'extlist'."""
50 extlist = [ext for ext in extlist if ext.name == modname]
51 return len(extlist)
52
53class PyBuildExt(build_ext):
54
55 def build_extensions(self):
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +000056
57 # Detect which modules should be compiled
58 self.detect_modules()
59
60 # Remove modules that are present on the disabled list
61 self.extensions = [ext for ext in self.extensions
62 if ext.name not in disabled_module_list]
63
64 # Fix up the autodetected modules, prefixing all the source files
65 # with Modules/ and adding Python's include directory to the path.
66 (srcdir,) = sysconfig.get_config_vars('srcdir')
67
68 #
69 moddir = os.path.join(os.getcwd(), 'Modules', srcdir)
70 moddir = os.path.normpath(moddir)
71 srcdir, tail = os.path.split(moddir)
72 srcdir = os.path.normpath(srcdir)
73 moddir = os.path.normpath(moddir)
74
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +000075 for ext in self.extensions[:]:
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +000076 ext.sources = [ os.path.join(moddir, filename)
77 for filename in ext.sources ]
78 ext.include_dirs.append( '.' ) # to get config.h
Andrew M. Kuchlinge3d6e412001-01-19 02:50:34 +000079 ext.include_dirs.append( os.path.join(srcdir, './Include') )
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +000080
Andrew M. Kuchlinge7c87322001-01-19 16:58:21 +000081 # If a module has already been built statically,
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +000082 # don't build it here
Andrew M. Kuchlinge7c87322001-01-19 16:58:21 +000083 if ext.name in sys.builtin_module_names:
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +000084 self.extensions.remove(ext)
Andrew M. Kuchling5bbc7b92001-01-18 20:39:34 +000085
86 # When you run "make CC=altcc" or something similar, you really want
87 # those environment variables passed into the setup.py phase. Here's
88 # a small set of useful ones.
89 compiler = os.environ.get('CC')
90 linker_so = os.environ.get('LDSHARED')
91 args = {}
92 # unfortunately, distutils doesn't let us provide separate C and C++
93 # compilers
94 if compiler is not None:
95 args['compiler_so'] = compiler
96 if linker_so is not None:
97 args['linker_so'] = linker_so + ' -shared'
98 self.compiler.set_executables(**args)
99
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000100 build_ext.build_extensions(self)
101
102 def detect_modules(self):
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000103 # Ensure that /usr/local is always used
104 if '/usr/local/lib' not in self.compiler.library_dirs:
105 self.compiler.library_dirs.append('/usr/local/lib')
106 if '/usr/local/include' not in self.compiler.include_dirs:
107 self.compiler.include_dirs.append( '/usr/local/include' )
108
109 # lib_dirs and inc_dirs are used to search for files;
110 # if a file is found in one of those directories, it can
111 # be assumed that no additional -I,-L directives are needed.
112 lib_dirs = self.compiler.library_dirs + ['/lib', '/usr/lib']
113 inc_dirs = ['/usr/include'] + self.compiler.include_dirs
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000114 exts = []
115
Andrew M. Kuchling5ddb25f2001-01-23 22:21:11 +0000116 # Check for MacOS X, which doesn't need libm.a at all
117 math_libs = ['m']
118 if sys.platform == 'Darwin1.2':
119 math_libs = []
120
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000121 # XXX Omitted modules: gl, pure, dl, SGI-specific modules
122
123 #
124 # The following modules are all pretty straightforward, and compile
125 # on pretty much any POSIXish platform.
126 #
127
128 # Some modules that are normally always on:
129 exts.append( Extension('regex', ['regexmodule.c', 'regexpr.c']) )
130 exts.append( Extension('pcre', ['pcremodule.c', 'pypcre.c']) )
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000131
Andrew M. Kuchlingd5c43062001-01-17 15:59:25 +0000132 exts.append( Extension('xreadlines', ['xreadlinesmodule.c']) )
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000133
134 # array objects
135 exts.append( Extension('array', ['arraymodule.c']) )
136 # complex math library functions
Andrew M. Kuchling5ddb25f2001-01-23 22:21:11 +0000137 exts.append( Extension('cmath', ['cmathmodule.c'],
138 libraries=math_libs) )
139
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000140 # math library functions, e.g. sin()
Andrew M. Kuchling5ddb25f2001-01-23 22:21:11 +0000141 exts.append( Extension('math', ['mathmodule.c'],
142 libraries=math_libs) )
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000143 # fast string operations implemented in C
144 exts.append( Extension('strop', ['stropmodule.c']) )
145 # time operations and variables
Andrew M. Kuchling5ddb25f2001-01-23 22:21:11 +0000146 exts.append( Extension('time', ['timemodule.c'],
147 libraries=math_libs) )
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000148 # operator.add() and similar goodies
149 exts.append( Extension('operator', ['operator.c']) )
150 # access to the builtin codecs and codec registry
151 exts.append( Extension('_codecs', ['_codecsmodule.c']) )
152 # static Unicode character database
Marc-André Lemburg14970be2001-01-22 10:38:27 +0000153 exts.append( Extension('unicodedata', ['unicodedata.c']) )
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000154 # Unicode Character Name expansion hash table
155 exts.append( Extension('ucnhash', ['ucnhash.c']) )
156 # access to ISO C locale support
157 exts.append( Extension('_locale', ['_localemodule.c']) )
158
159 # Modules with some UNIX dependencies -- on by default:
160 # (If you have a really backward UNIX, select and socket may not be
161 # supported...)
162
163 # fcntl(2) and ioctl(2)
164 exts.append( Extension('fcntl', ['fcntlmodule.c']) )
165 # pwd(3)
166 exts.append( Extension('pwd', ['pwdmodule.c']) )
167 # grp(3)
168 exts.append( Extension('grp', ['grpmodule.c']) )
169 # posix (UNIX) errno values
170 exts.append( Extension('errno', ['errnomodule.c']) )
171 # select(2); not on ancient System V
172 exts.append( Extension('select', ['selectmodule.c']) )
173
174 # The md5 module implements the RSA Data Security, Inc. MD5
175 # Message-Digest Algorithm, described in RFC 1321. The necessary files
176 # md5c.c and md5.h are included here.
177 exts.append( Extension('md5', ['md5module.c', 'md5c.c']) )
178
179 # The sha module implements the SHA checksum algorithm.
180 # (NIST's Secure Hash Algorithm.)
181 exts.append( Extension('sha', ['shamodule.c']) )
182
Andrew M. Kuchling5bbc7b92001-01-18 20:39:34 +0000183 # Tommy Burnette's 'new' module (creates new empty objects of certain
184 # kinds):
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000185 exts.append( Extension('new', ['newmodule.c']) )
186
187 # Helper module for various ascii-encoders
188 exts.append( Extension('binascii', ['binascii.c']) )
189
190 # Fred Drake's interface to the Python parser
191 exts.append( Extension('parser', ['parsermodule.c']) )
192
193 # Digital Creations' cStringIO and cPickle
194 exts.append( Extension('cStringIO', ['cStringIO.c']) )
195 exts.append( Extension('cPickle', ['cPickle.c']) )
196
197 # Memory-mapped files (also works on Win32).
198 exts.append( Extension('mmap', ['mmapmodule.c']) )
199
200 # Lance Ellinghaus's modules:
201 # enigma-inspired encryption
202 exts.append( Extension('rotor', ['rotormodule.c']) )
203 # syslog daemon interface
204 exts.append( Extension('syslog', ['syslogmodule.c']) )
205
206 # George Neville-Neil's timing module:
207 exts.append( Extension('timing', ['timingmodule.c']) )
208
209 #
Andrew M. Kuchling5bbc7b92001-01-18 20:39:34 +0000210 # Here ends the simple stuff. From here on, modules need certain
211 # libraries, are platform-specific, or present other surprises.
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000212 #
213
214 # Multimedia modules
215 # These don't work for 64-bit platforms!!!
216 # These represent audio samples or images as strings:
217
218 # Disabled on 64-bit platforms
219 if sys.maxint != 9223372036854775807L:
220 # Operations on audio samples
221 exts.append( Extension('audioop', ['audioop.c']) )
222 # Operations on images
223 exts.append( Extension('imageop', ['imageop.c']) )
224 # Read SGI RGB image files (but coded portably)
225 exts.append( Extension('rgbimg', ['rgbimgmodule.c']) )
226
227 # readline
Andrew M. Kuchling4f9e9432001-01-17 20:20:44 +0000228 if (self.compiler.find_library_file(lib_dirs, 'readline')):
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000229 exts.append( Extension('readline', ['readline.c'],
230 libraries=['readline', 'termcap']) )
231
232 # The crypt module is now disabled by default because it breaks builds
233 # on many systems (where -lcrypt is needed), e.g. Linux (I believe).
234
235 if self.compiler.find_library_file(lib_dirs, 'crypt'):
236 libs = ['crypt']
237 else:
238 libs = []
239 exts.append( Extension('crypt', ['cryptmodule.c'], libraries=libs) )
240
241 # socket(2)
242 # Detect SSL support for the socket module
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000243 ssl_incs = find_file('openssl/ssl.h', inc_dirs,
Andrew M. Kuchlinge7c87322001-01-19 16:58:21 +0000244 ['/usr/local/ssl/include',
245 '/usr/contrib/ssl/include/'
246 ]
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000247 )
248 ssl_libs = find_library_file(self.compiler, 'ssl',lib_dirs,
Andrew M. Kuchlinge7c87322001-01-19 16:58:21 +0000249 ['/usr/local/ssl/lib',
250 '/usr/contrib/ssl/lib/'
251 ] )
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000252
253 if (ssl_incs is not None and
254 ssl_libs is not None):
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000255 exts.append( Extension('_socket', ['socketmodule.c'],
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000256 include_dirs = ssl_incs,
257 library_dirs = ssl_libs,
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000258 libraries = ['ssl', 'crypto'],
259 define_macros = [('USE_SSL',1)] ) )
260 else:
261 exts.append( Extension('_socket', ['socketmodule.c']) )
262
263 # Modules that provide persistent dictionary-like semantics. You will
264 # probably want to arrange for at least one of them to be available on
265 # your machine, though none are defined by default because of library
266 # dependencies. The Python module anydbm.py provides an
267 # implementation independent wrapper for these; dumbdbm.py provides
268 # similar functionality (but slower of course) implemented in Python.
269
270 # The standard Unix dbm module:
271 if (self.compiler.find_library_file(lib_dirs, 'ndbm')):
272 exts.append( Extension('dbm', ['dbmmodule.c'],
273 libraries = ['ndbm'] ) )
274 else:
275 exts.append( Extension('dbm', ['dbmmodule.c']) )
276
277 # Anthony Baxter's gdbm module. GNU dbm(3) will require -lgdbm:
278 if (self.compiler.find_library_file(lib_dirs, 'gdbm')):
279 exts.append( Extension('gdbm', ['gdbmmodule.c'],
280 libraries = ['gdbm'] ) )
281
282 # Berkeley DB interface.
283 #
284 # This requires the Berkeley DB code, see
285 # ftp://ftp.cs.berkeley.edu/pub/4bsd/db.1.85.tar.gz
286 #
287 # Edit the variables DB and DBPORT to point to the db top directory
288 # and the subdirectory of PORT where you built it.
289 #
290 # (See http://electricrain.com/greg/python/bsddb3/ for an interface to
291 # BSD DB 3.x.)
292
293 # Note: If a db.h file is found by configure, bsddb will be enabled
294 # automatically via Setup.config.in. It only needs to be enabled here
295 # if it is not automatically enabled there; check the generated
296 # Setup.config before enabling it here.
297
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000298 db_incs = find_file('db_185.h', inc_dirs, [])
299 if (db_incs is not None and
300 self.compiler.find_library_file(lib_dirs, 'db') ):
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000301 exts.append( Extension('bsddb', ['bsddbmodule.c'],
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000302 include_dirs = db_incs,
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000303 libraries = ['db'] ) )
304
305 # The mpz module interfaces to the GNU Multiple Precision library.
306 # You need to ftp the GNU MP library.
307 # This was originally written and tested against GMP 1.2 and 1.3.2.
308 # It has been modified by Rob Hooft to work with 2.0.2 as well, but I
309 # haven't tested it recently. For a more complete module,
310 # refer to pympz.sourceforge.net.
311
312 # A compatible MP library unencombered by the GPL also exists. It was
313 # posted to comp.sources.misc in volume 40 and is widely available from
314 # FTP archive sites. One URL for it is:
315 # ftp://gatekeeper.dec.com/.b/usenet/comp.sources.misc/volume40/fgmp/part01.Z
316
317 # Anthony Baxter's gdbm module. GNU dbm(3) will require -lgdbm:
318 if (self.compiler.find_library_file(lib_dirs, 'gmp')):
319 exts.append( Extension('mpz', ['mpzmodule.c'],
320 libraries = ['gmp'] ) )
321
322
323 # Unix-only modules
324 if sys.platform not in ['mac', 'win32']:
325 # Steen Lumholt's termios module
326 exts.append( Extension('termios', ['termios.c']) )
327 # Jeremy Hylton's rlimit interface
328 exts.append( Extension('resource', ['resource.c']) )
329
330 if (self.compiler.find_library_file(lib_dirs, 'nsl')):
331 exts.append( Extension('nis', ['nismodule.c'],
332 libraries = ['nsl']) )
333
334 # Curses support, requring the System V version of curses, often
335 # provided by the ncurses library.
336 if sys.platform == 'sunos4':
337 include_dirs += ['/usr/5include']
338 lib_dirs += ['/usr/5lib']
339
340 if (self.compiler.find_library_file(lib_dirs, 'ncurses')):
341 curses_libs = ['ncurses']
342 exts.append( Extension('_curses', ['_cursesmodule.c'],
343 libraries = curses_libs) )
344 elif (self.compiler.find_library_file(lib_dirs, 'curses')):
345 if (self.compiler.find_library_file(lib_dirs, 'terminfo')):
346 curses_libs = ['curses', 'terminfo']
347 else:
348 curses_libs = ['curses', 'termcap']
349
350 exts.append( Extension('_curses', ['_cursesmodule.c'],
351 libraries = curses_libs) )
352
353 # If the curses module is enabled, check for the panel module
354 if (os.path.exists('Modules/_curses_panel.c') and
355 module_enabled(exts, '_curses') and
356 self.compiler.find_library_file(lib_dirs, 'panel')):
357 exts.append( Extension('_curses_panel', ['_curses_panel.c'],
358 libraries = ['panel'] + curses_libs) )
359
360
361
362 # Lee Busby's SIGFPE modules.
363 # The library to link fpectl with is platform specific.
364 # Choose *one* of the options below for fpectl:
365
366 if sys.platform == 'irix5':
367 # For SGI IRIX (tested on 5.3):
368 exts.append( Extension('fpectl', ['fpectlmodule.c'],
369 libraries=['fpe']) )
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000370 elif 0: # XXX how to detect SunPro?
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000371 # For Solaris with SunPro compiler (tested on Solaris 2.5 with SunPro C 4.2):
372 # (Without the compiler you don't have -lsunmath.)
373 #fpectl fpectlmodule.c -R/opt/SUNWspro/lib -lsunmath -lm
374 pass
375 else:
376 # For other systems: see instructions in fpectlmodule.c.
377 #fpectl fpectlmodule.c ...
378 exts.append( Extension('fpectl', ['fpectlmodule.c']) )
379
380
381 # Andrew Kuchling's zlib module.
382 # This require zlib 1.1.3 (or later).
383 # See http://www.cdrom.com/pub/infozip/zlib/
384 if (self.compiler.find_library_file(lib_dirs, 'z')):
385 exts.append( Extension('zlib', ['zlibmodule.c'],
386 libraries = ['z']) )
387
388 # Interface to the Expat XML parser
389 #
390 # Expat is written by James Clark and must be downloaded separately
391 # (see below). The pyexpat module was written by Paul Prescod after a
392 # prototype by Jack Jansen.
393 #
Andrew M. Kuchling5bbc7b92001-01-18 20:39:34 +0000394 # The Expat dist includes Windows .lib and .dll files. Home page is
395 # at http://www.jclark.com/xml/expat.html, the current production
396 # release is always ftp://ftp.jclark.com/pub/xml/expat.zip.
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000397 #
398 # EXPAT_DIR, below, should point to the expat/ directory created by
399 # unpacking the Expat source distribution.
400 #
Andrew M. Kuchling5bbc7b92001-01-18 20:39:34 +0000401 # Note: the expat build process doesn't yet build a libexpat.a; you
402 # can do this manually while we try convince the author to add it. To
403 # do so, cd to EXPAT_DIR, run "make" if you have not done so, then
404 # run:
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000405 #
406 # ar cr libexpat.a xmltok/*.o xmlparse/*.o
407 #
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000408 expat_defs = []
409 expat_incs = find_file('expat.h', inc_dirs, [])
410 if expat_incs is not None:
411 # expat.h was found
412 expat_defs = [('HAVE_EXPAT_H', 1)]
413 else:
414 expat_incs = find_file('xmlparse.h', inc_dirs, [])
415
Martin v. Löwis1ab29b22001-01-21 10:54:52 +0000416 if (expat_incs is not None and
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000417 self.compiler.find_library_file(lib_dirs, 'expat')):
418 exts.append( Extension('pyexpat', ['pyexpat.c'],
419 define_macros = expat_defs,
420 libraries = ['expat']) )
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000421
422 # Platform-specific libraries
423 plat = sys.platform
424 if plat == 'linux2':
425 # Linux-specific modules
426 exts.append( Extension('linuxaudiodev', ['linuxaudiodev.c']) )
427
428 if plat == 'sunos5':
429 # SunOS specific modules
430 exts.append( Extension('sunaudiodev', ['sunaudiodev.c']) )
431
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000432 self.extensions.extend(exts)
433
434 # Call the method for detecting whether _tkinter can be compiled
435 self.detect_tkinter(inc_dirs, lib_dirs)
436
437
438 def detect_tkinter(self, inc_dirs, lib_dirs):
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000439 # The _tkinter module.
440 #
441 # The command for _tkinter is long and site specific. Please
442 # uncomment and/or edit those parts as indicated. If you don't have a
443 # specific extension (e.g. Tix or BLT), leave the corresponding line
444 # commented out. (Leave the trailing backslashes in! If you
445 # experience strange errors, you may want to join all uncommented
446 # lines and remove the backslashes -- the backslash interpretation is
447 # done by the shell's "read" command and it may not be implemented on
448 # every system.
449
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000450 # Assume we haven't found any of the libraries or include files
451 tcllib = tklib = tcl_includes = tk_includes = None
Andrew M. Kuchlingd5c43062001-01-17 15:59:25 +0000452 for version in ['8.4', '8.3', '8.2', '8.1', '8.0']:
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000453 tklib = self.compiler.find_library_file(lib_dirs,
454 'tk' + version )
455 tcllib = self.compiler.find_library_file(lib_dirs,
456 'tcl' + version )
457 if tklib and tcllib:
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000458 # Exit the loop when we've found the Tcl/Tk libraries
459 break
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000460
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000461 # Now check for the header files
462 if tklib and tcllib:
463 # Check for the include files on Debian, where
464 # they're put in /usr/include/{tcl,tk}X.Y
465 debian_tcl_include = ( '/usr/include/tcl' + version )
466 debian_tk_include = ( '/usr/include/tk' + version )
467 tcl_includes = find_file('tcl.h', inc_dirs,
468 [debian_tcl_include]
469 )
470 tk_includes = find_file('tk.h', inc_dirs,
471 [debian_tk_include]
472 )
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000473
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000474 if (tcllib is None or tklib is None and
475 tcl_includes is None or tk_includes is None):
476 # Something's missing, so give up
477 return
478
479 # OK... everything seems to be present for Tcl/Tk.
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000480
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000481 include_dirs = [] ; libs = [] ; defs = [] ; added_lib_dirs = []
482 for dir in tcl_includes + tk_includes:
483 if dir not in include_dirs:
484 include_dirs.append(dir)
485
486 # Check for various platform-specific directories
487 if sys.platform == 'sunos5':
488 include_dirs.append('/usr/openwin/include')
489 added_lib_dirs.append('/usr/openwin/lib')
490 elif os.path.exists('/usr/X11R6/include'):
491 include_dirs.append('/usr/X11R6/include')
492 added_lib_dirs.append('/usr/X11R6/lib')
493 elif os.path.exists('/usr/X11R5/include'):
494 include_dirs.append('/usr/X11R5/include')
495 added_lib_dirs.append('/usr/X11R5/lib')
496 else:
497 # Assume default location for X11
498 include_dirs.append('/usr/X11/include')
499 added_lib_dirs.append('/usr/X11/lib')
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000500
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000501 # Check for Tix extension
502 if self.compiler.find_library_file(lib_dirs + added_lib_dirs, 'tix4.1.8.0'):
503 defs.append( ('WITH_TIX', 1) )
504 libs.append('tix4.1.8.0')
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000505
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000506 # Check for BLT extension
507 if self.compiler.find_library_file(lib_dirs + added_lib_dirs, 'BLT8.0'):
508 defs.append( ('WITH_BLT', 1) )
509 libs.append('BLT8.0')
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000510
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000511 # Add the Tcl/Tk libraries
512 libs.append('tk'+version)
513 libs.append('tcl'+version)
514
515 if sys.platform in ['aix3', 'aix4']:
516 libs.append('ld')
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000517
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000518 # Finally, link with the X11 libraries
519 libs.append('X11')
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000520
Andrew M. Kuchlingfbe73762001-01-18 18:44:20 +0000521 ext = Extension('_tkinter', ['_tkinter.c', 'tkappinit.c'],
522 define_macros=[('WITH_APPINIT', 1)] + defs,
523 include_dirs = include_dirs,
524 libraries = libs,
525 library_dirs = added_lib_dirs,
526 )
527 self.extensions.append(ext)
528
529 # XXX handle these, but how to detect?
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000530 # *** Uncomment and edit for PIL (TkImaging) extension only:
531 # -DWITH_PIL -I../Extensions/Imaging/libImaging tkImaging.c \
532 # *** Uncomment and edit for TOGL extension only:
533 # -DWITH_TOGL togl.c \
534 # *** Uncomment these for TOGL extension only:
535 # -lGL -lGLU -lXext -lXmu \
536
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000537def main():
538 setup(name = 'Python standard library',
Neil Schemenauere7e2ece2001-01-17 21:58:00 +0000539 version = '%d.%d' % sys.version_info[:2],
Andrew M. Kuchling00e0f212001-01-17 15:23:23 +0000540 cmdclass = {'build_ext':PyBuildExt},
541 # The struct module is defined here, because build_ext won't be
542 # called unless there's at least one extension module defined.
543 ext_modules=[Extension('struct', ['structmodule.c'])]
544 )
545
546# --install-platlib
547if __name__ == '__main__':
548 sysconfig.set_python_build()
549 main()