Skip to content

Commit

Permalink
Add `emxomf' option to generate OMF files on OS/2
Browse files Browse the repository at this point in the history
1. Generate OMF objs with `-Zomf' compiler flags
2. Generate OMF libs with `.lib' suffix using `emxomfar' as a librarian
  • Loading branch information
komh committed Jan 10, 2025
1 parent fce7944 commit 56e3d52
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 1 deletion.
6 changes: 5 additions & 1 deletion mesonbuild/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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}'
Expand Down
2 changes: 2 additions & 0 deletions mesonbuild/compilers/compilers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
7 changes: 7 additions & 0 deletions mesonbuild/compilers/detect.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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']


Expand Down Expand Up @@ -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]
Expand All @@ -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
Expand Down Expand Up @@ -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)')

Expand Down
1 change: 1 addition & 0 deletions mesonbuild/linkers/detect.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
7 changes: 7 additions & 0 deletions mesonbuild/linkers/linkers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions mesonbuild/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ class ArgparseKWs(TypedDict, total=False):
'pkg_config_path',
'cmake_prefix_path',
'vsenv',
'emxomf',
}

@total_ordering
Expand Down Expand Up @@ -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'),
Expand Down

0 comments on commit 56e3d52

Please sign in to comment.