Pillow/winbuild/build_dep.py

302 lines
8.1 KiB
Python
Raw Normal View History

from unzip import unzip
2014-03-25 09:38:45 +04:00
from untar import untar
2015-06-20 06:43:14 +03:00
import os
2016-08-29 15:06:48 +03:00
from config import compilers, compiler_from_env, libs
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)
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
for compiler in compilers.values():
try:
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):
if '.zip' in src:
return unzip(src, dest)
if '.tar.gz' in src or '.tgz' in src:
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():
2017-03-27 01:08:16 +03:00
filename = lib['filename']
if name == 'openjpeg':
for compiler in compilers.values():
2015-06-26 10:39:13 +03:00
if not os.path.exists(os.path.join(
build_dir, lib['dir']+compiler['inc_dir'])):
extract(filename, build_dir)
2015-06-20 06:43:14 +03:00
os.rename(os.path.join(build_dir, lib['dir']),
2015-06-26 10:39:13 +03:00
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):
return r"""
rem build openjpeg
setlocal
@echo on
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
""" % compiler
2015-06-20 06:43:14 +03:00
2015-06-26 20:08:40 +03:00
def cp_tk(ver_85, ver_86):
2015-08-25 15:27:18 +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\
""" % 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
2017-01-12 22:28:24 +03:00
""" + "\n".join(r'set %s=%%BUILD%%\%s' % (k.upper(), v['dir'])
2015-06-20 06:43:14 +03:00
for (k, v) in libs.items() if v['dir'])
def setup_compiler(compiler):
return r"""setlocal EnableDelayedExpansion
call "%%ProgramFiles%%\Microsoft SDKs\Windows\%(env_version)s\Bin\SetEnv.Cmd" /Release %(env_flags)s
set INCLIB=%%INCLIB%%\%(inc_dir)s
""" % compiler
2015-06-20 06:43:14 +03:00
def end_compiler():
return """
endlocal
"""
2015-06-20 06:43:14 +03:00
def nmake_openjpeg(compiler):
2014-08-23 03:14:19 +04:00
atts = {'op_ver': '2.1'}
atts.update(compiler)
return r"""
rem build openjpeg
setlocal
@echo on
cd /D %%OPENJPEG%%%(inc_dir)s
2014-08-23 03:14:19 +04:00
%%CMAKE%% -DBUILD_THIRDPARTY:BOOL=OFF -G "NMake Makefiles" .
nmake -f Makefile clean
nmake -f Makefile
copy /Y /B bin\* %%INCLIB%%
2014-08-23 03:14:19 +04:00
mkdir %%INCLIB%%\openjpeg-%(op_ver)s
copy /Y /B src\lib\openjp2\*.h %%INCLIB%%\openjpeg-%(op_ver)s
endlocal
2014-08-23 03:14:19 +04:00
""" % atts
2015-06-20 06:43:14 +03:00
2014-08-23 03:14:19 +04:00
def msbuild_openjpeg(compiler):
atts = {'op_ver': '2.1'}
atts.update(compiler)
return r"""
rem build openjpeg
setlocal
@echo on
cd /D %%OPENJPEG%%%(inc_dir)s
%%CMAKE%% -DBUILD_THIRDPARTY:BOOL=OFF -G "NMake Makefiles" .
nmake -f Makefile clean
nmake -f Makefile
copy /Y /B bin\* %%INCLIB%%
mkdir %%INCLIB%%\openjpeg-%(op_ver)s
copy /Y /B src\lib\openjp2\*.h %%INCLIB%%\openjpeg-%(op_ver)s
endlocal
""" % atts
def nmake_libs(compiler):
# undone -- pre, makes, headers, libs
return r"""
rem Build libjpeg
setlocal
2014-03-25 09:38:45 +04:00
cd /D %%JPEG%%
nmake -f makefile.vc setup-vc6
nmake -f makefile.vc clean
2014-08-23 08:35:56 +04:00
nmake -f makefile.vc 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 -f win32\Makefile.msc clean
2014-08-23 08:35:56 +04:00
nmake -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
cd /D %%WEBP%%
2014-08-23 04:06:11 +04:00
rd /S /Q %%WEBP%%\output\release-static
nmake -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
rem do after building jpeg and zlib
2014-03-25 09:38:45 +04:00
copy %%~dp0\nmake.opt %%TIFF%%
2014-03-25 09:38:45 +04:00
cd /D %%TIFF%%
nmake -f makefile.vc clean
2014-08-23 04:06:30 +04:00
nmake -f makefile.vc lib
copy /Y /B libtiff\*.dll %%INCLIB%%
copy /Y /B libtiff\*.lib %%INCLIB%%
copy /Y /B libtiff\tiff*.h %%INCLIB%%
endlocal
2014-03-25 09:38:45 +04:00
""" % compiler
2015-06-20 06:43:14 +03:00
2014-08-23 03:14:19 +04:00
def msbuild_freetype(compiler):
2015-06-20 04:34:34 +03:00
if compiler['env_version'] == 'v7.1':
return msbuild_freetype_71(compiler)
return msbuild_freetype_70(compiler)
2015-06-20 06:43:14 +03:00
def msbuild_freetype_71(compiler):
return r"""
rem Build freetype
setlocal
rd /S /Q %%FREETYPE%%\objs
2015-06-20 06:43:14 +03:00
%%MSBUILD%% %%FREETYPE%%\builds\windows\vc%(vc_version)s\freetype.sln /t:Clean;Build /p:Configuration="Release" /p:Platform=%(platform)s /m
xcopy /Y /E /Q %%FREETYPE%%\include %%INCLIB%%
copy /Y /B %%FREETYPE%%\objs\vc%(vc_version)s\%(platform)s\*.lib %%INCLIB%%\freetype.lib
endlocal
2015-06-20 06:43:14 +03:00
""" % compiler
def msbuild_freetype_70(compiler):
return r"""
rem Build freetype
setlocal
py -3 %%~dp0\fixproj.py %%FREETYPE%%\builds\windows\vc%(vc_version)s\freetype.sln %(platform)s
py -3 %%~dp0\fixproj.py %%FREETYPE%%\builds\windows\vc%(vc_version)s\freetype.vcproj %(platform)s
rd /S /Q %%FREETYPE%%\objs
2015-06-20 06:43:14 +03:00
%%MSBUILD%% %%FREETYPE%%\builds\windows\vc%(vc_version)s\freetype.sln /t:Clean;Build /p:Configuration="LIB Release";Platform=%(platform)s /m
xcopy /Y /E /Q %%FREETYPE%%\include %%INCLIB%%
xcopy /Y /E /Q %%FREETYPE%%\objs\win32\vc%(vc_version)s %%INCLIB%%
copy /Y /B %%FREETYPE%%\objs\win32\vc%(vc_version)s\*.lib %%INCLIB%%\freetype.lib
endlocal
2015-06-20 06:43:14 +03:00
""" % compiler
2014-08-23 03:14:19 +04:00
def build_lcms2(compiler):
2015-06-20 06:43:14 +03:00
if compiler['env_version'] == 'v7.1':
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"""
2015-06-20 06:43:14 +03:00
if compiler['platform'] == 'x64':
return ''
2015-06-20 01:32:08 +03:00
"""Build LCMS on VC2008. This version is only 32bit/Win32"""
2014-08-23 03:14:19 +04:00
return r"""
rem Build lcms2
setlocal
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
2015-06-20 01:32:08 +03:00
%%MSBUILD%% %%LCMS%%\Projects\VC%(vc_version)s\lcms2.sln /t:Clean /p:Configuration="Release" /p:Platform=Win32 /m
%%MSBUILD%% %%LCMS%%\Projects\VC%(vc_version)s\lcms2.sln /t:lcms2_static /p:Configuration="Release" /p:Platform=Win32 /m
xcopy /Y /E /Q %%LCMS%%\include %%INCLIB%%
2014-08-23 03:14:19 +04:00
copy /Y /B %%LCMS%%\Projects\VC%(vc_version)s\Release\*.lib %%INCLIB%%
2015-06-20 01:32:08 +03:00
endlocal
""" % compiler
2015-06-20 06:43:14 +03:00
2015-06-20 01:32:08 +03:00
def build_lcms_71(compiler):
return r"""
rem Build lcms2
setlocal
rd /S /Q %%LCMS%%\Lib
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=%(platform)s /m
%%MSBUILD%% %%LCMS%%\Projects\VC%(vc_version)s\lcms2.sln /t:lcms2_static /p:Configuration="Release" /p:Platform=%(platform)s /m
xcopy /Y /E /Q %%LCMS%%\include %%INCLIB%%
2014-08-23 03:14:19 +04:00
copy /Y /B %%LCMS%%\Lib\MS\*.lib %%INCLIB%%
endlocal
""" % compiler
def add_compiler(compiler):
script.append(setup_compiler(compiler))
2015-06-10 23:16:17 +03:00
script.append(nmake_libs(compiler))
2014-08-23 03:14:19 +04:00
2015-06-20 06:43:14 +03:00
# script.append(extract_openjpeg(compiler))
2015-06-11 00:37:25 +03:00
script.append(msbuild_freetype(compiler))
2015-06-20 01:32:08 +03:00
script.append(build_lcms2(compiler))
2015-06-20 06:43:14 +03:00
# script.append(nmake_openjpeg(compiler))
script.append(end_compiler())
mkdirs()
2016-08-29 14:53:48 +03:00
extract_libs()
2016-08-29 15:06:48 +03:00
script = [header(),
cp_tk(libs['tk-8.5']['version'],
libs['tk-8.6']['version'])]
if 'PYTHON' in os.environ:
2016-08-29 15:06:48 +03:00
add_compiler(compiler_from_env())
else:
2015-06-20 06:43:14 +03:00
# for compiler in compilers.values():
# add_compiler(compiler)
add_compiler(compilers[(7.0, 32)])
# add_compiler(compilers[(7.1, 64)])
2015-06-20 06:43:14 +03:00
with open('build_deps.cmd', 'w') as f:
f.write("\n".join(script))