2009-07-27 14:10:43 +00:00
|
|
|
import os
|
2009-11-30 09:28:23 +00:00
|
|
|
import sys
|
2009-07-27 14:10:43 +00:00
|
|
|
from distutils.core import setup, Extension
|
|
|
|
|
2009-11-30 09:28:23 +00:00
|
|
|
# --with-zlib: use zlib for compressing and decompressing
|
|
|
|
# --without-zlib: ^ negated
|
|
|
|
# --with-zlib=<dir>: path to zlib if needed
|
|
|
|
# --with-libmemcached=<dir>: path to libmemcached package if needed
|
2009-11-30 08:43:05 +00:00
|
|
|
|
2009-12-30 12:45:19 +00:00
|
|
|
cmd = None
|
2009-11-30 09:28:23 +00:00
|
|
|
use_zlib = True
|
|
|
|
pkgdirs = [] # incdirs and libdirs get these
|
2009-11-30 08:43:05 +00:00
|
|
|
libs = ["memcached"]
|
|
|
|
defs = []
|
2009-07-27 14:10:43 +00:00
|
|
|
incdirs = []
|
|
|
|
libdirs = []
|
|
|
|
|
2010-03-16 22:06:18 +00:00
|
|
|
def append_env(L, e):
|
|
|
|
v = os.environ.get(e)
|
|
|
|
if v and os.path.exists(v):
|
|
|
|
L.append(v)
|
|
|
|
|
|
|
|
append_env(pkgdirs, "LIBMEMCACHED")
|
|
|
|
append_env(pkgdirs, "ZLIB")
|
|
|
|
|
2009-11-30 09:28:23 +00:00
|
|
|
# Hack up sys.argv, yay
|
|
|
|
unprocessed = []
|
|
|
|
for arg in sys.argv[1:]:
|
|
|
|
if arg == "--with-zlib":
|
|
|
|
use_zlib = True
|
|
|
|
continue
|
|
|
|
elif arg == "--without-zlib":
|
|
|
|
use_zlib = False
|
|
|
|
continue
|
2009-12-30 12:45:19 +00:00
|
|
|
elif arg == "--gen-setup":
|
|
|
|
cmd = arg[2:]
|
2009-11-30 09:28:23 +00:00
|
|
|
elif "=" in arg:
|
|
|
|
if arg.startswith("--with-libmemcached=") or \
|
|
|
|
arg.startswith("--with-zlib="):
|
|
|
|
pkgdirs.append(arg.split("=", 1)[1])
|
|
|
|
continue
|
|
|
|
unprocessed.append(arg)
|
|
|
|
sys.argv[1:] = unprocessed
|
|
|
|
|
|
|
|
for pkgdir in pkgdirs:
|
|
|
|
incdirs.append(os.path.join(pkgdir, "include"))
|
|
|
|
libdirs.append(os.path.join(pkgdir, "lib"))
|
2009-07-27 14:10:43 +00:00
|
|
|
|
2009-11-30 08:43:05 +00:00
|
|
|
if use_zlib:
|
|
|
|
libs.append("z")
|
|
|
|
defs.append(("USE_ZLIB", None))
|
2009-09-05 00:08:04 +00:00
|
|
|
|
2009-07-27 14:10:43 +00:00
|
|
|
pylibmc_ext = Extension("_pylibmc", ["_pylibmcmodule.c"],
|
2009-11-30 08:43:05 +00:00
|
|
|
libraries=libs, include_dirs=incdirs,
|
|
|
|
library_dirs=libdirs, define_macros=defs)
|
|
|
|
|
2009-12-30 12:45:19 +00:00
|
|
|
# Hidden secret: if environment variable GEN_SETUP is set, generate Setup file.
|
|
|
|
if cmd == "gen-setup":
|
|
|
|
line = " ".join((
|
|
|
|
pylibmc_ext.name,
|
|
|
|
" ".join("-l" + lib for lib in pylibmc_ext.libraries),
|
|
|
|
" ".join("-I" + incdir for incdir in pylibmc_ext.include_dirs),
|
|
|
|
" ".join("-L" + libdir for libdir in pylibmc_ext.library_dirs),
|
|
|
|
" ".join("-D" + name + ("=" + str(value), "")[value is None] for (name, value) in pylibmc_ext.define_macros)))
|
|
|
|
open("Setup", "w").write(line + "\n")
|
|
|
|
sys.exit(0)
|
|
|
|
|
2009-11-30 08:43:05 +00:00
|
|
|
readme_text = open("README.rst", "U").read()
|
|
|
|
version = open("pylibmc-version.h", "U").read().strip().split("\"")[1]
|
2009-07-27 14:10:43 +00:00
|
|
|
|
2009-09-19 19:42:37 +00:00
|
|
|
setup(name="pylibmc", version=version,
|
2010-01-03 18:20:47 +00:00
|
|
|
url="http://sendapatch.se/projects/pylibmc/",
|
2009-09-07 18:58:55 +00:00
|
|
|
author="Ludvig Ericson", author_email="ludvig@lericson.se",
|
2009-07-27 14:10:43 +00:00
|
|
|
license="3-clause BSD <http://www.opensource.org/licenses/bsd-license.php>",
|
2009-12-30 13:28:32 +00:00
|
|
|
description="Quick and small memcached client for Python",
|
|
|
|
long_description=readme_text,
|
2010-09-17 18:17:40 +00:00
|
|
|
ext_modules=[pylibmc_ext], packages=["pylibmc"])
|