Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Meson #240

Merged
merged 5 commits into from
Dec 6, 2023
Merged

Meson #240

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion fdpp/cdata.S → fdpp/kernel/cdata.S
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*/

%include "segs.inc"
#include "../hdr/version.h"
#include "version.h"

segment CONST2

Expand Down
12 changes: 7 additions & 5 deletions fdpp/kernel/makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ PPINC = $(TOP)/include/fdpp
AVER = $(shell echo FDPP_API_VER | cpp -include $(PPINC)/thunks.h - | tail -n 1)
BVER = $(shell echo BPRM_VER | cpp -include $(PPINC)/bprm.h - | tail -n 1)
TARGET=fdppkrnl.$(AVER).$(BVER)
VERSION = 1.7
CPPFLAGS += -I$(TOP)/fdpp

NASMFLAGS += -i$(SRC) -i$(HDR) -f elf32

Expand Down Expand Up @@ -94,15 +96,15 @@ $(PPOBJS): %.o: %.asm makefile

plt.o: plt.asm plt.inc $(SRC)/segs.inc

plt.asm: $(srcdir)/$(T)/plt.S $(SRC)/glob_asm.h $(TOP)/include/fdpp/bprm.h \
plt.asm: $(srcdir)/plt.S $(SRC)/glob_asm.h $(TOP)/include/fdpp/bprm.h \
$(srcdir)/$(T)/thunks_priv.h $(srcdir)/makefile
$(CPP) -iquote $(PPINC) -P $< >$@ || ($(RM) $@ ; false)
$(CPP) $(CPPFLAGS) -iquote $(PPINC) -P $< >$@ || ($(RM) $@ ; false)

GIT_DESCRIBE := $(shell git describe)

cdata.asm: $(srcdir)/$(T)/cdata.S $(HDR)/version.h $(GIT_REV) $(srcdir)/makefile
$(CPP) $(CPPFLAGS) -DKERNEL_VERSION="$(VERSION) [GIT: $(GIT_DESCRIBE)]" \
-P $< | sed 's/" "/","/g' >$@
cdata.asm: $(srcdir)/cdata.S $(HDR)/version.h $(GIT_REV) $(srcdir)/makefile
$(CPP) -iquote $(HDR) -DKERNEL_VERSION="$(VERSION) [GIT: $(GIT_DESCRIBE)]" \
-DCMA=, -P $< >$@

thunk_calls.tmp: $(SRC)/proto.h
srcdir=$(srcdir)/$(T)/parsers CPP="$(CPP)" \
Expand Down
85 changes: 85 additions & 0 deletions fdpp/kernel/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
project('kernel', ['nasm', 'c'], version: '1.7')
TOP = '../..'
PD = TOP / 'fdpp/parsers/parse_decls.sh'
SRC = TOP / 'kernel'
DSRC = SRC / 'drivers'
kernel_ld = TOP / 'kernel.ld'
rel_inc = TOP / 'include/fdpp'
abs_inc = meson.current_source_dir() / rel_inc
incdir = include_directories(rel_inc)
cpp = meson.get_compiler('c')
AVER = cpp.get_define('FDPP_API_VER',
include_directories: incdir,
prefix: '#include "thunks.h"')
BVER = cpp.get_define('BPRM_VER',
include_directories: incdir,
prefix: '#include "bprm.h"')
FVER = AVER + '.' + BVER
TARGET = 'fdppkrnl.' + FVER
GIT_DESCRIBE = run_command('git', 'describe', check: true).stdout().strip()
hdr = [TOP / 'kernel', TOP / 'hdr', TOP / 'fdpp', rel_inc]
incdir2 = include_directories(hdr)
sfiles = cpp.preprocess(['cdata.S', 'plt.S'],
output : '@BASENAME@.asm',
include_directories: incdir2,
compile_args : [
'-D__ASSEMBLER__',
'-DKERNEL_VERSION=' + meson.project_version() +
' [GIT: ' + GIT_DESCRIBE + ']',
'-DCMA=,', '-P'])
env = environment()
env.set('CPP', 'cpp')
env.set('srcdir', meson.current_source_dir() / '../parsers')
tct = custom_target('thunk_calls.tmp',
output: 'thunk_calls.tmp',
input: SRC / 'proto.h',
env: env,
command: [PD, '1', '@INPUT@'],
capture: true)
plt_inc = custom_target('plt.inc',
output: 'plt.inc',
input: tct,
command: [PD, '3', '@INPUT@'],
capture: true)

