1 # Autodetecting setup.py script for building the Python extensions
3 # Modified for BeOS build. Donn Cave, March 27 2001.
5 __version__
= "special BeOS after 1.37"
8 from distutils
import sysconfig
9 from distutils
import text_file
10 from distutils
.errors
import *
11 from distutils
.core
import Extension
, setup
12 from distutils
.command
.build_ext
import build_ext
14 # This global variable is used to hold the list of modules to be disabled.
15 disabled_module_list
= ['dbm', 'mmap', 'resource', 'nis']
17 def find_file(filename
, std_dirs
, paths
):
18 """Searches for the directory where a given file is located,
19 and returns a possibly-empty list of additional directories, or None
20 if the file couldn't be found at all.
22 'filename' is the name of a file, such as readline.h or libcrypto.a.
23 'std_dirs' is the list of standard system directories; if the
24 file is found in one of them, no additional directives are needed.
25 'paths' is a list of additional locations to check; if the file is
26 found in one of them, the resulting list will contain the directory.
29 # Check the standard locations
31 f
= os
.path
.join(dir, filename
)
32 if os
.path
.exists(f
): return []
34 # Check the additional directories
36 f
= os
.path
.join(dir, filename
)
43 def find_library_file(compiler
, libname
, std_dirs
, paths
):
44 filename
= compiler
.library_filename(libname
, lib_type
='shared')
45 result
= find_file(filename
, std_dirs
, paths
)
46 if result
is not None: return result
48 filename
= compiler
.library_filename(libname
, lib_type
='static')
49 result
= find_file(filename
, std_dirs
, paths
)
52 def module_enabled(extlist
, modname
):
53 """Returns whether the module 'modname' is present in the list
54 of extensions 'extlist'."""
55 extlist
= [ext
for ext
in extlist
if ext
.name
== modname
]
58 class PyBuildExt(build_ext
):
60 def build_extensions(self
):
62 # Detect which modules should be compiled
65 # Remove modules that are present on the disabled list
66 self
.extensions
= [ext
for ext
in self
.extensions
67 if ext
.name
not in disabled_module_list
]
69 # Fix up the autodetected modules, prefixing all the source files
70 # with Modules/ and adding Python's include directory to the path.
71 (srcdir
,) = sysconfig
.get_config_vars('srcdir')
73 # Figure out the location of the source code for extension modules
74 moddir
= os
.path
.join(os
.getcwd(), srcdir
, 'Modules')
75 moddir
= os
.path
.normpath(moddir
)
76 srcdir
, tail
= os
.path
.split(moddir
)
77 srcdir
= os
.path
.normpath(srcdir
)
78 moddir
= os
.path
.normpath(moddir
)
80 # Fix up the paths for scripts, too
81 self
.distribution
.scripts
= [os
.path
.join(srcdir
, filename
)
82 for filename
in self
.distribution
.scripts
]
84 for ext
in self
.extensions
[:]:
85 ext
.sources
= [ os
.path
.join(moddir
, filename
)
86 for filename
in ext
.sources
]
87 ext
.include_dirs
.append( '.' ) # to get config.h
88 ext
.include_dirs
.append( os
.path
.join(srcdir
, './Include') )
90 # If a module has already been built statically,
92 if ext
.name
in sys
.builtin_module_names
:
93 self
.extensions
.remove(ext
)
95 # Parse Modules/Setup to figure out which modules are turned
97 input = text_file
.TextFile('Modules/Setup', join_lines
=1)
100 line
= input.readline()
103 remove_modules
.append( line
[0] )
106 for ext
in self
.extensions
[:]:
107 if ext
.name
in remove_modules
:
108 self
.extensions
.remove(ext
)
110 # When you run "make CC=altcc" or something similar, you really want
111 # those environment variables passed into the setup.py phase. Here's
112 # a small set of useful ones.
113 compiler
= os
.environ
.get('CC')
114 linker_so
= os
.environ
.get('LDSHARED')
116 # unfortunately, distutils doesn't let us provide separate C and C++
118 if compiler
is not None:
119 args
['compiler_so'] = compiler
120 if linker_so
is not None:
121 args
['linker_so'] = linker_so
+ ' -shared'
122 self
.compiler
.set_executables(**args
)
124 build_ext
.build_extensions(self
)
126 def build_extension(self
, ext
):
129 build_ext
.build_extension(self
, ext
)
130 except (CCompilerError
, DistutilsError
), why
:
131 self
.announce('WARNING: building of extension "%s" failed: %s' %
132 (ext
.name
, sys
.exc_info()[1]))
134 def get_platform (self
):
135 # Get value of sys.platform
136 platform
= sys
.platform
137 if platform
[:6] =='cygwin':
139 elif platform
[:4] =='beos':
144 def detect_modules(self
):
146 belibs
= os
.environ
['BELIBRARIES'].split(';')
148 belibs
= ['/boot/beos/system/lib']
149 belibs
.append('/boot/home/config/lib')
150 self
.compiler
.library_dirs
.append('/boot/home/config/lib')
152 beincl
= os
.environ
['BEINCLUDES'].split(';')
155 beincl
.append('/boot/home/config/include')
156 self
.compiler
.include_dirs
.append('/boot/home/config/include')
157 # lib_dirs and inc_dirs are used to search for files;
158 # if a file is found in one of those directories, it can
159 # be assumed that no additional -I,-L directives are needed.
164 platform
= self
.get_platform()
166 # Check for MacOS X, which doesn't need libm.a at all
168 if platform
in ['Darwin1.2', 'beos']:
171 # XXX Omitted modules: gl, pure, dl, SGI-specific modules
174 # The following modules are all pretty straightforward, and compile
175 # on pretty much any POSIXish platform.
178 # Some modules that are normally always on:
179 exts
.append( Extension('regex', ['regexmodule.c', 'regexpr.c']) )
180 exts
.append( Extension('pcre', ['pcremodule.c', 'pypcre.c']) )
182 exts
.append( Extension('_weakref', ['_weakref.c']) )
183 exts
.append( Extension('_symtable', ['symtablemodule.c']) )
184 exts
.append( Extension('xreadlines', ['xreadlinesmodule.c']) )
187 exts
.append( Extension('array', ['arraymodule.c']) )
188 # complex math library functions
189 exts
.append( Extension('cmath', ['cmathmodule.c'],
190 libraries
=math_libs
) )
192 # math library functions, e.g. sin()
193 exts
.append( Extension('math', ['mathmodule.c'],
194 libraries
=math_libs
) )
195 # fast string operations implemented in C
196 exts
.append( Extension('strop', ['stropmodule.c']) )
197 # time operations and variables
198 exts
.append( Extension('time', ['timemodule.c'],
199 libraries
=math_libs
) )
200 # operator.add() and similar goodies
201 exts
.append( Extension('operator', ['operator.c']) )
202 # access to the builtin codecs and codec registry
203 exts
.append( Extension('_codecs', ['_codecsmodule.c']) )
204 # Python C API test module
205 exts
.append( Extension('_testcapi', ['_testcapimodule.c']) )
206 # static Unicode character database
207 exts
.append( Extension('unicodedata', ['unicodedata.c']) )
208 # access to ISO C locale support
209 exts
.append( Extension('_locale', ['_localemodule.c']) )
211 # Modules with some UNIX dependencies -- on by default:
212 # (If you have a really backward UNIX, select and socket may not be
215 # fcntl(2) and ioctl(2)
216 exts
.append( Extension('fcntl', ['fcntlmodule.c']) )
218 exts
.append( Extension('pwd', ['pwdmodule.c']) )
220 exts
.append( Extension('grp', ['grpmodule.c']) )
221 # posix (UNIX) errno values
222 exts
.append( Extension('errno', ['errnomodule.c']) )
223 # select(2); not on ancient System V
224 exts
.append( Extension('select', ['selectmodule.c']) )
226 # The md5 module implements the RSA Data Security, Inc. MD5
227 # Message-Digest Algorithm, described in RFC 1321. The necessary files
228 # md5c.c and md5.h are included here.
229 exts
.append( Extension('md5', ['md5module.c', 'md5c.c']) )
231 # The sha module implements the SHA checksum algorithm.
232 # (NIST's Secure Hash Algorithm.)
233 exts
.append( Extension('sha', ['shamodule.c']) )
235 # Tommy Burnette's 'new' module (creates new empty objects of certain
237 exts
.append( Extension('new', ['newmodule.c']) )
239 # Helper module for various ascii-encoders
240 exts
.append( Extension('binascii', ['binascii.c']) )
242 # Fred Drake's interface to the Python parser
243 exts
.append( Extension('parser', ['parsermodule.c']) )
245 # Digital Creations' cStringIO and cPickle
246 exts
.append( Extension('cStringIO', ['cStringIO.c']) )
247 exts
.append( Extension('cPickle', ['cPickle.c']) )
249 # Memory-mapped files (also works on Win32).
250 exts
.append( Extension('mmap', ['mmapmodule.c']) )
252 # Lance Ellinghaus's modules:
253 # enigma-inspired encryption
254 exts
.append( Extension('rotor', ['rotormodule.c']) )
255 # syslog daemon interface
256 exts
.append( Extension('syslog', ['syslogmodule.c']) )
258 # George Neville-Neil's timing module:
259 exts
.append( Extension('timing', ['timingmodule.c']) )
262 # Here ends the simple stuff. From here on, modules need certain
263 # libraries, are platform-specific, or present other surprises.
267 # These don't work for 64-bit platforms!!!
268 # These represent audio samples or images as strings:
270 # Disabled on 64-bit platforms
271 if sys
.maxint
!= 9223372036854775807L:
272 # Operations on audio samples
273 exts
.append( Extension('audioop', ['audioop.c']) )
274 # Operations on images
275 exts
.append( Extension('imageop', ['imageop.c']) )
276 # Read SGI RGB image files (but coded portably)
277 exts
.append( Extension('rgbimg', ['rgbimgmodule.c']) )
280 if self
.compiler
.find_library_file(lib_dirs
, 'readline'):
281 readline_libs
= ['readline']
282 if self
.compiler
.find_library_file(lib_dirs
+
283 ['/usr/lib/termcap'],
285 readline_libs
.append('termcap')
286 exts
.append( Extension('readline', ['readline.c'],
287 library_dirs
=['/usr/lib/termcap'],
288 libraries
=readline_libs
) )
290 # The crypt module is now disabled by default because it breaks builds
291 # on many systems (where -lcrypt is needed), e.g. Linux (I believe).
293 if self
.compiler
.find_library_file(lib_dirs
, 'crypt'):
297 exts
.append( Extension('crypt', ['cryptmodule.c'], libraries
=libs
) )
300 # Detect SSL support for the socket module
301 ssl_incs
= find_file('openssl/ssl.h', inc_dirs
,
302 ['/usr/local/ssl/include',
303 '/usr/contrib/ssl/include/'
306 ssl_libs
= find_library_file(self
.compiler
, 'ssl',lib_dirs
,
307 ['/usr/local/ssl/lib',
308 '/usr/contrib/ssl/lib/'
311 if (ssl_incs
is not None and
312 ssl_libs
is not None):
313 exts
.append( Extension('_socket', ['socketmodule.c'],
314 include_dirs
= ssl_incs
,
315 library_dirs
= ssl_libs
,
316 libraries
= ['ssl', 'crypto'],
317 define_macros
= [('USE_SSL',1)] ) )
319 exts
.append( Extension('_socket', ['socketmodule.c']) )
321 # Modules that provide persistent dictionary-like semantics. You will
322 # probably want to arrange for at least one of them to be available on
323 # your machine, though none are defined by default because of library
324 # dependencies. The Python module anydbm.py provides an
325 # implementation independent wrapper for these; dumbdbm.py provides
326 # similar functionality (but slower of course) implemented in Python.
328 # The standard Unix dbm module:
329 if platform
not in ['cygwin']:
330 if (self
.compiler
.find_library_file(lib_dirs
, 'ndbm')):
331 exts
.append( Extension('dbm', ['dbmmodule.c'],
332 libraries
= ['ndbm'] ) )
334 exts
.append( Extension('dbm', ['dbmmodule.c']) )
336 # Anthony Baxter's gdbm module. GNU dbm(3) will require -lgdbm:
337 if (self
.compiler
.find_library_file(lib_dirs
, 'gdbm')):
338 exts
.append( Extension('gdbm', ['gdbmmodule.c'],
339 libraries
= ['gdbm'] ) )
341 # Berkeley DB interface.
343 # This requires the Berkeley DB code, see
344 # ftp://ftp.cs.berkeley.edu/pub/4bsd/db.1.85.tar.gz
346 # Edit the variables DB and DBPORT to point to the db top directory
347 # and the subdirectory of PORT where you built it.
349 # (See http://electricrain.com/greg/python/bsddb3/ for an interface to
353 if self
.compiler
.find_library_file(lib_dirs
, 'db'):
356 db185_incs
= find_file('db_185.h', inc_dirs
,
357 ['/usr/include/db3', '/usr/include/db2'])
358 db_inc
= find_file('db.h', inc_dirs
, ['/usr/include/db1'])
359 if db185_incs
is not None:
360 exts
.append( Extension('bsddb', ['bsddbmodule.c'],
361 include_dirs
= db185_incs
,
362 define_macros
=[('HAVE_DB_185_H',1)],
363 libraries
= dblib
) )
364 elif db_inc
is not None:
365 exts
.append( Extension('bsddb', ['bsddbmodule.c'],
366 include_dirs
= db_inc
,
369 # The mpz module interfaces to the GNU Multiple Precision library.
370 # You need to ftp the GNU MP library.
371 # This was originally written and tested against GMP 1.2 and 1.3.2.
372 # It has been modified by Rob Hooft to work with 2.0.2 as well, but I
373 # haven't tested it recently. For a more complete module,
374 # refer to pympz.sourceforge.net.
376 # A compatible MP library unencombered by the GPL also exists. It was
377 # posted to comp.sources.misc in volume 40 and is widely available from
378 # FTP archive sites. One URL for it is:
379 # ftp://gatekeeper.dec.com/.b/usenet/comp.sources.misc/volume40/fgmp/part01.Z
381 if (self
.compiler
.find_library_file(lib_dirs
, 'gmp')):
382 exts
.append( Extension('mpz', ['mpzmodule.c'],
383 libraries
= ['gmp'] ) )
387 if platform
not in ['mac', 'win32']:
388 # Steen Lumholt's termios module
389 exts
.append( Extension('termios', ['termios.c']) )
390 # Jeremy Hylton's rlimit interface
391 if platform
not in ['cygwin']:
392 exts
.append( Extension('resource', ['resource.c']) )
394 # Generic dynamic loading module
395 #exts.append( Extension('dl', ['dlmodule.c']) )
397 # Sun yellow pages. Some systems have the functions in libc.
398 if platform
not in ['cygwin']:
399 if (self
.compiler
.find_library_file(lib_dirs
, 'nsl')):
403 exts
.append( Extension('nis', ['nismodule.c'],
406 # Curses support, requring the System V version of curses, often
407 # provided by the ncurses library.
408 if platform
== 'sunos4':
409 inc_dirs
+= ['/usr/5include']
410 lib_dirs
+= ['/usr/5lib']
412 if (self
.compiler
.find_library_file(lib_dirs
, 'ncurses')):
413 curses_libs
= ['ncurses']
414 exts
.append( Extension('_curses', ['_cursesmodule.c'],
415 libraries
= curses_libs
) )
416 elif (self
.compiler
.find_library_file(lib_dirs
, 'curses')):
417 if (self
.compiler
.find_library_file(lib_dirs
, 'terminfo')):
418 curses_libs
= ['curses', 'terminfo']
420 curses_libs
= ['curses', 'termcap']
422 exts
.append( Extension('_curses', ['_cursesmodule.c'],
423 libraries
= curses_libs
) )
425 # If the curses module is enabled, check for the panel module
426 if (os
.path
.exists('Modules/_curses_panel.c') and
427 module_enabled(exts
, '_curses') and
428 self
.compiler
.find_library_file(lib_dirs
, 'panel')):
429 exts
.append( Extension('_curses_panel', ['_curses_panel.c'],
430 libraries
= ['panel'] + curses_libs
) )
434 # Lee Busby's SIGFPE modules.
435 # The library to link fpectl with is platform specific.
436 # Choose *one* of the options below for fpectl:
438 if platform
== 'irix5':
439 # For SGI IRIX (tested on 5.3):
440 exts
.append( Extension('fpectl', ['fpectlmodule.c'],
442 elif 0: # XXX how to detect SunPro?
443 # For Solaris with SunPro compiler (tested on Solaris 2.5 with SunPro C 4.2):
444 # (Without the compiler you don't have -lsunmath.)
445 #fpectl fpectlmodule.c -R/opt/SUNWspro/lib -lsunmath -lm
448 # For other systems: see instructions in fpectlmodule.c.
449 #fpectl fpectlmodule.c ...
450 exts
.append( Extension('fpectl', ['fpectlmodule.c']) )
453 # Andrew Kuchling's zlib module.
454 # This require zlib 1.1.3 (or later).
455 # See http://www.cdrom.com/pub/infozip/zlib/
456 if (self
.compiler
.find_library_file(lib_dirs
, 'z')):
457 exts
.append( Extension('zlib', ['zlibmodule.c'],
460 # Interface to the Expat XML parser
462 # Expat is written by James Clark and must be downloaded separately
463 # (see below). The pyexpat module was written by Paul Prescod after a
464 # prototype by Jack Jansen.
466 # The Expat dist includes Windows .lib and .dll files. Home page is
467 # at http://www.jclark.com/xml/expat.html, the current production
468 # release is always ftp://ftp.jclark.com/pub/xml/expat.zip.
470 # EXPAT_DIR, below, should point to the expat/ directory created by
471 # unpacking the Expat source distribution.
473 # Note: the expat build process doesn't yet build a libexpat.a; you
474 # can do this manually while we try convince the author to add it. To
475 # do so, cd to EXPAT_DIR, run "make" if you have not done so, then
478 # ar cr libexpat.a xmltok/*.o xmlparse/*.o
481 expat_incs
= find_file('expat.h', inc_dirs
, [])
482 if expat_incs
is not None:
484 expat_defs
= [('HAVE_EXPAT_H', 1)]
486 expat_incs
= find_file('xmlparse.h', inc_dirs
, [])
488 if (expat_incs
is not None and
489 self
.compiler
.find_library_file(lib_dirs
, 'expat')):
490 exts
.append( Extension('pyexpat', ['pyexpat.c'],
491 define_macros
= expat_defs
,
492 libraries
= ['expat']) )
494 # Platform-specific libraries
495 if platform
== 'linux2':
496 # Linux-specific modules
497 exts
.append( Extension('linuxaudiodev', ['linuxaudiodev.c']) )
499 if platform
== 'sunos5':
500 # SunOS specific modules
501 exts
.append( Extension('sunaudiodev', ['sunaudiodev.c']) )
503 self
.extensions
.extend(exts
)
505 # Call the method for detecting whether _tkinter can be compiled
506 self
.detect_tkinter(inc_dirs
, lib_dirs
)
509 def detect_tkinter(self
, inc_dirs
, lib_dirs
):
510 # The _tkinter module.
512 # Assume we haven't found any of the libraries or include files
513 tcllib
= tklib
= tcl_includes
= tk_includes
= None
514 for version
in ['8.4', '8.3', '8.2', '8.1', '8.0']:
515 tklib
= self
.compiler
.find_library_file(lib_dirs
,
517 tcllib
= self
.compiler
.find_library_file(lib_dirs
,
520 # Exit the loop when we've found the Tcl/Tk libraries
523 # Now check for the header files
525 # Check for the include files on Debian, where
526 # they're put in /usr/include/{tcl,tk}X.Y
527 debian_tcl_include
= [ '/usr/include/tcl' + version
]
528 debian_tk_include
= [ '/usr/include/tk' + version
] + debian_tcl_include
529 tcl_includes
= find_file('tcl.h', inc_dirs
, debian_tcl_include
)
530 tk_includes
= find_file('tk.h', inc_dirs
, debian_tk_include
)
532 if (tcllib
is None or tklib
is None and
533 tcl_includes
is None or tk_includes
is None):
534 # Something's missing, so give up
537 # OK... everything seems to be present for Tcl/Tk.
539 include_dirs
= [] ; libs
= [] ; defs
= [] ; added_lib_dirs
= []
540 for dir in tcl_includes
+ tk_includes
:
541 if dir not in include_dirs
:
542 include_dirs
.append(dir)
544 # Check for various platform-specific directories
545 platform
= self
.get_platform()
546 if platform
== 'sunos5':
547 include_dirs
.append('/usr/openwin/include')
548 added_lib_dirs
.append('/usr/openwin/lib')
549 elif os
.path
.exists('/usr/X11R6/include'):
550 include_dirs
.append('/usr/X11R6/include')
551 added_lib_dirs
.append('/usr/X11R6/lib')
552 elif os
.path
.exists('/usr/X11R5/include'):
553 include_dirs
.append('/usr/X11R5/include')
554 added_lib_dirs
.append('/usr/X11R5/lib')
556 # Assume default location for X11
557 include_dirs
.append('/usr/X11/include')
558 added_lib_dirs
.append('/usr/X11/lib')
560 # Check for BLT extension
561 if self
.compiler
.find_library_file(lib_dirs
+ added_lib_dirs
, 'BLT8.0'):
562 defs
.append( ('WITH_BLT', 1) )
563 libs
.append('BLT8.0')
565 # Add the Tcl/Tk libraries
566 libs
.append('tk'+version
)
567 libs
.append('tcl'+version
)
569 if platform
in ['aix3', 'aix4']:
572 # Finally, link with the X11 libraries
575 ext
= Extension('_tkinter', ['_tkinter.c', 'tkappinit.c'],
576 define_macros
=[('WITH_APPINIT', 1)] + defs
,
577 include_dirs
= include_dirs
,
579 library_dirs
= added_lib_dirs
,
581 self
.extensions
.append(ext
)
583 # XXX handle these, but how to detect?
584 # *** Uncomment and edit for PIL (TkImaging) extension only:
585 # -DWITH_PIL -I../Extensions/Imaging/libImaging tkImaging.c \
586 # *** Uncomment and edit for TOGL extension only:
587 # -DWITH_TOGL togl.c \
588 # *** Uncomment these for TOGL extension only:
589 # -lGL -lGLU -lXext -lXmu \
592 setup(name
= 'Python standard library',
593 version
= '%d.%d' % sys
.version_info
[:2],
594 cmdclass
= {'build_ext':PyBuildExt
},
595 # The struct module is defined here, because build_ext won't be
596 # called unless there's at least one extension module defined.
597 ext_modules
=[Extension('struct', ['structmodule.c'])],
600 scripts
= ['Tools/scripts/pydoc']
604 if __name__
== '__main__':
605 sysconfig
.set_python_build()