From 0099490350b2eb61c4b7f1370d4ddb547c8e8600 Mon Sep 17 00:00:00 2001 From: "alexey.lysiuk" Date: Wed, 30 Dec 2020 11:08:36 +0200 Subject: [PATCH] build script: move platform-specific header preparation to a dedicated function --- build.py | 51 +++++++++++++++++++++++++++++---------------------- 1 file changed, 29 insertions(+), 22 deletions(-) diff --git a/build.py b/build.py index 4fb844b2..5906cf61 100755 --- a/build.py +++ b/build.py @@ -242,6 +242,33 @@ Cflags: -I${{includedir}} {cflags} with open(pkgconfig_path + filename, 'w') as f: f.write(pc_content) + def make_platform_header(self, builder: 'Builder', header: str): + include_path = self.prefix + os.sep + 'include' + os.sep + include_platform_path = include_path + + header_parts = header.rsplit(os.sep, 1) + if len(header_parts) == 1: + header_parts.insert(0, '') + + include_platform_path += header_parts[0] + os.sep + builder.architecture() + os.makedirs(include_platform_path, exist_ok=True) + + root_header = include_path + header + shutil.move(root_header, include_platform_path) + + with open(root_header, 'w') as f: + f.write(f''' +#pragma once + +#if defined(__x86_64__) +# include "x86_64/{header_parts[1]}" +#elif defined(__aarch64__) +# include "arm64/{header_parts[1]}" +#else +# error Unknown architecture +#endif +''') + class MakeTarget(Target): def __init__(self, name=None): @@ -743,28 +770,8 @@ class FfiTarget(ConfigureMakeStaticDependencyTarget): def post_build(self, builder: 'Builder'): super().post_build(builder) - include_path = self.prefix + os.sep + 'include' + os.sep - include_platform_path = include_path + builder.architecture() - os.makedirs(include_platform_path, exist_ok=True) - - headers = ('ffi.h', 'ffitarget.h') - - for header in headers: - root_header = include_path + header - shutil.move(root_header, include_platform_path) - - with open(root_header, 'w') as f: - f.write(f''' -#pragma once - -#if defined(__x86_64__) -# include "x86_64/{header}" -#elif defined(__aarch64__) -# include "arm64/{header}" -#else -# error Unknown architecture -#endif -''') + for header in ('ffi.h', 'ffitarget.h'): + self.make_platform_header(builder, header) class FlacTarget(ConfigureMakeStaticDependencyTarget):