aboutsummaryrefslogtreecommitdiff
path: root/Makefile
diff options
context:
space:
mode:
authorTianhao Wang <shrik3@riseup.net>2023-03-14 01:38:04 +0100
committerTianhao Wang <shrik3@riseup.net>2023-03-14 01:38:04 +0100
commit15328de186d12fa72d120f3ee3b593eca94b45d3 (patch)
tree22b9fb9be19f1c1aaae889fd6e0d958e66da279d /Makefile
parentafa2f55b20ba56ac824573a9acea6ecad050d555 (diff)
rework makefile, include other asm sources
Diffstat (limited to 'Makefile')
-rw-r--r--Makefile75
1 files changed, 65 insertions, 10 deletions
diff --git a/Makefile b/Makefile
index 552c0e7..3ef7cc1 100644
--- a/Makefile
+++ b/Makefile
@@ -3,29 +3,69 @@
# for those (me included) who are not sure about
# the building process.
# TODO reorganize...
-#
+# TODO add dependencies (.d) if necessary but I don't think so...
+# the librustubs is cargo self-contained), others are asm code,
+# for which dep files are not needed
+# And .. I don't think I'll add c/c++ files to this project..
+# TODO replace hardcoded values with variables
+# TODO there can be more options of grub-mkrescue
+# TODO put the startup.s elsewhere (I don't like it in the root dir)
-all: bootdisk.iso
+# verbose for testing; VERBOSE=@ to turn off..
+VERBOSE=@
+BUILD = build
+ARCH = x86_64
+ASM_SOURCES = $(shell find ./src -name "*.s")
+ASM_OBJECTS = $(patsubst %.s,_%.o, $(notdir $(ASM_SOURCES)))
+ASM = nasm
+ASMOBJFORMAT = elf64
+
+# I don't like this style... but what can I do?
+ASMOBJ_PREFIXED = $(addprefix $(BUILD)/,$(ASM_OBJECTS))
+# Setting directories to look for missing source files
+VPATH = $(sort $(dir $(ASM_SOURCES)))
+
+LINKER_SCRIPT = ./src/arch/$(ARCH)/linker.ld
+# include --release flag to build optimized code
+# FIXME make the rust core work
+# CARGO_XBUILD_FLAG = -Z build-std=core,alloc
+CARGO_XBUILD_FLAG =
+ifneq ($(CARGO_XBUILD_FLAG), --release)
+ RUST_BUILD = debug
+else
+ RUST_BUILD = release
+endif
+
+RUST_OBJECT = target/$(ARCH)-rustubs/$(RUST_BUILD)/librustubs.a
+
+all: bootdisk.iso
bootdisk.iso : kernel
- cp kernel isofiles/boot/
- grub-mkrescue /usr/lib/grub/i386-pc -o bootdisk.iso isofiles
+ $(VERBOSE) cp kernel isofiles/boot/
+ $(VERBOSE) grub-mkrescue /usr/lib/grub/i386-pc -o bootdisk.iso isofiles
+
+# Note: explicitly tell the linker to use startup: as the entry point (we have no main here)
+kernel : rust_kernel startup.o $(ASMOBJ_PREFIXED)
+ $(VERBOSE) ld -static -e startup -T $(LINKER_SCRIPT) -o ./kernel $(BUILD)/startup.o $(ASMOBJ_PREFIXED) $(RUST_OBJECT)
+
+# Note: this target works when the VPATH is set correctly
+$(BUILD)/_%.o : %.s
+ @echo "ASM $@"
+ @if test \( ! \( -d $(@D) \) \) ;then mkdir -p $(@D);fi
+ $(VERBOSE) $(ASM) -f $(ASMOBJFORMAT) -o $@ $<
-# Link the rust library against the objects from asm code (currently only the startup.o),
-# later we'll use wildcards
-kernel : rust_kernel startup.o
- ld -static -e startup -T ./src/arch/x86_64/linker.ld -o ./kernel startup.o target/x86_64-rustubs/debug/librustubs.a
# install xbuild first. (cargo install xbuild)
# Compile the rust part: note that the the cargo crate is of type [staticlib], if you don't
# define this, the linker will have troubles, especially when we use a "no_std" build
rust_kernel:
- cargo xbuild --target x86_64-rustubs.json
+ cargo xbuild --target $(ARCH)-rustubs.json $(CARGO_XBUILD_FLAG)
# need nasm
startup.o:
- nasm -f elf64 -o startup.o src/arch/x86_64/asm/startup.s
+ @if test \( ! \( -d $(@D) \) \) ;then mkdir -p $(@D);fi
+ nasm -f elf64 -o $(BUILD)/startup.o startup.s
clean:
cargo clean
@@ -33,6 +73,21 @@ clean:
rm -f startup.o
rm -f kernel
rm -f isofiles/boot/kernel
+ rm -f build/*
qemu: bootdisk.iso
qemu-system-x86_64 -drive file=./bootdisk.iso,format=raw -k en-us
+
+
+test:
+ @echo "---BUILD DIR---"
+ @echo $(BUILD)
+ @echo "---ASM SRC---"
+ @echo $(ASM_SOURCES)
+ @echo "---ASM OBJ---"
+ @echo $(ASM_OBJECTS)
+ @echo "---ASM OBJ PREFIXED"
+ @echo $(ASMOBJ_PREFIXED)
+
+
+.PHONY: clean qemu