# $Id: setup.py.in 475516 2006-11-16 01:12:40Z grahamd $ from distutils.core import setup, Extension import sys import re import os.path try: __file__ except NameError: __file__ = '.' # TODO: improve the intelligence here... WINBUILD = ("bdist_wininst" in sys.argv) or (os.name == "nt") def getconfigure_option(option_name): """gets an option from the config.status file""" config_status_file = 'config.status' if not os.path.exists(config_status_file): raise AssertionError("config.status not found in expected location (%s)" % config_status_file) header = open(config_status_file, 'r') r = re.compile(r's,\s*@%s@,\s*(?P[^,]+),\s*' % (option_name)) for line in header.readlines(): m = r.search(line) if m is not None: return m.group('OPTION_STRING') raise AssertionError("unable to find @%s@ definition in %s", (option_name, config_status_file)) def getapxs_location(): """finds the location of apxs from the config.status file""" return getconfigure_option("APXS") def getapxs_option(option): APXS = getapxs_location() import commands return commands.getoutput("%s -q %s" % (APXS, option)) def getapache_srcdir(): """returns apache src directory""" srcdir = os.getenv("APACHESRC") assert not (srcdir is None and WINBUILD), ( 'You need to define the APACHESRC environment variable under Windows' ) assert os.path.isdir(srcdir), 'Cannot find Apache in %s'%srcdir assert ( os.path.isdir(os.path.join(srcdir,'include')) and os.path.isdir(os.path.join(srcdir,'lib')) ), "The Apache in %s does not contain include and lib directories" return srcdir def getapache_includedir(): """returns apache include directory""" apache_srcdir = getapache_srcdir() if apache_srcdir is None: return getapxs_option("INCLUDEDIR") else: return os.path.join(getapache_srcdir(), "include") def getapache_libdir(): """returns apache lib directory""" apache_srcdir = getapache_srcdir() if apache_srcdir is None: return getapxs_option("LIBDIR") else: return os.path.join(apache_srcdir, "lib") modpy_src_files = ("mod_wsgi.c",) class finallist(list): """this represents a list that cannot be appended to...""" def append(self, object): return class ModWSGIExtension(Extension): """a class that actually builds the mod_wsgi.so extension for Apache (yikes)""" def __init__(self, source_dir, include_dirs, library_dirs): if WINBUILD: apr1 = 0 for dir in library_dirs: if os.path.exists(os.path.join(dir, 'libapr-1.lib')): apr1 = 1 if apr1: libraries = ['libhttpd', 'libapr-1', 'libaprutil-1', 'ws2_32'] else: libraries = ['libhttpd', 'libapr', 'libaprutil', 'ws2_32'] else: libraries = ['apr-0', 'aprutil-0'] Extension.__init__(self, "mod_wsgi_so", sources = [os.path.join(source_dir, source_file) for source_file in modpy_src_files], include_dirs=include_dirs, libraries = libraries, library_dirs=library_dirs ) if WINBUILD: self.define_macros.extend([('WIN32', None),('NDEBUG', None),('_WINDOWS', None)]) # TODO : no version resource for now # self.sources.append(os.path.join(source_dir, "Version.rc")) else: # TODO: fix this to autodetect if required... self.include_dirs.append("/usr/include/apr-0") # this is a hack to prevent build_ext from trying to append "initmod_wsgi" to the export symbols self.export_symbols = finallist(self.export_symbols) if WINBUILD: # build mod_wsgi.so src_dir = "." include_dir = "." scripts = [] data_files = [] ModWSGIModule = ModWSGIExtension(src_dir, [include_dir, getapache_includedir()], [getapache_libdir()]) ext_modules = [ModWSGIModule, ] else: scripts = [] data_files = [] ext_modules = [] import string from distutils import sysconfig if sys.platform == "darwin": if not '-undefined' in sysconfig.get_config_var("LDSHARED").split(): sysconfig._config_vars["LDSHARED"] = \ string.replace(sysconfig.get_config_var("LDSHARED"), \ " -bundle "," -bundle -flat_namespace -undefined suppress ") sysconfig._config_vars["BLDSHARED"] = \ string.replace(sysconfig.get_config_var("BLDSHARED"), \ " -bundle "," -bundle -flat_namespace -undefined suppress ") setup(name="mod_wsgi", version="1.0.0", description="mod_wsgi ", author="Graham Dumpleton", # TODO : author_email="", url="http://www.modwsgi.org/", packages=[], package_dir={}, scripts=scripts, data_files=data_files, ext_modules=ext_modules) # makes emacs go into python mode ### Local Variables: ### mode:python ### End: