Pillow/winbuild/build_dep.py

329 lines
8.4 KiB
Python
Raw Normal View History

2015-06-20 06:43:14 +03:00
import os
2018-10-08 11:43:11 +03:00
from build import vc_setup
from config import all_compilers, bit_from_env, compiler_from_env, compilers, libs
from fetch import fetch
from untar import untar
from unzip import unzip
2015-06-20 06:43:14 +03:00
def _relpath(*args):
2015-06-20 06:43:14 +03:00
return os.path.join(os.getcwd(), *args)
2019-06-13 18:54:57 +03:00
build_dir = _relpath("build")
inc_dir = _relpath("depends")
2015-06-20 06:43:14 +03:00
def check_sig(filename, signame):
2015-06-20 06:43:14 +03:00
# UNDONE -- need gpg
return filename
2015-06-20 06:43:14 +03:00
def mkdirs():
try:
os.mkdir(build_dir)
2015-06-20 04:34:34 +03:00
except OSError:
pass
try:
os.mkdir(inc_dir)
2015-06-20 04:34:34 +03:00
except OSError:
pass
2018-10-08 11:43:11 +03:00
for compiler in all_compilers():
try:
2019-06-13 18:54:57 +03:00
os.mkdir(os.path.join(inc_dir, compiler["inc_dir"]))
2015-06-20 04:34:34 +03:00
except OSError:
pass
2015-06-20 06:43:14 +03:00
2014-03-25 09:38:45 +04:00
def extract(src, dest):
2019-06-13 18:54:57 +03:00
if ".zip" in src:
2014-03-25 09:38:45 +04:00
return unzip(src, dest)
2019-06-13 18:54:57 +03:00
if ".tar.gz" in src or ".tgz" in src:
2014-03-25 09:38:45 +04:00
return untar(src, dest)
2015-06-20 06:43:14 +03:00
2016-08-29 14:53:48 +03:00
def extract_libs():
2015-06-20 06:43:14 +03:00
for name, lib in libs.items():
2019-10-28 15:11:13 +03:00
filename = fetch(lib["url"])
2019-06-13 18:54:57 +03:00
if name == "openjpeg":
2018-10-08 11:43:11 +03:00
for compiler in all_compilers():
2019-06-13 18:54:57 +03:00
if not os.path.exists(
os.path.join(build_dir, lib["dir"] + compiler["inc_dir"])
):
extract(filename, build_dir)
2019-06-13 18:54:57 +03:00
os.rename(
os.path.join(build_dir, lib["dir"]),
os.path.join(build_dir, lib["dir"] + compiler["inc_dir"]),
)
else:
2017-03-27 01:08:16 +03:00
extract(filename, build_dir)
2015-06-20 06:43:14 +03:00
def extract_openjpeg(compiler):
2019-06-13 18:54:57 +03:00
return (
r"""
rem build openjpeg
setlocal
cd %%BUILD%%
mkdir %%INCLIB%%\openjpeg-2.0
copy /Y /B openjpeg-2.0.0-win32-x86\include\openjpeg-2.0 %%INCLIB%%\openjpeg-2.0
copy /Y /B openjpeg-2.0.0-win32-x86\bin\ %%INCLIB%%
copy /Y /B openjpeg-2.0.0-win32-x86\lib\ %%INCLIB%%
endlocal
2019-06-13 18:54:57 +03:00
"""
% compiler
)
2015-06-20 06:43:14 +03:00
2015-06-26 20:08:40 +03:00
def cp_tk(ver_85, ver_86):
2019-06-13 18:54:57 +03:00
versions = {"ver_85": ver_85, "ver_86": ver_86}
return (
r"""
2015-06-26 20:08:40 +03:00
mkdir %%INCLIB%%\tcl85\include\X11
copy /Y /B %%BUILD%%\tcl%(ver_85)s\generic\*.h %%INCLIB%%\tcl85\include\
copy /Y /B %%BUILD%%\tk%(ver_85)s\generic\*.h %%INCLIB%%\tcl85\include\
copy /Y /B %%BUILD%%\tk%(ver_85)s\xlib\X11\* %%INCLIB%%\tcl85\include\X11\
mkdir %%INCLIB%%\tcl86\include\X11
copy /Y /B %%BUILD%%\tcl%(ver_86)s\generic\*.h %%INCLIB%%\tcl86\include\
copy /Y /B %%BUILD%%\tk%(ver_86)s\generic\*.h %%INCLIB%%\tcl86\include\
copy /Y /B %%BUILD%%\tk%(ver_86)s\xlib\X11\* %%INCLIB%%\tcl86\include\X11\
2019-06-13 18:54:57 +03:00
"""
% versions
)
2015-06-20 06:43:14 +03:00
def header():
return r"""setlocal
set MSBUILD=C:\Windows\Microsoft.NET\Framework64\v4.0.30319\MSBuild.exe
2015-06-11 01:03:32 +03:00
set CMAKE="cmake.exe"
set INCLIB=%~dp0\depends
set BUILD=%~dp0\build
2019-06-13 18:54:57 +03:00
""" + "\n".join(
r"set {}=%BUILD%\{}".format(k.upper(), v["dir"])
2019-06-13 18:54:57 +03:00
for (k, v) in libs.items()
if v["dir"]
)
2015-06-20 06:43:14 +03:00
def setup_compiler(compiler):
2019-06-13 18:54:57 +03:00
return (
r"""setlocal EnableDelayedExpansion
call "%%ProgramFiles%%\Microsoft SDKs\Windows\%(env_version)s\Bin\SetEnv.Cmd" /Release %(env_flags)s
echo on
set INCLIB=%%INCLIB%%\%(inc_dir)s
2019-06-13 18:54:57 +03:00
""" # noqa: E501
% compiler
)
2015-06-20 06:43:14 +03:00
def end_compiler():
return """
endlocal
"""
2015-06-20 06:43:14 +03:00
2019-04-17 13:55:31 +03:00
def nmake_openjpeg(compiler, bit):
2019-06-13 18:54:57 +03:00
if compiler["env_version"] == "v7.0":
2019-04-17 13:55:31 +03:00
return ""
2019-06-13 18:54:57 +03:00
atts = {"op_ver": "2.3.1"}
2014-08-23 03:14:19 +04:00
atts.update(compiler)
2019-06-13 18:54:57 +03:00
return (
r"""
rem build openjpeg
setlocal
2019-06-13 18:54:57 +03:00
"""
+ vc_setup(compiler, bit)
+ r"""
cd /D %%OPENJPEG%%%(inc_dir)s
2014-08-23 03:14:19 +04:00
%%CMAKE%% -DBUILD_THIRDPARTY:BOOL=OFF -DBUILD_SHARED_LIBS:BOOL=OFF -DCMAKE_BUILD_TYPE=Release -G "NMake Makefiles" .
nmake -nologo -f Makefile clean
nmake -nologo -f Makefile
2014-08-23 03:14:19 +04:00
copy /Y /B bin\* %%INCLIB%%
mkdir %%INCLIB%%\openjpeg-%(op_ver)s
copy /Y /B src\lib\openjp2\*.h %%INCLIB%%\openjpeg-%(op_ver)s
endlocal
2019-06-13 18:54:57 +03:00
""" # noqa: E501
% atts
)
2014-08-23 03:14:19 +04:00
2018-10-08 11:43:11 +03:00
def nmake_libs(compiler, bit):
# undone -- pre, makes, headers, libs
2019-06-13 18:54:57 +03:00
script = (
r"""
rem Build libjpeg
setlocal
2019-06-13 18:54:57 +03:00
"""
+ vc_setup(compiler, bit)
+ r"""
2014-03-25 09:38:45 +04:00
cd /D %%JPEG%%
nmake -nologo -f makefile.vc setup-vc6
nmake -nologo -f makefile.vc clean
nmake -nologo -f makefile.vc nodebug=1 libjpeg.lib
copy /Y /B *.dll %%INCLIB%%
copy /Y /B *.lib %%INCLIB%%
copy /Y /B j*.h %%INCLIB%%
endlocal
rem Build zlib
setlocal
2014-03-25 09:38:45 +04:00
cd /D %%ZLIB%%
nmake -nologo -f win32\Makefile.msc clean
nmake -nologo -f win32\Makefile.msc zlib.lib
copy /Y /B *.dll %%INCLIB%%
copy /Y /B *.lib %%INCLIB%%
copy /Y /B zlib.lib %%INCLIB%%\z.lib
copy /Y /B zlib.h %%INCLIB%%
copy /Y /B zconf.h %%INCLIB%%
endlocal
2014-03-25 09:38:45 +04:00
rem Build webp
setlocal
2019-06-13 18:54:57 +03:00
"""
+ vc_setup(compiler, bit)
+ r"""
2014-03-25 09:38:45 +04:00
cd /D %%WEBP%%
2014-08-23 04:06:11 +04:00
rd /S /Q %%WEBP%%\output\release-static
nmake -nologo -f Makefile.vc CFG=release-static RTLIBCFG=static OBJDIR=output all
copy /Y /B output\release-static\%(webp_platform)s\lib\* %%INCLIB%%
2014-08-23 04:06:11 +04:00
mkdir %%INCLIB%%\webp
copy /Y /B src\webp\*.h %%INCLIB%%\\webp
2014-03-25 09:38:45 +04:00
endlocal
rem Build libtiff
setlocal
2019-06-13 18:54:57 +03:00
"""
+ vc_setup(compiler, bit)
+ r"""
rem do after building jpeg and zlib
copy %%~dp0\tiff.opt %%TIFF%%\nmake.opt
2014-03-25 09:38:45 +04:00
cd /D %%TIFF%%
nmake -nologo -f makefile.vc clean
nmake -nologo -f makefile.vc lib
copy /Y /B libtiff\*.dll %%INCLIB%%
copy /Y /B libtiff\*.lib %%INCLIB%%
copy /Y /B libtiff\tiff*.h %%INCLIB%%
endlocal
2018-10-08 11:43:11 +03:00
"""
2019-06-13 18:54:57 +03:00
)
2018-10-08 11:43:11 +03:00
return script % compiler
2015-06-20 06:43:14 +03:00
2019-04-06 04:56:29 +03:00
def msbuild_freetype(compiler, bit):
script = r"""
rem Build freetype
setlocal
rd /S /Q %%FREETYPE%%\objs
2019-04-06 04:56:29 +03:00
set DefaultPlatformToolset=v100
"""
properties = r"""/p:Configuration="Release" /p:Platform=%(platform)s"""
if bit == 64:
2019-06-13 18:54:57 +03:00
script += (
r"copy /Y /B "
+ r'"C:\Program Files (x86)\Microsoft SDKs\Windows\v7.1A\Lib\x64\*.Lib" '
+ r"%%FREETYPE%%\builds\windows\vc2010"
)
2019-04-06 04:56:29 +03:00
properties += r" /p:_IsNativeEnvironment=false"
2019-06-13 18:54:57 +03:00
script += (
r"""
%%MSBUILD%% %%FREETYPE%%\builds\windows\vc2010\freetype.sln /t:Clean;Build """
+ properties
+ r""" /m
xcopy /Y /E /Q %%FREETYPE%%\include %%INCLIB%%
2019-04-06 04:56:29 +03:00
"""
2019-06-13 18:54:57 +03:00
)
2019-04-06 04:56:29 +03:00
freetypeReleaseDir = r"%%FREETYPE%%\objs\%(platform)s\Release"
2019-06-13 18:54:57 +03:00
script += (
r"""
copy /Y /B """
+ freetypeReleaseDir
+ r"""\freetype.lib %%INCLIB%%\freetype.lib
copy /Y /B """
+ freetypeReleaseDir
+ r"""\freetype.dll %%INCLIB%%\..\freetype.dll
endlocal
2019-04-06 04:56:29 +03:00
"""
2019-06-13 18:54:57 +03:00
)
return script % compiler
2015-06-20 06:43:14 +03:00
2014-08-23 03:14:19 +04:00
def build_lcms2(compiler):
2019-06-13 18:54:57 +03:00
if compiler["env_version"] == "v7.1":
2015-06-20 06:43:14 +03:00
return build_lcms_71(compiler)
return build_lcms_70(compiler)
2015-06-20 01:32:08 +03:00
def build_lcms_70(compiler):
"""Link error here on x64"""
2019-06-13 18:54:57 +03:00
if compiler["platform"] == "x64":
return ""
2015-06-20 06:43:14 +03:00
2015-06-20 01:32:08 +03:00
"""Build LCMS on VC2008. This version is only 32bit/Win32"""
2019-06-13 18:54:57 +03:00
return (
r"""
rem Build lcms2
setlocal
set LCMS=%%LCMS-2.7%%
2014-08-23 03:14:19 +04:00
rd /S /Q %%LCMS%%\Lib
2014-08-23 04:07:08 +04:00
rd /S /Q %%LCMS%%\Projects\VC%(vc_version)s\Release
%%MSBUILD%% %%LCMS%%\Projects\VC%(vc_version)s\lcms2.sln /t:Clean /p:Configuration="Release" /p:Platform=Win32 /m
2019-04-06 04:41:59 +03:00
%%MSBUILD%% %%LCMS%%\Projects\VC%(vc_version)s\lcms2.sln /t:lcms2_static /p:Configuration="Release" /p:Platform=Win32 /p:PlatformToolset=v90 /m
xcopy /Y /E /Q %%LCMS%%\include %%INCLIB%%
2019-04-06 04:41:59 +03:00
copy /Y /B %%LCMS%%\Lib\MS\*.lib %%INCLIB%%
2015-06-20 01:32:08 +03:00
endlocal
2019-06-13 18:54:57 +03:00
""" # noqa: E501
% compiler
)
2015-06-20 01:32:08 +03:00
2015-06-20 06:43:14 +03:00
2015-06-20 01:32:08 +03:00
def build_lcms_71(compiler):
2019-06-13 18:54:57 +03:00
return (
r"""
2015-06-20 01:32:08 +03:00
rem Build lcms2
setlocal
set LCMS=%%LCMS-2.8%%
2015-06-20 01:32:08 +03:00
rd /S /Q %%LCMS%%\Lib
rd /S /Q %%LCMS%%\Projects\VC%(vc_version)s\Release
powershell -Command "(gc Projects\VC2015\lcms2_static\lcms2_static.vcxproj) -replace 'MultiThreadedDLL', 'MultiThreaded' | Out-File -encoding ASCII Projects\VC2015\lcms2_static\lcms2_static.vcxproj"
%%MSBUILD%% %%LCMS%%\Projects\VC%(vc_version)s\lcms2.sln /t:Clean /p:Configuration="Release" /p:Platform=%(platform)s /m
%%MSBUILD%% %%LCMS%%\Projects\VC%(vc_version)s\lcms2.sln /t:lcms2_static /p:Configuration="Release" /p:Platform=%(platform)s /m
2015-06-20 01:32:08 +03:00
xcopy /Y /E /Q %%LCMS%%\include %%INCLIB%%
2014-08-23 03:14:19 +04:00
copy /Y /B %%LCMS%%\Lib\MS\*.lib %%INCLIB%%
endlocal
2019-06-13 18:54:57 +03:00
""" # noqa: E501
% compiler
)
2019-01-27 12:38:33 +03:00
2018-10-08 11:43:11 +03:00
def add_compiler(compiler, bit):
script.append(setup_compiler(compiler))
2018-10-08 11:43:11 +03:00
script.append(nmake_libs(compiler, bit))
2014-08-23 03:14:19 +04:00
2015-06-20 06:43:14 +03:00
# script.append(extract_openjpeg(compiler))
2019-04-06 04:56:29 +03:00
script.append(msbuild_freetype(compiler, bit))
2015-06-20 01:32:08 +03:00
script.append(build_lcms2(compiler))
2019-04-17 13:55:31 +03:00
script.append(nmake_openjpeg(compiler, bit))
script.append(end_compiler())
mkdirs()
2016-08-29 14:53:48 +03:00
extract_libs()
2019-06-13 18:54:57 +03:00
script = [header(), cp_tk(libs["tk-8.5"]["version"], libs["tk-8.6"]["version"])]
2019-06-13 18:54:57 +03:00
if "PYTHON" in os.environ:
2018-10-08 11:43:11 +03:00
add_compiler(compiler_from_env(), bit_from_env())
else:
2018-10-08 11:43:11 +03:00
# for compiler in all_compilers():
# add_compiler(compiler)
2019-04-06 04:41:59 +03:00
add_compiler(compilers[7.0][2010][32], 32)
2019-06-13 18:54:57 +03:00
with open("build_deps.cmd", "w") as f:
2015-06-20 06:43:14 +03:00
f.write("\n".join(script))