162 lines
3.9 KiB
Meson
162 lines
3.9 KiB
Meson
project(
|
|
'zinnia',
|
|
license: 'ISC',
|
|
version: '0.1.0',
|
|
meson_version: '>=1.5.0',
|
|
default_options: [
|
|
'c_std=gnu23',
|
|
'werror=true',
|
|
'warning_level=2',
|
|
'strip=true',
|
|
],
|
|
)
|
|
|
|
if get_option('headers_only')
|
|
install_subdir('include/uapi', install_dir: get_option('includedir'))
|
|
pkg = import('pkgconfig')
|
|
pkg.generate(name: 'zinnia', description: 'Zinnia user API')
|
|
subdir_done()
|
|
endif
|
|
|
|
add_languages('c', native: false, required: true)
|
|
|
|
# Check if we're using a sane compiler.
|
|
c_compiler = meson.get_compiler('c')
|
|
|
|
# We require a compiler that supports the GNU C dialect.
|
|
assert(c_compiler.has_define('__GNUC__'))
|
|
|
|
add_project_arguments(
|
|
'-Wno-unused',
|
|
'-Wno-unused-parameter',
|
|
'-fno-stack-protector',
|
|
'-ffunction-sections',
|
|
'-fdata-sections',
|
|
'-ffreestanding',
|
|
'-fno-stack-protector',
|
|
language: 'c',
|
|
)
|
|
|
|
add_project_link_arguments(
|
|
'-ffreestanding',
|
|
'-nostdlib',
|
|
'-znoexecstack',
|
|
'-Wl,--gc-sections',
|
|
'-Wl,--build-id=none',
|
|
language: 'c',
|
|
)
|
|
|
|
common_includes = [
|
|
include_directories('include'),
|
|
include_directories('arch' / target_machine.cpu_family() / 'include'),
|
|
]
|
|
|
|
cfg = configuration_data()
|
|
cfg.set_quoted('ZINNIA_VERSION', meson.project_version())
|
|
cfg.set_quoted('ZINNIA_ARCH', target_machine.cpu_family())
|
|
cfg.set_quoted('ZINNIA_COMPILER_ID', c_compiler.get_id() + ' ' + c_compiler.version())
|
|
cfg.set_quoted('ZINNIA_LINKER_ID', c_compiler.get_linker_id())
|
|
|
|
# Parse kernel config
|
|
kv = import('keyval')
|
|
kconfig = kv.load(get_option('config_path'))
|
|
foreach k, v : kconfig
|
|
if v == 'y'
|
|
cfg.set10(k, true)
|
|
elif v == 'n'
|
|
cfg.set10(k, false)
|
|
else
|
|
cfg.set(k, v)
|
|
endif
|
|
endforeach
|
|
|
|
kernel_c_args = ['-DIN_KERNEL']
|
|
|
|
kernel_lds = meson.current_source_dir() / 'boot' / 'kernel.ld'
|
|
kernel_link_args = [
|
|
'-T' + kernel_lds,
|
|
'-Wl,--export-dynamic',
|
|
]
|
|
|
|
kernel_includes = []
|
|
kernel_sources = []
|
|
modules = {}
|
|
|
|
# These dirs go first so we can add arch-specific flags to drivers.
|
|
subdir('arch' / target_machine.cpu_family())
|
|
subdir('boot')
|
|
subdir('core')
|
|
subdir('syscalls')
|
|
|
|
# Device and file system drivers.
|
|
subdir('dev')
|
|
subdir('fs')
|
|
|
|
configure_file(
|
|
configuration: cfg,
|
|
output: 'config.h',
|
|
)
|
|
|
|
mod_summary = {}
|
|
foreach name, v : modules
|
|
is_modular = v.get('modular', false)
|
|
mod_sources = v.get('sources')
|
|
mod_c_args = v.get('c_args', [])
|
|
mod_link_args = v.get('link_args', [])
|
|
mod_includes = v.get('include_directories', [])
|
|
mod_link = v.get('link_with', [])
|
|
|
|
if is_modular
|
|
shared_library(
|
|
name,
|
|
sources: mod_sources,
|
|
c_args: ['-fPIC', '-fPIE', '-DIN_MODULE', mod_c_args],
|
|
link_args: [
|
|
'-T' + module_lds, mod_link_args,
|
|
],
|
|
link_depends: module_lds,
|
|
include_directories: [
|
|
common_includes,
|
|
kernel_includes, # We want this, actually
|
|
mod_includes,
|
|
],
|
|
name_prefix: '',
|
|
name_suffix: 'kso',
|
|
link_with: mod_link,
|
|
override_options: ['b_lundef=false'],
|
|
#link_depends: kernel.full_path(),
|
|
)
|
|
else
|
|
kernel_sources += mod_sources
|
|
kernel_c_args += mod_c_args
|
|
kernel_includes += mod_includes
|
|
kernel_link_args += mod_link_args
|
|
endif
|
|
|
|
if is_modular
|
|
mod_summary += {name: 'mod'}
|
|
else
|
|
mod_summary += {name: 'builtin'}
|
|
endif
|
|
endforeach
|
|
|
|
# Kernel
|
|
executable(
|
|
'zinnia',
|
|
include_directories: [
|
|
common_includes,
|
|
kernel_includes,
|
|
],
|
|
c_args: [kernel_c_args],
|
|
link_args: kernel_link_args,
|
|
link_depends: kernel_lds,
|
|
sources: kernel_sources,
|
|
install: true,
|
|
install_dir: get_option('datadir') / 'zinnia',
|
|
pie: true,
|
|
)
|
|
|
|
# Print a summary
|
|
summary(mod_summary, section: 'Driver configuration')
|
|
summary(kconfig, bool_yn: true, section: 'Kernel configuration')
|