| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
__version__ = "special BeOS after 1.37" |
| 6 |
|
| 7 |
import sys, os |
| 8 |
from distutils import sysconfig |
| 9 |
from distutils import text_file |
| 10 |
from distutils.errors import * |
| 11 |
from distutils.core import Extension, setup |
| 12 |
from distutils.command.build_ext import build_ext |
| 13 |
|
| 14 |
|
| 15 |
disabled_module_list = ['dbm', 'mmap', 'resource', 'nis'] |
| 16 |
|
| 17 |
def find_file(filename, std_dirs, paths): |
| 18 |
"""Searches for the directory where a given file is located, |
| 19 |
and returns a possibly-empty list of additional directories, or None |
| 20 |
if the file couldn't be found at all. |
| 21 |
|
| 22 |
'filename' is the name of a file, such as readline.h or libcrypto.a. |
| 23 |
'std_dirs' is the list of standard system directories; if the |
| 24 |
file is found in one of them, no additional directives are needed. |
| 25 |
'paths' is a list of additional locations to check; if the file is |
| 26 |
found in one of them, the resulting list will contain the directory. |
| 27 |
""" |
| 28 |
|
| 29 |
|
| 30 |
for dir in std_dirs: |
| 31 |
f = os.path.join(dir, filename) |
| 32 |
if os.path.exists(f): return [] |
| 33 |
|
| 34 |
|
| 35 |
for dir in paths: |
| 36 |
f = os.path.join(dir, filename) |
| 37 |
if os.path.exists(f): |
| 38 |
return [dir] |
| 39 |
|
| 40 |
|
| 41 |
return None |
| 42 |
|
| 43 |
def find_library_file(compiler, libname, std_dirs, paths): |
| 44 |
filename = compiler.library_filename(libname, lib_type='shared') |
| 45 |
result = find_file(filename, std_dirs, paths) |
| 46 |
if result is not None: return result |
| 47 |
|
| 48 |
filename = compiler.library_filename(libname, lib_type='static') |
| 49 |
result = find_file(filename, std_dirs, paths) |
| 50 |
return result |
| 51 |
|
| 52 |
def module_enabled(extlist, modname): |
| 53 |
"""Returns whether the module 'modname' is present in the list |
| 54 |
of extensions 'extlist'.""" |
| 55 |
extlist = [ext for ext in extlist if ext.name == modname] |
| 56 |
return len(extlist) |
| 57 |
|
| 58 |
class PyBuildExt(build_ext): |
| 59 |
|
| 60 |
def build_extensions(self): |
| 61 |
|
| 62 |
|
| 63 |
self.detect_modules() |
| 64 |
|
| 65 |
|
| 66 |
self.extensions = [ext for ext in self.extensions |
| 67 |
if ext.name not in disabled_module_list] |
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
(srcdir,) = sysconfig.get_config_vars('srcdir') |
| 72 |
|
| 73 |
|
| 74 |
moddir = os.path.join(os.getcwd(), srcdir, 'Modules') |
| 75 |
moddir = os.path.normpath(moddir) |
| 76 |
srcdir, tail = os.path.split(moddir) |
| 77 |
srcdir = os.path.normpath(srcdir) |
| 78 |
moddir = os.path.normpath(moddir) |
| 79 |
|
| 80 |
|
| 81 |
self.distribution.scripts = [os.path.join(srcdir, filename) |
| 82 |
for filename in self.distribution.scripts] |
| 83 |
|
| 84 |
for ext in self.extensions[:]: |
| 85 |
ext.sources = [ os.path.join(moddir, filename) |
| 86 |
for filename in ext.sources ] |
| 87 |
ext.include_dirs.append( '.' ) |
| 88 |
ext.include_dirs.append( os.path.join(srcdir, './Include') ) |
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
if ext.name in sys.builtin_module_names: |
| 93 |
self.extensions.remove(ext) |
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
input = text_file.TextFile('Modules/Setup', join_lines=1) |
| 98 |
remove_modules = [] |
| 99 |
while 1: |
| 100 |
line = input.readline() |
| 101 |
if not line: break |
| 102 |
line = line.split() |
| 103 |
remove_modules.append( line[0] ) |
| 104 |
input.close() |
| 105 |
|
| 106 |
for ext in self.extensions[:]: |
| 107 |
if ext.name in remove_modules: |
| 108 |
self.extensions.remove(ext) |
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
compiler = os.environ.get('CC') |
| 114 |
linker_so = os.environ.get('LDSHARED') |
| 115 |
args = {} |
| 116 |
|
| 117 |
|
| 118 |
if compiler is not None: |
| 119 |
args['compiler_so'] = compiler |
| 120 |
if linker_so is not None: |
| 121 |
args['linker_so'] = linker_so + ' -shared' |
| 122 |
self.compiler.set_executables(**args) |
| 123 |
|
| 124 |
build_ext.build_extensions(self) |
| 125 |
|
| 126 |
def build_extension(self, ext): |
| 127 |
|
| 128 |
try: |
| 129 |
build_ext.build_extension(self, ext) |
| 130 |
except (CCompilerError, DistutilsError), why: |
| 131 |
self.announce('WARNING: building of extension "%s" failed: %s' % |
| 132 |
(ext.name, sys.exc_info()[1])) |
| 133 |
|
| 134 |
def get_platform (self): |
| 135 |
|
| 136 |
platform = sys.platform |
| 137 |
if platform[:6] =='cygwin': |
| 138 |
platform = 'cygwin' |
| 139 |
elif platform[:4] =='beos': |
| 140 |
platform = 'beos' |
| 141 |
|
| 142 |
return platform |
| 143 |
|
| 144 |
def detect_modules(self): |
| 145 |
try: |
| 146 |
belibs = os.environ['BELIBRARIES'].split(';') |
| 147 |
except KeyError: |
| 148 |
belibs = ['/boot/beos/system/lib'] |
| 149 |
belibs.append('/boot/home/config/lib') |
| 150 |
self.compiler.library_dirs.append('/boot/home/config/lib') |
| 151 |
try: |
| 152 |
beincl = os.environ['BEINCLUDES'].split(';') |
| 153 |
except KeyError: |
| 154 |
beincl = [] |
| 155 |
beincl.append('/boot/home/config/include') |
| 156 |
self.compiler.include_dirs.append('/boot/home/config/include') |
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
lib_dirs = belibs |
| 161 |
inc_dirs = beincl |
| 162 |
exts = [] |
| 163 |
|
| 164 |
platform = self.get_platform() |
| 165 |
|
| 166 |
|
| 167 |
math_libs = ['m'] |
| 168 |
if platform in ['Darwin1.2', 'beos']: |
| 169 |
math_libs = [] |
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
exts.append( Extension('_weakref', ['_weakref.c']) ) |
| 180 |
exts.append( Extension('_symtable', ['symtablemodule.c']) ) |
| 181 |
|
| 182 |
|
| 183 |
exts.append( Extension('array', ['arraymodule.c']) ) |
| 184 |
|
| 185 |
exts.append( Extension('cmath', ['cmathmodule.c'], |
| 186 |
libraries=math_libs) ) |
| 187 |
|
| 188 |
|
| 189 |
exts.append( Extension('math', ['mathmodule.c'], |
| 190 |
libraries=math_libs) ) |
| 191 |
|
| 192 |
exts.append( Extension('strop', ['stropmodule.c']) ) |
| 193 |
|
| 194 |
exts.append( Extension('time', ['timemodule.c'], |
| 195 |
libraries=math_libs) ) |
| 196 |
|
| 197 |
exts.append( Extension('operator', ['operator.c']) ) |
| 198 |
|
| 199 |
exts.append( Extension('_codecs', ['_codecsmodule.c']) ) |
| 200 |
|
| 201 |
exts.append( Extension('_testcapi', ['_testcapimodule.c']) ) |
| 202 |
|
| 203 |
exts.append( Extension('unicodedata', ['unicodedata.c']) ) |
| 204 |
|
| 205 |
exts.append( Extension('_locale', ['_localemodule.c']) ) |
| 206 |
|
| 207 |
|
| 208 |
|
| 209 |
|
| 210 |
|
| 211 |
|
| 212 |
exts.append( Extension('fcntl', ['fcntlmodule.c']) ) |
| 213 |
|
| 214 |
exts.append( Extension('pwd', ['pwdmodule.c']) ) |
| 215 |
|
| 216 |
exts.append( Extension('grp', ['grpmodule.c']) ) |
| 217 |
|
| 218 |
exts.append( Extension('errno', ['errnomodule.c']) ) |
| 219 |
|
| 220 |
exts.append( Extension('select', ['selectmodule.c']) ) |
| 221 |
|
| 222 |
|
| 223 |
|
| 224 |
|
| 225 |
exts.append( Extension('md5', ['md5module.c', 'md5c.c']) ) |
| 226 |
|
| 227 |
|
| 228 |
|
| 229 |
exts.append( Extension('sha', ['shamodule.c']) ) |
| 230 |
|
| 231 |
|
| 232 |
exts.append( Extension('binascii', ['binascii.c']) ) |
| 233 |
|
| 234 |
|
| 235 |
exts.append( Extension('parser', ['parsermodule.c']) ) |
| 236 |
|
| 237 |
|
| 238 |
exts.append( Extension('cStringIO', ['cStringIO.c']) ) |
| 239 |
exts.append( Extension('cPickle', ['cPickle.c']) ) |
| 240 |
|
| 241 |
|
| 242 |
exts.append( Extension('mmap', ['mmapmodule.c']) ) |
| 243 |
|
| 244 |
|
| 245 |
exts.append( Extension('syslog', ['syslogmodule.c']) ) |
| 246 |
|
| 247 |
|
| 248 |
exts.append( Extension('timing', ['timingmodule.c']) ) |
| 249 |
|
| 250 |
|
| 251 |
|
| 252 |
|
| 253 |
|
| 254 |
|
| 255 |
|
| 256 |
|
| 257 |
|
| 258 |
|
| 259 |
|
| 260 |
if sys.maxint != 9223372036854775807L: |
| 261 |
|
| 262 |
exts.append( Extension('audioop', ['audioop.c']) ) |
| 263 |
|
| 264 |
exts.append( Extension('imageop', ['imageop.c']) ) |
| 265 |
|
| 266 |
exts.append( Extension('rgbimg', ['rgbimgmodule.c']) ) |
| 267 |
|
| 268 |
|
| 269 |
if self.compiler.find_library_file(lib_dirs, 'readline'): |
| 270 |
readline_libs = ['readline'] |
| 271 |
if self.compiler.find_library_file(lib_dirs + |
| 272 |
['/usr/lib/termcap'], |
| 273 |
'termcap'): |
| 274 |
readline_libs.append('termcap') |
| 275 |
exts.append( Extension('readline', ['readline.c'], |
| 276 |
library_dirs=['/usr/lib/termcap'], |
| 277 |
libraries=readline_libs) ) |
| 278 |
|
| 279 |
|
| 280 |
|
| 281 |
|
| 282 |
if self.compiler.find_library_file(lib_dirs, 'crypt'): |
| 283 |
libs = ['crypt'] |
| 284 |
else: |
| 285 |
libs = [] |
| 286 |
exts.append( Extension('crypt', ['cryptmodule.c'], libraries=libs) ) |
| 287 |
|
| 288 |
|
| 289 |
|
| 290 |
ssl_incs = find_file('openssl/ssl.h', inc_dirs, |
| 291 |
['/usr/local/ssl/include', |
| 292 |
'/usr/contrib/ssl/include/' |
| 293 |
] |
| 294 |
) |
| 295 |
ssl_libs = find_library_file(self.compiler, 'ssl',lib_dirs, |
| 296 |
['/usr/local/ssl/lib', |
| 297 |
'/usr/contrib/ssl/lib/' |
| 298 |
] ) |
| 299 |
|
| 300 |
if (ssl_incs is not None and |
| 301 |
ssl_libs is not None): |
| 302 |
exts.append( Extension('_socket', ['socketmodule.c'], |
| 303 |
include_dirs = ssl_incs, |
| 304 |
library_dirs = ssl_libs, |
| 305 |
libraries = ['ssl', 'crypto'], |
| 306 |
define_macros = [('USE_SSL',1)] ) ) |
| 307 |
else: |
| 308 |
exts.append( Extension('_socket', ['socketmodule.c']) ) |
| 309 |
|
| 310 |
|
| 311 |
|
| 312 |
|
| 313 |
|
| 314 |
|
| 315 |
|
| 316 |
|
| 317 |
|
| 318 |
if platform not in ['cygwin']: |
| 319 |
if (self.compiler.find_library_file(lib_dirs, 'ndbm')): |
| 320 |
exts.append( Extension('dbm', ['dbmmodule.c'], |
| 321 |
libraries = ['ndbm'] ) ) |
| 322 |
else: |
| 323 |
exts.append( Extension('dbm', ['dbmmodule.c']) ) |
| 324 |
|
| 325 |
|
| 326 |
if (self.compiler.find_library_file(lib_dirs, 'gdbm')): |
| 327 |
exts.append( Extension('gdbm', ['gdbmmodule.c'], |
| 328 |
libraries = ['gdbm'] ) ) |
| 329 |
|
| 330 |
|
| 331 |
|
| 332 |
|
| 333 |
|
| 334 |
|
| 335 |
|
| 336 |
|
| 337 |
|
| 338 |
|
| 339 |
|
| 340 |
|
| 341 |
dblib = [] |
| 342 |
if self.compiler.find_library_file(lib_dirs, 'db'): |
| 343 |
dblib = ['db'] |
| 344 |
|
| 345 |
db185_incs = find_file('db_185.h', inc_dirs, |
| 346 |
['/usr/include/db3', '/usr/include/db2']) |
| 347 |
db_inc = find_file('db.h', inc_dirs, ['/usr/include/db1']) |
| 348 |
if db185_incs is not None: |
| 349 |
exts.append( Extension('bsddb', ['bsddbmodule.c'], |
| 350 |
include_dirs = db185_incs, |
| 351 |
define_macros=[('HAVE_DB_185_H',1)], |
| 352 |
libraries = dblib ) ) |
| 353 |
elif db_inc is not None: |
| 354 |
exts.append( Extension('bsddb', ['bsddbmodule.c'], |
| 355 |
include_dirs = db_inc, |
| 356 |
libraries = dblib) ) |
| 357 |
|
| 358 |
|
| 359 |
if platform == 'win32': |
| 360 |
|
| 361 |
exts.append( Extension('termios', ['termios.c']) ) |
| 362 |
|
| 363 |
if platform not in ['cygwin']: |
| 364 |
exts.append( Extension('resource', ['resource.c']) ) |
| 365 |
|
| 366 |
|
| 367 |
|
| 368 |
|
| 369 |
|
| 370 |
if platform not in ['cygwin']: |
| 371 |
if (self.compiler.find_library_file(lib_dirs, 'nsl')): |
| 372 |
libs = ['nsl'] |
| 373 |
else: |
| 374 |
libs = [] |
| 375 |
exts.append( Extension('nis', ['nismodule.c'], |
| 376 |
libraries = libs) ) |
| 377 |
|
| 378 |
|
| 379 |
|
| 380 |
if (self.compiler.find_library_file(lib_dirs, 'ncurses')): |
| 381 |
curses_libs = ['ncurses'] |
| 382 |
exts.append( Extension('_curses', ['_cursesmodule.c'], |
| 383 |
libraries = curses_libs) ) |
| 384 |
elif (self.compiler.find_library_file(lib_dirs, 'curses')): |
| 385 |
if (self.compiler.find_library_file(lib_dirs, 'terminfo')): |
| 386 |
curses_libs = ['curses', 'terminfo'] |
| 387 |
else: |
| 388 |
curses_libs = ['curses', 'termcap'] |
| 389 |
|
| 390 |
exts.append( Extension('_curses', ['_cursesmodule.c'], |
| 391 |
libraries = curses_libs) ) |
| 392 |
|
| 393 |
|
| 394 |
if (os.path.exists('Modules/_curses_panel.c') and |
| 395 |
module_enabled(exts, '_curses') and |
| 396 |
self.compiler.find_library_file(lib_dirs, 'panel')): |
| 397 |
exts.append( Extension('_curses_panel', ['_curses_panel.c'], |
| 398 |
libraries = ['panel'] + curses_libs) ) |
| 399 |
|
| 400 |
|
| 401 |
|
| 402 |
|
| 403 |
|
| 404 |
|
| 405 |
|
| 406 |
if platform == 'irix5': |
| 407 |
|
| 408 |
exts.append( Extension('fpectl', ['fpectlmodule.c'], |
| 409 |
libraries=['fpe']) ) |
| 410 |
elif 0: |
| 411 |
|
| 412 |
|
| 413 |
|
| 414 |
pass |
| 415 |
else: |
| 416 |
|
| 417 |
|
| 418 |
exts.append( Extension('fpectl', ['fpectlmodule.c']) ) |
| 419 |
|
| 420 |
|
| 421 |
|
| 422 |
|
| 423 |
|
| 424 |
if (self.compiler.find_library_file(lib_dirs, 'z')): |
| 425 |
exts.append( Extension('zlib', ['zlibmodule.c'], |
| 426 |
libraries = ['z']) ) |
| 427 |
|
| 428 |
|
| 429 |
|
| 430 |
|
| 431 |
|
| 432 |
|
| 433 |
|
| 434 |
|
| 435 |
|
| 436 |
|
| 437 |
|
| 438 |
|
| 439 |
|
| 440 |
|
| 441 |
|
| 442 |
|
| 443 |
|
| 444 |
|
| 445 |
|
| 446 |
|
| 447 |
|
| 448 |
expat_defs = [] |
| 449 |
expat_incs = find_file('expat.h', inc_dirs, []) |
| 450 |
if expat_incs is not None: |
| 451 |
|
| 452 |
expat_defs = [('HAVE_EXPAT_H', 1)] |
| 453 |
else: |
| 454 |
expat_incs = find_file('xmlparse.h', inc_dirs, []) |
| 455 |
|
| 456 |
if (expat_incs is not None and |
| 457 |
self.compiler.find_library_file(lib_dirs, 'expat')): |
| 458 |
exts.append( Extension('pyexpat', ['pyexpat.c'], |
| 459 |
define_macros = expat_defs, |
| 460 |
libraries = ['expat']) ) |
| 461 |
|
| 462 |
|
| 463 |
if platform == 'linux2': |
| 464 |
|
| 465 |
exts.append( Extension('linuxaudiodev', ['linuxaudiodev.c']) ) |
| 466 |
|
| 467 |
if platform == 'sunos5': |
| 468 |
|
| 469 |
exts.append( Extension('sunaudiodev', ['sunaudiodev.c']) ) |
| 470 |
|
| 471 |
self.extensions.extend(exts) |
| 472 |
|
| 473 |
|
| 474 |
self.detect_tkinter(inc_dirs, lib_dirs) |
| 475 |
|
| 476 |
|
| 477 |
def detect_tkinter(self, inc_dirs, lib_dirs): |
| 478 |
|
| 479 |
|
| 480 |
|
| 481 |
tcllib = tklib = tcl_includes = tk_includes = None |
| 482 |
for version in ['8.4', '8.3', '8.2', '8.1', '8.0']: |
| 483 |
tklib = self.compiler.find_library_file(lib_dirs, |
| 484 |
'tk' + version ) |
| 485 |
tcllib = self.compiler.find_library_file(lib_dirs, |
| 486 |
'tcl' + version ) |
| 487 |
if tklib and tcllib: |
| 488 |
|
| 489 |
break |
| 490 |
|
| 491 |
|
| 492 |
if tklib and tcllib: |
| 493 |
|
| 494 |
|
| 495 |
debian_tcl_include = [ '/usr/include/tcl' + version ] |
| 496 |
debian_tk_include = [ '/usr/include/tk' + version ] + debian_tcl_include |
| 497 |
tcl_includes = find_file('tcl.h', inc_dirs, debian_tcl_include) |
| 498 |
tk_includes = find_file('tk.h', inc_dirs, debian_tk_include) |
| 499 |
|
| 500 |
if (tcllib is None or tklib is None and |
| 501 |
tcl_includes is None or tk_includes is None): |
| 502 |
|
| 503 |
return |
| 504 |
|
| 505 |
|
| 506 |
|
| 507 |
include_dirs = [] ; libs = [] ; defs = [] ; added_lib_dirs = [] |
| 508 |
for dir in tcl_includes + tk_includes: |
| 509 |
if dir not in include_dirs: |
| 510 |
include_dirs.append(dir) |
| 511 |
|
| 512 |
|
| 513 |
platform = self.get_platform() |
| 514 |
if platform == 'sunos5': |
| 515 |
include_dirs.append('/usr/openwin/include') |
| 516 |
added_lib_dirs.append('/usr/openwin/lib') |
| 517 |
elif os.path.exists('/usr/X11R6/include'): |
| 518 |
include_dirs.append('/usr/X11R6/include') |
| 519 |
added_lib_dirs.append('/usr/X11R6/lib') |
| 520 |
elif os.path.exists('/usr/X11R5/include'): |
| 521 |
include_dirs.append('/usr/X11R5/include') |
| 522 |
added_lib_dirs.append('/usr/X11R5/lib') |
| 523 |
else: |
| 524 |
|
| 525 |
include_dirs.append('/usr/X11/include') |
| 526 |
added_lib_dirs.append('/usr/X11/lib') |
| 527 |
|
| 528 |
|
| 529 |
if self.compiler.find_library_file(lib_dirs + added_lib_dirs, 'BLT8.0'): |
| 530 |
defs.append( ('WITH_BLT', 1) ) |
| 531 |
libs.append('BLT8.0') |
| 532 |
|
| 533 |
|
| 534 |
libs.append('tk'+version) |
| 535 |
libs.append('tcl'+version) |
| 536 |
|
| 537 |
if platform in ['aix3', 'aix4']: |
| 538 |
libs.append('ld') |
| 539 |
|
| 540 |
|
| 541 |
libs.append('X11') |
| 542 |
|
| 543 |
ext = Extension('_tkinter', ['_tkinter.c', 'tkappinit.c'], |
| 544 |
define_macros=[('WITH_APPINIT', 1)] + defs, |
| 545 |
include_dirs = include_dirs, |
| 546 |
libraries = libs, |
| 547 |
library_dirs = added_lib_dirs, |
| 548 |
) |
| 549 |
self.extensions.append(ext) |
| 550 |
|
| 551 |
|
| 552 |
|
| 553 |
|
| 554 |
|
| 555 |
|
| 556 |
|
| 557 |
|
| 558 |
|
| 559 |
def main(): |
| 560 |
setup(name = 'Python standard library', |
| 561 |
version = '%d.%d' % sys.version_info[:2], |
| 562 |
cmdclass = {'build_ext':PyBuildExt}, |
| 563 |
|
| 564 |
|
| 565 |
ext_modules=[Extension('struct', ['structmodule.c'])], |
| 566 |
|
| 567 |
|
| 568 |
scripts = ['Tools/scripts/pydoc'] |
| 569 |
) |
| 570 |
|
| 571 |
|
| 572 |
if __name__ == '__main__': |
| 573 |
sysconfig.set_python_build() |
| 574 |
main() |