From 56e3d52d7da23ff308767396dda2a15389f88bb2 Mon Sep 17 00:00:00 2001 From: KO Myung-Hun Date: Wed, 8 Nov 2023 22:08:54 +0900 Subject: [PATCH] Add `emxomf' option to generate OMF files on OS/2 1. Generate OMF objs with `-Zomf' compiler flags 2. Generate OMF libs with `.lib' suffix using `emxomfar' as a librarian --- mesonbuild/build.py | 6 +++++- mesonbuild/compilers/compilers.py | 2 ++ mesonbuild/compilers/detect.py | 7 +++++++ mesonbuild/linkers/detect.py | 1 + mesonbuild/linkers/linkers.py | 7 +++++++ mesonbuild/options.py | 2 ++ 6 files changed, 24 insertions(+), 1 deletion(-) diff --git a/mesonbuild/build.py b/mesonbuild/build.py index b34c798e23bf..b2e86c85b1ec 100644 --- a/mesonbuild/build.py +++ b/mesonbuild/build.py @@ -2175,6 +2175,8 @@ def post_init(self) -> None: self.suffix = 'rlib' elif self.rust_crate_type == 'staticlib': self.suffix = 'a' + elif self.environment.machines[self.for_machine].is_os2() and self.get_option(OptionKey('emxomf')): + self.suffix = 'lib' else: if 'c' in self.compilers and self.compilers['c'].get_id() == 'tasking': self.suffix = 'ma' if self.options.get_value('b_lto') and not self.prelink else 'a' @@ -2375,7 +2377,9 @@ def determine_filenames(self): self.filename_tpl = '{0.prefix}{0.name}.{0.suffix}' elif self.environment.machines[self.for_machine].is_os2(): suffix = 'dll' - import_filename_tpl = '{0.name}_dll.a' + # Import library is called foo_dll.a or foo_dll.lib + import_filename_tpl = '{0.name}_dll' + import_filename_tpl += '.lib' if self.environment.coredata.get_option(OptionKey('emxomf')) else '.a' self.filename_tpl = '{0.shortname}' if self.shortname else '{0.name}' if self.soversion: self.filename_tpl += '{0.soversion}' diff --git a/mesonbuild/compilers/compilers.py b/mesonbuild/compilers/compilers.py index 58669706214f..a51473fb0f52 100644 --- a/mesonbuild/compilers/compilers.py +++ b/mesonbuild/compilers/compilers.py @@ -293,6 +293,8 @@ def are_asserts_disabled(options: KeyedOptionDictType) -> bool: def get_base_compile_args(options: 'KeyedOptionDictType', compiler: 'Compiler', env: 'Environment') -> T.List[str]: args: T.List[str] = [] + if mesonlib.is_os2() and options[OptionKey('emxomf')].value: + args += ['-Zomf'] try: if options.get_value(OptionKey('b_lto')): args.extend(compiler.get_lto_compile_args( diff --git a/mesonbuild/compilers/detect.py b/mesonbuild/compilers/detect.py index 7bd48d10c320..9ee9138498d3 100644 --- a/mesonbuild/compilers/detect.py +++ b/mesonbuild/compilers/detect.py @@ -6,6 +6,7 @@ from ..mesonlib import ( MesonException, EnvironmentException, MachineChoice, join_args, search_version, is_windows, Popen_safe, Popen_safe_logged, windows_proof_rm, + is_os2, ) from ..envconfig import BinaryTable from .. import mlog @@ -78,6 +79,7 @@ defaults['cuda_static_linker'] = ['nvlink'] defaults['gcc_static_linker'] = ['gcc-ar'] defaults['clang_static_linker'] = ['llvm-ar'] +defaults['emxomf_static_linker'] = ['emxomfar'] defaults['nasm'] = ['nasm', 'yasm'] @@ -156,6 +158,7 @@ def _handle_exceptions( def detect_static_linker(env: 'Environment', compiler: Compiler) -> StaticLinker: from . import d from ..linkers import linkers + from ..options import OptionKey linker = env.lookup_binary_entry(compiler.for_machine, 'ar') if linker is not None: trials = [linker] @@ -165,6 +168,8 @@ def detect_static_linker(env: 'Environment', compiler: Compiler) -> StaticLinker trials = [defaults['cuda_static_linker']] + default_linkers elif compiler.get_argument_syntax() == 'msvc': trials = [defaults['vs_static_linker'], defaults['clang_cl_static_linker']] + elif is_os2() and env.coredata.get_option(OptionKey('emxomf')): + trials = [defaults['emxomf_static_linker']] + default_linkers elif compiler.id == 'gcc': # Use gcc-ar if available; needed for LTO trials = [defaults['gcc_static_linker']] + default_linkers @@ -251,6 +256,8 @@ def detect_static_linker(env: 'Environment', compiler: Compiler) -> StaticLinker return linkers.AIXArLinker(linker) if p.returncode == 1 and err.startswith('ar: bad option: --'): # Solaris return linkers.ArLinker(compiler.for_machine, linker) + if p.returncode == 1 and err.startswith('emxomfar'): + return linkers.EmxomfArLinker(compiler.for_machine, linker) _handle_exceptions(popen_exceptions, trials, 'linker') raise EnvironmentException('Unreachable code (exception to make mypy happy)') diff --git a/mesonbuild/linkers/detect.py b/mesonbuild/linkers/detect.py index a7504a5b1fbd..c927c8e209ae 100644 --- a/mesonbuild/linkers/detect.py +++ b/mesonbuild/linkers/detect.py @@ -27,6 +27,7 @@ defaults['cuda_static_linker'] = ['nvlink'] defaults['gcc_static_linker'] = ['gcc-ar'] defaults['clang_static_linker'] = ['llvm-ar'] +defaults['emxomf_static_linker'] = ['emxomfar'] def __failed_to_detect_linker(compiler: T.List[str], args: T.List[str], stdout: str, stderr: str) -> 'T.NoReturn': msg = 'Unable to detect linker for compiler `{}`\nstdout: {}\nstderr: {}'.format( diff --git a/mesonbuild/linkers/linkers.py b/mesonbuild/linkers/linkers.py index 17926dbe351a..b4abcc31f7ec 100644 --- a/mesonbuild/linkers/linkers.py +++ b/mesonbuild/linkers/linkers.py @@ -546,6 +546,13 @@ def get_output_args(self, target: str) -> T.List[str]: def get_linker_always_args(self) -> T.List[str]: return ['-r'] + +class EmxomfArLinker(ArLinker): + id = 'emxomfar' + + def get_std_link_args(self, env: 'Environment', is_thin: bool) -> T.List[str]: + return ['cr'] + def prepare_rpaths(raw_rpaths: T.Tuple[str, ...], build_dir: str, from_dir: str) -> T.List[str]: # The rpaths we write must be relative if they point to the build dir, # because otherwise they have different length depending on the build diff --git a/mesonbuild/options.py b/mesonbuild/options.py index 1566f940c98c..12fef00ccdd4 100644 --- a/mesonbuild/options.py +++ b/mesonbuild/options.py @@ -88,6 +88,7 @@ class ArgparseKWs(TypedDict, total=False): 'pkg_config_path', 'cmake_prefix_path', 'vsenv', + 'emxomf', } @total_ordering @@ -647,6 +648,7 @@ def add_to_argparse(self, name: str, parser: argparse.ArgumentParser, help_suffi (OptionKey('wrap_mode'), BuiltinOption(UserComboOption, 'Wrap mode', 'default', choices=['default', 'nofallback', 'nodownload', 'forcefallback', 'nopromote'])), (OptionKey('force_fallback_for'), BuiltinOption(UserArrayOption, 'Force fallback for those subprojects', [])), (OptionKey('vsenv'), BuiltinOption(UserBooleanOption, 'Activate Visual Studio environment', False, readonly=True)), + (OptionKey('emxomf'), BuiltinOption(UserBooleanOption, "Whether to use OMF format on OS/2", False)), # Pkgconfig module (OptionKey('pkgconfig.relocatable'),