| 1 |
#!/usr/bin/env python |
| 2 |
|
| 3 |
|
| 4 |
__license__ = 'GPL v3' |
| 5 |
__copyright__ = '2009, Kovid Goyal <[email protected]>' |
| 6 |
__docformat__ = 'restructuredtext en' |
| 7 |
|
| 8 |
import os |
| 9 |
import re |
| 10 |
import shutil |
| 11 |
import subprocess |
| 12 |
from functools import lru_cache |
| 13 |
|
| 14 |
from setup import isfreebsd, ishaiku, islinux, ismacos, iswindows |
| 15 |
|
| 16 |
NMAKE = RC = msvc = MT = win_inc = win_lib = win_cc = win_ld = None |
| 17 |
|
| 18 |
|
| 19 |
@lru_cache(maxsize=2) |
| 20 |
def pyqt_sip_abi_version(): |
| 21 |
import PyQt6 |
| 22 |
|
| 23 |
if getattr(PyQt6, '__file__', None): |
| 24 |
bindings_path = os.path.join(os.path.dirname(PyQt6.__file__), 'bindings', 'QtCore', 'QtCore.toml') |
| 25 |
if os.path.exists(bindings_path): |
| 26 |
with open(bindings_path) as f: |
| 27 |
raw = f.read() |
| 28 |
m = re.search(r'^sip-abi-version\s*=\s*"(.+?)"', raw, flags=re.MULTILINE) |
| 29 |
if m is not None: |
| 30 |
return m.group(1) |
| 31 |
|
| 32 |
|
| 33 |
def merge_paths(a, b): |
| 34 |
a = [os.path.normcase(os.path.normpath(x)) for x in a.split(os.pathsep)] |
| 35 |
for q in b.split(os.pathsep): |
| 36 |
q = os.path.normcase(os.path.normpath(q)) |
| 37 |
if q not in a: |
| 38 |
a.append(q) |
| 39 |
return os.pathsep.join(a) |
| 40 |
|
| 41 |
|
| 42 |
if iswindows: |
| 43 |
from setup.vcvars import query_vcvarsall |
| 44 |
|
| 45 |
env = query_vcvarsall() |
| 46 |
win_path = env['PATH'] |
| 47 |
os.environ['PATH'] = merge_paths(env['PATH'], os.environ['PATH']) |
| 48 |
NMAKE = 'nmake.exe' |
| 49 |
RC = 'rc.exe' |
| 50 |
MT = 'mt.exe' |
| 51 |
win_cc = 'cl.exe' |
| 52 |
win_ld = 'link.exe' |
| 53 |
win_inc = [x for x in env['INCLUDE'].split(os.pathsep) if x] |
| 54 |
win_lib = [x for x in env['LIB'].split(os.pathsep) if x] |
| 55 |
for key in env: |
| 56 |
if key != 'PATH': |
| 57 |
os.environ[key] = env[key] |
| 58 |
|
| 59 |
QMAKE = 'qmake' |
| 60 |
for x in ('qmake6', 'qmake-qt6', 'qt6-qmake', 'qmake'): |
| 61 |
q = shutil.which(x) |
| 62 |
if q: |
| 63 |
QMAKE = q |
| 64 |
break |
| 65 |
QMAKE = os.environ.get('QMAKE', QMAKE) |
| 66 |
if iswindows and not QMAKE.lower().endswith('.exe'): |
| 67 |
QMAKE += '.exe' |
| 68 |
CMAKE = 'cmake' |
| 69 |
CMAKE = os.environ.get('CMAKE', CMAKE) |
| 70 |
|
| 71 |
PKGCONFIG = shutil.which('pkg-config') |
| 72 |
PKGCONFIG = os.environ.get('PKG_CONFIG', PKGCONFIG) |
| 73 |
if (islinux or ishaiku) and not PKGCONFIG: |
| 74 |
raise SystemExit('Failed to find pkg-config on your system. You can use the environment variable PKG_CONFIG to point to the pkg-config executable') |
| 75 |
|
| 76 |
|
| 77 |
def run_pkgconfig(name, envvar, default, flag, prefix): |
| 78 |
ans = [] |
| 79 |
if envvar: |
| 80 |
ev = os.environ.get(envvar, None) |
| 81 |
if ev: |
| 82 |
ans = [x.strip() for x in ev.split(os.pathsep)] |
| 83 |
ans = [x for x in ans if x and (prefix == '-l' or os.path.exists(x))] |
| 84 |
if not ans: |
| 85 |
try: |
| 86 |
raw = subprocess.Popen([PKGCONFIG, flag, name], stdout=subprocess.PIPE).stdout.read().decode('utf-8') |
| 87 |
ans = [x.strip() for x in raw.split(prefix)] |
| 88 |
ans = [x for x in ans if x and (prefix == '-l' or os.path.exists(x))] |
| 89 |
except Exception: |
| 90 |
print('Failed to run pkg-config:', PKGCONFIG, 'for:', name) |
| 91 |
|
| 92 |
return ans or ([default] if default else []) |
| 93 |
|
| 94 |
|
| 95 |
def pkgconfig_include_dirs(name, envvar, default): |
| 96 |
return run_pkgconfig(name, envvar, default, '--cflags-only-I', '-I') |
| 97 |
|
| 98 |
|
| 99 |
def pkgconfig_lib_dirs(name, envvar, default): |
| 100 |
return run_pkgconfig(name, envvar, default, '--libs-only-L', '-L') |
| 101 |
|
| 102 |
|
| 103 |
def pkgconfig_libs(name, envvar, default): |
| 104 |
return run_pkgconfig(name, envvar, default, '--libs-only-l', '-l') |
| 105 |
|
| 106 |
|
| 107 |
def consolidate(envvar, default): |
| 108 |
val = os.environ.get(envvar, default) |
| 109 |
ans = [x.strip() for x in val.split(os.pathsep)] |
| 110 |
return [x for x in ans if x and os.path.exists(x)] |
| 111 |
|
| 112 |
|
| 113 |
qraw = None |
| 114 |
|
| 115 |
|
| 116 |
def readvar(name): |
| 117 |
global qraw |
| 118 |
if qraw is None: |
| 119 |
qraw = subprocess.check_output([QMAKE, '-query']).decode('utf-8') |
| 120 |
return re.search(f'^{name}:(.+)$', qraw, flags=re.M).group(1).strip() |
| 121 |
|
| 122 |
|
| 123 |
qt = {x: readvar(y) for x, y in {'libs': 'QT_INSTALL_LIBS', 'plugins': 'QT_INSTALL_PLUGINS', 'version_str': 'QT_VERSION'}.items()} |
| 124 |
qmakespec = readvar('QMAKE_SPEC') if iswindows else None |
| 125 |
qt['version'] = tuple(map(int, qt['version_str'].split('.')[:2])) |
| 126 |
freetype_lib_dirs = [] |
| 127 |
freetype_libs = [] |
| 128 |
freetype_inc_dirs = [] |
| 129 |
|
| 130 |
podofo_inc = '/usr/include/podofo' |
| 131 |
podofo_lib = '/usr/lib' |
| 132 |
|
| 133 |
usb_library = 'usb' if isfreebsd else 'usb-1.0' |
| 134 |
|
| 135 |
chmlib_inc_dirs = chmlib_lib_dirs = [] |
| 136 |
|
| 137 |
sqlite_inc_dirs = [] |
| 138 |
|
| 139 |
icu_inc_dirs = [] |
| 140 |
icu_lib_dirs = [] |
| 141 |
|
| 142 |
zlib_inc_dirs = [] |
| 143 |
zlib_lib_dirs = [] |
| 144 |
|
| 145 |
hunspell_inc_dirs = [] |
| 146 |
hunspell_lib_dirs = [] |
| 147 |
|
| 148 |
hyphen_inc_dirs = [] |
| 149 |
hyphen_lib_dirs = [] |
| 150 |
|
| 151 |
ffmpeg_inc_dirs = [] |
| 152 |
ffmpeg_lib_dirs = [] |
| 153 |
|
| 154 |
uchardet_inc_dirs, uchardet_lib_dirs, uchardet_libs = [], [], ['uchardet'] |
| 155 |
|
| 156 |
openssl_inc_dirs, openssl_lib_dirs = [], [] |
| 157 |
|
| 158 |
piper_inc_dirs, piper_lib_dirs, piper_libs = [], [], [] |
| 159 |
|
| 160 |
ICU = sw = '' |
| 161 |
|
| 162 |
if iswindows: |
| 163 |
prefix = sw = os.environ.get('SW', r'C:\cygwin64\home\kovid\sw') |
| 164 |
sw_inc_dir = os.path.join(prefix, 'include') |
| 165 |
sw_lib_dir = os.path.join(prefix, 'lib') |
| 166 |
icu_inc_dirs = [sw_inc_dir] |
| 167 |
icu_lib_dirs = [sw_lib_dir] |
| 168 |
hyphen_inc_dirs = [sw_inc_dir] |
| 169 |
hyphen_lib_dirs = [sw_lib_dir] |
| 170 |
openssl_inc_dirs = [sw_inc_dir] |
| 171 |
openssl_lib_dirs = [sw_lib_dir] |
| 172 |
uchardet_inc_dirs = [sw_inc_dir] |
| 173 |
uchardet_lib_dirs = [sw_lib_dir] |
| 174 |
sqlite_inc_dirs = [sw_inc_dir] |
| 175 |
chmlib_inc_dirs = [sw_inc_dir] |
| 176 |
chmlib_lib_dirs = [sw_lib_dir] |
| 177 |
freetype_lib_dirs = [sw_lib_dir] |
| 178 |
freetype_libs = ['freetype'] |
| 179 |
freetype_inc_dirs = [os.path.join(sw_inc_dir, 'freetype2'), sw_inc_dir] |
| 180 |
hunspell_inc_dirs = [os.path.join(sw_inc_dir, 'hunspell')] |
| 181 |
hunspell_lib_dirs = [sw_lib_dir] |
| 182 |
zlib_inc_dirs = [sw_inc_dir] |
| 183 |
zlib_lib_dirs = [sw_lib_dir] |
| 184 |
podofo_inc = os.path.join(sw_inc_dir, 'podofo') |
| 185 |
podofo_lib = sw_lib_dir |
| 186 |
piper_inc_dirs = [sw_inc_dir, os.path.join(sw_inc_dir, 'onnxruntime')] |
| 187 |
piper_lib_dirs = [sw_lib_dir] |
| 188 |
piper_libs = ['espeak-ng', 'onnxruntime'] |
| 189 |
elif ismacos: |
| 190 |
sw = os.environ.get('SW', os.path.expanduser('~/sw')) |
| 191 |
sw_inc_dir = os.path.join(sw, 'include') |
| 192 |
sw_lib_dir = os.path.join(sw, 'lib') |
| 193 |
sw_bin_dir = os.path.join(sw, 'bin') |
| 194 |
podofo_inc = os.path.join(sw_inc_dir, 'podofo') |
| 195 |
hunspell_inc_dirs = [os.path.join(sw_inc_dir, 'hunspell')] |
| 196 |
podofo_lib = sw_lib_dir |
| 197 |
freetype_libs = ['freetype'] |
| 198 |
freetype_inc_dirs = [sw + '/include/freetype2'] |
| 199 |
uchardet_inc_dirs = [sw + '/include/uchardet'] |
| 200 |
SSL = os.environ.get('OPENSSL_DIR', os.path.join(sw, 'private', 'ssl')) |
| 201 |
openssl_inc_dirs = [os.path.join(SSL, 'include')] |
| 202 |
openssl_lib_dirs = [os.path.join(SSL, 'lib')] |
| 203 |
if os.path.exists(os.path.join(sw_bin_dir, 'cmake')): |
| 204 |
CMAKE = os.path.join(sw_bin_dir, 'cmake') |
| 205 |
piper_inc_dirs = [sw_inc_dir, os.path.join(sw_inc_dir, 'onnxruntime')] |
| 206 |
piper_lib_dirs = [sw_lib_dir] |
| 207 |
piper_libs = ['espeak-ng', 'onnxruntime'] |
| 208 |
else: |
| 209 |
freetype_inc_dirs = pkgconfig_include_dirs('freetype2', 'FT_INC_DIR', '/usr/include/freetype2') |
| 210 |
freetype_lib_dirs = pkgconfig_lib_dirs('freetype2', 'FT_LIB_DIR', '/usr/lib') |
| 211 |
freetype_libs = pkgconfig_libs('freetype2', '', '') |
| 212 |
hunspell_inc_dirs = pkgconfig_include_dirs('hunspell', 'HUNSPELL_INC_DIR', '/usr/include/hunspell') |
| 213 |
hunspell_lib_dirs = pkgconfig_lib_dirs('hunspell', 'HUNSPELL_LIB_DIR', '/usr/lib') |
| 214 |
sw = os.environ.get('SW', os.path.expanduser('~/sw')) |
| 215 |
podofo_inc = '/usr/include/podofo' |
| 216 |
podofo_lib = '/usr/lib' |
| 217 |
if not os.path.exists(podofo_inc + '/podofo.h'): |
| 218 |
podofo_inc = os.path.join(sw, 'include', 'podofo') |
| 219 |
podofo_lib = os.path.join(sw, 'lib') |
| 220 |
uchardet_inc_dirs = pkgconfig_include_dirs('uchardet', '', '/usr/include/uchardet') |
| 221 |
uchardet_lib_dirs = pkgconfig_lib_dirs('uchardet', '', '/usr/lib') |
| 222 |
uchardet_libs = pkgconfig_libs('uchardet', '', '') |
| 223 |
piper_inc_dirs = pkgconfig_include_dirs('espeak-ng', '', '/usr/include') + pkgconfig_include_dirs('libonnxruntime', '', '/usr/include/onnxruntime') |
| 224 |
piper_lib_dirs = pkgconfig_lib_dirs('espeak-ng', '', '/usr/lib') + pkgconfig_lib_dirs('libonnxruntime', '', '/usr/lib') |
| 225 |
piper_libs = pkgconfig_libs('espeak-ng', '', 'espeak-ng') + pkgconfig_libs('libonnxruntime', '', 'onnxruntime') |
| •226 |
for x in ('libavcodec', 'libavformat', 'libavdevice', 'libavfilter', 'libavutil', 'libswresample', 'libswscale'): |
| 227 |
for inc in pkgconfig_include_dirs(x, '', '/usr/include'): |
| 228 |
if inc and inc not in ffmpeg_inc_dirs: |
| 229 |
ffmpeg_inc_dirs.append(inc) |
| 230 |
for lib in pkgconfig_lib_dirs(x, '', '/usr/lib'): |
| 231 |
if lib and lib not in ffmpeg_lib_dirs: |
| 232 |
ffmpeg_lib_dirs.append(lib) |
| 233 |
|
| 234 |
if os.path.exists(os.path.join(sw, 'ffmpeg')): |
| 235 |
ffmpeg_inc_dirs = [os.path.join(sw, 'ffmpeg', 'include')] + ffmpeg_inc_dirs |
| 236 |
ffmpeg_lib_dirs = [os.path.join(sw, 'ffmpeg', 'bin' if iswindows else 'lib')] + ffmpeg_lib_dirs |
| 237 |
|
| 238 |
|
| 239 |
if 'PODOFO_PREFIX' in os.environ: |
| 240 |
os.environ['PODOFO_LIB_DIR'] = os.path.join(os.environ['PODOFO_PREFIX'], 'lib') |
| 241 |
os.environ['PODOFO_INC_DIR'] = os.path.join(os.environ['PODOFO_PREFIX'], 'include', 'podofo') |
| 242 |
os.environ['PODOFO_LIB_NAME'] = os.path.join(os.environ['PODOFO_PREFIX'], 'lib', 'libpodofo.so') |
| 243 |
podofo_lib = os.environ.get('PODOFO_LIB_DIR', podofo_lib) |
| 244 |
podofo_inc = os.environ.get('PODOFO_INC_DIR', podofo_inc) |
| 245 |
podofo = os.environ.get('PODOFO_LIB_NAME', 'podofo') |
| 246 |
|
| 247 |
podofo_error = ( |
| 248 |
None |
| 249 |
if os.path.exists(os.path.join(podofo_inc, 'podofo.h')) |
| 250 |
else ( |
| 251 |
'PoDoFo not found on your system. Various PDF related', |
| 252 |
' functionality will not work. Use the PODOFO_INC_DIR and', |
| 253 |
' PODOFO_LIB_DIR environment variables.', |
| 254 |
) |
| 255 |
) |
| 256 |
podofo_inc_dirs = [podofo_inc, os.path.dirname(podofo_inc)] |
| 257 |
podofo_lib_dirs = [podofo_lib] |