libucontext/meson.build

168 lines
3.2 KiB
Meson
Raw Normal View History

2021-01-03 05:15:53 +00:00
project(
'libucontext',
'c',
meson_version : '>=0.55.0',
default_options: ['c_std=gnu11', 'default_library=both'],
2021-01-03 05:15:53 +00:00
version : run_command('head', files('VERSION')).stdout()
)
cpu = host_machine.cpu_family()
if cpu == 'sh4'
cpu = 'sh'
endif
project_description = 'Portable implementation of ucontext'
project_headers = [
'include/libucontext/libucontext.h'
]
project_source_files = [
'arch' / cpu / 'getcontext.S',
'arch' / cpu / 'setcontext.S',
'arch' / cpu / 'swapcontext.S',
]
if cpu in ['mips', 'mips64']
project_source_files += [
'arch' / cpu / 'makecontext.S'
]
else
project_source_files += [
'arch' / cpu / 'makecontext.c'
]
endif
if cpu in ['ppc', 'ppc64']
project_source_files += [
'arch' / cpu / 'retfromsyscall.c'
]
endif
if cpu not in ['mips', 'mips64', 'ppc', 'ppc64', 's390x']
project_source_files += [
'arch' / cpu / 'trampoline.c'
]
2021-01-08 13:55:51 +00:00
else
project_source_files += [
'arch' / cpu / 'startcontext.S'
]
2021-01-03 05:15:53 +00:00
endif
project_includes = [
'include',
'arch/common'
]
build_args = [
'-D_BSD_SOURCE'
2021-01-03 05:15:53 +00:00
]
# ===================================================================
# ======
# Options
# ======
freestanding = get_option('freestanding')
export_unprefixed = get_option('export_unprefixed')
build_posix = true
if freestanding
build_args += '-DFREESTANDING'
build_posix = false
export_unprefixed = false
2021-01-08 13:55:51 +00:00
project_headers += ['arch' / cpu / 'freestanding/bits.h']
2021-01-03 05:15:53 +00:00
else
2021-01-08 13:55:51 +00:00
project_headers += ['arch/common/bits.h']
2021-01-03 05:15:53 +00:00
endif
if export_unprefixed
build_args += '-DEXPORT_UNPREFIXED'
endif
# ======
# Target
# ======
headers = include_directories(project_includes)
libucontext_target = library(
2021-01-03 05:15:53 +00:00
'ucontext',
project_source_files,
2021-01-09 07:55:58 +00:00
version: '1',
install : not meson.is_subproject(),
2021-01-03 05:15:53 +00:00
c_args : build_args,
2021-01-08 13:55:51 +00:00
pic: true,
2021-01-03 05:15:53 +00:00
include_directories : headers,
)
libucontext_dep = declare_dependency(
include_directories: headers,
link_with : libucontext_target
)
if build_posix
libucontext_posix_target = library(
2021-01-03 05:15:53 +00:00
'ucontext_posix',
project_source_files + ['libucontext_posix.c'],
2021-01-09 07:55:58 +00:00
version: '1',
install : not meson.is_subproject(),
2021-01-03 05:15:53 +00:00
c_args : build_args,
2021-01-08 13:55:51 +00:00
pic: true,
2021-01-03 05:15:53 +00:00
include_directories : headers,
)
libucontext_posix_dep = declare_dependency(
include_directories: headers,
link_with : libucontext_posix_target
)
endif
# =======
# Project
# =======
if not meson.is_subproject()
2021-01-03 05:15:53 +00:00
# Make this library usable from the system's
# package manager.
install_headers(project_headers, subdir : meson.project_name())
pkg_mod = import('pkgconfig')
pkg_mod.generate(
name : meson.project_name(),
filebase : meson.project_name(),
description : project_description,
subdirs : meson.project_name(),
libraries : libucontext_target,
)
endif
# ====
# Docs
# ====
# TODO: meson.build for docs
if not meson.is_subproject()
2021-01-03 05:15:53 +00:00
#subdir('docs')
endif
# ==========
# Unit Tests
# ==========
test('test_libucontext',
executable(
'test_libucontext',
files('test_libucontext.c'),
dependencies : libucontext_dep,
install : false
)
)
if build_posix
test('test_libucontext_posix',
2021-01-03 05:15:53 +00:00
executable(
'test_libucontext_posix',
files('test_libucontext_posix.c'),
dependencies : [libucontext_dep, libucontext_posix_dep],
2021-01-03 05:15:53 +00:00
install : false
)
)
endif