Skip to content

Commit

Permalink
build system rework [#146]
Browse files Browse the repository at this point in the history
Split out the kernel build to get smaller makefiles.
Some configure simplifications.
  • Loading branch information
stsp committed Nov 22, 2023
1 parent 7dd4d20 commit d59194b
Show file tree
Hide file tree
Showing 5 changed files with 148 additions and 108 deletions.
8 changes: 2 additions & 6 deletions configure
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
SCRIPTPATH="$( cd "$(dirname "$0")" ; pwd -P )"
CWD=`pwd -P`
if [ ! -f configure ]; then
ln -sf "$SCRIPTPATH"/makefile makefile
echo "srcdir = $SCRIPTPATH" >config.mak

mkdir fdpp 2>/dev/null
cd fdpp
echo "srcdir = $SCRIPTPATH/fdpp" >config.mak
mkdir thunk_gen 2>/dev/null
cd thunk_gen
echo "srcdir = $SCRIPTPATH/fdpp/thunk_gen" >config.mak
ln -sf "$SCRIPTPATH"/fdpp/thunk_gen/makefile makefile
"$SCRIPTPATH/fdpp"/configure
fi
16 changes: 12 additions & 4 deletions fdpp/configure
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
SCRIPTPATH="$( cd "$(dirname "$0")" ; pwd -P )"

do_sub() {
mkdir $1 2>/dev/null
cd $1
echo "srcdir = $SCRIPTPATH/$1" >config.mak
ln -sf "$SCRIPTPATH/$1"/makefile makefile
cd ..
}

TOPDIR=`realpath "$SCRIPTPATH/.."`
if [ ! -f configure ]; then
ln -sf "$SCRIPTPATH"/makefile makefile
echo "srcdir = $SCRIPTPATH" >config.mak
mkdir thunk_gen 2>/dev/null
cd thunk_gen
echo "srcdir = $SCRIPTPATH/thunk_gen" >config.mak
ln -sf "$SCRIPTPATH"/thunk_gen/makefile makefile

do_sub thunk_gen
do_sub kernel
fi
113 changes: 113 additions & 0 deletions fdpp/kernel/makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
T = ..
-include config.mak
-include $(T)/local.mak
srcdir ?= $(CURDIR)

include $(srcdir)/$(T)/defs.mak
include $(srcdir)/$(T)/clang.mak

TOP = $(abspath $(srcdir)/$(T)/..)
HDR = $(TOP)/hdr
SRC = $(TOP)/kernel
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)

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

ASMS = kernel.asm entry.asm io.asm console.asm serial.asm printer.asm \
execrh.asm nlssupt.asm procsupt.asm dosidle.asm int2f.asm \
nls_hc.asm intr.asm irqstack.asm \
cpu.asm
DASMS = floppy.asm rdpcclk.asm wrpcclk.asm wratclk.asm
OBJS = $(ASMS:.asm=.o)
DOBJS = $(DASMS:.asm=.o)
PPASMS = plt.S cdata.S
PPOBJS = $(PPASMS:.S=.o)

# *Explicit Rules*

ALL = $(T)/$(TARGET).elf $(T)/$(TARGET).map

all: $(ALL)

want_loadaddr = 0
ifeq ($(want_loadaddr),1)
LA = --defsym=loadaddr=0xfa100
else
LA = --emit-relocs
endif
want_pie = 0
ifeq ($(want_pie),1)
PF = -pie
endif

# New makes have a way to avoid parallel invocation with the use of &:
# On old make you would write "%.elf %.map :" which is a bit silly
# given the names are fixed. Also $(TARGET).% won't work that way at all:
# you need to explicitly list all files that are created simultaneously,
# and yet use pattern in all of them.
DEPS_OF_ELF = $(srcdir)/$(T)/kernel.ld $(OBJS) $(PPOBJS) $(DOBJS)
need = 4.3
ifneq ($(filter $(need),$(firstword $(sort $(MAKE_VERSION) $(need)))),)
$(T)/$(TARGET).elf $(T)/$(TARGET).map &: $(DEPS_OF_ELF)
else
$(T)/%.elf $(T)/%.map : $(DEPS_OF_ELF)
endif
$(CROSS_LD) -melf_i386 -static -Map=$(T)/$(TARGET).map -o $(T)/$(TARGET).elf \
$(LA) $(PF) $(^:%.ld=-T%.ld)
chmod -x $(T)/$(TARGET).elf

