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