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