clean:
-$(RM) .tstamp *.inc *.o *.tmp $(GEN_ASMS)

# *Individual File Dependencies*
#apisupt.o: $(SRC)/apisupt.asm $(SRC)/segs.inc
console.o: $(SRC)/console.asm $(SRC)/io.inc
cpu.o: $(SRC)/cpu.asm $(SRC)/segs.inc
dosidle.o: $(SRC)/dosidle.asm $(SRC)/segs.inc
entry.o: $(SRC)/entry.asm $(SRC)/segs.inc $(HDR)/stacks.inc
execrh.o: $(SRC)/execrh.asm $(SRC)/segs.inc
int2f.o: $(SRC)/int2f.asm $(SRC)/segs.inc $(HDR)/stacks.inc
intr.o: $(SRC)/intr.asm $(SRC)/segs.inc
io.o: $(SRC)/io.asm $(SRC)/segs.inc $(HDR)/stacks.inc
irqstack.o: $(SRC)/irqstack.asm $(SRC)/segs.inc
kernel.o: $(SRC)/kernel.asm $(SRC)/segs.inc
nls_hc.o: $(SRC)/nls_hc.asm $(SRC)/segs.inc
nlssupt.o: $(SRC)/nlssupt.asm $(SRC)/segs.inc $(HDR)/stacks.inc
printer.o: $(SRC)/printer.asm $(SRC)/io.inc
procsupt.o: $(SRC)/procsupt.asm $(SRC)/segs.inc $(HDR)/stacks.inc
serial.o: $(SRC)/serial.asm $(SRC)/io.inc

GEN_ASMS = plt.asm cdata.asm
GEN_TMP = thunk_calls.tmp plt.inc

$(OBJS): %.o: $(SRC)/%.asm makefile
$(NASM) $(NASMFLAGS) -o $@ $<

$(DOBJS): %.o: $(SRC)/drivers/%.asm makefile
$(NASM) $(NASMFLAGS) -o $@ $<

$(PPOBJS): %.o: %.asm makefile
$(NASM) $(NASMFLAGS) -o $@ $<

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

plt.asm: $(srcdir)/$(T)/plt.S $(SRC)/glob_asm.h $(TOP)/include/fdpp/bprm.h \
$(srcdir)/$(T)/thunks_priv.h $(srcdir)/makefile
$(CPP) -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' >$@

thunk_calls.tmp: $(SRC)/proto.h
srcdir=$(srcdir)/$(T)/parsers CPP="$(CPP)" \
$(srcdir)/$(T)/parsers/parse_decls.sh 1 $< >$@ || \
($(RM) $@ ; false)
plt.inc: thunk_calls.tmp
$(srcdir)/$(T)/parsers/parse_decls.sh 3 $< >$@ || \
($(RM) $@ ; false)
96 changes: 14 additions & 82 deletions fdpp/makefile
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
T = .
-include config.mak
-include local.mak
-include $(T)/local.mak
srcdir ?= $(CURDIR)
# the below is needed to prevent _our_ srcdir being passed
# down to rpmbuild/debuild, and, subsequently, to their make!
unexport srcdir
MAKEOVERRIDES =

include $(srcdir)/defs.mak
include $(srcdir)/clang.mak
include $(srcdir)/$(T)/defs.mak
include $(srcdir)/$(T)/clang.mak

TOP = $(abspath $(srcdir)/..)
TOP = $(abspath $(srcdir)/$(T)/..)
HDR = $(TOP)/hdr
SRC = $(TOP)/kernel
PPINC = $(TOP)/include/fdpp
Expand All @@ -36,88 +37,42 @@ GIT_DESCRIBE := $(shell git describe)

CPPFLAGS += -I . -I $(FD_EXT_H) -I $(SRC) -I $(srcdir) \
-DFDPPKRNLDIR=$(DATADIR)/fdpp \
-DKRNL_ELFNAME=$(TARGET).elf -DKRNL_MAP_NAME=$(TARGET).map \
-DKERNEL_VERSION="$(VERSION) [GIT: $(GIT_DESCRIBE)]"
NASMFLAGS += -i$(SRC)/ -f elf32

# *List Macros*
# Only 8 files per definition; this is limitation of DOS batch
# files (only 9 directly accessible parameters).

