Merge pull request #240 from mgorny/master

Support explicitly disabling features via --disable-* options
This commit is contained in:
Alex Clark ☺ 2013-06-12 09:37:26 -07:00
commit 4aed8d64b7

164
setup.py
View File

@ -94,6 +94,48 @@ LCMS_ROOT = None
class pil_build_ext(build_ext):
class feature:
zlib = jpeg = tiff = freetype = tcl = tk = lcms = webp = None
required = []
def require(self, feat):
return feat in self.required
def want(self, feat):
return getattr(self, feat) is None
def __iter__(self):
for x in dir(self):
if x[1] != '_':
yield x
feature = feature()
user_options = build_ext.user_options + [
('disable-%s' % x, None, 'Disable support for %s' % x)
for x in feature
] + [
('enable-%s' % x, None, 'Enable support for %s' % x)
for x in feature
]
def initialize_options(self):
build_ext.initialize_options(self)
for x in self.feature:
setattr(self, 'disable_%s' % x, None)
setattr(self, 'enable_%s' % x, None)
def finalize_options(self):
build_ext.finalize_options(self)
for x in self.feature:
if getattr(self, 'disable_%s' % x):
setattr(self.feature, x, False)
if getattr(self, 'enable_%s' % x):
raise ValueError(
'Conflicting options: --enable-%s and --disable-%s'
% (x, x))
if getattr(self, 'enable_%s' % x):
self.feature.required.append(x)
def build_extensions(self):
global TCL_ROOT
@ -223,72 +265,84 @@ class pil_build_ext(build_ext):
#
# look for available libraries
class feature:
zlib = jpeg = tiff = freetype = tcl = tk = lcms = webp = None
feature = feature()
feature = self.feature
if _find_include_file(self, "zlib.h"):
if _find_library_file(self, "z"):
feature.zlib = "z"
elif sys.platform == "win32" and _find_library_file(self, "zlib"):
feature.zlib = "zlib" # alternative name
if feature.want('zlib'):
if _find_include_file(self, "zlib.h"):
if _find_library_file(self, "z"):
feature.zlib = "z"
elif sys.platform == "win32" and _find_library_file(self, "zlib"):
feature.zlib = "zlib" # alternative name
if _find_include_file(self, "jpeglib.h"):
if _find_library_file(self, "jpeg"):
feature.jpeg = "jpeg"
elif (
sys.platform == "win32" and
_find_library_file(self, "libjpeg")):
feature.jpeg = "libjpeg" # alternative name
if feature.want('jpeg'):
if _find_include_file(self, "jpeglib.h"):
if _find_library_file(self, "jpeg"):
feature.jpeg = "jpeg"
elif (
sys.platform == "win32" and
_find_library_file(self, "libjpeg")):
feature.jpeg = "libjpeg" # alternative name
if _find_library_file(self, "tiff"):
feature.tiff = "tiff"
if sys.platform == "win32" and _find_library_file(self, "libtiff"):
feature.tiff = "libtiff"
if sys.platform == "darwin" and _find_library_file(self, "libtiff"):
feature.tiff = "libtiff"
if feature.want('tiff'):
if _find_library_file(self, "tiff"):
feature.tiff = "tiff"
if sys.platform == "win32" and _find_library_file(self, "libtiff"):
feature.tiff = "libtiff"
if sys.platform == "darwin" and _find_library_file(self, "libtiff"):
feature.tiff = "libtiff"
if _find_library_file(self, "freetype"):
# look for freetype2 include files
freetype_version = 0
for dir in self.compiler.include_dirs:
if os.path.isfile(os.path.join(dir, "ft2build.h")):
freetype_version = 21
if feature.want('freetype'):
if _find_library_file(self, "freetype"):
# look for freetype2 include files
freetype_version = 0
for dir in self.compiler.include_dirs:
if os.path.isfile(os.path.join(dir, "ft2build.h")):
freetype_version = 21
dir = os.path.join(dir, "freetype2")
break
dir = os.path.join(dir, "freetype2")
break
dir = os.path.join(dir, "freetype2")
if os.path.isfile(os.path.join(dir, "ft2build.h")):
freetype_version = 21
break
if os.path.isdir(os.path.join(dir, "freetype")):
freetype_version = 20
break
if freetype_version:
feature.freetype = "freetype"
feature.freetype_version = freetype_version
if dir:
_add_directory(self.compiler.include_dirs, dir, 0)
if os.path.isfile(os.path.join(dir, "ft2build.h")):
freetype_version = 21
break
if os.path.isdir(os.path.join(dir, "freetype")):
freetype_version = 20
break
if freetype_version:
feature.freetype = "freetype"
feature.freetype_version = freetype_version
if dir:
_add_directory(self.compiler.include_dirs, dir, 0)
if _find_include_file(self, "lcms.h"):
if _find_library_file(self, "lcms"):
feature.lcms = "lcms"
if feature.want('lcms'):
if _find_include_file(self, "lcms.h"):
if _find_library_file(self, "lcms"):
feature.lcms = "lcms"
if _tkinter and _find_include_file(self, "tk.h"):
# the library names may vary somewhat (e.g. tcl84 or tcl8.4)
version = TCL_VERSION[0] + TCL_VERSION[2]
if _find_library_file(self, "tcl" + version):
feature.tcl = "tcl" + version
elif _find_library_file(self, "tcl" + TCL_VERSION):
feature.tcl = "tcl" + TCL_VERSION
if _find_library_file(self, "tk" + version):
feature.tk = "tk" + version
elif _find_library_file(self, "tk" + TCL_VERSION):
feature.tk = "tk" + TCL_VERSION
if feature.want('tcl'):
if _find_library_file(self, "tcl" + version):
feature.tcl = "tcl" + version
elif _find_library_file(self, "tcl" + TCL_VERSION):
feature.tcl = "tcl" + TCL_VERSION
if feature.want('tk'):
if _find_library_file(self, "tk" + version):
feature.tk = "tk" + version
elif _find_library_file(self, "tk" + TCL_VERSION):
feature.tk = "tk" + TCL_VERSION
if (_find_include_file(self, "webp/encode.h") and
_find_include_file(self, "webp/decode.h")):
if _find_library_file(self, "webp"): # in googles precompiled zip it is call "libwebp"
feature.webp = "webp"
if feature.want('webp'):
if (_find_include_file(self, "webp/encode.h") and
_find_include_file(self, "webp/decode.h")):
if _find_library_file(self, "webp"): # in googles precompiled zip it is call "libwebp"
feature.webp = "webp"
for f in feature:
if not getattr(feature, f) and feature.require(f):
raise ValueError(
'--enable-%s requested but %s not found, aborting.'
% (f, f))
#
# core library