summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKO Myung-Hun <komh@chollian.net>2023-11-08 22:08:54 +0900
committerDylan Baker <dylan@pnwbakers.com>2025-11-14 08:16:23 -0800
commit9d26b9713931ffe67c1b7ec79eb1e8c03839fd89 (patch)
tree077682f75e750557d8bbe3bcda3d82ff68bb7af3
parent6b87395b15a16a353ca28ad641dc7ff71de5f1e6 (diff)
downloadmeson-9d26b9713931ffe67c1b7ec79eb1e8c03839fd89.tar.gz
Add `os2_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
-rw-r--r--docs/markdown/Builtin-options.md11
-rw-r--r--mesonbuild/build.py7
-rw-r--r--mesonbuild/compilers/detect.py6
-rw-r--r--mesonbuild/compilers/mixins/gnu.py6
-rw-r--r--mesonbuild/linkers/detect.py13
-rw-r--r--mesonbuild/linkers/linkers.py17
-rw-r--r--mesonbuild/options.py2
-rw-r--r--mesonbuild/utils/universal.py1
8 files changed, 57 insertions, 6 deletions
diff --git a/docs/markdown/Builtin-options.md b/docs/markdown/Builtin-options.md
index da9fc8d44..5b4da125b 100644
--- a/docs/markdown/Builtin-options.md
+++ b/docs/markdown/Builtin-options.md
@@ -98,6 +98,7 @@ machine](#specifying-options-per-machine) section for details.
| wrap_mode {default, nofallback,<br>nodownload, forcefallback, nopromote} | default | Wrap mode to use | no | no |
| force_fallback_for | [] | Force fallback for those dependencies | no | no |
| vsenv | false | Activate Visual Studio environment | no | no |
+| os2_emxomf | false | Use OMF format on OS/2 | no | no |
(For the Rust language only, `warning_level=0` disables all warnings).
@@ -203,6 +204,16 @@ When `default_both_libraries` is 'auto', passing a [[@both_libs]] dependency
in [[both_libraries]] will link the static dependency with the static lib,
and the shared dependency with the shared lib.
+#### Details for `os2_emxomf`
+
+The `--os2_emxomf` argument is supported since `1.10.0`, `-Dos2_emxomf=true`
+syntax is supported since `1.10.0`.
+
+Setting the `os2_emxomf` option to `true` forces to use emxomf toolchains in
+order to generate OMF files instead of aout toolchains.
+
+`os2_emxomf` is `false` by default.
+
## Base options
These are set in the same way as universal options, either by
diff --git a/mesonbuild/build.py b/mesonbuild/build.py
index 2a095b022..90cb4666d 100644
--- a/mesonbuild/build.py
+++ b/mesonbuild/build.py
@@ -2369,6 +2369,8 @@ class StaticLibrary(BuildTarget):
suffix = 'rlib'
elif self.rust_crate_type == 'staticlib':
suffix = 'a'
+ elif self.environment.machines[self.for_machine].is_os2() and self.environment.coredata.optstore.get_value_for(OptionKey('os2_emxomf')):
+ suffix = 'lib'
else:
suffix = 'a'
if 'c' in self.compilers and self.compilers['c'].get_id() == 'tasking' and not self.prelink:
@@ -2559,8 +2561,9 @@ class SharedLibrary(BuildTarget):
# Shared library is of the form foo.dll
prefix = prefix if prefix is not None else ''
suffix = suffix if suffix is not None else 'dll'
- # Import library is called foo_dll.a
- import_suffix = import_suffix if import_suffix is not None else '_dll.a'
+ # Import library is called foo_dll.a or foo_dll.lib
+ if import_suffix is None:
+ import_suffix = '_dll.lib' if self.environment.coredata.optstore.get_value_for(OptionKey('os2_emxomf')) else '_dll.a'
import_filename_tpl = '{0.prefix}{0.name}' + import_suffix
filename_tpl = '{0.shortname}' if self.shortname else '{0.prefix}{0.name}'
if self.soversion:
diff --git a/mesonbuild/compilers/detect.py b/mesonbuild/compilers/detect.py
index 2dbeac04a..bf72d347c 100644
--- a/mesonbuild/compilers/detect.py
+++ b/mesonbuild/compilers/detect.py
@@ -80,6 +80,7 @@ defaults['clang_cl_static_linker'] = ['llvm-lib']
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']
@@ -158,6 +159,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]
@@ -167,6 +169,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 env.machines[compiler.for_machine].is_os2() and env.coredata.optstore.get_value_for(OptionKey('os2_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
@@ -256,6 +260,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/compilers/mixins/gnu.py b/mesonbuild/compilers/mixins/gnu.py
index 21258ce48..d8f4f68a8 100644
--- a/mesonbuild/compilers/mixins/gnu.py
+++ b/mesonbuild/compilers/mixins/gnu.py
@@ -666,6 +666,12 @@ class GnuCompiler(GnuLikeCompiler):
def get_profile_use_args(self) -> T.List[str]:
return super().get_profile_use_args() + ['-fprofile-correction']
+ def get_always_args(self) -> T.List[str]:
+ args: T.List[str] = []
+ if self.info.is_os2() and self.get_linker_id() == 'emxomfld':
+ args += ['-Zomf']
+ return super().get_always_args() + args
+
class GnuCStds(Compiler):
diff --git a/mesonbuild/linkers/detect.py b/mesonbuild/linkers/detect.py
index 4fefa2b75..5ff19ae3d 100644
--- a/mesonbuild/linkers/detect.py
+++ b/mesonbuild/linkers/detect.py
@@ -27,6 +27,7 @@ defaults['clang_cl_static_linker'] = ['llvm-lib']
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(
@@ -128,6 +129,7 @@ def guess_nix_linker(env: 'Environment', compiler: T.List[str], comp_class: T.Ty
:extra_args: Any additional arguments required (such as a source file)
"""
from . import linkers
+ from ..options import OptionKey
env.add_lang_args(comp_class.language, comp_class, for_machine)
extra_args = extra_args or []
@@ -146,6 +148,9 @@ def guess_nix_linker(env: 'Environment', compiler: T.List[str], comp_class: T.Ty
override = comp_class.use_linker_args(value[0], comp_version)
check_args += override
+ if env.machines[for_machine].is_os2() and env.coredata.optstore.get_value_for(OptionKey('os2_emxomf')):
+ check_args += ['-Zomf']
+
mlog.debug('-----')
p, o, e = Popen_safe_logged(compiler + check_args, msg='Detecting linker via')
@@ -252,8 +257,12 @@ def guess_nix_linker(env: 'Environment', compiler: T.List[str], comp_class: T.Ty
compiler, for_machine, comp_class.LINKER_PREFIX, override,
system=system, version=v
)
- elif 'ld.exe: unrecognized option' in e or 'emxomfld: invalid option' in e:
- linker = linkers.OS2DynamicLinker(
+ elif 'ld.exe: unrecognized option' in e:
+ linker = linkers.OS2AoutDynamicLinker(
+ compiler, for_machine, comp_class.LINKER_PREFIX, override,
+ version='none')
+ elif 'emxomfld: invalid option' in e:
+ linker = linkers.OS2OmfDynamicLinker(
compiler, for_machine, comp_class.LINKER_PREFIX, override,
version='none')
else:
diff --git a/mesonbuild/linkers/linkers.py b/mesonbuild/linkers/linkers.py
index b28c71491..ce9ca4f37 100644
--- a/mesonbuild/linkers/linkers.py
+++ b/mesonbuild/linkers/linkers.py
@@ -571,6 +571,13 @@ class TaskingStaticLinker(StaticLinker):
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
@@ -1825,8 +1832,6 @@ class TaskingLinker(DynamicLinker):
class OS2DynamicLinker(PosixDynamicLinkerMixin, DynamicLinker):
"""ld and emxomfld"""
- id = 'ld.os2'
-
def get_allow_undefined_args(self) -> T.List[str]:
return []
@@ -1842,3 +1847,11 @@ class OS2DynamicLinker(PosixDynamicLinkerMixin, DynamicLinker):
def get_always_args(self) -> T.List[str]:
return ['-Zomf']
+
+
+class OS2AoutDynamicLinker(OS2DynamicLinker):
+ id = 'ld.os2'
+
+
+class OS2OmfDynamicLinker(OS2DynamicLinker):
+ id = 'emxomfld'
diff --git a/mesonbuild/options.py b/mesonbuild/options.py
index 196bb6cb5..1ae07fdbc 100644
--- a/mesonbuild/options.py
+++ b/mesonbuild/options.py
@@ -105,6 +105,7 @@ _BUILTIN_NAMES = {
'pkg_config_path',
'cmake_prefix_path',
'vsenv',
+ 'os2_emxomf',
}
_BAD_VALUE = 'Qwert Zuiopü'
@@ -733,6 +734,7 @@ BUILTIN_CORE_OPTIONS: T.Mapping[OptionKey, AnyOptionType] = {
UserComboOption('wrap_mode', 'Wrap mode', 'default', choices=['default', 'nofallback', 'nodownload', 'forcefallback', 'nopromote']),
UserStringArrayOption('force_fallback_for', 'Force fallback for those subprojects', []),
UserBooleanOption('vsenv', 'Activate Visual Studio environment', False, readonly=True),
+ UserBooleanOption('os2_emxomf', 'Use OMF format on OS/2', False),
# Pkgconfig module
UserBooleanOption('pkgconfig.relocatable', 'Generate pkgconfig files as relocatable', False),
diff --git a/mesonbuild/utils/universal.py b/mesonbuild/utils/universal.py
index db187f0b0..467d4f5d5 100644
--- a/mesonbuild/utils/universal.py
+++ b/mesonbuild/utils/universal.py
@@ -2243,6 +2243,7 @@ _BUILTIN_NAMES = {
'pkg_config_path',
'cmake_prefix_path',
'vsenv',
+ 'os2_emxomf',
}