1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217
|
# Copyright (C) 2000, 2001, 2013 Gregory Trubetskoy
# Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007 Apache Software Foundation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
#
# $Id: setup.py.in 475516 2006-11-16 01:12:40Z grahamd $
import sys
if sys.version_info[0]*100 + sys.version_info[1] > 310:
from setuptools import setup, Extension
import sysconfig
else:
from distutils.core import setup, Extension
from distutils import sysconfig
import string
import re
import os.path
if sys.version[0] == '2':
from commands import getoutput
else:
from subprocess import getoutput
try:
__file__
except NameError:
__file__ = '.'
def getmp_rootdir():
"""gets the root directory of the mod_python source tree..."""
return os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))
def getmp_srcdir():
"""gets the src subdirectory of the mod_python source tree..."""
return os.path.join(getmp_rootdir(), 'src')
def getmp_includedir():
"""gets the src subdirectory of the mod_python source tree..."""
return os.path.join(getmp_rootdir(), 'src', 'include')
def getmp_mpdir():
"""gets the mod_python dir"""
return os.path.join(getmp_rootdir(), 'lib', 'python', 'mod_python')
def getconfigure_option(option_name):
"""gets an option from the config.status file"""
config_status_file = os.path.join(getmp_rootdir(), '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<OPTION_STRING>[^,]+),\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 getmp_version():
return getoutput('./version.sh')
def getapxs_location():
"""finds the location of apxs from the config.status file"""
return getconfigure_option("APXS")
def getapxs_option(option):
APXS = getapxs_location()
return getoutput("%s -q %s" % (APXS, option))
def getapache_srcdir():
"""returns apache src directory"""
return os.getenv("APACHESRC")
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")
def generate_version_py():
with open(os.path.join(getmp_mpdir(), 'version.py'), 'w') as version_py:
version_py.write('# THIS FILE IS AUTO-GENERATED BY setup.py\n\n')
version_py.write('version = "%s"\n' % getmp_version())
version_py.write('\n# Some build-time constants:\n')
version_py.write('HTTPD = "@HTTPD@"\n')
version_py.write('HTTPD_VERSION = "@HTTPD_VERSION@"\n')
version_py.write('APR_VERSION = "@APR_VERSION@"\n')
version_py.write('LIBEXECDIR = "@LIBEXECDIR@"\n')
version_py.write('SYSCONFDIR = "@SYSCONFDIR@"\n')
version_py.write('PYTHON_BIN = "@PYTHON_BIN@"\n')
VER = getmp_version()
# TODO: improve the intelligence here...
winbuild = ("bdist_wininst" in sys.argv) or (os.name == "nt")
class PSPExtension(Extension):
"""a class that helps build the PSP extension"""
def __init__(self, source_dir, include_dirs):
Extension.__init__(self, "mod_python._psp",
[os.path.join(source_dir, source_file) for source_file in
("psp_string.c", "psp_parser.c", "_pspmodule.c")],
include_dirs=include_dirs
)
if winbuild:
self.define_macros.extend([('WIN32', None), ('NDEBUG', None), ('_WINDOWS', None)])
PSPModule = PSPExtension(getmp_srcdir(), [getmp_includedir()])
modpy_src_files = ("mod_python.c", "_apachemodule.c", "connobject.c", "filterobject.c",
"hlist.c", "hlistobject.c", "requestobject.c", "serverobject.c", "tableobject.c",
"util.c", "finfoobject.c")
class finallist(list):
"""this represents a list that cannot be appended to..."""
def append(self, object):
return
class ModPyExtension(Extension):
"""a class that actually builds the mod_python.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_python_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)])
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_python" to the export symbols
self.export_symbols = finallist(self.export_symbols)
if winbuild:
# build mod_python.so
ModPyModule = ModPyExtension(getmp_srcdir(), [getmp_includedir(), getapache_includedir()], [getapache_libdir()])
scripts = ["win32_postinstall.py"]
# put the mod_python.so file in the Python root ...
# win32_postinstall.py will pick it up from there...
# data_files = [("", [(os.path.join(getmp_srcdir(), 'Release', 'mod_python.so'))])]
data_files = []
ext_modules = [ModPyModule, PSPModule]
else:
scripts = []
data_files = []
ext_modules = [PSPModule]
generate_version_py()
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_python",
version=VER,
description="Apache/Python Integration",
author="Gregory Trubetskoy et al",
author_email="mod_python@modpython.org",
url="http://www.modpython.org/",
packages=["mod_python"],
package_dir={'mod_python': os.path.join(getmp_rootdir(), 'lib', 'python', 'mod_python')},
scripts=scripts,
data_files=data_files,
ext_modules=ext_modules)
# makes emacs go into python mode
### Local Variables:
### mode:python
### End:
|