Andrew M. Kuchling | 00e0f21 | 2001-01-17 15:23:23 +0000 | [diff] [blame] | 1 | # To be fixed: |
| 2 | # Implement --disable-modules setting |
Andrew M. Kuchling | 00e0f21 | 2001-01-17 15:23:23 +0000 | [diff] [blame] | 3 | |
| 4 | import sys, os, string, getopt |
| 5 | from distutils import sysconfig |
| 6 | from distutils.core import Extension, setup |
| 7 | from distutils.command.build_ext import build_ext |
| 8 | |
| 9 | # This global variable is used to hold the list of modules to be disabled. |
| 10 | disabled_module_list = [] |
| 11 | |
Andrew M. Kuchling | fbe7376 | 2001-01-18 18:44:20 +0000 | [diff] [blame^] | 12 | def 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. Kuchling | 00e0f21 | 2001-01-17 15:23:23 +0000 | [diff] [blame] | 36 | return None |
| 37 | |
Andrew M. Kuchling | fbe7376 | 2001-01-18 18:44:20 +0000 | [diff] [blame^] | 38 | def 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. Kuchling | 00e0f21 | 2001-01-17 15:23:23 +0000 | [diff] [blame] | 47 | def 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 | |
| 53 | class PyBuildExt(build_ext): |
| 54 | |
| 55 | def build_extensions(self): |
| 56 | from distutils.ccompiler import new_compiler |
| 57 | from distutils.sysconfig import customize_compiler |
| 58 | |
| 59 | # Detect which modules should be compiled |
| 60 | self.detect_modules() |
| 61 | |
| 62 | # Remove modules that are present on the disabled list |
| 63 | self.extensions = [ext for ext in self.extensions |
| 64 | if ext.name not in disabled_module_list] |
| 65 | |
| 66 | # Fix up the autodetected modules, prefixing all the source files |
| 67 | # with Modules/ and adding Python's include directory to the path. |
| 68 | (srcdir,) = sysconfig.get_config_vars('srcdir') |
| 69 | |
| 70 | # |
| 71 | moddir = os.path.join(os.getcwd(), 'Modules', srcdir) |
| 72 | moddir = os.path.normpath(moddir) |
| 73 | srcdir, tail = os.path.split(moddir) |
| 74 | srcdir = os.path.normpath(srcdir) |
| 75 | moddir = os.path.normpath(moddir) |
| 76 | |
Andrew M. Kuchling | fbe7376 | 2001-01-18 18:44:20 +0000 | [diff] [blame^] | 77 | for ext in self.extensions[:]: |
Andrew M. Kuchling | 00e0f21 | 2001-01-17 15:23:23 +0000 | [diff] [blame] | 78 | ext.sources = [ os.path.join(moddir, filename) |
| 79 | for filename in ext.sources ] |
| 80 | ext.include_dirs.append( '.' ) # to get config.h |
Andrew M. Kuchling | fbe7376 | 2001-01-18 18:44:20 +0000 | [diff] [blame^] | 81 | |
| 82 | # Try importing a module; if it's already been built statically, |
| 83 | # don't build it here |
| 84 | try: |
| 85 | __import__(ext.name) |
| 86 | except ImportError: |
| 87 | pass # Not built, so this is what we expect |
| 88 | else: |
| 89 | self.extensions.remove(ext) |
Andrew M. Kuchling | 00e0f21 | 2001-01-17 15:23:23 +0000 | [diff] [blame] | 90 | |
Andrew M. Kuchling | 00e0f21 | 2001-01-17 15:23:23 +0000 | [diff] [blame] | 91 | build_ext.build_extensions(self) |
| 92 | |
| 93 | def detect_modules(self): |
Andrew M. Kuchling | fbe7376 | 2001-01-18 18:44:20 +0000 | [diff] [blame^] | 94 | # Ensure that /usr/local is always used |
| 95 | if '/usr/local/lib' not in self.compiler.library_dirs: |
| 96 | self.compiler.library_dirs.append('/usr/local/lib') |
| 97 | if '/usr/local/include' not in self.compiler.include_dirs: |
| 98 | self.compiler.include_dirs.append( '/usr/local/include' ) |
| 99 | |
| 100 | # lib_dirs and inc_dirs are used to search for files; |
| 101 | # if a file is found in one of those directories, it can |
| 102 | # be assumed that no additional -I,-L directives are needed. |
| 103 | lib_dirs = self.compiler.library_dirs + ['/lib', '/usr/lib'] |
| 104 | inc_dirs = ['/usr/include'] + self.compiler.include_dirs |
Andrew M. Kuchling | 00e0f21 | 2001-01-17 15:23:23 +0000 | [diff] [blame] | 105 | exts = [] |
| 106 | |
| 107 | # XXX Omitted modules: gl, pure, dl, SGI-specific modules |
| 108 | |
| 109 | # |
| 110 | # The following modules are all pretty straightforward, and compile |
| 111 | # on pretty much any POSIXish platform. |
| 112 | # |
| 113 | |
| 114 | # Some modules that are normally always on: |
| 115 | exts.append( Extension('regex', ['regexmodule.c', 'regexpr.c']) ) |
| 116 | exts.append( Extension('pcre', ['pcremodule.c', 'pypcre.c']) ) |
Andrew M. Kuchling | 00e0f21 | 2001-01-17 15:23:23 +0000 | [diff] [blame] | 117 | |
Andrew M. Kuchling | d5c4306 | 2001-01-17 15:59:25 +0000 | [diff] [blame] | 118 | exts.append( Extension('xreadlines', ['xreadlinesmodule.c']) ) |
Andrew M. Kuchling | 00e0f21 | 2001-01-17 15:23:23 +0000 | [diff] [blame] | 119 | |
| 120 | # array objects |
| 121 | exts.append( Extension('array', ['arraymodule.c']) ) |
| 122 | # complex math library functions |
| 123 | exts.append( Extension('cmath', ['cmathmodule.c'], libraries=['m']) ) |
| 124 | # math library functions, e.g. sin() |
| 125 | exts.append( Extension('math', ['mathmodule.c'], libraries=['m']) ) |
| 126 | # fast string operations implemented in C |
| 127 | exts.append( Extension('strop', ['stropmodule.c']) ) |
| 128 | # time operations and variables |
| 129 | exts.append( Extension('time', ['timemodule.c'], libraries=['m']) ) |
| 130 | # operator.add() and similar goodies |
| 131 | exts.append( Extension('operator', ['operator.c']) ) |
| 132 | # access to the builtin codecs and codec registry |
| 133 | exts.append( Extension('_codecs', ['_codecsmodule.c']) ) |
| 134 | # static Unicode character database |
| 135 | exts.append( Extension('unicodedata', ['unicodedata.c', 'unicodedatabase.c']) ) |
| 136 | # Unicode Character Name expansion hash table |
| 137 | exts.append( Extension('ucnhash', ['ucnhash.c']) ) |
| 138 | # access to ISO C locale support |
| 139 | exts.append( Extension('_locale', ['_localemodule.c']) ) |
| 140 | |
| 141 | # Modules with some UNIX dependencies -- on by default: |
| 142 | # (If you have a really backward UNIX, select and socket may not be |
| 143 | # supported...) |
| 144 | |
| 145 | # fcntl(2) and ioctl(2) |
| 146 | exts.append( Extension('fcntl', ['fcntlmodule.c']) ) |
| 147 | # pwd(3) |
| 148 | exts.append( Extension('pwd', ['pwdmodule.c']) ) |
| 149 | # grp(3) |
| 150 | exts.append( Extension('grp', ['grpmodule.c']) ) |
| 151 | # posix (UNIX) errno values |
| 152 | exts.append( Extension('errno', ['errnomodule.c']) ) |
| 153 | # select(2); not on ancient System V |
| 154 | exts.append( Extension('select', ['selectmodule.c']) ) |
| 155 | |
| 156 | # The md5 module implements the RSA Data Security, Inc. MD5 |
| 157 | # Message-Digest Algorithm, described in RFC 1321. The necessary files |
| 158 | # md5c.c and md5.h are included here. |
| 159 | exts.append( Extension('md5', ['md5module.c', 'md5c.c']) ) |
| 160 | |
| 161 | # The sha module implements the SHA checksum algorithm. |
| 162 | # (NIST's Secure Hash Algorithm.) |
| 163 | exts.append( Extension('sha', ['shamodule.c']) ) |
| 164 | |
| 165 | # Tommy Burnette's 'new' module (creates new empty objects of certain kinds): |
| 166 | exts.append( Extension('new', ['newmodule.c']) ) |
| 167 | |
| 168 | # Helper module for various ascii-encoders |
| 169 | exts.append( Extension('binascii', ['binascii.c']) ) |
| 170 | |
| 171 | # Fred Drake's interface to the Python parser |
| 172 | exts.append( Extension('parser', ['parsermodule.c']) ) |
| 173 | |
| 174 | # Digital Creations' cStringIO and cPickle |
| 175 | exts.append( Extension('cStringIO', ['cStringIO.c']) ) |
| 176 | exts.append( Extension('cPickle', ['cPickle.c']) ) |
| 177 | |
| 178 | # Memory-mapped files (also works on Win32). |
| 179 | exts.append( Extension('mmap', ['mmapmodule.c']) ) |
| 180 | |
| 181 | # Lance Ellinghaus's modules: |
| 182 | # enigma-inspired encryption |
| 183 | exts.append( Extension('rotor', ['rotormodule.c']) ) |
| 184 | # syslog daemon interface |
| 185 | exts.append( Extension('syslog', ['syslogmodule.c']) ) |
| 186 | |
| 187 | # George Neville-Neil's timing module: |
| 188 | exts.append( Extension('timing', ['timingmodule.c']) ) |
| 189 | |
| 190 | # |
| 191 | # Here ends the simple stuff. From here on, modules need certain libraries, |
| 192 | # are platform-specific, or present other surprises. |
| 193 | # |
| 194 | |
| 195 | # Multimedia modules |
| 196 | # These don't work for 64-bit platforms!!! |
| 197 | # These represent audio samples or images as strings: |
| 198 | |
| 199 | # Disabled on 64-bit platforms |
| 200 | if sys.maxint != 9223372036854775807L: |
| 201 | # Operations on audio samples |
| 202 | exts.append( Extension('audioop', ['audioop.c']) ) |
| 203 | # Operations on images |
| 204 | exts.append( Extension('imageop', ['imageop.c']) ) |
| 205 | # Read SGI RGB image files (but coded portably) |
| 206 | exts.append( Extension('rgbimg', ['rgbimgmodule.c']) ) |
| 207 | |
| 208 | # readline |
Andrew M. Kuchling | 4f9e943 | 2001-01-17 20:20:44 +0000 | [diff] [blame] | 209 | if (self.compiler.find_library_file(lib_dirs, 'readline')): |
Andrew M. Kuchling | 00e0f21 | 2001-01-17 15:23:23 +0000 | [diff] [blame] | 210 | exts.append( Extension('readline', ['readline.c'], |
| 211 | libraries=['readline', 'termcap']) ) |
| 212 | |
| 213 | # The crypt module is now disabled by default because it breaks builds |
| 214 | # on many systems (where -lcrypt is needed), e.g. Linux (I believe). |
| 215 | |
| 216 | if self.compiler.find_library_file(lib_dirs, 'crypt'): |
| 217 | libs = ['crypt'] |
| 218 | else: |
| 219 | libs = [] |
| 220 | exts.append( Extension('crypt', ['cryptmodule.c'], libraries=libs) ) |
| 221 | |
| 222 | # socket(2) |
| 223 | # Detect SSL support for the socket module |
Andrew M. Kuchling | fbe7376 | 2001-01-18 18:44:20 +0000 | [diff] [blame^] | 224 | ssl_incs = find_file('openssl/ssl.h', inc_dirs, |
| 225 | ['/usr/local/ssl/include'] |
| 226 | ) |
| 227 | ssl_libs = find_library_file(self.compiler, 'ssl',lib_dirs, |
| 228 | ['/usr/local/ssl/lib'] ) |
| 229 | |
| 230 | if (ssl_incs is not None and |
| 231 | ssl_libs is not None): |
Andrew M. Kuchling | 00e0f21 | 2001-01-17 15:23:23 +0000 | [diff] [blame] | 232 | exts.append( Extension('_socket', ['socketmodule.c'], |
Andrew M. Kuchling | fbe7376 | 2001-01-18 18:44:20 +0000 | [diff] [blame^] | 233 | include_dirs = ssl_incs, |
| 234 | library_dirs = ssl_libs, |
Andrew M. Kuchling | 00e0f21 | 2001-01-17 15:23:23 +0000 | [diff] [blame] | 235 | libraries = ['ssl', 'crypto'], |
| 236 | define_macros = [('USE_SSL',1)] ) ) |
| 237 | else: |
| 238 | exts.append( Extension('_socket', ['socketmodule.c']) ) |
| 239 | |
| 240 | # Modules that provide persistent dictionary-like semantics. You will |
| 241 | # probably want to arrange for at least one of them to be available on |
| 242 | # your machine, though none are defined by default because of library |
| 243 | # dependencies. The Python module anydbm.py provides an |
| 244 | # implementation independent wrapper for these; dumbdbm.py provides |
| 245 | # similar functionality (but slower of course) implemented in Python. |
| 246 | |
| 247 | # The standard Unix dbm module: |
| 248 | if (self.compiler.find_library_file(lib_dirs, 'ndbm')): |
| 249 | exts.append( Extension('dbm', ['dbmmodule.c'], |
| 250 | libraries = ['ndbm'] ) ) |
| 251 | else: |
| 252 | exts.append( Extension('dbm', ['dbmmodule.c']) ) |
| 253 | |
| 254 | # Anthony Baxter's gdbm module. GNU dbm(3) will require -lgdbm: |
| 255 | if (self.compiler.find_library_file(lib_dirs, 'gdbm')): |
| 256 | exts.append( Extension('gdbm', ['gdbmmodule.c'], |
| 257 | libraries = ['gdbm'] ) ) |
| 258 | |
| 259 | # Berkeley DB interface. |
| 260 | # |
| 261 | # This requires the Berkeley DB code, see |
| 262 | # ftp://ftp.cs.berkeley.edu/pub/4bsd/db.1.85.tar.gz |
| 263 | # |
| 264 | # Edit the variables DB and DBPORT to point to the db top directory |
| 265 | # and the subdirectory of PORT where you built it. |
| 266 | # |
| 267 | # (See http://electricrain.com/greg/python/bsddb3/ for an interface to |
| 268 | # BSD DB 3.x.) |
| 269 | |
| 270 | # Note: If a db.h file is found by configure, bsddb will be enabled |
| 271 | # automatically via Setup.config.in. It only needs to be enabled here |
| 272 | # if it is not automatically enabled there; check the generated |
| 273 | # Setup.config before enabling it here. |
| 274 | |
Andrew M. Kuchling | fbe7376 | 2001-01-18 18:44:20 +0000 | [diff] [blame^] | 275 | db_incs = find_file('db_185.h', inc_dirs, []) |
| 276 | if (db_incs is not None and |
| 277 | self.compiler.find_library_file(lib_dirs, 'db') ): |
Andrew M. Kuchling | 00e0f21 | 2001-01-17 15:23:23 +0000 | [diff] [blame] | 278 | exts.append( Extension('bsddb', ['bsddbmodule.c'], |
Andrew M. Kuchling | fbe7376 | 2001-01-18 18:44:20 +0000 | [diff] [blame^] | 279 | include_dirs = db_incs, |
Andrew M. Kuchling | 00e0f21 | 2001-01-17 15:23:23 +0000 | [diff] [blame] | 280 | libraries = ['db'] ) ) |
| 281 | |
| 282 | # The mpz module interfaces to the GNU Multiple Precision library. |
| 283 | # You need to ftp the GNU MP library. |
| 284 | # This was originally written and tested against GMP 1.2 and 1.3.2. |
| 285 | # It has been modified by Rob Hooft to work with 2.0.2 as well, but I |
| 286 | # haven't tested it recently. For a more complete module, |
| 287 | # refer to pympz.sourceforge.net. |
| 288 | |
| 289 | # A compatible MP library unencombered by the GPL also exists. It was |
| 290 | # posted to comp.sources.misc in volume 40 and is widely available from |
| 291 | # FTP archive sites. One URL for it is: |
| 292 | # ftp://gatekeeper.dec.com/.b/usenet/comp.sources.misc/volume40/fgmp/part01.Z |
| 293 | |
| 294 | # Anthony Baxter's gdbm module. GNU dbm(3) will require -lgdbm: |
| 295 | if (self.compiler.find_library_file(lib_dirs, 'gmp')): |
| 296 | exts.append( Extension('mpz', ['mpzmodule.c'], |
| 297 | libraries = ['gmp'] ) ) |
| 298 | |
| 299 | |
| 300 | # Unix-only modules |
| 301 | if sys.platform not in ['mac', 'win32']: |
| 302 | # Steen Lumholt's termios module |
| 303 | exts.append( Extension('termios', ['termios.c']) ) |
| 304 | # Jeremy Hylton's rlimit interface |
| 305 | exts.append( Extension('resource', ['resource.c']) ) |
| 306 | |
| 307 | if (self.compiler.find_library_file(lib_dirs, 'nsl')): |
| 308 | exts.append( Extension('nis', ['nismodule.c'], |
| 309 | libraries = ['nsl']) ) |
| 310 | |
| 311 | # Curses support, requring the System V version of curses, often |
| 312 | # provided by the ncurses library. |
| 313 | if sys.platform == 'sunos4': |
| 314 | include_dirs += ['/usr/5include'] |
| 315 | lib_dirs += ['/usr/5lib'] |
| 316 | |
| 317 | if (self.compiler.find_library_file(lib_dirs, 'ncurses')): |
| 318 | curses_libs = ['ncurses'] |
| 319 | exts.append( Extension('_curses', ['_cursesmodule.c'], |
| 320 | libraries = curses_libs) ) |
| 321 | elif (self.compiler.find_library_file(lib_dirs, 'curses')): |
| 322 | if (self.compiler.find_library_file(lib_dirs, 'terminfo')): |
| 323 | curses_libs = ['curses', 'terminfo'] |
| 324 | else: |
| 325 | curses_libs = ['curses', 'termcap'] |
| 326 | |
| 327 | exts.append( Extension('_curses', ['_cursesmodule.c'], |
| 328 | libraries = curses_libs) ) |
| 329 | |
| 330 | # If the curses module is enabled, check for the panel module |
| 331 | if (os.path.exists('Modules/_curses_panel.c') and |
| 332 | module_enabled(exts, '_curses') and |
| 333 | self.compiler.find_library_file(lib_dirs, 'panel')): |
| 334 | exts.append( Extension('_curses_panel', ['_curses_panel.c'], |
| 335 | libraries = ['panel'] + curses_libs) ) |
| 336 | |
| 337 | |
| 338 | |
| 339 | # Lee Busby's SIGFPE modules. |
| 340 | # The library to link fpectl with is platform specific. |
| 341 | # Choose *one* of the options below for fpectl: |
| 342 | |
| 343 | if sys.platform == 'irix5': |
| 344 | # For SGI IRIX (tested on 5.3): |
| 345 | exts.append( Extension('fpectl', ['fpectlmodule.c'], |
| 346 | libraries=['fpe']) ) |
Andrew M. Kuchling | fbe7376 | 2001-01-18 18:44:20 +0000 | [diff] [blame^] | 347 | elif 0: # XXX how to detect SunPro? |
Andrew M. Kuchling | 00e0f21 | 2001-01-17 15:23:23 +0000 | [diff] [blame] | 348 | # For Solaris with SunPro compiler (tested on Solaris 2.5 with SunPro C 4.2): |
| 349 | # (Without the compiler you don't have -lsunmath.) |
| 350 | #fpectl fpectlmodule.c -R/opt/SUNWspro/lib -lsunmath -lm |
| 351 | pass |
| 352 | else: |
| 353 | # For other systems: see instructions in fpectlmodule.c. |
| 354 | #fpectl fpectlmodule.c ... |
| 355 | exts.append( Extension('fpectl', ['fpectlmodule.c']) ) |
| 356 | |
| 357 | |
| 358 | # Andrew Kuchling's zlib module. |
| 359 | # This require zlib 1.1.3 (or later). |
| 360 | # See http://www.cdrom.com/pub/infozip/zlib/ |
| 361 | if (self.compiler.find_library_file(lib_dirs, 'z')): |
| 362 | exts.append( Extension('zlib', ['zlibmodule.c'], |
| 363 | libraries = ['z']) ) |
| 364 | |
| 365 | # Interface to the Expat XML parser |
| 366 | # |
| 367 | # Expat is written by James Clark and must be downloaded separately |
| 368 | # (see below). The pyexpat module was written by Paul Prescod after a |
| 369 | # prototype by Jack Jansen. |
| 370 | # |
| 371 | # The Expat dist includes Windows .lib and .dll files. Home page is at |
| 372 | # http://www.jclark.com/xml/expat.html, the current production release is |
| 373 | # always ftp://ftp.jclark.com/pub/xml/expat.zip. |
| 374 | # |
| 375 | # EXPAT_DIR, below, should point to the expat/ directory created by |
| 376 | # unpacking the Expat source distribution. |
| 377 | # |
| 378 | # Note: the expat build process doesn't yet build a libexpat.a; you can |
| 379 | # do this manually while we try convince the author to add it. To do so, |
| 380 | # cd to EXPAT_DIR, run "make" if you have not done so, then run: |
| 381 | # |
| 382 | # ar cr libexpat.a xmltok/*.o xmlparse/*.o |
| 383 | # |
Andrew M. Kuchling | fbe7376 | 2001-01-18 18:44:20 +0000 | [diff] [blame^] | 384 | expat_defs = [] |
| 385 | expat_incs = find_file('expat.h', inc_dirs, []) |
| 386 | if expat_incs is not None: |
| 387 | # expat.h was found |
| 388 | expat_defs = [('HAVE_EXPAT_H', 1)] |
| 389 | else: |
| 390 | expat_incs = find_file('xmlparse.h', inc_dirs, []) |
| 391 | |
| 392 | if (expat_incs and |
| 393 | self.compiler.find_library_file(lib_dirs, 'expat')): |
| 394 | exts.append( Extension('pyexpat', ['pyexpat.c'], |
| 395 | define_macros = expat_defs, |
| 396 | libraries = ['expat']) ) |
Andrew M. Kuchling | 00e0f21 | 2001-01-17 15:23:23 +0000 | [diff] [blame] | 397 | |
| 398 | # Platform-specific libraries |
| 399 | plat = sys.platform |
| 400 | if plat == 'linux2': |
| 401 | # Linux-specific modules |
| 402 | exts.append( Extension('linuxaudiodev', ['linuxaudiodev.c']) ) |
| 403 | |
| 404 | if plat == 'sunos5': |
| 405 | # SunOS specific modules |
| 406 | exts.append( Extension('sunaudiodev', ['sunaudiodev.c']) ) |
| 407 | |
Andrew M. Kuchling | fbe7376 | 2001-01-18 18:44:20 +0000 | [diff] [blame^] | 408 | self.extensions.extend(exts) |
| 409 | |
| 410 | # Call the method for detecting whether _tkinter can be compiled |
| 411 | self.detect_tkinter(inc_dirs, lib_dirs) |
| 412 | |
| 413 | |
| 414 | def detect_tkinter(self, inc_dirs, lib_dirs): |
Andrew M. Kuchling | 00e0f21 | 2001-01-17 15:23:23 +0000 | [diff] [blame] | 415 | # The _tkinter module. |
| 416 | # |
| 417 | # The command for _tkinter is long and site specific. Please |
| 418 | # uncomment and/or edit those parts as indicated. If you don't have a |
| 419 | # specific extension (e.g. Tix or BLT), leave the corresponding line |
| 420 | # commented out. (Leave the trailing backslashes in! If you |
| 421 | # experience strange errors, you may want to join all uncommented |
| 422 | # lines and remove the backslashes -- the backslash interpretation is |
| 423 | # done by the shell's "read" command and it may not be implemented on |
| 424 | # every system. |
| 425 | |
Andrew M. Kuchling | fbe7376 | 2001-01-18 18:44:20 +0000 | [diff] [blame^] | 426 | # Assume we haven't found any of the libraries or include files |
| 427 | tcllib = tklib = tcl_includes = tk_includes = None |
Andrew M. Kuchling | d5c4306 | 2001-01-17 15:59:25 +0000 | [diff] [blame] | 428 | for version in ['8.4', '8.3', '8.2', '8.1', '8.0']: |
Andrew M. Kuchling | fbe7376 | 2001-01-18 18:44:20 +0000 | [diff] [blame^] | 429 | tklib = self.compiler.find_library_file(lib_dirs, |
| 430 | 'tk' + version ) |
| 431 | tcllib = self.compiler.find_library_file(lib_dirs, |
| 432 | 'tcl' + version ) |
| 433 | if tklib and tcllib: |
Andrew M. Kuchling | 00e0f21 | 2001-01-17 15:23:23 +0000 | [diff] [blame] | 434 | # Exit the loop when we've found the Tcl/Tk libraries |
| 435 | break |
Andrew M. Kuchling | 00e0f21 | 2001-01-17 15:23:23 +0000 | [diff] [blame] | 436 | |
Andrew M. Kuchling | fbe7376 | 2001-01-18 18:44:20 +0000 | [diff] [blame^] | 437 | # Now check for the header files |
| 438 | if tklib and tcllib: |
| 439 | # Check for the include files on Debian, where |
| 440 | # they're put in /usr/include/{tcl,tk}X.Y |
| 441 | debian_tcl_include = ( '/usr/include/tcl' + version ) |
| 442 | debian_tk_include = ( '/usr/include/tk' + version ) |
| 443 | tcl_includes = find_file('tcl.h', inc_dirs, |
| 444 | [debian_tcl_include] |
| 445 | ) |
| 446 | tk_includes = find_file('tk.h', inc_dirs, |
| 447 | [debian_tk_include] |
| 448 | ) |
Andrew M. Kuchling | 00e0f21 | 2001-01-17 15:23:23 +0000 | [diff] [blame] | 449 | |
Andrew M. Kuchling | fbe7376 | 2001-01-18 18:44:20 +0000 | [diff] [blame^] | 450 | if (tcllib is None or tklib is None and |
| 451 | tcl_includes is None or tk_includes is None): |
| 452 | # Something's missing, so give up |
| 453 | return |
| 454 | |
| 455 | # OK... everything seems to be present for Tcl/Tk. |
Andrew M. Kuchling | 00e0f21 | 2001-01-17 15:23:23 +0000 | [diff] [blame] | 456 | |
Andrew M. Kuchling | fbe7376 | 2001-01-18 18:44:20 +0000 | [diff] [blame^] | 457 | include_dirs = [] ; libs = [] ; defs = [] ; added_lib_dirs = [] |
| 458 | for dir in tcl_includes + tk_includes: |
| 459 | if dir not in include_dirs: |
| 460 | include_dirs.append(dir) |
| 461 | |
| 462 | # Check for various platform-specific directories |
| 463 | if sys.platform == 'sunos5': |
| 464 | include_dirs.append('/usr/openwin/include') |
| 465 | added_lib_dirs.append('/usr/openwin/lib') |
| 466 | elif os.path.exists('/usr/X11R6/include'): |
| 467 | include_dirs.append('/usr/X11R6/include') |
| 468 | added_lib_dirs.append('/usr/X11R6/lib') |
| 469 | elif os.path.exists('/usr/X11R5/include'): |
| 470 | include_dirs.append('/usr/X11R5/include') |
| 471 | added_lib_dirs.append('/usr/X11R5/lib') |
| 472 | else: |
| 473 | # Assume default location for X11 |
| 474 | include_dirs.append('/usr/X11/include') |
| 475 | added_lib_dirs.append('/usr/X11/lib') |
Andrew M. Kuchling | 00e0f21 | 2001-01-17 15:23:23 +0000 | [diff] [blame] | 476 | |
Andrew M. Kuchling | fbe7376 | 2001-01-18 18:44:20 +0000 | [diff] [blame^] | 477 | # Check for Tix extension |
| 478 | if self.compiler.find_library_file(lib_dirs + added_lib_dirs, 'tix4.1.8.0'): |
| 479 | defs.append( ('WITH_TIX', 1) ) |
| 480 | libs.append('tix4.1.8.0') |
Andrew M. Kuchling | 00e0f21 | 2001-01-17 15:23:23 +0000 | [diff] [blame] | 481 | |
Andrew M. Kuchling | fbe7376 | 2001-01-18 18:44:20 +0000 | [diff] [blame^] | 482 | # Check for BLT extension |
| 483 | if self.compiler.find_library_file(lib_dirs + added_lib_dirs, 'BLT8.0'): |
| 484 | defs.append( ('WITH_BLT', 1) ) |
| 485 | libs.append('BLT8.0') |
Andrew M. Kuchling | 00e0f21 | 2001-01-17 15:23:23 +0000 | [diff] [blame] | 486 | |
Andrew M. Kuchling | fbe7376 | 2001-01-18 18:44:20 +0000 | [diff] [blame^] | 487 | # Add the Tcl/Tk libraries |
| 488 | libs.append('tk'+version) |
| 489 | libs.append('tcl'+version) |
| 490 | |
| 491 | if sys.platform in ['aix3', 'aix4']: |
| 492 | libs.append('ld') |
Andrew M. Kuchling | 00e0f21 | 2001-01-17 15:23:23 +0000 | [diff] [blame] | 493 | |
Andrew M. Kuchling | fbe7376 | 2001-01-18 18:44:20 +0000 | [diff] [blame^] | 494 | # Finally, link with the X11 libraries |
| 495 | libs.append('X11') |
Andrew M. Kuchling | 00e0f21 | 2001-01-17 15:23:23 +0000 | [diff] [blame] | 496 | |
Andrew M. Kuchling | fbe7376 | 2001-01-18 18:44:20 +0000 | [diff] [blame^] | 497 | ext = Extension('_tkinter', ['_tkinter.c', 'tkappinit.c'], |
| 498 | define_macros=[('WITH_APPINIT', 1)] + defs, |
| 499 | include_dirs = include_dirs, |
| 500 | libraries = libs, |
| 501 | library_dirs = added_lib_dirs, |
| 502 | ) |
| 503 | self.extensions.append(ext) |
| 504 | |
| 505 | # XXX handle these, but how to detect? |
Andrew M. Kuchling | 00e0f21 | 2001-01-17 15:23:23 +0000 | [diff] [blame] | 506 | # *** Uncomment and edit for PIL (TkImaging) extension only: |
| 507 | # -DWITH_PIL -I../Extensions/Imaging/libImaging tkImaging.c \ |
| 508 | # *** Uncomment and edit for TOGL extension only: |
| 509 | # -DWITH_TOGL togl.c \ |
| 510 | # *** Uncomment these for TOGL extension only: |
| 511 | # -lGL -lGLU -lXext -lXmu \ |
| 512 | |
Andrew M. Kuchling | 00e0f21 | 2001-01-17 15:23:23 +0000 | [diff] [blame] | 513 | def main(): |
| 514 | setup(name = 'Python standard library', |
Neil Schemenauer | e7e2ece | 2001-01-17 21:58:00 +0000 | [diff] [blame] | 515 | version = '%d.%d' % sys.version_info[:2], |
Andrew M. Kuchling | 00e0f21 | 2001-01-17 15:23:23 +0000 | [diff] [blame] | 516 | cmdclass = {'build_ext':PyBuildExt}, |
| 517 | # The struct module is defined here, because build_ext won't be |
| 518 | # called unless there's at least one extension module defined. |
| 519 | ext_modules=[Extension('struct', ['structmodule.c'])] |
| 520 | ) |
| 521 | |
| 522 | # --install-platlib |
| 523 | if __name__ == '__main__': |
| 524 | sysconfig.set_python_build() |
| 525 | main() |
| 526 | |