ASMS = kernel.asm entry.asm io.asm console.asm serial.asm printer.asm \
execrh.asm nlssupt.asm procsupt.asm dosidle.asm int2f.asm \
nls_hc.asm intr.asm irqstack.asm \
cpu.asm
DASMS = floppy.asm rdpcclk.asm wrpcclk.asm wratclk.asm
OBJS = $(ASMS:.asm=.o)
DOBJS = $(DASMS:.asm=.o)
PPASMS = plt.S cdata.S
PPOBJS = $(PPASMS:.S=.o)
-DKRNL_ELFNAME=$(TARGET).elf -DKRNL_MAP_NAME=$(TARGET).map

# *Explicit Rules*

ALL = $(FDPPLIB) $(FDPPDEVL) $(TARGET).elf $(TARGET).map $(GEN_EXT)

all: $(ALL)

want_loadaddr = 0
ifeq ($(want_loadaddr),1)
LA = --defsym=loadaddr=0xfa100
else
LA = --emit-relocs
endif
want_pie = 0
ifeq ($(want_pie),1)
PF = -pie
endif

.PHONY: $(TARGET).elf $(TARGET).map
# New makes have a way to avoid parallel invocation with the use of &:
# On old make you would write "%.elf %.map :" which is a bit silly
# given the names are fixed. Also $(TARGET).% won't work that way at all:
# you need to explicitly list all files that are created simultaneously,
# and yet use pattern in all of them.
DEPS_OF_ELF = $(srcdir)/kernel.ld $(OBJS) $(PPOBJS) $(DOBJS)
need = 4.3
ifneq ($(filter $(need),$(firstword $(sort $(MAKE_VERSION) $(need)))),)
$(TARGET).elf $(TARGET).map &: $(DEPS_OF_ELF)
$(TARGET).elf $(TARGET).map &:
else
%.elf %.map : $(DEPS_OF_ELF)
%.elf %.map:
endif
$(CROSS_LD) -melf_i386 -static -Map=$(TARGET).map -o $@ \
$(LA) $(PF) $(^:%.ld=-T%.ld)
chmod -x $@
$(MAKE) -C kernel

clean:
$(MAKE) -C kernel clean
+cd thunk_gen && $(MAKE) srcdir=$(abspath $(srcdir))/thunk_gen clean
-$(RM) .tstamp *.map $(TARGET).elf *.inc \
*.o $(GEN_CC) $(FDPPDEVL) $(FDPPLIB) *.tmp $(GEN_HEADERS) \
$(GEN_HEADERS_FD) $(GEN_ASMS) \
*.pc *.so *.elf

# *Individual File Dependencies*
#apisupt.o: $(SRC)/apisupt.asm $(SRC)/segs.inc
console.o: $(SRC)/console.asm $(SRC)/io.inc
cpu.o: $(SRC)/cpu.asm $(SRC)/segs.inc
dosidle.o: $(SRC)/dosidle.asm $(SRC)/segs.inc
entry.o: $(SRC)/entry.asm $(SRC)/segs.inc $(HDR)/stacks.inc
execrh.o: $(SRC)/execrh.asm $(SRC)/segs.inc
int2f.o: $(SRC)/int2f.asm $(SRC)/segs.inc $(HDR)/stacks.inc
intr.o: $(SRC)/intr.asm $(SRC)/segs.inc
io.o: $(SRC)/io.asm $(SRC)/segs.inc $(HDR)/stacks.inc
irqstack.o: $(SRC)/irqstack.asm $(SRC)/segs.inc
kernel.o: $(SRC)/kernel.asm $(SRC)/segs.inc
nls_hc.o: $(SRC)/nls_hc.asm $(SRC)/segs.inc
nlssupt.o: $(SRC)/nlssupt.asm $(SRC)/segs.inc $(HDR)/stacks.inc
printer.o: $(SRC)/printer.asm $(SRC)/io.inc
procsupt.o: $(SRC)/procsupt.asm $(SRC)/segs.inc $(HDR)/stacks.inc
serial.o: $(SRC)/serial.asm $(SRC)/io.inc

