zdoom-macos-deps/aedi/target/library_tier3.py
2022-06-19 09:54:48 +03:00

201 lines
7.4 KiB
Python

#
# Helper module to build macOS version of various source ports
# Copyright (C) 2020-2022 Alexey Lysiuk
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
from .base import *
class ExpatTarget(CMakeStaticDependencyTarget):
def __init__(self, name='expat'):
super().__init__(name)
def prepare_source(self, state: BuildState):
state.download_source(
'https://github.com/libexpat/libexpat/releases/download/R_2_4_1/expat-2.4.1.tar.xz',
'cf032d0dba9b928636548e32b327a2d66b1aab63c4f4a13dd132c2d1d2f2fb6a')
def configure(self, state: BuildState):
opts = state.options
opts['EXPAT_BUILD_EXAMPLES'] = 'NO'
opts['EXPAT_BUILD_TESTS'] = 'NO'
opts['EXPAT_BUILD_TOOLS'] = 'NO'
super().configure(state)
class FreeImageTarget(MakeTarget):
def __init__(self, name='freeimage'):
super().__init__(name)
def prepare_source(self, state: BuildState):
state.download_source(
'https://downloads.sourceforge.net/project/freeimage/Source%20Distribution/3.18.0/FreeImage3180.zip',
'f41379682f9ada94ea7b34fe86bf9ee00935a3147be41b6569c9605a53e438fd',
patches='freeimage-fix-arm64')
HEADER_FILE = 'Source/FreeImage.h'
def detect(self, state: BuildState) -> bool:
return state.has_source_file(self.HEADER_FILE)
def configure(self, state: BuildState):
super().configure(state)
# These flags are copied from Makefile.gnu
common_flags = ' -O3 -fPIC -fexceptions -fvisibility=hidden'
env = state.environment
env['CFLAGS'] += common_flags + ' -std=gnu89 -Wno-implicit-function-declaration'
env['CXXFLAGS'] += common_flags + ' -Wno-ctor-dtor-privacy'
for option in ('-f', 'Makefile.gnu', 'libfreeimage.a'):
state.options[option] = None
def post_build(self, state: BuildState):
include_path = state.install_path / 'include'
os.makedirs(include_path, exist_ok=True)
shutil.copy(state.build_path / self.HEADER_FILE, include_path)
lib_path = state.install_path / 'lib'
os.makedirs(lib_path, exist_ok=True)
shutil.copy(state.build_path / 'libfreeimage.a', lib_path)
self.write_pc_file(state, version='3.18.0', libs='-lfreeimage -lc++')
class FtglTarget(ConfigureMakeStaticDependencyTarget):
def __init__(self, name='ftgl'):
super().__init__(name)
def prepare_source(self, state: BuildState):
state.download_source(
'https://downloads.sourceforge.net/project/ftgl/FTGL%20Source/2.1.3~rc5/ftgl-2.1.3-rc5.tar.gz',
'5458d62122454869572d39f8aa85745fc05d5518001bcefa63bd6cbb8d26565b',
patches='ftgl-support-arm64')
def detect(self, state: BuildState) -> bool:
return state.has_source_file('ftgl.pc.in')
def configure(self, state: BuildState):
opts = state.options
opts['--with-glut-inc'] = '/dev/null'
opts['--with-glut-lib'] = '/dev/null'
super().configure(state)
class GlewTarget(CMakeStaticDependencyTarget):
def __init__(self, name='glew'):
super().__init__(name)
self.src_root = 'build/cmake'
def prepare_source(self, state: BuildState):
state.download_source(
'https://github.com/nigels-com/glew/releases/download/glew-2.2.0/glew-2.2.0.tgz',
'd4fc82893cfb00109578d0a1a2337fb8ca335b3ceccf97b97e5cc7f08e4353e1')
def configure(self, state: BuildState):
state.options['BUILD_UTILS'] = 'NO'
super().configure(state)
LINKER_FLAGS = '-framework OpenGL'
def post_build(self, state: BuildState):
super().post_build(state)
def update_linker_flags(line: str):
link_var = ' INTERFACE_LINK_LIBRARIES '
if line.startswith(link_var):
return f'{link_var}"{GlewTarget.LINKER_FLAGS}"\n'
return line
cmake_module = state.install_path / 'lib/cmake/glew/glew-targets.cmake'
self.update_text_file(cmake_module, update_linker_flags)
@staticmethod
def _process_pkg_config(pcfile: Path, line: str) -> str:
libs = 'Libs:'
if line.startswith(libs):
return libs + ' -L${libdir} -lGLEW ' + GlewTarget.LINKER_FLAGS + os.linesep
return line
class WxWidgetsTarget(CMakeStaticDependencyTarget):
def __init__(self, name='wxwidgets'):
super().__init__(name)
def prepare_source(self, state: BuildState):
state.download_source(
'https://github.com/wxWidgets/wxWidgets/releases/download/v3.1.5/wxWidgets-3.1.5.tar.bz2',
'd7b3666de33aa5c10ea41bb9405c40326e1aeb74ee725bb88f90f1d50270a224',
patches='wxwidgets-library-suffix')
def configure(self, state: BuildState):
opts = state.options
opts['wxBUILD_SHARED'] = 'NO'
opts['wxUSE_LIBLZMA'] = 'YES'
opts['wxUSE_LIBSDL'] = 'NO'
opts['wxUSE_LIBJPEG'] = 'sys'
opts['wxUSE_LIBPNG'] = 'sys'
opts['wxUSE_LIBTIFF'] = 'sys'
super().configure(state)
def post_build(self, state: BuildState):
super().post_build(state)
# Replace prefix in setup.h
def patch_setup_h(line: str):
prefix = '#define wxINSTALL_PREFIX '
return f'{prefix}"/usr/local"\n' if line.startswith(prefix) else line
setup_h_path = state.install_path / 'lib/wx/include/osx_cocoa-unicode-static-3.1/wx/setup.h'
self.update_text_file(setup_h_path, patch_setup_h)
# Fix a few wx-config entries
def patch_wx_config(line: str):
prefix = 'prefix=${input_option_prefix-${this_prefix:-'
is_cross_func = 'is_cross() '
is_cross_test = 'is_cross && target='
output_option_cc = '[ -z "$output_option_cc" '
output_option_cxx = '[ -z "$output_option_cxx" '
output_option_ld = '[ -z "$output_option_ld" '
ldlibs_gl = 'ldlibs_gl='
if line.startswith(prefix):
return prefix + '$(cd "${0%/*}/.."; pwd)}}\n'
elif line.startswith(is_cross_func):
return is_cross_func + '{ false; }\n'
elif line.startswith(is_cross_test):
return is_cross_test + '""\n'
elif line.startswith(output_option_cc):
return output_option_cc + '] || echo "gcc"\n'
elif line.startswith(output_option_cxx):
return output_option_cxx + '] || echo "g++"\n'
elif line.startswith(output_option_ld):
return output_option_ld + '] || echo "g++ -o"\n'
elif line.startswith(ldlibs_gl):
return ldlibs_gl + '"-lwx_baseu-3.1 -lwx_osx_cocoau_core-3.1 -framework OpenGL"\n'
return line
wx_config_path = state.install_path / 'bin/wx-config'
self.update_text_file(wx_config_path, patch_wx_config)