SRCS = [
SRC/'console.asm',
SRC/'cpu.asm',
SRC/'dosidle.asm',
SRC/'entry.asm',
SRC/'execrh.asm',
SRC/'int2f.asm',
SRC/'intr.asm',
SRC/'io.asm',
SRC/'irqstack.asm',
SRC/'kernel.asm',
SRC/'nls_hc.asm',
SRC/'nlssupt.asm',
SRC/'printer.asm',
SRC/'procsupt.asm',
SRC/'serial.asm',

DSRC/'floppy.asm',
DSRC/'rdpcclk.asm',
DSRC/'wrpcclk.asm',
DSRC/'wratclk.asm',
]

nargs = ['-DXCPU=186', '-DWITHFAT32', '-DFDPP']

lib = static_library('dummy',
[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'])
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@'],
install: true,
install_dir: get_option('datadir') / 'fdpp',
install_mode: 'rw-r--r--',
build_by_default: true)
File renamed without changes.
13 changes: 13 additions & 0 deletions fdpp/kernel/toolchain.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[binaries]
nasm = 'nasm-segelf'
c = 'gcc'
strip = 'llvm-strip'

[constants]
arch = 'i386-linux-gnu'

[host_machine]
system = 'linux'
cpu_family = 'x86'
cpu = 'i386'
endian = 'little'
25 changes: 25 additions & 0 deletions fdpp/loader/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
project('loader', 'c', version: '0.1')
TOP = '../..'
rel_inc = TOP / 'include/fdpp'
abs_inc = meson.current_source_dir() / rel_inc
lelf = dependency('libelf')
incdir = include_directories(rel_inc)
cpp = meson.get_compiler('c')
AVER = cpp.get_define('FDPP_API_VER',
include_directories: incdir,
prefix: '#include "thunks.h"')
BVER = cpp.get_define('BPRM_VER',
include_directories: incdir,
prefix: '#include "bprm.h"')
FVER = AVER + '.' + BVER
TARGET = 'fdppkrnl.' + FVER
shared_library('fdldr', 'elf.c', 'loader.c',
dependencies: lelf, include_directories: incdir,
version: FVER,
c_args: [
'-DFDPPKRNLDIR=' + get_option('prefix') / get_option('datadir') / 'fdpp',
'-DKRNL_ELFNAME=' + TARGET + '.elf',
'-DKRNL_MAP_NAME=' + TARGET + '.map'
],
install: true,
install_dir: get_option('libdir') / 'fdpp')
151 changes: 151 additions & 0 deletions fdpp/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
project('libfdpp', ['c', 'cpp'], version: '0.1')
TOP = '..'
MF = meson.current_source_dir() / 'parsers/mkfar.sh'
MA = meson.current_source_dir() / 'parsers/mkasmdefs.sh'
PD = meson.current_source_dir() / 'parsers/parse_decls.sh'
M4 = meson.current_source_dir() / 'parsers/thunks.m4'
TG = './thunk_gen/build/thunk_gen'
TFLAGS = ['-a', '2', '-p', '2']
SRC = TOP / 'kernel'
rel_inc = TOP / 'include/fdpp'
abs_inc = meson.current_source_dir() / rel_inc
incdir = include_directories(rel_inc)
cpp = meson.get_compiler('c')
AVER = cpp.get_define('FDPP_API_VER',
include_directories: incdir,
prefix: '#include "thunks.h"')
BVER = cpp.get_define('BPRM_VER',
include_directories: incdir,
prefix: '#include "bprm.h"')
FVER = AVER + '.' + BVER
TARGET = 'fdppkrnl.' + FVER

CFILES = [
SRC / 'blockio.c',
SRC / 'break.c',
SRC / 'chario.c',
SRC / 'dosfns.c',
SRC / 'dsk.c',
SRC / 'error.c',
SRC / 'fatdir.c',
SRC / 'fatfs.c',
SRC / 'fattab.c',
SRC / 'fcbfns.c',
SRC / 'hmamgr.c',
SRC / 'inthndlr.c',
SRC / 'ioctl.c',
SRC / 'memmgr.c',
SRC / 'misc.c',
SRC / 'newstuff.c',
SRC / 'network.c',
SRC / 'nls.c',
SRC / 'strings.c',
SRC / 'sysclk.c',
SRC / 'systime.c',
SRC / 'task.c',
SRC / 'config.c',
SRC / 'initoem.c',
SRC / 'main.c',
SRC / 'inithma.c',
SRC / 'dyninit.c',
SRC / 'initdisk.c',
SRC / 'initclk.c',
SRC / 'prf.c',
SRC / 'share.c']

ccgen = generator(find_program(MF),
output: '@BASENAME@.cc',
arguments: '@INPUT@',
capture: true)
ccfiles = ccgen.process(CFILES)

gad = custom_target('glob_asmdefs.h',
output: 'glob_asmdefs.h',
input: SRC / 'glob_asm.h',
command: [MA, '@INPUT@'],
capture: true)

GEN_TMP = { '1':'thunk_calls.tmp', '2':'thunk_asms.tmp' }
GEN_H = { 'plt_asmc.h':'4', 'plt_asmp.h':'5' }

env = environment()
env.set('CPP', 'cpp')
env.set('srcdir', meson.current_source_dir() / 'parsers')
pd = find_program(PD)
gtgen = generator(pd,
arguments: ['@EXTRA_ARGS@', '@INPUT@'],
output: '@BASENAME@.tmp',
capture: true)
gt = []
foreach n: GEN_TMP.keys()
gt += gtgen.process(SRC / 'proto.h',
extra_args: n,
env: ['CPP=cpp', 'srcdir=' + meson.current_source_dir() / 'parsers'])
endforeach
GEN = { GEN_TMP['1']:gt[0], GEN_TMP['2']:gt[1] }
pac = custom_target('plt_asmc.h',
output: 'plt_asmc.h',
input: GEN['thunk_asms.tmp'],
command: [PD, GEN_H['plt_asmc.h'], '@INPUT@'],
env: env,
capture: true)
pap = custom_target('plt_asmp.h',
output: 'plt_asmp.h',
input: GEN['thunk_asms.tmp'],
command: [PD, GEN_H['plt_asmp.h'], '@INPUT@'],
env: env,
capture: true)

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'],
feed: true,
capture: true)