HDRS = $(wildcard $(HDR)/*.h) $(wildcard $(SRC)/*.h)
PLPHDRS = farobj.hpp farptr.hpp dispatch.hpp ctors.hpp
_PPHDRS = $(PLPHDRS) dosobj.h farhlp.hpp thunks_priv.h smalloc.h \
farhlp_sta.h
PPHDRS = $(addprefix $(srcdir)/,$(_PPHDRS))
GEN_HEADERS = thunk_calls.h thunk_asms.h
GEN_HEADERS = thunk_calls.h thunk_asms.h plt_asmc.h plt_asmp.h
GEN_HEADERS_FD = glob_asmdefs.h
GEN_ASMS = plt.asm cdata.asm
# dont change file order in GEN_TMP as it matches the gen script
Expand Down Expand Up @@ -186,15 +141,6 @@ $(FDPP_CCOBJS): %.o: $(srcdir)/%.cc $(GEN_HEADERS) $(PPHDRS) $(srcdir)/makefile
$(FDPP_CPPOBJS): %.o: $(srcdir)/%.cpp $(PPHDRS) $(srcdir)/makefile
$(CC) $(CFLAGS) -o $@ $<

$(OBJS): %.o: $(SRC)/%.asm makefile
$(NASM) $(NASMFLAGS) -o $@ $<

$(DOBJS): %.o: $(SRC)/drivers/%.asm makefile
$(NASM) $(NASMFLAGS) -o $@ $<

$(PPOBJS): %.o: %.asm makefile
$(NASM) $(NASMFLAGS) -o $@ $<

$(GEN_CC): %.cc: $(SRC)/%.c makefile
$(srcdir)/parsers/mkfar.sh $< >$@

Expand All @@ -205,15 +151,6 @@ $(FDPPLIB): $(OBJECTS) $(FDPP_COBJS) $(FDPP_CCOBJS) $(FDPP_CPPOBJS)
$(FDPPDEVL): $(FDPPLIB)
ln -sf $< $@

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

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

cdata.asm: $(srcdir)/cdata.S $(HDR)/version.h $(GIT_REV) $(srcdir)/makefile
$(CPP) $(CPPFLAGS) -P $< | sed 's/" "/","/g' >$@

_pos = $(if $(findstring $1,$2),$(call _pos,$1,\
$(wordlist 2,$(words $2),$2),x $3),$3)
pos = $(words $(call _pos,$1,$2))
Expand All @@ -222,8 +159,6 @@ pars = srcdir=$(srcdir)/parsers CPP="$(CPP)" \
($(RM) $@ ; false)
$(filter %.tmp,$(GEN_TMP)): $(SRC)/proto.h
$(pars)
plt.inc: thunk_calls.tmp
$(pars)
plt_asmc.h plt_asmp.h: thunk_asms.tmp
$(pars)

Expand Down Expand Up @@ -264,15 +199,12 @@ uninstall:
$(RM) -r $(DESTDIR)$(PREFIX)/include/fdpp

$(TGZ):
cd $(TOP) && git archive -o $(CURDIR)/$(TAR) --prefix=$(PKG)/ HEAD
gzip $(TAR)
cd $(TOP) && git archive -o $(TOP)/$(TAR) --prefix=$(PKG)/ HEAD
gzip $(TOP)/$(TAR)
.PHONY: $(TGZ)

tar: $(TGZ)

deb:
debuild -i -us -uc -b

$(GEN_EXT): %: $(srcdir)/%.in makefile
sed \
-e 's!@PREFIX[@]!$(PREFIX)!g' \
Expand Down
23 changes: 7 additions & 16 deletions makefile
Original file line number Diff line number Diff line change
@@ -1,27 +1,18 @@
-include config.mak
srcdir ?= $(CURDIR)

define mdir
if [ ! -f $(1)/makefile ]; then \
mkdir $(1) 2>/dev/null ; \
ln -s $(srcdir)/$(1)/makefile $(1)/makefile ; \
fi
cd $(1) && $(MAKE) srcdir=$(srcdir)/$(1) $(2)
endef

all:
$(MAKE) nasm-segelf
+$(call mdir,fdpp,all)
$(MAKE) -C fdpp

clean install uninstall tar:
$(MAKE) -C fdpp $@

clean:
+$(call mdir,fdpp,clean)
.PHONY: tar deb rpm nasm-segelf install uninstall

rpm: fdpp.spec.rpkg
git clean -fd
rpkg local

install uninstall deb tar:
cd fdpp && $(MAKE) srcdir=$(srcdir)/fdpp $@
deb:
debuild -i -us -uc -b

nasm-segelf:
$@ --version 2>/dev/null || \
Expand Down

0 comments on commit d59194b

Please sign in to comment.