From bbfec6c98aeaa28938fbdc1b0dc8ff6fbdddf27f Mon Sep 17 00:00:00 2001 From: Patrick Wuttke Date: Sun, 4 Aug 2024 12:53:07 +0200 Subject: [PATCH] More recipes (libjpeg, libz, imagemagick). --- SConscript | 26 ++++++++++++++++++++++++-- recipes/CMakeProject/recipe.py | 8 +++++++- recipes/ImageMagick/recipe.py | 12 ++++++++++++ recipes/libjpeg-turbo/recipe.py | 11 +++++++++++ recipes/libpng/recipe.py | 5 +++-- recipes/zlib/recipe.py | 12 ++++++++++++ 6 files changed, 69 insertions(+), 5 deletions(-) create mode 100644 recipes/ImageMagick/recipe.py create mode 100644 recipes/libjpeg-turbo/recipe.py create mode 100644 recipes/zlib/recipe.py diff --git a/SConscript b/SConscript index 2193455..b983cc3 100644 --- a/SConscript +++ b/SConscript @@ -65,6 +65,21 @@ def _make_interface(env: Environment, dependencies: list = []): 'CPPDEFINES': kwargs.get('CPPDEFINES', []) } +def _lib_filename(name: str, type: str = 'static') -> str: + # TODO: windows + ext = { + 'static': 'a', + 'shared': 'so' + }[type] + return f'lib{name}.{ext}' + +def _find_lib(env: Environment, name: str, paths: 'list[str]', type : str = 'static'): + for path in paths: + lib_path = os.path.join(path, _lib_filename(name, type)) + if os.path.exists(lib_path): + return lib_path + return None + def _error(env: Environment, message: str): print(message, file=sys.stderr) env.Exit(1) @@ -81,6 +96,12 @@ def _wrap_builder(builder, is_lib: bool = False): kwargs['LIBS'] = copy.copy(env['LIBS']) for dependency in dependencies: _inject_dependency(dependency, kwargs) + libs_copy = list(kwargs['LIBS']) + for lib in libs_copy: + if isinstance(lib, str) and os.path.isabs(lib): + kwargs['LIBS'].remove(lib) + kwargs['source'].append(lib) + result = builder(*args, **kwargs) if is_lib: # generate a new libconf @@ -365,11 +386,11 @@ if env['COMPILER_FAMILY'] == 'gcc' or env['COMPILER_FAMILY'] == 'clang': elif build_type == 'release': env.Append(CCFLAGS = ['-Wno-unused-variable', '-Wno-unused-parameter', '-Wno-unused-but-set-variable', '-Wno-unused-local-typedef', '-Wno-unused-local-typedefs', '-O2'], CPPDEFINES = [f'{config["PREPROCESSOR_PREFIX"]}_RELEASE', 'NDEBUG']) - + if enable_asan: env.Append(CCFLAGS = ['-fsanitize=address', '-fno-omit-frame-pointer']) env.Append(LINKFLAGS = ['-fsanitize=address']) - + elif env['COMPILER_FAMILY'] == 'cl': # C4201: nonstandard extension used : nameless struct/union - I use it and want to continue using it # C4127: conditional expression is constant - some libs (CRC, format) don't compile with this enabled # TODO: fix? @@ -395,6 +416,7 @@ env.AddMethod(_cook, 'Cook') env.AddMethod(_parse_lib_conf, 'ParseLibConf') env.AddMethod(_rglob, 'RGlob') env.AddMethod(_make_interface, 'MakeInterface') +env.AddMethod(_find_lib, 'FindLib') env.AddMethod(_error, 'Error') env.AddMethod(_wrap_builder(env.Library, is_lib = True), 'Library') env.AddMethod(_wrap_builder(env.StaticLibrary, is_lib = True), 'StaticLibrary') diff --git a/recipes/CMakeProject/recipe.py b/recipes/CMakeProject/recipe.py index 936e7c6..a62655e 100644 --- a/recipes/CMakeProject/recipe.py +++ b/recipes/CMakeProject/recipe.py @@ -33,9 +33,15 @@ def cook(env: Environment, project_root: str, generate_args: 'list[str]' = [], b run_cmd(['cmake', '--install', *install_args, cmd_quote(build_dir)]) pathlib.Path(install_dir, _BUILT_STAMPFILE).touch() + libpath = [] + for lib_folder in ('lib', 'lib64'): + full_path = os.path.join(install_dir, lib_folder) + if os.path.exists(full_path): + libpath.append(full_path) + return { 'install_dir': install_dir, - 'LIBPATH': [os.path.join(install_dir, 'lib')], + 'LIBPATH': libpath, 'CPPPATH': [os.path.join(install_dir, 'include')] } diff --git a/recipes/ImageMagick/recipe.py b/recipes/ImageMagick/recipe.py new file mode 100644 index 0000000..7adc0a1 --- /dev/null +++ b/recipes/ImageMagick/recipe.py @@ -0,0 +1,12 @@ + +from SCons.Script import * + +def cook(env: Environment, git_ref = 'main') -> dict: + repo = env.Cook('GitBranch', repo_name = 'ImageMagick', remote_url = 'https://github.com/ImageMagick/ImageMagick.git', git_ref = git_ref) + checkout_root = repo['checkout_root'] + build_result = env.Cook('AutotoolsProject', checkout_root) + return { + 'LIBPATH': build_result['LIBPATH'], + 'CPPPATH': build_result['CPPPATH'], + 'LIBS': ['backtrace'] + } diff --git a/recipes/libjpeg-turbo/recipe.py b/recipes/libjpeg-turbo/recipe.py new file mode 100644 index 0000000..3c1afe6 --- /dev/null +++ b/recipes/libjpeg-turbo/recipe.py @@ -0,0 +1,11 @@ + +from SCons.Script import * + +def cook(env: Environment, git_ref = 'main') -> dict: + repo = env.Cook('GitBranch', repo_name = 'libjpeg-turbo', remote_url = 'https://github.com/libjpeg-turbo/libjpeg-turbo.git', git_ref = git_ref) + checkout_root = repo['checkout_root'] + build_result = env.Cook('CMakeProject', checkout_root) + return { + 'CPPPATH': build_result['CPPPATH'], + 'LIBS': [env.FindLib('jpeg', paths=build_result['LIBPATH'])], + } diff --git a/recipes/libpng/recipe.py b/recipes/libpng/recipe.py index 764bb39..10f1632 100644 --- a/recipes/libpng/recipe.py +++ b/recipes/libpng/recipe.py @@ -2,11 +2,12 @@ from SCons.Script import * def cook(env: Environment, git_ref = 'master') -> dict: + lib_z = env.Cook('zlib') repo = env.Cook('GitBranch', repo_name = 'libpng', remote_url = 'https://git.code.sf.net/p/libpng/code.git', git_ref = git_ref) checkout_root = repo['checkout_root'] build_result = env.Cook('AutotoolsProject', checkout_root) return { - 'LIBPATH': build_result['LIBPATH'], 'CPPPATH': build_result['CPPPATH'], - 'LIBS': ['png'] + 'LIBS': [env.FindLib('png16', paths=build_result['LIBPATH'])], + 'DEPENDENCIES': [lib_z] } diff --git a/recipes/zlib/recipe.py b/recipes/zlib/recipe.py new file mode 100644 index 0000000..9a52032 --- /dev/null +++ b/recipes/zlib/recipe.py @@ -0,0 +1,12 @@ + +import os +from SCons.Script import * + +def cook(env: Environment, git_ref: str = 'master') -> dict: + repo = env.Cook('GitBranch', repo_name = 'zlib', remote_url = 'https://github.com/madler/zlib.git', git_ref = git_ref) + extracted_root = repo['checkout_root'] + build_result = env.Cook('CMakeProject', project_root=extracted_root) + return { + 'CPPPATH': [os.path.join(build_result['install_dir'], 'install')], + 'LIBS': [env.FindLib('z', paths=build_result['LIBPATH'])] + }