find_program('autom4te')
ta = custom_target('thunk_asms.h',
output: 'thunk_asms.h',
input: [ta1, ta2],
command: ['sh', '-c', 'cat @INPUT0@ | sort | uniq | autom4te -l m4sugar ' +
M4 + ' - | cat - @INPUT1@'],
capture: true)

FDPP_CFILES = ['smalloc.c', 'farhlp_sta.c']
ccgen = generator(find_program('echo'),
arguments: ['#include', '"@INPUT@"'],
output: '@BASENAME@.cc',
capture: true)
ppccf = ccgen.process(FDPP_CFILES)

FDPP_CCFILES = ['thunks.cc', 'thunks_c.cc', 'thunks_a.cc', 'thunks_p.cc',
'dosobj.cc']
CPPFILES = ['objhlp.cpp', 'ctors.cpp', 'farhlp.cpp', 'objtrace.cpp']
hdr = [TOP / 'kernel', TOP / 'hdr', TOP / 'fdpp', rel_inc]
incdir2 = include_directories(hdr)
shared_library('fdpp', [ccfiles, ppccf, FDPP_CCFILES, CPPFILES],
include_directories: incdir2,
version: FVER,
sources: [gad, pac, pap, tc, ta],
cpp_args: ['-DFDPP', '-DDEBUG', '-DWITHFAT32',
'-fno-threadsafe-statics',
'-Werror=packed-non-pod', '-Wno-unknown-warning-option',
'-Wno-format-invalid-specifier', '-Wno-c99-designator'
],
link_args: ['-Wl,-Bsymbolic'],
install: true,
install_dir: get_option('libdir') / 'fdpp')
2 changes: 2 additions & 0 deletions fdpp/parsers/mkasmdefs.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/bin/sh

