From 0b95ba91f201589251e105245741911f07bae846 Mon Sep 17 00:00:00 2001 From: Adrien Bourmault Date: Tue, 9 Apr 2019 23:35:31 +0200 Subject: [PATCH] Makefile big enhancement --- Makefile | 153 ++++++++++++++++++-------------------- ProjectTree | 40 +++++----- kaleid/kernel/init/init.c | 2 + 3 files changed, 95 insertions(+), 100 deletions(-) diff --git a/Makefile b/Makefile index 2c4a3d0..9be191e 100644 --- a/Makefile +++ b/Makefile @@ -23,26 +23,36 @@ #=----------------------------------------------------------------------------=# .PHONY: all test test32 debug gdb install_mbr clean OS/K -all : OS/K ## VARIABLES ----------------------------------------------------------------- # -#Programs +# Debug +mode ?= debug + +# Programs ASM=nasm LD=ld CCNAME=x86_64-elf-gcc - ASMFLAGS=-f elf64 LDFLAGS=-melf_x86_64 COPTIM=-O2 CWARNS=-Wall -Wextra -Werror=implicit-function-declaration CINCLUDES=-Iinclude CFLAGS1=-nostdlib -ffreestanding -mcmodel=large -std=gnu11 -CFLAGS2= -c -g -mno-red-zone -mno-mmx -mno-sse -mno-sse2 +CFLAGS2= -c -mno-red-zone -mno-mmx -mno-sse -mno-sse2 CFLAGS=$(CFLAGS1) $(CFLAGS2) + +ifeq ($(mode), release) +CFLAGS += -D_NO_DEBUG +dep += dust +endif +ifeq ($(mode), debug) +CFLAGS += -g +endif + KCC=$(CCNAME) $(COPTIM) $(CWARNS) $(CFLAGS) $(CINCLUDES) -D_OSK_SOURCE -D_KALEID_KERNEL -#Folders +# Folders MBRDIR=boot/grub LOADERDIR=boot/loader KALEIDDIR=kaleid @@ -52,37 +62,42 @@ KOBJDIR=build/obj/kaleid LOBJDIR=build/obj/boot BINDIR=build/bin BUILDDIR=build - vpath %.c $(KALEIDDIR) -#Color codes +# Color codes CL='\033[0;32m' CL2='\033[1;36m' CL3='\033[0m' NC='\033[1;37m' -# Lib C -LibCObj= $(KOBJDIR)/atoi.o $(KOBJDIR)/ctype.o \ - $(KOBJDIR)/itoa.o $(KOBJDIR)/mem.o \ - $(KOBJDIR)/rand.o $(KOBJDIR)/sprintf.o \ - $(KOBJDIR)/status.o $(KOBJDIR)/string.o \ - $(KOBJDIR)/strtol.o $(KOBJDIR)/argv.o \ - $(KOBJDIR)/prog.o $(KOBJDIR)/atol.o \ - $(KOBJDIR)/atou.o $(KOBJDIR)/atoul.o \ - $(KOBJDIR)/utoa.o $(KOBJDIR)/ltoa.o \ - $(KOBJDIR)/ultoa.o + +## SOURCES INSCRIPTION-------------------------------------------------------- # + +# Lib C sources +LibCSources= libc/atoi.c libc/itoa.c \ + libc/mem.c libc/ctype.c \ + libc/rand.c libc/sprintf.c \ + libc/status.c libc/string.c \ + libc/strtol.c extras/argv.c \ + extras/prog.c # Kernel sources -KernSources=libbuf/buf.c libbuf/bput.c \ - libbuf/bprint.c kernel/cpu/cpuid.c \ - kernel/cpu/idt.c kernel/init/init.c \ - kernel/init/table.c kernel/io/cursor.c \ - kernel/ke/log.c kernel/io/vga.c \ - kernel/ke/panic.c kernel/mm/map.c \ - kernel/mm/heap.c kernel/mm/malloc.c \ - kernel/mm/gdt.c kernel/ps/sched.c \ +KernSources= libbuf/buf.c libbuf/bput.c \ + libbuf/bprint.c kernel/cpu/cpuid.c \ + kernel/cpu/idt.c kernel/init/init.c \ + kernel/init/table.c kernel/io/cursor.c \ + kernel/ke/log.c kernel/io/vga.c \ + kernel/ke/panic.c kernel/mm/map.c \ + kernel/mm/heap.c kernel/mm/malloc.c \ + kernel/mm/gdt.c kernel/ps/sched.c \ KernObj=$(patsubst %.c,$(KOBJDIR)/%.o,$(KernSources)) +LibCObj=$(patsubst %.c,$(KOBJDIR)/%.o,$(LibCSources)) + + +## KALEID MAKEFILE ----------------------------------------------------------- # + +all : OS/K $(dep) ## MISC MAKEFILE ------------------------------------------------------------- # ./ProjectTree: ./.stylehlp_sh @@ -94,67 +109,37 @@ KernObj=$(patsubst %.c,$(KOBJDIR)/%.o,$(KernSources)) $(KOBJDIR): @mkdir -p $(KOBJDIR) -## Lib C MAKEFILE ------------------------------------------------------------ # -$(KOBJDIR)/atoi.o: $(KALEIDDIR)/libc/atoi.c $(INCLUDEDIR)/*/*.h | $(KOBJDIR) - @$(KCC) -D_NEED_ATOI $< -o $@ - @echo ${CL2}[$@] ${CL}Compiled.${CL3} -$(KOBJDIR)/atol.o: $(KALEIDDIR)/libc/atoi.c $(INCLUDEDIR)/*/*.h | $(KOBJDIR) - @$(KCC) -D_NEED_ATOL $< -o $@ - @echo ${CL2}[$@] ${CL}Compiled.${CL3} -$(KOBJDIR)/atou.o: $(KALEIDDIR)/libc/atoi.c $(INCLUDEDIR)/*/*.h | $(KOBJDIR) - @$(KCC) -D_NEED_ATOU $< -o $@ - @echo ${CL2}[$@] ${CL}Compiled.${CL3} -$(KOBJDIR)/atoul.o: $(KALEIDDIR)/libc/atoi.c $(INCLUDEDIR)/*/*.h | $(KOBJDIR) - @$(KCC) -D_NEED_ATOUL $< -o $@ - @echo ${CL2}[$@] ${CL}Compiled.${CL3} -$(KOBJDIR)/itoa.o: $(KALEIDDIR)/libc/itoa.c $(INCLUDEDIR)/*/*.h | $(KOBJDIR) - @$(KCC) -D_NEED_ITOA $< -o $@ - @echo ${CL2}[$@] ${CL}Compiled.${CL3} -$(KOBJDIR)/ltoa.o: $(KALEIDDIR)/libc/itoa.c $(INCLUDEDIR)/*/*.h | $(KOBJDIR) - @$(KCC) -D_NEED_LTOA $< -o $@ - @echo ${CL2}[$@] ${CL}Compiled.${CL3} -$(KOBJDIR)/utoa.o: $(KALEIDDIR)/libc/itoa.c $(INCLUDEDIR)/*/*.h | $(KOBJDIR) - @$(KCC) -D_NEED_UTOA $< -o $@ - @echo ${CL2}[$@] ${CL}Compiled.${CL3} -$(KOBJDIR)/ultoa.o: $(KALEIDDIR)/libc/itoa.c $(INCLUDEDIR)/*/*.h | $(KOBJDIR) - @$(KCC) -D_NEED_ULTOA $< -o $@ - @echo ${CL2}[$@] ${CL}Compiled.${CL3} -$(KOBJDIR)/mem.o: $(KALEIDDIR)/libc/mem.c $(INCLUDEDIR)/*/*.h | $(KOBJDIR) - @$(KCC) -fno-strict-aliasing $< -o $@ - @echo ${CL2}[$@] ${CL}Compiled.${CL3} -$(KOBJDIR)/ctype.o: $(KALEIDDIR)/libc/ctype.c $(INCLUDEDIR)/*/*.h | $(KOBJDIR) - @$(KCC) $< -o $@ - @echo ${CL2}[$@] ${CL}Compiled.${CL3} -$(KOBJDIR)/rand.o: $(KALEIDDIR)/libc/rand.c $(INCLUDEDIR)/*/*.h | $(KOBJDIR) - @$(KCC) $< -o $@ - @echo ${CL2}[$@] ${CL}Compiled.${CL3} -$(KOBJDIR)/sprintf.o: $(KALEIDDIR)/libc/sprintf.c $(INCLUDEDIR)/*/*.h | $(KOBJDIR) - @$(KCC) $< -o $@ - @echo ${CL2}[$@] ${CL}Compiled.${CL3} -$(KOBJDIR)/status.o: $(KALEIDDIR)/libc/status.c $(INCLUDEDIR)/*/*.h | $(KOBJDIR) - @$(KCC) $< -o $@ - @echo ${CL2}[$@] ${CL}Compiled.${CL3} -$(KOBJDIR)/string.o: $(KALEIDDIR)/libc/string.c $(INCLUDEDIR)/*/*.h | $(KOBJDIR) - @$(KCC) $< -o $@ - @echo ${CL2}[$@] ${CL}Compiled.${CL3} -$(KOBJDIR)/strtol.o: $(KALEIDDIR)/libc/strtol.c $(INCLUDEDIR)/*/*.h | $(KOBJDIR) - @$(KCC) $< -o $@ - @echo ${CL2}[$@] ${CL}Compiled.${CL3} -$(KOBJDIR)/argv.o: $(KALEIDDIR)/extras/argv.c $(INCLUDEDIR)/*/*.h | $(KOBJDIR) - @$(KCC) $< -o $@ - @echo ${CL2}[$@] ${CL}Compiled.${CL3} -$(KOBJDIR)/prog.o: $(KALEIDDIR)/extras/prog.c $(INCLUDEDIR)/*/*.h | $(KOBJDIR) - @$(KCC) $< -o $@ +## LIB C MAKEFILE ------------------------------------------------------------ # +$(KOBJDIR)/libc/atoi.o: $(KALEIDDIR)/libc/atoi.c $(INCLUDEDIR)/*/*.h | $(KOBJDIR) + @mkdir -p $(shell dirname $@) + @$(KCC) -D_NEED_ATOI $< -o $@.1 + @$(KCC) -D_NEED_ATOL $< -o $@.2 + @$(KCC) -D_NEED_ATOU $< -o $@.3 + @$(KCC) -D_NEED_ATOUL $< -o $@.4 + @$(LD) -r $@.1 $@.2 $@.3 $@.4 -o $@ @echo ${CL2}[$@] ${CL}Compiled.${CL3} -## KERNEL MAKEFILE ----------------------------------------------------------- # -$(KOBJDIR)/%.o: %.c $(INCLUDEDIR)/*/*.h +$(KOBJDIR)/libc/itoa.o: $(KALEIDDIR)/libc/itoa.c $(INCLUDEDIR)/*/*.h | $(KOBJDIR) @mkdir -p $(shell dirname $@) - @$(KCC) $< -o $@ + @$(KCC) -D_NEED_ITOA $< -o $@.1 + @$(KCC) -D_NEED_LTOA $< -o $@.2 + @$(KCC) -D_NEED_UTOA $< -o $@.3 + @$(KCC) -D_NEED_ULTOA $< -o $@.4 + @$(LD) -r $@.1 $@.2 $@.3 $@.4 -o $@ + @echo ${CL2}[$@] ${CL}Compiled.${CL3} + +$(KOBJDIR)/libc/mem.o: $(KALEIDDIR)/libc/mem.c $(INCLUDEDIR)/*/*.h | $(KOBJDIR) + @mkdir -p $(shell dirname $@) + @$(KCC) -fno-strict-aliasing $< -o $@ @echo ${CL2}[$@] ${CL}Compiled.${CL3} ## MAIN MAKEFILE ------------------------------------------------------------- # +$(KOBJDIR)/%.o: %.c $(INCLUDEDIR)/*/*.h | $(KOBJDIR) + @mkdir -p $(shell dirname $@) + @$(KCC) $< -o $@ + @echo ${CL2}[$@] ${CL}Compiled.${CL3} + test: all @qemu-system-x86_64 -m 4G -hda $(BUILDDIR)/bin/disk.img \ -d cpu_reset,guest_errors,pcall,int 2> $(BUILDDIR)/qemu.log & @@ -187,11 +172,15 @@ install_mbr: $(BINDIR)/disk.img $(MBRDIR)/grub.cfg @rmdir $(BINDIR)/disk @echo ${CL2}[$@] ${CL}Success.${CL3} +dust: + -@$(MBRDIR)/umount.sh $(BINDIR)/disk || /bin/true + @rm -Rf $(OBJDIR)/* + @echo ${CL2}[$@] ${CL}Cleaned.${CL3} clean: -@$(MBRDIR)/umount.sh $(BINDIR)/disk || /bin/true @rm -Rvf ./ProjectTree $(BUILDDIR)/*.log - @rm -Rvf $(BINDIR)/* $(KernObj) $(LibCObj) $(OBJDIR)/* - @echo ${CL2}[[$@]] ${CL}Cleaned.${CL3} + @rm -Rvf $(BINDIR)/* $(OBJDIR)/* + @echo ${CL2}[$@] ${CL}Cleaned.${CL3} $(BINDIR)/kaleid: $(LOBJDIR)/kaleid.x86_64 @echo ${CL2}[$@] ${NC}Objcopy...${CL3} @@ -220,7 +209,7 @@ $(BINDIR)/disk.img: $(MBRDIR)/create_disk.sh OS/K: $(BINDIR)/kaleid $(BINDIR)/disk.img ./ProjectTree @mkdir -p $(BINDIR)/disk - @echo ${CL2}[[$@]] ${NC}Integrating kernel...${CL3} + @echo ${CL2}[[$@]] ${NC}Integrating kernel, $(mode) mode.${CL3} -@$(MBRDIR)/umount.sh $(BINDIR)/disk || /bin/true @$(MBRDIR)/mount.sh $(BINDIR)/disk.img $(BINDIR)/disk @cp $(BINDIR)/kaleid $(BINDIR)/disk/boot/kaleid diff --git a/ProjectTree b/ProjectTree index a8b117d..bb8d75a 100644 --- a/ProjectTree +++ b/ProjectTree @@ -55,6 +55,9 @@ │   │   │   ├── kaleid.x86_64 │   │   │   └── loader.o │   │   └── kaleid +│   │   ├── extras +│   │   │   ├── argv.o +│   │   │   └── prog.o │   │   ├── kernel │   │   │   ├── cpu │   │   │   │   ├── cpuid.o @@ -79,23 +82,24 @@ │   │   │   ├── bprint.o │   │   │   ├── bput.o │   │   │   └── buf.o -│   │   ├── argv.o -│   │   ├── atoi.o -│   │   ├── atol.o -│   │   ├── atoul.o -│   │   ├── atou.o -│   │   ├── ctype.o -│   │   ├── itoa.o -│   │   ├── ltoa.o -│   │   ├── mem.o -│   │   ├── prog.o -│   │   ├── rand.o -│   │   ├── sprintf.o -│   │   ├── status.o -│   │   ├── string.o -│   │   ├── strtol.o -│   │   ├── ultoa.o -│   │   └── utoa.o +│   │   └── libc +│   │   ├── atoi.o +│   │   ├── atoi.o.1 +│   │   ├── atoi.o.2 +│   │   ├── atoi.o.3 +│   │   ├── atoi.o.4 +│   │   ├── ctype.o +│   │   ├── itoa.o +│   │   ├── itoa.o.1 +│   │   ├── itoa.o.2 +│   │   ├── itoa.o.3 +│   │   ├── itoa.o.4 +│   │   ├── mem.o +│   │   ├── rand.o +│   │   ├── sprintf.o +│   │   ├── status.o +│   │   ├── string.o +│   │   └── strtol.o │   ├── grub.log │   └── kernel.ld ├── include @@ -174,4 +178,4 @@ ├── ProjectTree └── README.md -35 directories, 114 files +37 directories, 116 files diff --git a/kaleid/kernel/init/init.c b/kaleid/kernel/init/init.c index d84884c..115dc09 100644 --- a/kaleid/kernel/init/init.c +++ b/kaleid/kernel/init/init.c @@ -150,6 +150,8 @@ noreturn void BtStartKern(multiboot_info_t *mbInfo, uint mbMagic) MmInitHeap(); PsInitSched(); + KalAssert(0); + KeStartPanic("Test Panic %d", 4); // End this machine's suffering