Skip to content

Commit

Permalink
Merge pull request managarm#1122 from qookei/freestnd-hdrs-option
Browse files Browse the repository at this point in the history
meson: Add option to prevent using freestnd-c{,xx}-hdrs
  • Loading branch information
mintsuki authored Sep 7, 2024
2 parents d584611 + 69abd01 commit a4a0cdf
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ The following custom meson options are accepted, in addition to the [built-in op
- `build_tests`: Build the test suite (see below).
- `disable_x_option`: Disable `x` component of mlibc functionality. See `meson_options.txt` for a full list of possible values for `x`. This may be used to e.g disable POSIX and glibc extensions.
- `linux_kernel_headers`: Allows for directing mlibc to installed linux headers. [These can be obtained easily](https://docs.kernel.org/kbuild/headers_install.html), placed in a directory and this option set to the corresponding path. This is required if the linux option is enabled, i.e. when the linux option is not disabled.
- `use_freestnd_hdrs`: Use freestnd-c{,xx}-hdrs instead of looking for compiler headers. Useful if not using a compiler with the correct target triple.

The type of library to be built (static, shared, or both) is controlled by meson's `default_library` option. Passing `-Ddefault_library=static` effectively disables the dynamic linker.

Expand Down
16 changes: 10 additions & 6 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,25 @@ internal_conf = configuration_data()
mlibc_conf = configuration_data()

if not headers_only
add_languages('c', 'cpp')
c_compiler = meson.get_compiler('c')
cpp_compiler = meson.get_compiler('cpp')

target_triple = run_command(c_compiler.cmd_array(), '-dumpmachine', check: true).stdout()
use_freestnd_hdrs = get_option('use_freestnd_hdrs').disable_auto_if(
target_triple.to_lower().contains('mlibc'))

freestnd_c_hdrs_dep = dependency(
'freestnd-c-hdrs-' + host_machine.cpu_family(),
required: false,
required: use_freestnd_hdrs,
fallback: ['freestnd-c-hdrs', 'freestnd_c_hdrs_dep'],
)
libc_deps += freestnd_c_hdrs_dep
rtld_deps += freestnd_c_hdrs_dep

freestnd_cxx_hdrs_dep = dependency(
'freestnd-cxx-hdrs-' + host_machine.cpu_family(),
required: false,
required: use_freestnd_hdrs,
fallback: ['freestnd-cxx-hdrs', 'freestnd_cxx_hdrs_dep'],
)
libc_deps += freestnd_cxx_hdrs_dep
Expand All @@ -67,10 +75,6 @@ if not headers_only
libc_deps += frigg_dep
rtld_deps += frigg_dep

add_languages('c', 'cpp')
c_compiler = meson.get_compiler('c')
cpp_compiler = meson.get_compiler('cpp')

add_project_arguments('-Wno-unused-function', '-D__MLIBC_BUILDING_MLIBC', language: ['c', 'cpp'])
add_project_arguments('-nostdinc', '-fno-builtin', '-ffreestanding', language: ['c', 'cpp'])
add_project_arguments('-Werror=misleading-indentation', language: ['c', 'cpp'])
Expand Down
2 changes: 2 additions & 0 deletions meson_options.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,5 @@ option('linux_kernel_headers', type: 'string', value : '')
option('default_library_paths', type: 'array', value: [])
option('debug_allocator', type : 'boolean', value : false,
description : 'Enable the debug allocator, which uses mmap for every allocation and adds guard pages for each allocation')
option('use_freestnd_hdrs', type : 'feature', value : 'auto',
description : 'Use freestnd-c{,xx}-hdrs instead of looking for compiler headers')

0 comments on commit a4a0cdf

Please sign in to comment.