grep "__ASM(" $1 | grep -v '^/' | grep -v '#define' | \
sed -E 's/.+, (.+)\).*/#define \1 __ASYM\(__\1\)/'
grep "__ASM_ARR(" $1 | grep -v '^/' | grep -v '#define' | \
Expand Down
2 changes: 2 additions & 0 deletions fdpp/parsers/mkfar.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/bin/sh

mkfar() {
sed -E \
-e ':loop' \
Expand Down
16 changes: 16 additions & 0 deletions fdpp/thunk_gen/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
project('thunk_gen', 'c', version: '0.1')

flex = find_program('flex', required: true)
bison = find_program('bison', required: true)

lgen = generator(flex,
output : '@PLAINNAME@.yy.c',
arguments : ['-o', '@OUTPUT@', '@INPUT@'])
lfiles = lgen.process('thunk_gen.l')

pgen = generator(bison,
output : ['@BASENAME@.tab.c', '@BASENAME@.tab.h'],
arguments : ['@INPUT@', '--defines=@OUTPUT1@', '--output=@OUTPUT0@'])
pfiles = pgen.process('thunk_gen.y')

executable('thunk_gen', lfiles, pfiles)
2 changes: 2 additions & 0 deletions fdpp/toolchain.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[binaries]
cpp = 'clang++'
File renamed without changes.
8 changes: 4 additions & 4 deletions hdr/portab.h
Original file line number Diff line number Diff line change
Expand Up @@ -315,11 +315,11 @@ typedef WORD BOOL;
/* Convienence defines */
/* */
#define FOREVER while(TRUE)
#ifndef max
#define max(a,b) (((a) > (b)) ? (a) : (b))
#ifndef _max
#define _max(a,b) (((a) > (b)) ? (a) : (b))
#endif
#ifndef min
#define min(a,b) (((a) < (b)) ? (a) : (b))
#ifndef _min
#define _min(a,b) (((a) < (b)) ? (a) : (b))
#endif

#ifdef WITHFAT32
Expand Down
5 changes: 4 additions & 1 deletion hdr/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@
#endif

/* actual version string */
#define KVS(v) "FDPP kernel " #v " (compiled " __DATE__ ")"
#ifndef CMA
#define CMA
#endif
#define KVS(v) "FDPP kernel " CMA #v CMA " (compiled " CMA __DATE__ CMA ")"
#define xKVS(v) KVS(v)
#define KERNEL_VERSION_STRING xKVS(KERNEL_VERSION)
4 changes: 2 additions & 2 deletions kernel/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -1564,7 +1564,7 @@ STATIC VOID Files(char * pLine)
}

/* Got the value, assign either default or new value */
Config.cfgFiles = max(Config.cfgFiles, nFiles);
Config.cfgFiles = _max(Config.cfgFiles, nFiles);
Config.cfgFilesHigh = 0;
}

Expand Down Expand Up @@ -1950,7 +1950,7 @@ STATIC BOOL LoadCountryInfo(char *filenam, UWORD ctryCode, UWORD codePage)
nlsPackageHardcoded.cntry = entry.country;
nlsPackageHardcoded.cp = entry.codepage;
subf_data.length = /* MS-DOS "CTYINFO" is up to 38 bytes */
min(subf_data.length, sizeof(struct CountrySpecificInfo));
_min(subf_data.length, sizeof(struct CountrySpecificInfo));
}
if (hdr[i].id == 7)
{
Expand Down
Loading