diff --git a/Makefile b/Makefile index 5094846..8ea65d6 100644 --- a/Makefile +++ b/Makefile @@ -21,6 +21,8 @@ LD := $(ARCH)-elf-ld CFLAGS := -g3 -O0 -pipe -Wall +INITRAMFS := initramfs.cpio + CFLAGS += \ -std=gnu99 \ -ffreestanding \ @@ -69,34 +71,38 @@ export LD export QEMUFLAGS export CFLAGS export LDFLAGS +export INITRAMFS PHONY: default default: - $(Q)compiledb -n make $(KERNEL) - $(Q)make $(KERNEL) + $(Q)compiledb -n $(MAKE) --no-print-directory $(KERNEL) + $(Q)$(MAKE) --no-print-directory $(KERNEL) .PHONY: all all: $(KERNEL) - $(Q)compiledb -n make + $(Q)compiledb -n $(MAKE) --no-print-directory .PHONY: __build_all __build_all: $(Q)$(MAKE) --no-print-directory -f scripts/Makefile.build _all obj=. + $(Q)$(MAKE) --no-print-directory -C usr.bin $(KOBJ): __build_all -$(KERNEL): $(KOBJ) built-in.o linker.ld +$(KERNEL): $(KOBJ) linker.ld $(Q)echo " LD $@" $(Q)$(LD) $(KOBJ) $(LDFLAGS) -T linker.ld -o $@ .PHONY: clean clean: - $(Q)$(MAKE) -f scripts/Makefile.build _clean obj=. + $(Q)$(MAKE) --no-print-directory -f scripts/Makefile.build _clean obj=. + $(Q)$(MAKE) --no-print-directory -C usr.bin clean $(Q)rm -rf $(IMG) $(Q)rm -rf iso_root $(Q)rm -rf os_root $(Q)rm -rf edk2-ovmf $(Q)rm -rf os_root.img + $(Q)rm -rf $(INITRAMFS) print-%: $(Q)echo $($(*)) diff --git a/scripts/Makefile.build b/scripts/Makefile.build index b509b60..4d1c76b 100644 --- a/scripts/Makefile.build +++ b/scripts/Makefile.build @@ -4,10 +4,10 @@ # # Important to remember that this is run at the project-root-level, # all of it, as it is invoked with $(MAKE) -f -ifneq ($(shell test -e .config && echo -n yes),yes) - $(error Please type `make config` to generate a config) -endif --include .config +#ifneq ($(shell test -e .config && echo -n yes),yes) +# $(error Please type `make config` to generate a config) +#endif +#-include .config export obj-y := @@ -22,7 +22,11 @@ real-objs-y := $(addprefix $(obj)/, $(filter-out %/, $(obj-y))) subdir-objs-y := $(foreach d,$(subdir-y),$(obj)/$(d)/built-in.o) deps := $(real-objs-y:.o=.d) +ifeq ($(obj),.) +_all: $(subdir-objs-y) +else _all: $(obj)/built-in.o +endif $(obj)/%.o: $(obj)/%.c $(Q)echo " CC $@" diff --git a/scripts/Makefile.limine b/scripts/Makefile.limine index 781aea3..742ae32 100644 --- a/scripts/Makefile.limine +++ b/scripts/Makefile.limine @@ -1,7 +1,6 @@ # SPDX-License-Identifier: GPL-2.0-only # Makefile stuff for all the booting and bootloader related stuff # -INITRAMFS := initramfs.cpio $(IMG): limine/limine $(KERNEL) rm -rf $(IMG) @@ -27,7 +26,7 @@ $(IMG): limine/limine $(KERNEL) limine/limine: rm -rf limine git clone https://codeberg.org/Limine/Limine.git limine --branch=$(LIMINE_VERSION)-binary --depth=1 - $(MAKE) -C limine \ + $(MAKE) --no-print-directory -C limine \ CC="$(HOST_CC)" \ CFLAGS="$(HOST_CFLAGS)" \ CPPFLAGS="$(HOST_CPPFLAGS)" \ @@ -68,3 +67,4 @@ edk2-ovmf: distclean: make clean rm -rf limine + rm -rf $(INITRAMFS) diff --git a/usr.bin/Makefile b/usr.bin/Makefile new file mode 100644 index 0000000..3785333 --- /dev/null +++ b/usr.bin/Makefile @@ -0,0 +1,26 @@ +ifneq ($(V),1) + Q := @ +else + Q := +endif + +usr_dirs := utest +usr_bins := $(foreach d,$(usr_dirs),$d/$d) + +.PHONY: all $(usr_dirs) +all: initramfs + +$(usr_dirs): + $(Q)$(MAKE) --no-print-directory -C $@ DIR=usr.bin/$@ + +.PHONY: initramfs +initramfs: $(usr_dirs) + $(Q)mkdir -p ../initramfs/bin/ + $(Q)cp $(usr_bins) ../initramfs/bin/ + +.PHONY: clean +clean: + $(Q)for dir in $(usr_dirs); do \ + echo " CLEAN usr.bin/$$dir"; \ + $(MAKE) --no-print-directory -C $$dir clean; \ + done diff --git a/usr.bin/Makefile.common b/usr.bin/Makefile.common new file mode 100644 index 0000000..48da91c --- /dev/null +++ b/usr.bin/Makefile.common @@ -0,0 +1,30 @@ +ifneq ($(V),1) + Q := @ +else + Q := +endif + +USR_CFLAGS ?= -g3 -O0 -pipe -Wall -ffreestanding -nostdlib \ + -fno-stack-protector -m64 -march=x86-64 -mabi=sysv \ + -Iinclude -MMD + +USR_LDFLAGS ?= -nostdlib -static -m elf_x86_64 -z max-page-size=0x1000 + +$(OUT): $(UOBJ) + $(Q)echo " LD [U] $(DIR)/$@" + $(Q)$(LD) $(USR_LDFLAGS) -o $@ $^ + +%.o: %.c + $(Q)echo " CC [U] $(DIR)/$@" + $(Q)$(CC) $(USR_CFLAGS) -c $< -o $@ + +%.o: %.S + $(Q)echo " CC [U] $(DIR)/$@" + $(Q)$(CC) $(USR_CFLAGS) -c $< -o $@ + +clean: + $(Q)rm -rf $(UOBJ) $(OUT) + +print-%: + $(Q)echo $($(*)) + diff --git a/usr.bin/utest/Makefile b/usr.bin/utest/Makefile new file mode 100644 index 0000000..ee77b57 --- /dev/null +++ b/usr.bin/utest/Makefile @@ -0,0 +1,4 @@ +# SPDX-License-Identifier: GPL-2.0-only +OUT := utest +UOBJ := utest.o +-include ../Makefile.common diff --git a/usr.bin/utest/utest b/usr.bin/utest/utest new file mode 100755 index 0000000..a78ed5a Binary files /dev/null and b/usr.bin/utest/utest differ diff --git a/usr.bin/utest/utest.c b/usr.bin/utest/utest.c new file mode 100644 index 0000000..24cfbd9 --- /dev/null +++ b/usr.bin/utest/utest.c @@ -0,0 +1,6 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +void _start() +{ + while (1) + (void)0; +}