Files
magnitudelib/meson.build

90 lines
2.3 KiB
Meson
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# libk 轻量级特化 libc 库
# 架构识别
arch = get_option('arch')
arch_dir = 'arch/' + arch
# libk的头文件
# 创建包含多个目录的对象
libk_inc = include_directories(
'arch', # 架构头文件路径
'src/include', # 源代码实现的头文件
arch_dir, # 架构特定头文件路径
)
# C 源文件变量声明
libk_sources = []
crt0_sources = []
# 引用编译文件添加
subdir('crt') # 启动入口实现
subdir('src') # C函数通用实现
subdir(arch_dir) # 汇编特化实现
# 生成静态库
libk = static_library(
'k-' + arch,
sources: libk_sources,
include_directories: libk_inc,
pic: false, # 内核必须固定地址
install: false, # 不安装到系统目录
override_options: [
'c_std=gnu11', # 明确C标准
],
# 编译器专属参数
c_args : [
'-nostdinc', # 禁止搜索标准头文件路径
'-ffreestanding', # 声明独立环境(无操作系统依赖)
'-fno-builtin', # 禁用GCC内置函数如memcpy
],
# 链接器专属参数
link_args : [
'-nostdlib', # 禁止链接标准库libc等
],
)
# 依赖声明
libk_dep = declare_dependency(
link_with: libk,
include_directories: libk_inc,
compile_args: [
'-DKERNEL_MODE', # 内核模式宏定义
]
)
# 生成 crt0 对象文件
cc = meson.get_compiler('c')
# 对象文件名
crt0_name = 'crt0-' + arch + '.o'
# 确保只有一个源文件crt0 通常只有一个入口文件)
if crt0_sources.length() != 1
error('crt0 must have exactly one source file')
endif
# crt0 文件
crt0_source = crt0_sources[0]
# 手动编译对象文件
crt0_obj = custom_target(
crt0_name,
input: crt0_source,
output: crt0_name,
command: [
cc.cmd_array(),
'-c', '@INPUT@',
'-o', '@OUTPUT@',
'-std=gnu11',
'-nostdinc',
'-ffreestanding',
'-fno-builtin',
'-nostdlib',
# 添加头文件搜索路径
'-I' + meson.current_source_dir() / 'arch',
'-I' + meson.current_source_dir() / 'src/include',
'-I' + meson.current_source_dir() / arch_dir,
],
build_by_default: true,
)