2 # -*- coding: iso-8859-1 -*-
6 """Setup script for the PycURL module distribution."""
12 import glob, os, re, sys, string
14 from distutils.core import setup
15 from distutils.extension import Extension
16 from distutils.util import split_quoted
17 from distutils.version import LooseVersion
23 runtime_library_dirs = []
25 extra_compile_args = []
29 def scan_argv(s, default):
32 while i < len(sys.argv):
34 if string.find(arg, s) == 0:
44 # append contents of an environment variable to library_dirs[]
45 def add_libdirs(envvar, sep, fatal=0):
46 v = os.environ.get(envvar)
49 for dir in string.split(v, sep):
50 dir = string.strip(dir)
53 dir = os.path.normpath(dir)
54 if os.path.isdir(dir):
55 if not dir in library_dirs:
56 library_dirs.append(dir)
58 print "FATAL: bad directory %s in environment variable %s" % (dir, envvar)
62 if sys.platform == "win32":
63 # Windows users have to configure the CURL_DIR path parameter to match
64 # their cURL source installation. The path set here is just an example
65 # and thus unlikely to match your installation.
66 CURL_DIR = r"c:\src\build\pycurl\curl-7.13.1"
67 CURL_DIR = scan_argv("--curl-dir=", CURL_DIR)
68 print "Using curl directory:", CURL_DIR
69 assert os.path.isdir(CURL_DIR), "please check CURL_DIR in setup.py"
70 include_dirs.append(os.path.join(CURL_DIR, "include"))
71 extra_objects.append(os.path.join(CURL_DIR, "lib", "libcurl.lib"))
72 extra_link_args.extend(["gdi32.lib", "winmm.lib", "ws2_32.lib",])
73 add_libdirs("LIB", ";")
74 if string.find(sys.version, "MSC") >= 0:
75 extra_compile_args.append("-O2")
76 extra_compile_args.append("-GF") # enable read-only string pooling
77 extra_compile_args.append("-WX") # treat warnings as errors
78 extra_link_args.append("/opt:nowin98") # use small section alignment
80 # Find out the rest the hard way
81 CURL_CONFIG = "curl-config"
82 CURL_CONFIG = scan_argv("--curl-config=", CURL_CONFIG)
83 d = os.popen("'%s' --version" % CURL_CONFIG).read()
87 raise Exception, ("`%s' not found -- please install the libcurl development files" % CURL_CONFIG)
88 print "Using %s (%s)" % (CURL_CONFIG, d)
89 for e in split_quoted(os.popen("'%s' --cflags" % CURL_CONFIG).read()):
91 # do not add /usr/include
92 if not re.search(r"^\/+usr\/+include\/*$", e[2:]):
93 include_dirs.append(e[2:])
95 extra_compile_args.append(e)
96 for e in split_quoted(os.popen("'%s' --libs" % CURL_CONFIG).read()):
98 libraries.append(e[2:])
100 library_dirs.append(e[2:])
102 extra_link_args.append(e)
104 libraries.append("curl")
105 # Add extra compile flag for MacOS X
106 if sys.platform[:-1] == "darwin":
107 extra_link_args.append("-flat_namespace")
110 ###############################################################################
112 def get_kw(**kw): return kw
117 os.path.join("src", "pycurl.c"),
119 include_dirs=include_dirs,
120 define_macros=define_macros,
121 library_dirs=library_dirs,
123 runtime_library_dirs=runtime_library_dirs,
124 extra_objects=extra_objects,
125 extra_compile_args=extra_compile_args,
126 extra_link_args=extra_link_args,
128 ##print ext.__dict__; sys.exit(1)
131 ###############################################################################
135 def get_data_files():
136 # a list of tuples with (path to install to, a list of local files)
138 if sys.platform == "win32":
139 datadir = os.path.join("doc", PACKAGE)
141 datadir = os.path.join("share", "doc", PACKAGE)
143 files = ["ChangeLog", "COPYING", "INSTALL", "README", "TODO",]
145 data_files.append((os.path.join(datadir), files))
146 files = glob.glob(os.path.join("doc", "*.html"))
148 data_files.append((os.path.join(datadir, "html"), files))
149 files = glob.glob(os.path.join("examples", "*.py"))
151 data_files.append((os.path.join(datadir, "examples"), files))
152 files = glob.glob(os.path.join("tests", "*.py"))
154 data_files.append((os.path.join(datadir, "tests"), files))
157 for install_dir, files in data_files:
160 assert os.path.isfile(f), (f, install_dir)
163 ##print get_data_files(); sys.exit(1)
166 ###############################################################################
171 description="PycURL -- cURL library module for Python",
172 author="Kjetil Jacobsen, Markus F.X.J. Oberhumer",
173 author_email="kjetilja@cs.uit.no, markus@oberhumer.com",
174 maintainer="Kjetil Jacobsen, Markus F.X.J. Oberhumer",
175 maintainer_email="kjetilja@cs.uit.no, markus@oberhumer.com",
176 url="http://pycurl.sourceforge.net/",
177 license="GNU Lesser General Public License (LGPL)",
178 data_files=get_data_files(),
181 This module provides Python bindings for the cURL library.""",
184 if sys.version >= "2.2":
185 setup_args["packages"] = [PY_PACKAGE]
186 setup_args["package_dir"] = { PY_PACKAGE: os.path.join('python', 'curl') }
189 ##print distutils.__version__
190 if LooseVersion(distutils.__version__) > LooseVersion("1.0.1"):
191 setup_args["platforms"] = "All"
192 if LooseVersion(distutils.__version__) < LooseVersion("1.0.3"):
193 setup_args["licence"] = setup_args["license"]
195 if __name__ == "__main__":
196 for o in ext.extra_objects:
197 assert os.path.isfile(o), o
198 # We can live with the deprecationwarning for a while
199 apply(setup, (), setup_args)