2021-04-09 12:10:36 +03:00
|
|
|
#!/usr/bin/env python3
|
2013-09-28 17:28:16 +04:00
|
|
|
# > pyroma .
|
|
|
|
# ------------------------------
|
|
|
|
# Checking .
|
|
|
|
# Found Pillow
|
|
|
|
# ------------------------------
|
|
|
|
# Final rating: 10/10
|
|
|
|
# Your cheese is so fresh most people think it's a cream: Mascarpone
|
|
|
|
# ------------------------------
|
2017-11-14 17:47:59 +03:00
|
|
|
|
2010-11-28 23:15:53 +03:00
|
|
|
import os
|
|
|
|
import re
|
|
|
|
import struct
|
2016-05-04 23:36:08 +03:00
|
|
|
import subprocess
|
2017-11-14 17:47:59 +03:00
|
|
|
import sys
|
|
|
|
import warnings
|
|
|
|
|
2022-10-28 13:02:19 +03:00
|
|
|
from setuptools import Extension, setup
|
2020-09-01 20:16:46 +03:00
|
|
|
from setuptools.command.build_ext import build_ext
|
2010-11-28 21:35:36 +03:00
|
|
|
|
2010-11-28 23:15:53 +03:00
|
|
|
|
2019-11-11 17:00:17 +03:00
|
|
|
def get_version():
|
|
|
|
version_file = "src/PIL/_version.py"
|
2022-10-13 05:20:11 +03:00
|
|
|
with open(version_file, encoding="utf-8") as f:
|
2019-11-11 17:00:17 +03:00
|
|
|
exec(compile(f.read(), version_file, "exec"))
|
|
|
|
return locals()["__version__"]
|
|
|
|
|
|
|
|
|
|
|
|
PILLOW_VERSION = get_version()
|
|
|
|
FREETYPE_ROOT = None
|
2020-11-25 22:33:33 +03:00
|
|
|
HARFBUZZ_ROOT = None
|
|
|
|
FRIBIDI_ROOT = None
|
2019-11-11 17:00:17 +03:00
|
|
|
IMAGEQUANT_ROOT = None
|
|
|
|
JPEG2K_ROOT = None
|
|
|
|
JPEG_ROOT = None
|
|
|
|
LCMS_ROOT = None
|
|
|
|
TIFF_ROOT = None
|
|
|
|
ZLIB_ROOT = None
|
2021-01-09 19:00:27 +03:00
|
|
|
FUZZING_BUILD = "LIB_FUZZING_ENGINE" in os.environ
|
2019-11-11 17:00:17 +03:00
|
|
|
|
2022-07-15 13:42:36 +03:00
|
|
|
if sys.platform == "win32" and sys.version_info >= (3, 12):
|
2020-10-12 10:38:36 +03:00
|
|
|
import atexit
|
|
|
|
|
|
|
|
atexit.register(
|
|
|
|
lambda: warnings.warn(
|
|
|
|
f"Pillow {PILLOW_VERSION} does not support Python "
|
|
|
|
f"{sys.version_info.major}.{sys.version_info.minor} and does not provide "
|
|
|
|
"prebuilt Windows binaries. We do not recommend building from source on "
|
|
|
|
"Windows.",
|
|
|
|
RuntimeWarning,
|
|
|
|
)
|
2019-06-13 18:54:57 +03:00
|
|
|
)
|
2017-11-14 17:47:59 +03:00
|
|
|
|
|
|
|
|
2016-03-15 14:16:22 +03:00
|
|
|
_IMAGING = ("decode", "encode", "map", "display", "outline", "path")
|
2010-11-28 23:15:53 +03:00
|
|
|
|
|
|
|
_LIB_IMAGING = (
|
2019-06-13 18:54:57 +03:00
|
|
|
"Access",
|
|
|
|
"AlphaComposite",
|
|
|
|
"Resample",
|
2019-11-24 04:13:48 +03:00
|
|
|
"Reduce",
|
2019-06-13 18:54:57 +03:00
|
|
|
"Bands",
|
|
|
|
"BcnDecode",
|
|
|
|
"BitDecode",
|
|
|
|
"Blend",
|
|
|
|
"Chops",
|
|
|
|
"ColorLUT",
|
|
|
|
"Convert",
|
|
|
|
"ConvertYCbCr",
|
|
|
|
"Copy",
|
|
|
|
"Crop",
|
|
|
|
"Dib",
|
|
|
|
"Draw",
|
|
|
|
"Effects",
|
|
|
|
"EpsEncode",
|
|
|
|
"File",
|
|
|
|
"Fill",
|
|
|
|
"Filter",
|
|
|
|
"FliDecode",
|
|
|
|
"Geometry",
|
|
|
|
"GetBBox",
|
|
|
|
"GifDecode",
|
|
|
|
"GifEncode",
|
|
|
|
"HexDecode",
|
|
|
|
"Histo",
|
|
|
|
"JpegDecode",
|
|
|
|
"JpegEncode",
|
|
|
|
"Matrix",
|
|
|
|
"ModeFilter",
|
|
|
|
"Negative",
|
|
|
|
"Offset",
|
|
|
|
"Pack",
|
|
|
|
"PackDecode",
|
|
|
|
"Palette",
|
|
|
|
"Paste",
|
|
|
|
"Quant",
|
|
|
|
"QuantOctree",
|
|
|
|
"QuantHash",
|
|
|
|
"QuantHeap",
|
|
|
|
"PcdDecode",
|
|
|
|
"PcxDecode",
|
|
|
|
"PcxEncode",
|
|
|
|
"Point",
|
|
|
|
"RankFilter",
|
|
|
|
"RawDecode",
|
|
|
|
"RawEncode",
|
|
|
|
"Storage",
|
|
|
|
"SgiRleDecode",
|
|
|
|
"SunRleDecode",
|
|
|
|
"TgaRleDecode",
|
|
|
|
"TgaRleEncode",
|
|
|
|
"Unpack",
|
|
|
|
"UnpackYCC",
|
|
|
|
"UnsharpMask",
|
|
|
|
"XbmDecode",
|
|
|
|
"XbmEncode",
|
|
|
|
"ZipDecode",
|
|
|
|
"ZipEncode",
|
|
|
|
"TiffDecode",
|
|
|
|
"Jpeg2KDecode",
|
|
|
|
"Jpeg2KEncode",
|
|
|
|
"BoxBlur",
|
|
|
|
"QuantPngQuant",
|
|
|
|
"codec_fd",
|
|
|
|
)
|
2010-11-28 23:15:53 +03:00
|
|
|
|
2021-01-02 14:47:08 +03:00
|
|
|
DEBUG = False
|
2010-11-28 23:15:53 +03:00
|
|
|
|
2017-12-04 15:35:05 +03:00
|
|
|
|
|
|
|
class DependencyException(Exception):
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
class RequiredDependencyException(Exception):
|
|
|
|
pass
|
|
|
|
|
2016-03-30 22:47:27 +03:00
|
|
|
|
2020-09-01 20:16:46 +03:00
|
|
|
PLATFORM_MINGW = os.name == "nt" and "GCC" in sys.version
|
2019-06-13 18:54:57 +03:00
|
|
|
PLATFORM_PYPY = hasattr(sys, "pypy_version_info")
|
2017-09-19 15:44:56 +03:00
|
|
|
|
2017-12-04 15:35:05 +03:00
|
|
|
|
2016-03-30 19:16:10 +03:00
|
|
|
def _dbg(s, tp=None):
|
|
|
|
if DEBUG:
|
|
|
|
if tp:
|
|
|
|
print(s % tp)
|
|
|
|
return
|
|
|
|
print(s)
|
|
|
|
|
2010-11-28 23:15:53 +03:00
|
|
|
|
2018-07-09 10:33:00 +03:00
|
|
|
def _find_library_dirs_ldconfig():
|
|
|
|
# Based on ctypes.util from Python 2
|
|
|
|
|
|
|
|
if sys.platform.startswith("linux") or sys.platform.startswith("gnu"):
|
2019-06-13 18:54:57 +03:00
|
|
|
if struct.calcsize("l") == 4:
|
|
|
|
machine = os.uname()[4] + "-32"
|
2018-07-09 10:33:00 +03:00
|
|
|
else:
|
2019-06-13 18:54:57 +03:00
|
|
|
machine = os.uname()[4] + "-64"
|
2018-07-09 10:33:00 +03:00
|
|
|
mach_map = {
|
2019-06-13 18:54:57 +03:00
|
|
|
"x86_64-64": "libc6,x86-64",
|
|
|
|
"ppc64-64": "libc6,64bit",
|
|
|
|
"sparc64-64": "libc6,64bit",
|
|
|
|
"s390x-64": "libc6,64bit",
|
|
|
|
"ia64-64": "libc6,IA-64",
|
|
|
|
}
|
|
|
|
abi_type = mach_map.get(machine, "libc6")
|
2018-07-09 10:33:00 +03:00
|
|
|
|
2018-12-26 14:09:12 +03:00
|
|
|
# Assuming GLIBC's ldconfig (with option -p)
|
|
|
|
# Alpine Linux uses musl that can't print cache
|
2023-03-30 08:55:18 +03:00
|
|
|
args = ["ldconfig", "-p"]
|
2022-03-04 08:42:24 +03:00
|
|
|
expr = rf".*\({abi_type}.*\) => (.*)"
|
2018-07-09 10:33:00 +03:00
|
|
|
env = dict(os.environ)
|
2019-06-13 18:54:57 +03:00
|
|
|
env["LC_ALL"] = "C"
|
|
|
|
env["LANG"] = "C"
|
2018-07-09 10:33:00 +03:00
|
|
|
|
|
|
|
elif sys.platform.startswith("freebsd"):
|
2023-03-30 08:55:18 +03:00
|
|
|
args = ["ldconfig", "-r"]
|
2019-06-13 18:54:57 +03:00
|
|
|
expr = r".* => (.*)"
|
2018-07-09 10:33:00 +03:00
|
|
|
env = {}
|
|
|
|
|
|
|
|
try:
|
2019-10-08 11:24:36 +03:00
|
|
|
p = subprocess.Popen(
|
|
|
|
args, stderr=subprocess.DEVNULL, stdout=subprocess.PIPE, env=env
|
|
|
|
)
|
2018-07-09 10:33:00 +03:00
|
|
|
except OSError: # E.g. command not found
|
2019-01-02 19:38:33 +03:00
|
|
|
return []
|
2018-07-09 10:33:00 +03:00
|
|
|
[data, _] = p.communicate()
|
|
|
|
if isinstance(data, bytes):
|
2021-12-05 07:59:27 +03:00
|
|
|
data = data.decode("latin1")
|
2018-07-09 10:33:00 +03:00
|
|
|
|
|
|
|
dirs = []
|
|
|
|
for dll in re.findall(expr, data):
|
|
|
|
dir = os.path.dirname(dll)
|
|
|
|
if dir not in dirs:
|
|
|
|
dirs.append(dir)
|
|
|
|
return dirs
|
|
|
|
|
|
|
|
|
2016-03-30 18:19:23 +03:00
|
|
|
def _add_directory(path, subdir, where=None):
|
|
|
|
if subdir is None:
|
2013-12-11 13:13:06 +04:00
|
|
|
return
|
2016-03-30 18:19:23 +03:00
|
|
|
subdir = os.path.realpath(subdir)
|
|
|
|
if os.path.isdir(subdir) and subdir not in path:
|
2010-11-28 23:15:53 +03:00
|
|
|
if where is None:
|
2019-06-13 18:54:57 +03:00
|
|
|
_dbg("Appending path %s", subdir)
|
2016-03-30 18:19:23 +03:00
|
|
|
path.append(subdir)
|
2010-11-28 23:15:53 +03:00
|
|
|
else:
|
2019-06-13 18:54:57 +03:00
|
|
|
_dbg("Inserting path %s", subdir)
|
2016-03-30 18:19:23 +03:00
|
|
|
path.insert(where, subdir)
|
2017-05-26 14:44:26 +03:00
|
|
|
elif subdir in path and where is not None:
|
|
|
|
path.remove(subdir)
|
|
|
|
path.insert(where, subdir)
|
2010-11-28 23:15:53 +03:00
|
|
|
|
|
|
|
|
|
|
|
def _find_include_file(self, include):
|
|
|
|
for directory in self.compiler.include_dirs:
|
2019-06-13 18:54:57 +03:00
|
|
|
_dbg("Checking for include file %s in %s", (include, directory))
|
2010-11-28 23:15:53 +03:00
|
|
|
if os.path.isfile(os.path.join(directory, include)):
|
2019-06-13 18:54:57 +03:00
|
|
|
_dbg("Found %s", include)
|
2010-11-28 23:15:53 +03:00
|
|
|
return 1
|
|
|
|
return 0
|
|
|
|
|
|
|
|
|
|
|
|
def _find_library_file(self, library):
|
2016-11-07 15:35:23 +03:00
|
|
|
ret = self.compiler.find_library_file(self.compiler.library_dirs, library)
|
2016-03-30 19:16:10 +03:00
|
|
|
if ret:
|
2019-06-13 18:54:57 +03:00
|
|
|
_dbg("Found library %s at %s", (library, ret))
|
2016-03-30 19:16:10 +03:00
|
|
|
else:
|
2019-06-13 18:54:57 +03:00
|
|
|
_dbg("Couldn't find library %s in %s", (library, self.compiler.library_dirs))
|
2016-03-30 19:16:10 +03:00
|
|
|
return ret
|
2013-05-12 03:56:02 +04:00
|
|
|
|
2010-11-28 23:15:53 +03:00
|
|
|
|
2020-11-25 19:27:12 +03:00
|
|
|
def _find_include_dir(self, dirname, include):
|
|
|
|
for directory in self.compiler.include_dirs:
|
|
|
|
_dbg("Checking for include file %s in %s", (include, directory))
|
|
|
|
if os.path.isfile(os.path.join(directory, include)):
|
|
|
|
_dbg("Found %s in %s", (include, directory))
|
|
|
|
return True
|
|
|
|
subdir = os.path.join(directory, dirname)
|
|
|
|
_dbg("Checking for include file %s in %s", (include, subdir))
|
|
|
|
if os.path.isfile(os.path.join(subdir, include)):
|
|
|
|
_dbg("Found %s in %s", (include, subdir))
|
|
|
|
return subdir
|
|
|
|
|
|
|
|
|
2023-03-12 15:17:39 +03:00
|
|
|
def _cmd_exists(cmd: str) -> bool:
|
2023-02-10 00:11:50 +03:00
|
|
|
if "PATH" not in os.environ:
|
2023-03-12 15:17:39 +03:00
|
|
|
return False
|
2016-07-25 01:02:11 +03:00
|
|
|
return any(
|
2016-12-04 18:59:53 +03:00
|
|
|
os.access(os.path.join(path, cmd), os.X_OK)
|
2016-07-25 01:02:11 +03:00
|
|
|
for path in os.environ["PATH"].split(os.pathsep)
|
|
|
|
)
|
2010-11-28 23:20:53 +03:00
|
|
|
|
2017-12-04 15:35:05 +03:00
|
|
|
|
2016-07-25 01:02:11 +03:00
|
|
|
def _pkg_config(name):
|
2022-04-23 14:58:30 +03:00
|
|
|
command = os.environ.get("PKG_CONFIG", "pkg-config")
|
|
|
|
for keep_system in (True, False):
|
|
|
|
try:
|
|
|
|
command_libs = [command, "--libs-only-L", name]
|
|
|
|
command_cflags = [command, "--cflags-only-I", name]
|
2022-05-03 02:19:09 +03:00
|
|
|
stderr = None
|
2022-04-23 14:58:30 +03:00
|
|
|
if keep_system:
|
|
|
|
command_libs.append("--keep-system-libs")
|
|
|
|
command_cflags.append("--keep-system-cflags")
|
2022-05-03 02:19:09 +03:00
|
|
|
stderr = subprocess.DEVNULL
|
2022-04-23 14:58:30 +03:00
|
|
|
if not DEBUG:
|
|
|
|
command_libs.append("--silence-errors")
|
|
|
|
command_cflags.append("--silence-errors")
|
2023-01-14 21:09:43 +03:00
|
|
|
libs = re.split(
|
2023-01-28 11:27:51 +03:00
|
|
|
r"(^|\s+)-L",
|
2022-05-03 02:19:09 +03:00
|
|
|
subprocess.check_output(command_libs, stderr=stderr)
|
2022-04-23 14:58:30 +03:00
|
|
|
.decode("utf8")
|
2023-01-14 21:09:43 +03:00
|
|
|
.strip(),
|
2023-01-28 11:27:51 +03:00
|
|
|
)[::2][1:]
|
2023-01-14 21:09:43 +03:00
|
|
|
cflags = re.split(
|
2023-01-28 11:27:51 +03:00
|
|
|
r"(^|\s+)-I",
|
2023-03-30 22:14:35 +03:00
|
|
|
subprocess.check_output(command_cflags).decode("utf8").strip(),
|
2023-01-28 11:27:51 +03:00
|
|
|
)[::2][1:]
|
2022-04-23 14:58:30 +03:00
|
|
|
return libs, cflags
|
|
|
|
except Exception:
|
|
|
|
pass
|
2016-07-25 01:02:11 +03:00
|
|
|
|
2017-12-04 15:35:05 +03:00
|
|
|
|
2010-11-28 23:15:53 +03:00
|
|
|
class pil_build_ext(build_ext):
|
2013-05-31 02:04:34 +04:00
|
|
|
class feature:
|
2019-06-13 18:54:57 +03:00
|
|
|
features = [
|
|
|
|
"zlib",
|
|
|
|
"jpeg",
|
|
|
|
"tiff",
|
|
|
|
"freetype",
|
2020-11-25 17:01:16 +03:00
|
|
|
"raqm",
|
2019-06-13 18:54:57 +03:00
|
|
|
"lcms",
|
|
|
|
"webp",
|
|
|
|
"webpmux",
|
|
|
|
"jpeg2000",
|
|
|
|
"imagequant",
|
2019-09-19 19:57:59 +03:00
|
|
|
"xcb",
|
2019-06-13 18:54:57 +03:00
|
|
|
]
|
2016-03-30 18:20:27 +03:00
|
|
|
|
2019-06-13 18:54:57 +03:00
|
|
|
required = {"jpeg", "zlib"}
|
2021-01-02 14:47:08 +03:00
|
|
|
vendor = set()
|
2013-05-31 02:04:34 +04:00
|
|
|
|
2016-03-30 18:20:27 +03:00
|
|
|
def __init__(self):
|
|
|
|
for f in self.features:
|
|
|
|
setattr(self, f, None)
|
|
|
|
|
2013-05-31 02:08:04 +04:00
|
|
|
def require(self, feat):
|
|
|
|
return feat in self.required
|
2014-06-24 10:34:05 +04:00
|
|
|
|
2013-06-08 10:14:44 +04:00
|
|
|
def want(self, feat):
|
|
|
|
return getattr(self, feat) is None
|
|
|
|
|
2021-02-27 18:52:46 +03:00
|
|
|
def want_vendor(self, feat):
|
|
|
|
return feat in self.vendor
|
2020-11-25 17:01:16 +03:00
|
|
|
|
2013-05-31 02:04:34 +04:00
|
|
|
def __iter__(self):
|
2019-09-30 17:56:31 +03:00
|
|
|
yield from self.features
|
2013-05-31 02:04:34 +04:00
|
|
|
|
|
|
|
feature = feature()
|
|
|
|
|
2019-06-13 18:54:57 +03:00
|
|
|
user_options = (
|
|
|
|
build_ext.user_options
|
2020-07-16 12:43:29 +03:00
|
|
|
+ [(f"disable-{x}", None, f"Disable support for {x}") for x in feature]
|
|
|
|
+ [(f"enable-{x}", None, f"Enable support for {x}") for x in feature]
|
2020-11-25 17:01:16 +03:00
|
|
|
+ [
|
2021-01-02 14:51:45 +03:00
|
|
|
(f"vendor-{x}", None, f"Use vendored version of {x}")
|
2020-11-25 17:01:16 +03:00
|
|
|
for x in ("raqm", "fribidi")
|
|
|
|
]
|
2019-06-13 18:54:57 +03:00
|
|
|
+ [
|
|
|
|
("disable-platform-guessing", None, "Disable platform guessing on Linux"),
|
|
|
|
("debug", None, "Debug logging"),
|
|
|
|
]
|
|
|
|
+ [("add-imaging-libs=", None, "Add libs to _imaging build")]
|
|
|
|
)
|
2013-05-31 02:04:34 +04:00
|
|
|
|
|
|
|
def initialize_options(self):
|
2016-04-25 18:03:36 +03:00
|
|
|
self.disable_platform_guessing = None
|
2018-10-08 11:43:11 +03:00
|
|
|
self.add_imaging_libs = ""
|
2013-05-31 02:04:34 +04:00
|
|
|
build_ext.initialize_options(self)
|
|
|
|
for x in self.feature:
|
2020-07-16 12:43:29 +03:00
|
|
|
setattr(self, f"disable_{x}", None)
|
|
|
|
setattr(self, f"enable_{x}", None)
|
2020-11-25 17:01:16 +03:00
|
|
|
for x in ("raqm", "fribidi"):
|
2021-01-02 14:51:45 +03:00
|
|
|
setattr(self, f"vendor_{x}", None)
|
2013-05-31 02:04:34 +04:00
|
|
|
|
|
|
|
def finalize_options(self):
|
|
|
|
build_ext.finalize_options(self)
|
2016-03-30 19:16:10 +03:00
|
|
|
if self.debug:
|
|
|
|
global DEBUG
|
|
|
|
DEBUG = True
|
2019-10-02 18:11:35 +03:00
|
|
|
if not self.parallel:
|
|
|
|
# If --parallel (or -j) wasn't specified, we want to reproduce the same
|
|
|
|
# behavior as before, that is, auto-detect the number of jobs.
|
|
|
|
try:
|
|
|
|
self.parallel = int(
|
|
|
|
os.environ.get("MAX_CONCURRENCY", min(4, os.cpu_count()))
|
|
|
|
)
|
|
|
|
except TypeError:
|
|
|
|
self.parallel = None
|
2013-05-31 02:04:34 +04:00
|
|
|
for x in self.feature:
|
2020-07-16 12:43:29 +03:00
|
|
|
if getattr(self, f"disable_{x}"):
|
2013-05-31 02:04:34 +04:00
|
|
|
setattr(self.feature, x, False)
|
2015-09-22 23:07:31 +03:00
|
|
|
self.feature.required.discard(x)
|
2019-06-13 18:54:57 +03:00
|
|
|
_dbg("Disabling %s", x)
|
2020-07-16 12:43:29 +03:00
|
|
|
if getattr(self, f"enable_{x}"):
|
2022-12-22 00:51:35 +03:00
|
|
|
msg = f"Conflicting options: --enable-{x} and --disable-{x}"
|
|
|
|
raise ValueError(msg)
|
2020-11-25 17:01:16 +03:00
|
|
|
if x == "freetype":
|
|
|
|
_dbg("--disable-freetype implies --disable-raqm")
|
|
|
|
if getattr(self, "enable_raqm"):
|
2022-12-22 00:51:35 +03:00
|
|
|
msg = (
|
2020-11-25 17:01:16 +03:00
|
|
|
"Conflicting options: --enable-raqm and --disable-freetype"
|
|
|
|
)
|
2022-12-22 00:51:35 +03:00
|
|
|
raise ValueError(msg)
|
2020-11-25 17:01:16 +03:00
|
|
|
setattr(self, "disable_raqm", True)
|
2020-07-16 12:43:29 +03:00
|
|
|
if getattr(self, f"enable_{x}"):
|
2019-06-13 18:54:57 +03:00
|
|
|
_dbg("Requiring %s", x)
|
2015-09-22 23:07:31 +03:00
|
|
|
self.feature.required.add(x)
|
2020-11-25 17:01:16 +03:00
|
|
|
if x == "raqm":
|
|
|
|
_dbg("--enable-raqm implies --enable-freetype")
|
|
|
|
self.feature.required.add("freetype")
|
|
|
|
for x in ("raqm", "fribidi"):
|
2021-01-02 14:51:45 +03:00
|
|
|
if getattr(self, f"vendor_{x}"):
|
2020-11-25 19:29:43 +03:00
|
|
|
if getattr(self, "disable_raqm"):
|
2022-12-22 00:51:35 +03:00
|
|
|
msg = f"Conflicting options: --vendor-{x} and --disable-raqm"
|
|
|
|
raise ValueError(msg)
|
2021-01-02 14:51:45 +03:00
|
|
|
if x == "fribidi" and not getattr(self, "vendor_raqm"):
|
2022-12-22 00:51:35 +03:00
|
|
|
msg = f"Conflicting options: --vendor-{x} and not --vendor-raqm"
|
|
|
|
raise ValueError(msg)
|
2021-01-02 14:47:08 +03:00
|
|
|
_dbg("Using vendored version of %s", x)
|
|
|
|
self.feature.vendor.add(x)
|
2013-05-31 02:04:34 +04:00
|
|
|
|
2020-11-25 17:01:16 +03:00
|
|
|
def _update_extension(self, name, libraries, define_macros=None, sources=None):
|
2020-09-01 20:16:46 +03:00
|
|
|
for extension in self.extensions:
|
|
|
|
if extension.name == name:
|
|
|
|
extension.libraries += libraries
|
|
|
|
if define_macros is not None:
|
|
|
|
extension.define_macros += define_macros
|
2020-11-25 17:01:16 +03:00
|
|
|
if sources is not None:
|
|
|
|
extension.sources += sources
|
2021-01-09 18:41:13 +03:00
|
|
|
if FUZZING_BUILD:
|
|
|
|
extension.language = "c++"
|
|
|
|
extension.extra_link_args = ["--stdlib=libc++"]
|
2020-09-01 20:16:46 +03:00
|
|
|
break
|
|
|
|
|
|
|
|
def _remove_extension(self, name):
|
|
|
|
for extension in self.extensions:
|
|
|
|
if extension.name == name:
|
|
|
|
self.extensions.remove(extension)
|
|
|
|
break
|
|
|
|
|
2021-11-11 12:51:13 +03:00
|
|
|
def get_macos_sdk_path(self):
|
|
|
|
try:
|
|
|
|
sdk_path = (
|
|
|
|
subprocess.check_output(["xcrun", "--show-sdk-path"])
|
|
|
|
.strip()
|
|
|
|
.decode("latin1")
|
|
|
|
)
|
|
|
|
except Exception:
|
|
|
|
sdk_path = None
|
|
|
|
if (
|
|
|
|
not sdk_path
|
|
|
|
or sdk_path == "/Applications/Xcode.app/Contents/Developer"
|
|
|
|
"/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk"
|
|
|
|
):
|
|
|
|
commandlinetools_sdk_path = (
|
|
|
|
"/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk"
|
|
|
|
)
|
|
|
|
if os.path.exists(commandlinetools_sdk_path):
|
|
|
|
sdk_path = commandlinetools_sdk_path
|
|
|
|
return sdk_path
|
|
|
|
|
2010-11-28 23:15:53 +03:00
|
|
|
def build_extensions(self):
|
|
|
|
library_dirs = []
|
|
|
|
include_dirs = []
|
|
|
|
|
2016-07-25 01:02:11 +03:00
|
|
|
pkg_config = None
|
2019-06-30 23:52:58 +03:00
|
|
|
if _cmd_exists(os.environ.get("PKG_CONFIG", "pkg-config")):
|
2016-07-25 01:02:11 +03:00
|
|
|
pkg_config = _pkg_config
|
|
|
|
|
2013-01-09 15:48:06 +04:00
|
|
|
#
|
|
|
|
# add configured kits
|
2019-06-13 18:54:57 +03:00
|
|
|
for root_name, lib_name in dict(
|
|
|
|
JPEG_ROOT="libjpeg",
|
|
|
|
JPEG2K_ROOT="libopenjp2",
|
|
|
|
TIFF_ROOT=("libtiff-5", "libtiff-4"),
|
|
|
|
ZLIB_ROOT="zlib",
|
|
|
|
FREETYPE_ROOT="freetype2",
|
2020-11-25 22:33:33 +03:00
|
|
|
HARFBUZZ_ROOT="harfbuzz",
|
|
|
|
FRIBIDI_ROOT="fribidi",
|
2019-06-13 18:54:57 +03:00
|
|
|
LCMS_ROOT="lcms2",
|
|
|
|
IMAGEQUANT_ROOT="libimagequant",
|
|
|
|
).items():
|
2016-07-25 01:02:11 +03:00
|
|
|
root = globals()[root_name]
|
2018-10-04 11:32:10 +03:00
|
|
|
|
|
|
|
if root is None and root_name in os.environ:
|
|
|
|
prefix = os.environ[root_name]
|
2019-06-13 18:54:57 +03:00
|
|
|
root = (os.path.join(prefix, "lib"), os.path.join(prefix, "include"))
|
2018-10-04 11:32:10 +03:00
|
|
|
|
2016-07-25 01:02:11 +03:00
|
|
|
if root is None and pkg_config:
|
|
|
|
if isinstance(lib_name, tuple):
|
|
|
|
for lib_name2 in lib_name:
|
2020-07-16 12:43:29 +03:00
|
|
|
_dbg(f"Looking for `{lib_name2}` using pkg-config.")
|
2016-07-25 01:02:11 +03:00
|
|
|
root = pkg_config(lib_name2)
|
|
|
|
if root:
|
|
|
|
break
|
|
|
|
else:
|
2020-07-16 12:43:29 +03:00
|
|
|
_dbg(f"Looking for `{lib_name}` using pkg-config.")
|
2016-07-25 01:02:11 +03:00
|
|
|
root = pkg_config(lib_name)
|
2013-01-09 15:48:06 +04:00
|
|
|
|
2016-10-31 03:43:32 +03:00
|
|
|
if isinstance(root, tuple):
|
2013-01-09 15:48:06 +04:00
|
|
|
lib_root, include_root = root
|
|
|
|
else:
|
|
|
|
lib_root = include_root = root
|
2016-07-25 01:02:11 +03:00
|
|
|
|
2023-01-14 21:09:43 +03:00
|
|
|
if lib_root is not None:
|
|
|
|
for lib_dir in lib_root:
|
|
|
|
_add_directory(library_dirs, lib_dir)
|
|
|
|
if include_root is not None:
|
|
|
|
for include_dir in include_root:
|
|
|
|
_add_directory(include_dirs, include_dir)
|
2013-01-09 15:48:06 +04:00
|
|
|
|
2019-05-02 00:35:27 +03:00
|
|
|
# respect CFLAGS/CPPFLAGS/LDFLAGS
|
|
|
|
for k in ("CFLAGS", "CPPFLAGS", "LDFLAGS"):
|
2013-12-11 13:04:24 +04:00
|
|
|
if k in os.environ:
|
2019-06-13 18:54:57 +03:00
|
|
|
for match in re.finditer(r"-I([^\s]+)", os.environ[k]):
|
2013-12-11 13:04:24 +04:00
|
|
|
_add_directory(include_dirs, match.group(1))
|
2019-06-13 18:54:57 +03:00
|
|
|
for match in re.finditer(r"-L([^\s]+)", os.environ[k]):
|
2013-12-11 13:04:24 +04:00
|
|
|
_add_directory(library_dirs, match.group(1))
|
|
|
|
|
|
|
|
# include, rpath, if set as environment variables:
|
2019-06-13 18:54:57 +03:00
|
|
|
for k in ("C_INCLUDE_PATH", "CPATH", "INCLUDE"):
|
2013-12-11 13:04:24 +04:00
|
|
|
if k in os.environ:
|
|
|
|
for d in os.environ[k].split(os.path.pathsep):
|
|
|
|
_add_directory(include_dirs, d)
|
|
|
|
|
2019-06-13 18:54:57 +03:00
|
|
|
for k in ("LD_RUN_PATH", "LIBRARY_PATH", "LIB"):
|
2013-12-11 13:04:24 +04:00
|
|
|
if k in os.environ:
|
|
|
|
for d in os.environ[k].split(os.path.pathsep):
|
|
|
|
_add_directory(library_dirs, d)
|
|
|
|
|
2020-07-24 12:58:17 +03:00
|
|
|
_add_directory(library_dirs, os.path.join(sys.prefix, "lib"))
|
|
|
|
_add_directory(include_dirs, os.path.join(sys.prefix, "include"))
|
2013-12-11 13:04:24 +04:00
|
|
|
|
2010-11-28 23:15:53 +03:00
|
|
|
#
|
|
|
|
# add platform directories
|
|
|
|
|
2016-05-01 12:57:50 +03:00
|
|
|
if self.disable_platform_guessing:
|
|
|
|
pass
|
2016-07-04 02:50:05 +03:00
|
|
|
|
2016-05-01 12:57:50 +03:00
|
|
|
elif sys.platform == "cygwin":
|
2010-11-28 23:15:53 +03:00
|
|
|
# pythonX.Y.dll.a is in the /usr/lib/pythonX.Y/config directory
|
2019-06-13 18:54:57 +03:00
|
|
|
_add_directory(
|
|
|
|
library_dirs,
|
2019-08-18 12:32:23 +03:00
|
|
|
os.path.join(
|
|
|
|
"/usr/lib", "python{}.{}".format(*sys.version_info), "config"
|
|
|
|
),
|
2019-06-13 18:54:57 +03:00
|
|
|
)
|
2010-11-28 23:15:53 +03:00
|
|
|
|
|
|
|
elif sys.platform == "darwin":
|
|
|
|
# attempt to make sure we pick freetype2 over other versions
|
|
|
|
_add_directory(include_dirs, "/sw/include/freetype2")
|
|
|
|
_add_directory(include_dirs, "/sw/lib/freetype2/include")
|
|
|
|
# fink installation directories
|
|
|
|
_add_directory(library_dirs, "/sw/lib")
|
|
|
|
_add_directory(include_dirs, "/sw/include")
|
|
|
|
# darwin ports installation directories
|
|
|
|
_add_directory(library_dirs, "/opt/local/lib")
|
|
|
|
_add_directory(include_dirs, "/opt/local/include")
|
2014-05-10 19:11:04 +04:00
|
|
|
|
|
|
|
# if Homebrew is installed, use its lib and include directories
|
2013-10-02 19:36:47 +04:00
|
|
|
try:
|
2019-06-13 18:54:57 +03:00
|
|
|
prefix = (
|
|
|
|
subprocess.check_output(["brew", "--prefix"])
|
|
|
|
.strip()
|
|
|
|
.decode("latin1")
|
|
|
|
)
|
2017-12-04 15:35:05 +03:00
|
|
|
except Exception:
|
2014-05-10 19:11:04 +04:00
|
|
|
# Homebrew not installed
|
|
|
|
prefix = None
|
|
|
|
|
|
|
|
ft_prefix = None
|
|
|
|
|
|
|
|
if prefix:
|
|
|
|
# add Homebrew's include and lib directories
|
2019-06-13 18:54:57 +03:00
|
|
|
_add_directory(library_dirs, os.path.join(prefix, "lib"))
|
|
|
|
_add_directory(include_dirs, os.path.join(prefix, "include"))
|
2020-09-01 20:16:46 +03:00
|
|
|
_add_directory(
|
|
|
|
include_dirs, os.path.join(prefix, "opt", "zlib", "include")
|
|
|
|
)
|
2019-06-13 18:54:57 +03:00
|
|
|
ft_prefix = os.path.join(prefix, "opt", "freetype")
|
2014-05-10 19:11:04 +04:00
|
|
|
|
|
|
|
if ft_prefix and os.path.isdir(ft_prefix):
|
|
|
|
# freetype might not be linked into Homebrew's prefix
|
2019-06-13 18:54:57 +03:00
|
|
|
_add_directory(library_dirs, os.path.join(ft_prefix, "lib"))
|
|
|
|
_add_directory(include_dirs, os.path.join(ft_prefix, "include"))
|
2014-05-10 19:11:04 +04:00
|
|
|
else:
|
2014-06-24 10:34:05 +04:00
|
|
|
# fall back to freetype from XQuartz if
|
|
|
|
# Homebrew's freetype is missing
|
2014-05-10 19:11:04 +04:00
|
|
|
_add_directory(library_dirs, "/usr/X11/lib")
|
|
|
|
_add_directory(include_dirs, "/usr/X11/include")
|
2013-12-11 12:56:40 +04:00
|
|
|
|
2021-11-11 12:51:13 +03:00
|
|
|
sdk_path = self.get_macos_sdk_path()
|
2020-10-13 17:02:04 +03:00
|
|
|
if sdk_path:
|
|
|
|
_add_directory(library_dirs, os.path.join(sdk_path, "usr", "lib"))
|
|
|
|
_add_directory(include_dirs, os.path.join(sdk_path, "usr", "include"))
|
2019-06-13 18:54:57 +03:00
|
|
|
elif (
|
|
|
|
sys.platform.startswith("linux")
|
|
|
|
or sys.platform.startswith("gnu")
|
|
|
|
or sys.platform.startswith("freebsd")
|
|
|
|
):
|
2018-07-09 10:33:00 +03:00
|
|
|
for dirname in _find_library_dirs_ldconfig():
|
|
|
|
_add_directory(library_dirs, dirname)
|
2023-01-01 21:32:21 +03:00
|
|
|
if sys.platform.startswith("linux") and os.environ.get("ANDROID_ROOT"):
|
2017-08-09 15:22:58 +03:00
|
|
|
# termux support for android.
|
|
|
|
# system libraries (zlib) are installed in /system/lib
|
|
|
|
# headers are at $PREFIX/include
|
|
|
|
# user libs are at $PREFIX/lib
|
2018-12-27 14:11:24 +03:00
|
|
|
_add_directory(
|
2021-10-24 14:38:13 +03:00
|
|
|
library_dirs,
|
|
|
|
os.path.join(
|
|
|
|
os.environ["ANDROID_ROOT"],
|
2021-10-24 14:39:07 +03:00
|
|
|
"lib" if struct.calcsize("l") == 4 else "lib64",
|
|
|
|
),
|
2018-12-27 14:11:24 +03:00
|
|
|
)
|
2015-12-27 22:43:27 +03:00
|
|
|
|
2013-11-14 16:10:19 +04:00
|
|
|
elif sys.platform.startswith("netbsd"):
|
2015-07-28 12:59:52 +03:00
|
|
|
_add_directory(library_dirs, "/usr/pkg/lib")
|
|
|
|
_add_directory(include_dirs, "/usr/pkg/include")
|
2013-11-14 16:10:19 +04:00
|
|
|
|
2015-07-27 19:17:49 +03:00
|
|
|
elif sys.platform.startswith("sunos5"):
|
2016-03-15 14:16:22 +03:00
|
|
|
_add_directory(library_dirs, "/opt/local/lib")
|
|
|
|
_add_directory(include_dirs, "/opt/local/include")
|
2015-09-11 12:28:19 +03:00
|
|
|
|
2010-11-28 23:15:53 +03:00
|
|
|
# FIXME: check /opt/stuff directories here?
|
|
|
|
|
|
|
|
# standard locations
|
2016-04-25 18:03:36 +03:00
|
|
|
if not self.disable_platform_guessing:
|
|
|
|
_add_directory(library_dirs, "/usr/local/lib")
|
|
|
|
_add_directory(include_dirs, "/usr/local/include")
|
2010-11-28 23:15:53 +03:00
|
|
|
|
2016-04-25 18:03:36 +03:00
|
|
|
_add_directory(library_dirs, "/usr/lib")
|
|
|
|
_add_directory(include_dirs, "/usr/include")
|
2016-05-30 16:28:08 +03:00
|
|
|
# alpine, at least
|
|
|
|
_add_directory(library_dirs, "/lib")
|
2010-11-28 23:15:53 +03:00
|
|
|
|
2014-03-14 18:35:09 +04:00
|
|
|
if sys.platform == "win32":
|
2019-04-27 03:42:53 +03:00
|
|
|
# on Windows, look for the OpenJPEG libraries in the location that
|
|
|
|
# the official installer puts them
|
2019-06-13 18:54:57 +03:00
|
|
|
program_files = os.environ.get("ProgramFiles", "")
|
2014-05-27 15:43:54 +04:00
|
|
|
best_version = (0, 0)
|
|
|
|
best_path = None
|
|
|
|
for name in os.listdir(program_files):
|
2019-06-13 18:54:57 +03:00
|
|
|
if name.startswith("OpenJPEG "):
|
|
|
|
version = tuple(int(x) for x in name[9:].strip().split("."))
|
2014-05-27 15:43:54 +04:00
|
|
|
if version > best_version:
|
|
|
|
best_version = version
|
|
|
|
best_path = os.path.join(program_files, name)
|
|
|
|
|
|
|
|
if best_path:
|
2019-06-13 18:54:57 +03:00
|
|
|
_dbg("Adding %s to search list", best_path)
|
|
|
|
_add_directory(library_dirs, os.path.join(best_path, "lib"))
|
|
|
|
_add_directory(include_dirs, os.path.join(best_path, "include"))
|
2014-03-14 18:35:09 +04:00
|
|
|
|
2010-11-28 23:15:53 +03:00
|
|
|
#
|
|
|
|
# insert new dirs *before* default libs, to avoid conflicts
|
|
|
|
# between Python PYD stub libs and real libraries
|
|
|
|
|
|
|
|
self.compiler.library_dirs = library_dirs + self.compiler.library_dirs
|
|
|
|
self.compiler.include_dirs = include_dirs + self.compiler.include_dirs
|
|
|
|
|
|
|
|
#
|
|
|
|
# look for available libraries
|
|
|
|
|
2013-05-31 02:04:34 +04:00
|
|
|
feature = self.feature
|
|
|
|
|
2019-06-13 18:54:57 +03:00
|
|
|
if feature.want("zlib"):
|
|
|
|
_dbg("Looking for zlib")
|
2013-05-31 02:04:34 +04:00
|
|
|
if _find_include_file(self, "zlib.h"):
|
|
|
|
if _find_library_file(self, "z"):
|
|
|
|
feature.zlib = "z"
|
2019-06-13 18:54:57 +03:00
|
|
|
elif sys.platform == "win32" and _find_library_file(self, "zlib"):
|
2013-05-31 02:04:34 +04:00
|
|
|
feature.zlib = "zlib" # alternative name
|
|
|
|
|
2019-06-13 18:54:57 +03:00
|
|
|
if feature.want("jpeg"):
|
|
|
|
_dbg("Looking for jpeg")
|
2013-05-31 02:04:34 +04:00
|
|
|
if _find_include_file(self, "jpeglib.h"):
|
|
|
|
if _find_library_file(self, "jpeg"):
|
|
|
|
feature.jpeg = "jpeg"
|
2019-06-13 18:54:57 +03:00
|
|
|
elif sys.platform == "win32" and _find_library_file(self, "libjpeg"):
|
2013-05-31 02:04:34 +04:00
|
|
|
feature.jpeg = "libjpeg" # alternative name
|
|
|
|
|
2014-05-31 02:47:27 +04:00
|
|
|
feature.openjpeg_version = None
|
2019-06-13 18:54:57 +03:00
|
|
|
if feature.want("jpeg2000"):
|
|
|
|
_dbg("Looking for jpeg2000")
|
2014-05-27 15:43:54 +04:00
|
|
|
best_version = None
|
|
|
|
best_path = None
|
2014-06-24 10:34:05 +04:00
|
|
|
|
2014-05-27 15:43:54 +04:00
|
|
|
# Find the best version
|
|
|
|
for directory in self.compiler.include_dirs:
|
2019-06-13 18:54:57 +03:00
|
|
|
_dbg("Checking for openjpeg-#.# in %s", directory)
|
2014-06-29 03:15:06 +04:00
|
|
|
try:
|
|
|
|
listdir = os.listdir(directory)
|
2014-08-28 15:44:19 +04:00
|
|
|
except Exception:
|
2020-04-07 09:58:21 +03:00
|
|
|
# OSError, FileNotFoundError
|
2014-06-29 03:15:06 +04:00
|
|
|
continue
|
|
|
|
for name in listdir:
|
2019-06-13 18:54:57 +03:00
|
|
|
if name.startswith("openjpeg-") and os.path.isfile(
|
|
|
|
os.path.join(directory, name, "openjpeg.h")
|
|
|
|
):
|
|
|
|
_dbg("Found openjpeg.h in %s/%s", (directory, name))
|
|
|
|
version = tuple(int(x) for x in name[9:].split("."))
|
2014-05-27 15:43:54 +04:00
|
|
|
if best_version is None or version > best_version:
|
|
|
|
best_version = version
|
|
|
|
best_path = os.path.join(directory, name)
|
2019-06-13 18:54:57 +03:00
|
|
|
_dbg(
|
|
|
|
"Best openjpeg version %s so far in %s",
|
|
|
|
(best_version, best_path),
|
|
|
|
)
|
2014-05-27 15:43:54 +04:00
|
|
|
|
2019-06-13 18:54:57 +03:00
|
|
|
if best_version and _find_library_file(self, "openjp2"):
|
2014-05-27 15:43:54 +04:00
|
|
|
# Add the directory to the include path so we can include
|
|
|
|
# <openjpeg.h> rather than having to cope with the versioned
|
|
|
|
# include path
|
|
|
|
_add_directory(self.compiler.include_dirs, best_path, 0)
|
2019-06-13 18:54:57 +03:00
|
|
|
feature.jpeg2000 = "openjp2"
|
|
|
|
feature.openjpeg_version = ".".join(str(x) for x in best_version)
|
2014-06-24 10:34:05 +04:00
|
|
|
|
2019-06-13 18:54:57 +03:00
|
|
|
if feature.want("imagequant"):
|
|
|
|
_dbg("Looking for imagequant")
|
|
|
|
if _find_include_file(self, "libimagequant.h"):
|
2016-05-05 22:36:45 +03:00
|
|
|
if _find_library_file(self, "imagequant"):
|
|
|
|
feature.imagequant = "imagequant"
|
|
|
|
elif _find_library_file(self, "libimagequant"):
|
|
|
|
feature.imagequant = "libimagequant"
|
|
|
|
|
2019-06-13 18:54:57 +03:00
|
|
|
if feature.want("tiff"):
|
|
|
|
_dbg("Looking for tiff")
|
|
|
|
if _find_include_file(self, "tiff.h"):
|
2016-03-30 19:16:10 +03:00
|
|
|
if _find_library_file(self, "tiff"):
|
|
|
|
feature.tiff = "tiff"
|
2019-06-13 18:54:57 +03:00
|
|
|
if sys.platform in ["win32", "darwin"] and _find_library_file(
|
|
|
|
self, "libtiff"
|
|
|
|
):
|
2016-03-30 19:16:10 +03:00
|
|
|
feature.tiff = "libtiff"
|
2013-05-31 02:04:34 +04:00
|
|
|
|
2019-06-13 18:54:57 +03:00
|
|
|
if feature.want("freetype"):
|
|
|
|
_dbg("Looking for freetype")
|
2013-05-31 02:04:34 +04:00
|
|
|
if _find_library_file(self, "freetype"):
|
|
|
|
# look for freetype2 include files
|
|
|
|
freetype_version = 0
|
2016-03-30 18:19:23 +03:00
|
|
|
for subdir in self.compiler.include_dirs:
|
2019-06-13 18:54:57 +03:00
|
|
|
_dbg("Checking for include file %s in %s", ("ft2build.h", subdir))
|
2016-03-30 18:19:23 +03:00
|
|
|
if os.path.isfile(os.path.join(subdir, "ft2build.h")):
|
2019-06-13 18:54:57 +03:00
|
|
|
_dbg("Found %s in %s", ("ft2build.h", subdir))
|
2013-05-31 02:04:34 +04:00
|
|
|
freetype_version = 21
|
2016-03-30 18:19:23 +03:00
|
|
|
subdir = os.path.join(subdir, "freetype2")
|
2013-05-31 02:04:34 +04:00
|
|
|
break
|
2016-03-30 18:19:23 +03:00
|
|
|
subdir = os.path.join(subdir, "freetype2")
|
2019-06-13 18:54:57 +03:00
|
|
|
_dbg("Checking for include file %s in %s", ("ft2build.h", subdir))
|
2016-03-30 18:19:23 +03:00
|
|
|
if os.path.isfile(os.path.join(subdir, "ft2build.h")):
|
2019-06-13 18:54:57 +03:00
|
|
|
_dbg("Found %s in %s", ("ft2build.h", subdir))
|
2013-05-31 02:04:34 +04:00
|
|
|
freetype_version = 21
|
|
|
|
break
|
|
|
|
if freetype_version:
|
|
|
|
feature.freetype = "freetype"
|
2016-03-30 18:19:23 +03:00
|
|
|
if subdir:
|
|
|
|
_add_directory(self.compiler.include_dirs, subdir, 0)
|
2013-05-31 02:04:34 +04:00
|
|
|
|
2020-11-25 19:27:12 +03:00
|
|
|
if feature.freetype and feature.want("raqm"):
|
2021-02-27 18:52:46 +03:00
|
|
|
if not feature.want_vendor("raqm"): # want system Raqm
|
2020-11-25 17:01:16 +03:00
|
|
|
_dbg("Looking for Raqm")
|
|
|
|
if _find_include_file(self, "raqm.h"):
|
|
|
|
if _find_library_file(self, "raqm"):
|
2020-11-25 19:27:12 +03:00
|
|
|
feature.raqm = "raqm"
|
2020-11-25 17:01:16 +03:00
|
|
|
elif _find_library_file(self, "libraqm"):
|
2020-11-25 19:27:12 +03:00
|
|
|
feature.raqm = "libraqm"
|
2021-02-27 18:52:46 +03:00
|
|
|
else: # want to build Raqm from src/thirdparty
|
2020-11-25 17:01:16 +03:00
|
|
|
_dbg("Looking for HarfBuzz")
|
2020-11-25 19:27:12 +03:00
|
|
|
feature.harfbuzz = None
|
|
|
|
hb_dir = _find_include_dir(self, "harfbuzz", "hb.h")
|
|
|
|
if hb_dir:
|
|
|
|
if isinstance(hb_dir, str):
|
|
|
|
_add_directory(self.compiler.include_dirs, hb_dir, 0)
|
2020-11-25 17:01:16 +03:00
|
|
|
if _find_library_file(self, "harfbuzz"):
|
|
|
|
feature.harfbuzz = "harfbuzz"
|
|
|
|
if feature.harfbuzz:
|
2021-02-27 18:52:46 +03:00
|
|
|
if not feature.want_vendor("fribidi"): # want system FriBiDi
|
2020-11-25 17:01:16 +03:00
|
|
|
_dbg("Looking for FriBiDi")
|
2020-11-25 19:27:12 +03:00
|
|
|
feature.fribidi = None
|
|
|
|
fribidi_dir = _find_include_dir(self, "fribidi", "fribidi.h")
|
|
|
|
if fribidi_dir:
|
|
|
|
if isinstance(fribidi_dir, str):
|
|
|
|
_add_directory(
|
|
|
|
self.compiler.include_dirs, fribidi_dir, 0
|
|
|
|
)
|
2020-11-25 17:01:16 +03:00
|
|
|
if _find_library_file(self, "fribidi"):
|
2020-11-25 19:27:12 +03:00
|
|
|
feature.fribidi = "fribidi"
|
|
|
|
feature.raqm = True
|
2021-02-27 18:52:46 +03:00
|
|
|
else: # want to build FriBiDi shim from src/thirdparty
|
2020-11-25 17:01:16 +03:00
|
|
|
feature.raqm = True
|
2020-11-25 14:21:42 +03:00
|
|
|
|
2019-06-13 18:54:57 +03:00
|
|
|
if feature.want("lcms"):
|
|
|
|
_dbg("Looking for lcms")
|
2013-10-02 10:05:56 +04:00
|
|
|
if _find_include_file(self, "lcms2.h"):
|
|
|
|
if _find_library_file(self, "lcms2"):
|
2014-08-23 03:14:19 +04:00
|
|
|
feature.lcms = "lcms2"
|
|
|
|
elif _find_library_file(self, "lcms2_static"):
|
2015-07-08 08:32:50 +03:00
|
|
|
# alternate Windows name.
|
2014-08-23 03:14:19 +04:00
|
|
|
feature.lcms = "lcms2_static"
|
2010-11-28 23:15:53 +03:00
|
|
|
|
2019-06-13 18:54:57 +03:00
|
|
|
if feature.want("webp"):
|
|
|
|
_dbg("Looking for webp")
|
|
|
|
if _find_include_file(self, "webp/encode.h") and _find_include_file(
|
|
|
|
self, "webp/decode.h"
|
|
|
|
):
|
2014-06-24 10:34:05 +04:00
|
|
|
# In Google's precompiled zip it is call "libwebp":
|
|
|
|
if _find_library_file(self, "webp"):
|
2013-05-31 02:04:34 +04:00
|
|
|
feature.webp = "webp"
|
2014-08-23 04:04:26 +04:00
|
|
|
elif _find_library_file(self, "libwebp"):
|
|
|
|
feature.webp = "libwebp"
|
2013-03-12 18:30:59 +04:00
|
|
|
|
2019-06-13 18:54:57 +03:00
|
|
|
if feature.want("webpmux"):
|
|
|
|
_dbg("Looking for webpmux")
|
|
|
|
if _find_include_file(self, "webp/mux.h") and _find_include_file(
|
|
|
|
self, "webp/demux.h"
|
|
|
|
):
|
|
|
|
if _find_library_file(self, "webpmux") and _find_library_file(
|
|
|
|
self, "webpdemux"
|
|
|
|
):
|
2013-07-05 00:57:05 +04:00
|
|
|
feature.webpmux = "webpmux"
|
2019-06-13 18:54:57 +03:00
|
|
|
if _find_library_file(self, "libwebpmux") and _find_library_file(
|
|
|
|
self, "libwebpdemux"
|
|
|
|
):
|
2014-08-23 04:04:26 +04:00
|
|
|
feature.webpmux = "libwebpmux"
|
2013-07-05 00:57:05 +04:00
|
|
|
|
2019-09-19 19:57:59 +03:00
|
|
|
if feature.want("xcb"):
|
|
|
|
_dbg("Looking for xcb")
|
|
|
|
if _find_include_file(self, "xcb/xcb.h"):
|
|
|
|
if _find_library_file(self, "xcb"):
|
|
|
|
feature.xcb = "xcb"
|
|
|
|
|
2013-05-31 02:08:04 +04:00
|
|
|
for f in feature:
|
|
|
|
if not getattr(feature, f) and feature.require(f):
|
2019-06-13 18:54:57 +03:00
|
|
|
if f in ("jpeg", "zlib"):
|
2016-11-11 20:12:07 +03:00
|
|
|
raise RequiredDependencyException(f)
|
2016-10-19 21:07:08 +03:00
|
|
|
raise DependencyException(f)
|
2016-12-04 18:59:53 +03:00
|
|
|
|
2010-11-28 23:15:53 +03:00
|
|
|
#
|
|
|
|
# core library
|
|
|
|
|
2018-10-08 11:43:11 +03:00
|
|
|
libs = self.add_imaging_libs.split()
|
2010-11-28 23:15:53 +03:00
|
|
|
defs = []
|
|
|
|
if feature.jpeg:
|
|
|
|
libs.append(feature.jpeg)
|
|
|
|
defs.append(("HAVE_LIBJPEG", None))
|
2014-03-12 20:25:59 +04:00
|
|
|
if feature.jpeg2000:
|
|
|
|
libs.append(feature.jpeg2000)
|
|
|
|
defs.append(("HAVE_OPENJPEG", None))
|
2020-05-24 02:07:42 +03:00
|
|
|
if sys.platform == "win32" and not PLATFORM_MINGW:
|
2014-03-29 07:29:58 +04:00
|
|
|
defs.append(("OPJ_STATIC", None))
|
2010-11-28 23:15:53 +03:00
|
|
|
if feature.zlib:
|
|
|
|
libs.append(feature.zlib)
|
|
|
|
defs.append(("HAVE_LIBZ", None))
|
2016-05-05 22:36:45 +03:00
|
|
|
if feature.imagequant:
|
|
|
|
libs.append(feature.imagequant)
|
|
|
|
defs.append(("HAVE_LIBIMAGEQUANT", None))
|
2013-03-09 07:51:59 +04:00
|
|
|
if feature.tiff:
|
|
|
|
libs.append(feature.tiff)
|
|
|
|
defs.append(("HAVE_LIBTIFF", None))
|
2020-08-30 05:32:49 +03:00
|
|
|
if sys.platform == "win32":
|
2021-03-26 04:54:11 +03:00
|
|
|
# This define needs to be defined if-and-only-if it was defined
|
|
|
|
# when compiling LibTIFF. LibTIFF doesn't expose it in `tiffconf.h`,
|
|
|
|
# so we have to guess; by default it is defined in all Windows builds.
|
|
|
|
# See #4237, #5243, #5359 for more information.
|
2020-08-30 05:30:47 +03:00
|
|
|
defs.append(("USE_WIN32_FILEIO", None))
|
2019-09-19 19:57:59 +03:00
|
|
|
if feature.xcb:
|
|
|
|
libs.append(feature.xcb)
|
|
|
|
defs.append(("HAVE_XCB", None))
|
2010-11-28 23:15:53 +03:00
|
|
|
if sys.platform == "win32":
|
|
|
|
libs.extend(["kernel32", "user32", "gdi32"])
|
2019-09-30 17:56:31 +03:00
|
|
|
if struct.unpack("h", b"\0\1")[0] == 1:
|
2010-11-28 23:15:53 +03:00
|
|
|
defs.append(("WORDS_BIGENDIAN", None))
|
|
|
|
|
2020-05-20 01:35:32 +03:00
|
|
|
if (
|
2020-05-20 13:31:14 +03:00
|
|
|
sys.platform == "win32"
|
|
|
|
and sys.version_info < (3, 9)
|
|
|
|
and not (PLATFORM_PYPY or PLATFORM_MINGW)
|
2020-05-20 01:35:32 +03:00
|
|
|
):
|
2020-07-16 12:43:29 +03:00
|
|
|
defs.append(("PILLOW_VERSION", f'"\\"{PILLOW_VERSION}\\""'))
|
2017-06-21 15:36:56 +03:00
|
|
|
else:
|
2020-07-16 12:43:29 +03:00
|
|
|
defs.append(("PILLOW_VERSION", f'"{PILLOW_VERSION}"'))
|
2017-04-19 17:39:39 +03:00
|
|
|
|
2020-09-01 20:16:46 +03:00
|
|
|
self._update_extension("PIL._imaging", libs, defs)
|
2010-11-28 23:15:53 +03:00
|
|
|
|
|
|
|
#
|
|
|
|
# additional libraries
|
|
|
|
|
|
|
|
if feature.freetype:
|
2020-11-25 17:01:16 +03:00
|
|
|
srcs = []
|
2016-01-27 08:09:26 +03:00
|
|
|
libs = ["freetype"]
|
|
|
|
defs = []
|
2020-11-25 17:01:16 +03:00
|
|
|
if feature.raqm:
|
2021-02-27 18:52:46 +03:00
|
|
|
if not feature.want_vendor("raqm"): # using system Raqm
|
2020-11-25 17:01:16 +03:00
|
|
|
defs.append(("HAVE_RAQM", None))
|
|
|
|
defs.append(("HAVE_RAQM_SYSTEM", None))
|
|
|
|
libs.append(feature.raqm)
|
2021-02-27 18:52:46 +03:00
|
|
|
else: # building Raqm from src/thirdparty
|
2020-11-25 17:01:16 +03:00
|
|
|
defs.append(("HAVE_RAQM", None))
|
|
|
|
srcs.append("src/thirdparty/raqm/raqm.c")
|
|
|
|
libs.append(feature.harfbuzz)
|
2021-02-27 18:52:46 +03:00
|
|
|
if not feature.want_vendor("fribidi"): # using system FriBiDi
|
2020-11-25 17:01:16 +03:00
|
|
|
defs.append(("HAVE_FRIBIDI_SYSTEM", None))
|
|
|
|
libs.append(feature.fribidi)
|
2021-02-27 18:52:46 +03:00
|
|
|
else: # building FriBiDi shim from src/thirdparty
|
2020-11-25 17:01:16 +03:00
|
|
|
srcs.append("src/thirdparty/fribidi-shim/fribidi.c")
|
|
|
|
self._update_extension("PIL._imagingft", libs, defs, srcs)
|
|
|
|
|
2020-09-01 20:16:46 +03:00
|
|
|
else:
|
|
|
|
self._remove_extension("PIL._imagingft")
|
2010-11-28 23:15:53 +03:00
|
|
|
|
2016-03-30 19:16:10 +03:00
|
|
|
if feature.lcms:
|
2010-11-28 23:15:53 +03:00
|
|
|
extra = []
|
|
|
|
if sys.platform == "win32":
|
|
|
|
extra.extend(["user32", "gdi32"])
|
2020-09-01 20:16:46 +03:00
|
|
|
self._update_extension("PIL._imagingcms", [feature.lcms] + extra)
|
|
|
|
else:
|
|
|
|
self._remove_extension("PIL._imagingcms")
|
2010-11-28 23:15:53 +03:00
|
|
|
|
2016-03-30 19:16:10 +03:00
|
|
|
if feature.webp:
|
2014-08-23 04:04:26 +04:00
|
|
|
libs = [feature.webp]
|
2013-07-05 00:57:05 +04:00
|
|
|
defs = []
|
|
|
|
|
|
|
|
if feature.webpmux:
|
|
|
|
defs.append(("HAVE_WEBPMUX", None))
|
2014-08-23 04:04:26 +04:00
|
|
|
libs.append(feature.webpmux)
|
2019-06-13 18:54:57 +03:00
|
|
|
libs.append(feature.webpmux.replace("pmux", "pdemux"))
|
2013-07-05 00:57:05 +04:00
|
|
|
|
2020-09-01 20:16:46 +03:00
|
|
|
self._update_extension("PIL._webp", libs, defs)
|
|
|
|
else:
|
|
|
|
self._remove_extension("PIL._webp")
|
2019-06-13 18:54:57 +03:00
|
|
|
|
2021-11-04 04:26:55 +03:00
|
|
|
tk_libs = ["psapi"] if sys.platform in ("win32", "cygwin") else []
|
2020-10-14 11:59:34 +03:00
|
|
|
self._update_extension("PIL._imagingtk", tk_libs)
|
2010-11-28 23:15:53 +03:00
|
|
|
|
|
|
|
build_ext.build_extensions(self)
|
|
|
|
|
|
|
|
#
|
2017-01-19 11:45:49 +03:00
|
|
|
# sanity checks
|
2010-11-28 23:15:53 +03:00
|
|
|
|
2017-01-19 11:45:49 +03:00
|
|
|
self.summary_report(feature)
|
2010-11-28 23:15:53 +03:00
|
|
|
|
2017-01-19 11:45:49 +03:00
|
|
|
def summary_report(self, feature):
|
2012-06-12 09:13:40 +04:00
|
|
|
print("-" * 68)
|
2013-05-12 04:12:27 +04:00
|
|
|
print("PIL SETUP SUMMARY")
|
2012-06-12 09:13:40 +04:00
|
|
|
print("-" * 68)
|
2020-07-16 12:43:29 +03:00
|
|
|
print(f"version Pillow {PILLOW_VERSION}")
|
2012-06-12 09:13:40 +04:00
|
|
|
v = sys.version.split("[")
|
2020-07-16 12:43:29 +03:00
|
|
|
print(f"platform {sys.platform} {v[0].strip()}")
|
2010-11-28 23:15:53 +03:00
|
|
|
for v in v[1:]:
|
2020-07-16 12:43:29 +03:00
|
|
|
print(f" [{v.strip()}")
|
2012-06-12 09:13:40 +04:00
|
|
|
print("-" * 68)
|
2010-11-28 23:15:53 +03:00
|
|
|
|
2021-02-27 18:52:46 +03:00
|
|
|
raqm_extra_info = ""
|
|
|
|
if feature.want_vendor("raqm"):
|
|
|
|
raqm_extra_info += "bundled"
|
|
|
|
if feature.want_vendor("fribidi"):
|
|
|
|
raqm_extra_info += ", FriBiDi shim"
|
|
|
|
|
2010-11-28 23:15:53 +03:00
|
|
|
options = [
|
|
|
|
(feature.jpeg, "JPEG"),
|
2019-06-13 18:54:57 +03:00
|
|
|
(feature.jpeg2000, "OPENJPEG (JPEG2000)", feature.openjpeg_version),
|
2010-11-28 23:15:53 +03:00
|
|
|
(feature.zlib, "ZLIB (PNG/ZIP)"),
|
2016-05-05 22:36:45 +03:00
|
|
|
(feature.imagequant, "LIBIMAGEQUANT"),
|
2013-12-30 07:10:49 +04:00
|
|
|
(feature.tiff, "LIBTIFF"),
|
2010-11-28 23:15:53 +03:00
|
|
|
(feature.freetype, "FREETYPE2"),
|
2021-02-27 18:52:46 +03:00
|
|
|
(feature.raqm, "RAQM (Text shaping)", raqm_extra_info),
|
2013-10-02 10:05:56 +04:00
|
|
|
(feature.lcms, "LITTLECMS2"),
|
2013-07-05 00:57:05 +04:00
|
|
|
(feature.webp, "WEBP"),
|
2016-03-15 14:16:22 +03:00
|
|
|
(feature.webpmux, "WEBPMUX"),
|
2019-09-20 02:14:35 +03:00
|
|
|
(feature.xcb, "XCB (X protocol)"),
|
2016-03-15 14:16:22 +03:00
|
|
|
]
|
2010-11-28 23:15:53 +03:00
|
|
|
|
|
|
|
all = 1
|
|
|
|
for option in options:
|
|
|
|
if option[0]:
|
2021-02-27 18:52:46 +03:00
|
|
|
extra_info = ""
|
2014-05-31 02:08:21 +04:00
|
|
|
if len(option) >= 3 and option[2]:
|
2021-02-27 18:52:46 +03:00
|
|
|
extra_info = f" ({option[2]})"
|
|
|
|
print(f"--- {option[1]} support available{extra_info}")
|
2010-11-28 23:15:53 +03:00
|
|
|
else:
|
2020-07-16 12:43:29 +03:00
|
|
|
print(f"*** {option[1]} support not available")
|
2010-11-28 23:15:53 +03:00
|
|
|
all = 0
|
|
|
|
|
2012-06-12 09:13:40 +04:00
|
|
|
print("-" * 68)
|
2010-11-28 23:15:53 +03:00
|
|
|
|
|
|
|
if not all:
|
2012-06-12 09:13:40 +04:00
|
|
|
print("To add a missing option, make sure you have the required")
|
2016-03-30 19:16:10 +03:00
|
|
|
print("library and headers.")
|
2019-06-13 18:54:57 +03:00
|
|
|
print(
|
|
|
|
"See https://pillow.readthedocs.io/en/latest/installation."
|
|
|
|
"html#building-from-source"
|
|
|
|
)
|
2013-03-14 15:07:46 +04:00
|
|
|
print("")
|
2010-11-28 23:15:53 +03:00
|
|
|
|
2012-06-12 09:13:40 +04:00
|
|
|
print("To check the build, run the selftest.py script.")
|
2013-03-14 15:07:46 +04:00
|
|
|
print("")
|
2010-11-28 23:15:53 +03:00
|
|
|
|
2014-06-27 19:57:49 +04:00
|
|
|
|
2015-01-21 02:00:58 +03:00
|
|
|
def debug_build():
|
2021-01-09 18:41:13 +03:00
|
|
|
return hasattr(sys, "gettotalrefcount") or FUZZING_BUILD
|
2015-01-21 02:00:58 +03:00
|
|
|
|
2017-11-14 17:47:59 +03:00
|
|
|
|
2020-09-01 20:16:46 +03:00
|
|
|
files = ["src/_imaging.c"]
|
|
|
|
for src_file in _IMAGING:
|
|
|
|
files.append("src/" + src_file + ".c")
|
|
|
|
for src_file in _LIB_IMAGING:
|
|
|
|
files.append(os.path.join("src/libImaging", src_file + ".c"))
|
|
|
|
ext_modules = [
|
|
|
|
Extension("PIL._imaging", files),
|
2020-11-25 17:01:16 +03:00
|
|
|
Extension("PIL._imagingft", ["src/_imagingft.c"]),
|
2020-09-01 20:16:46 +03:00
|
|
|
Extension("PIL._imagingcms", ["src/_imagingcms.c"]),
|
|
|
|
Extension("PIL._webp", ["src/_webp.c"]),
|
|
|
|
Extension("PIL._imagingtk", ["src/_imagingtk.c", "src/Tk/tkImaging.c"]),
|
|
|
|
Extension("PIL._imagingmath", ["src/_imagingmath.c"]),
|
|
|
|
Extension("PIL._imagingmorph", ["src/_imagingmorph.c"]),
|
|
|
|
]
|
|
|
|
|
2016-10-19 21:07:08 +03:00
|
|
|
try:
|
2019-06-13 18:54:57 +03:00
|
|
|
setup(
|
|
|
|
version=PILLOW_VERSION,
|
|
|
|
cmdclass={"build_ext": pil_build_ext},
|
2020-09-01 20:16:46 +03:00
|
|
|
ext_modules=ext_modules,
|
2019-06-13 18:54:57 +03:00
|
|
|
zip_safe=not (debug_build() or PLATFORM_MINGW),
|
|
|
|
)
|
2016-11-11 20:12:07 +03:00
|
|
|
except RequiredDependencyException as err:
|
2020-07-16 12:43:29 +03:00
|
|
|
msg = f"""
|
2016-10-19 21:07:08 +03:00
|
|
|
|
2020-07-16 12:43:29 +03:00
|
|
|
The headers or library files could not be found for {str(err)},
|
2016-10-19 21:07:08 +03:00
|
|
|
a required dependency when compiling Pillow from source.
|
|
|
|
|
|
|
|
Please see the install instructions at:
|
2017-02-14 12:27:02 +03:00
|
|
|
https://pillow.readthedocs.io/en/latest/installation.html
|
2016-10-19 21:07:08 +03:00
|
|
|
|
2020-07-16 12:43:29 +03:00
|
|
|
"""
|
2016-10-19 21:07:08 +03:00
|
|
|
sys.stderr.write(msg)
|
2016-11-11 20:12:07 +03:00
|
|
|
raise RequiredDependencyException(msg)
|
2016-10-19 21:07:08 +03:00
|
|
|
except DependencyException as err:
|
2020-07-16 12:43:29 +03:00
|
|
|
msg = f"""
|
2016-10-19 21:07:08 +03:00
|
|
|
|
2020-07-16 12:43:29 +03:00
|
|
|
The headers or library files could not be found for {str(err)},
|
|
|
|
which was requested by the option flag --enable-{str(err)}
|
2016-10-19 21:07:08 +03:00
|
|
|
|
2020-07-16 12:43:29 +03:00
|
|
|
"""
|
2016-10-19 21:07:08 +03:00
|
|
|
sys.stderr.write(msg)
|
|
|
|
raise DependencyException(msg)
|