From 7dd6671f98887869f59fc0780810256f8f2837c8 Mon Sep 17 00:00:00 2001 From: Stas Sergeev Date: Sun, 29 Dec 2024 21:27:40 +0300 Subject: [PATCH 1/2] mason: build kernel as executable [#146] ... instead of custom_target. This is very interesting, as it now uses clang -nostdlib for linking, which seems to work. This will probably simplify the cross-compilation, in case clang can find the proper cross ld. --- fdpp/kernel/meson.build | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/fdpp/kernel/meson.build b/fdpp/kernel/meson.build index b755993d..bded24c7 100644 --- a/fdpp/kernel/meson.build +++ b/fdpp/kernel/meson.build @@ -66,21 +66,15 @@ SRCS = [ nargs = ['-DXCPU=186', '-DWITHFAT32', '-DFDPP'] -lib = static_library('dummy', +executable(TARGET + '.elf', [SRCS, sfiles, plt_inc], include_directories: incdir2, nasm_args: nargs, - build_by_default: false) -nasm_ld = find_program(['i686-linux-gnu-ld', 'i386-elf-ld', 'x86_64-linux-gnu-ld', 'ld.bfd']) -custom_target(TARGET + '.elf', - output: [TARGET + '.elf', TARGET + '.map'], - input: lib.extract_all_objects(recursive: true), - command: [nasm_ld, '-melf_i386', '-static', - '-Map=@OUTPUT1@', '-o', '@OUTPUT0@', - '--emit-relocs', '-T' + kernel_ld, '@INPUT@'], + link_args: ['-Wl,-melf_i386', '-Wl,-static', + '-Wl,-Map=' + TARGET + '.map', '-nostdlib', + '-Wl,--emit-relocs', '-Wl,-T' + kernel_ld], install: true, install_dir: get_option('datadir') / 'fdpp', - install_mode: 'rw-r--r--', - build_by_default: true) + install_mode: 'rw-r--r--') VERSION = meson.project_version() From 0db3eea9e61a6ec30eb2758f6a7bb878348b1b3e Mon Sep 17 00:00:00 2001 From: Stas Sergeev Date: Mon, 30 Dec 2024 00:14:03 +0300 Subject: [PATCH 2/2] meson: run thunk_gen via make [#146] Who says that meson should not use make? It seems, mixing those 2 produces good results. :) --- fdpp/meson.build | 43 +++++++++++++++++++------------------------ fdpp/run_arg_in.sh | 10 ++++++++++ fdpp/run_arg_out.sh | 8 ++++++++ 3 files changed, 37 insertions(+), 24 deletions(-) create mode 100755 fdpp/run_arg_in.sh create mode 100755 fdpp/run_arg_out.sh diff --git a/fdpp/meson.build b/fdpp/meson.build index 452840b4..859438be 100644 --- a/fdpp/meson.build +++ b/fdpp/meson.build @@ -3,12 +3,11 @@ project('libfdpp', ['c', 'cpp'], default_options: ['cpp_std=c++20'], MF = meson.current_source_dir() / 'parsers/mkfar.sh' PD = meson.current_source_dir() / 'parsers/parse_decls.sh' +RAI = meson.current_source_dir() / 'run_arg_in.sh' +RAO = meson.current_source_dir() / 'run_arg_out.sh' tg = dependency('thunk_gen') -TG = tg.get_variable(pkgconfig: 'binary') -MA = tg.get_variable(pkgconfig: 'mkadscript') -TGS = tg.get_variable(pkgconfig: 'tgscript') -TGM4 = tg.get_variable(pkgconfig: 'm4script') -TFLAGS = ['-a', '2', '-p', '2'] +TGMK = tg.get_variable(pkgconfig: 'makeinc') +TFLAGS = '-a 2 -p 2' SRC = 'src' rel_inc = 'include/fdpp' incdir = include_directories(rel_inc) @@ -61,10 +60,13 @@ ccgen = generator(find_program(MF), capture: true) ccfiles = ccgen.process(CFILES) +make = find_program('make') + gad = custom_target('glob_asmdefs.h', output: 'glob_asmdefs.h', input: 'src/glob_asm.h', - command: [MA, '@INPUT@'], + command: [RAO, 'glob_asmdefs.h', make, '-f', TGMK, + 'glob_asmdefs.h', 'GLOB_ASM=@INPUT@'], capture: true) GEN_TMP = { '1':'thunk_calls.tmp', '2':'thunk_asms.tmp' } @@ -97,32 +99,25 @@ pap = custom_target('plt_asmp.h', env: env, capture: true) +tgenv = environment() +tgenv.set('TFLAGS', TFLAGS) + tc = custom_target('thunk_calls.h', output: 'thunk_calls.h', input: GEN['thunk_calls.tmp'], - command: [TG, TFLAGS], - feed: true, - capture: true) - -ta1 = custom_target('thunk_asms1.h', - output: 'thunk_asms1.h', - input: GEN['thunk_asms.tmp'], - command: [TG, TFLAGS, '1'], - feed: true, - capture: true) - -ta2 = custom_target('thunk_asms2.h', - output: 'thunk_asms2.h', - input: GEN['thunk_asms.tmp'], - command: [TG, TFLAGS, '2'], + command: [RAI, 'thunk_calls.tmp', 'thunk_calls.h', + make, '-f', TGMK, 'thunk_calls.h'], + env: tgenv, feed: true, capture: true) ta = custom_target('thunk_asms.h', output: 'thunk_asms.h', - input: [ta1, ta2], - command: ['sh', '-c', 'cat @INPUT0@ | ' + TGS + ' ' + TGM4 + - ' | cat - @INPUT1@'], + input: GEN['thunk_asms.tmp'], + command: [RAI, 'thunk_asms.tmp', 'thunk_asms.h', + make, '-f', TGMK, 'thunk_asms.h'], + env: tgenv, + feed: true, capture: true) FDPP_CFILES = ['smalloc.c', 'farhlp_sta.c'] diff --git a/fdpp/run_arg_in.sh b/fdpp/run_arg_in.sh new file mode 100755 index 00000000..3785965a --- /dev/null +++ b/fdpp/run_arg_in.sh @@ -0,0 +1,10 @@ +#!/bin/sh + +cat >$1 +shift +OUT=$1 +shift +PRG=$1 +shift +$PRG $* 1>&2 +cat $OUT diff --git a/fdpp/run_arg_out.sh b/fdpp/run_arg_out.sh new file mode 100755 index 00000000..60ec1afa --- /dev/null +++ b/fdpp/run_arg_out.sh @@ -0,0 +1,8 @@ +#!/bin/sh + +OUT=$1 +shift +PRG=$1 +shift +$PRG $* 1>&2 +cat $OUT