Makefile big enhancement

This commit is contained in:
Adrien Bourmault 2019-04-09 23:35:31 +02:00
parent ac626ae408
commit 0b95ba91f2
3 changed files with 95 additions and 100 deletions

131
Makefile
View File

@ -23,23 +23,33 @@
#=----------------------------------------------------------------------------=# #=----------------------------------------------------------------------------=#
.PHONY: all test test32 debug gdb install_mbr clean OS/K .PHONY: all test test32 debug gdb install_mbr clean OS/K
all : OS/K
## VARIABLES ----------------------------------------------------------------- # ## VARIABLES ----------------------------------------------------------------- #
# Debug
mode ?= debug
# Programs # Programs
ASM=nasm ASM=nasm
LD=ld LD=ld
CCNAME=x86_64-elf-gcc CCNAME=x86_64-elf-gcc
ASMFLAGS=-f elf64 ASMFLAGS=-f elf64
LDFLAGS=-melf_x86_64 LDFLAGS=-melf_x86_64
COPTIM=-O2 COPTIM=-O2
CWARNS=-Wall -Wextra -Werror=implicit-function-declaration CWARNS=-Wall -Wextra -Werror=implicit-function-declaration
CINCLUDES=-Iinclude CINCLUDES=-Iinclude
CFLAGS1=-nostdlib -ffreestanding -mcmodel=large -std=gnu11 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) 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 KCC=$(CCNAME) $(COPTIM) $(CWARNS) $(CFLAGS) $(CINCLUDES) -D_OSK_SOURCE -D_KALEID_KERNEL
# Folders # Folders
@ -52,7 +62,6 @@ KOBJDIR=build/obj/kaleid
LOBJDIR=build/obj/boot LOBJDIR=build/obj/boot
BINDIR=build/bin BINDIR=build/bin
BUILDDIR=build BUILDDIR=build
vpath %.c $(KALEIDDIR) vpath %.c $(KALEIDDIR)
# Color codes # Color codes
@ -61,16 +70,16 @@ CL2='\033[1;36m'
CL3='\033[0m' CL3='\033[0m'
NC='\033[1;37m' NC='\033[1;37m'
# Lib C
LibCObj= $(KOBJDIR)/atoi.o $(KOBJDIR)/ctype.o \ ## SOURCES INSCRIPTION-------------------------------------------------------- #
$(KOBJDIR)/itoa.o $(KOBJDIR)/mem.o \
$(KOBJDIR)/rand.o $(KOBJDIR)/sprintf.o \ # Lib C sources
$(KOBJDIR)/status.o $(KOBJDIR)/string.o \ LibCSources= libc/atoi.c libc/itoa.c \
$(KOBJDIR)/strtol.o $(KOBJDIR)/argv.o \ libc/mem.c libc/ctype.c \
$(KOBJDIR)/prog.o $(KOBJDIR)/atol.o \ libc/rand.c libc/sprintf.c \
$(KOBJDIR)/atou.o $(KOBJDIR)/atoul.o \ libc/status.c libc/string.c \
$(KOBJDIR)/utoa.o $(KOBJDIR)/ltoa.o \ libc/strtol.c extras/argv.c \
$(KOBJDIR)/ultoa.o extras/prog.c
# Kernel sources # Kernel sources
KernSources= libbuf/buf.c libbuf/bput.c \ KernSources= libbuf/buf.c libbuf/bput.c \
@ -83,6 +92,12 @@ KernSources=libbuf/buf.c libbuf/bput.c \
kernel/mm/gdt.c kernel/ps/sched.c \ kernel/mm/gdt.c kernel/ps/sched.c \
KernObj=$(patsubst %.c,$(KOBJDIR)/%.o,$(KernSources)) KernObj=$(patsubst %.c,$(KOBJDIR)/%.o,$(KernSources))
LibCObj=$(patsubst %.c,$(KOBJDIR)/%.o,$(LibCSources))
## KALEID MAKEFILE ----------------------------------------------------------- #
all : OS/K $(dep)
## MISC MAKEFILE ------------------------------------------------------------- # ## MISC MAKEFILE ------------------------------------------------------------- #
./ProjectTree: ./.stylehlp_sh ./ProjectTree: ./.stylehlp_sh
@ -94,67 +109,37 @@ KernObj=$(patsubst %.c,$(KOBJDIR)/%.o,$(KernSources))
$(KOBJDIR): $(KOBJDIR):
@mkdir -p $(KOBJDIR) @mkdir -p $(KOBJDIR)
## Lib C MAKEFILE ------------------------------------------------------------ # ## LIB C MAKEFILE ------------------------------------------------------------ #
$(KOBJDIR)/atoi.o: $(KALEIDDIR)/libc/atoi.c $(INCLUDEDIR)/*/*.h | $(KOBJDIR) $(KOBJDIR)/libc/atoi.o: $(KALEIDDIR)/libc/atoi.c $(INCLUDEDIR)/*/*.h | $(KOBJDIR)
@$(KCC) -D_NEED_ATOI $< -o $@ @mkdir -p $(shell dirname $@)
@echo ${CL2}[$@] ${CL}Compiled.${CL3} @$(KCC) -D_NEED_ATOI $< -o $@.1
$(KOBJDIR)/atol.o: $(KALEIDDIR)/libc/atoi.c $(INCLUDEDIR)/*/*.h | $(KOBJDIR) @$(KCC) -D_NEED_ATOL $< -o $@.2
@$(KCC) -D_NEED_ATOL $< -o $@ @$(KCC) -D_NEED_ATOU $< -o $@.3
@echo ${CL2}[$@] ${CL}Compiled.${CL3} @$(KCC) -D_NEED_ATOUL $< -o $@.4
$(KOBJDIR)/atou.o: $(KALEIDDIR)/libc/atoi.c $(INCLUDEDIR)/*/*.h | $(KOBJDIR) @$(LD) -r $@.1 $@.2 $@.3 $@.4 -o $@
@$(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 $@
@echo ${CL2}[$@] ${CL}Compiled.${CL3} @echo ${CL2}[$@] ${CL}Compiled.${CL3}
## KERNEL MAKEFILE ----------------------------------------------------------- # $(KOBJDIR)/libc/itoa.o: $(KALEIDDIR)/libc/itoa.c $(INCLUDEDIR)/*/*.h | $(KOBJDIR)
$(KOBJDIR)/%.o: %.c $(INCLUDEDIR)/*/*.h
@mkdir -p $(shell dirname $@) @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} @echo ${CL2}[$@] ${CL}Compiled.${CL3}
## MAIN MAKEFILE ------------------------------------------------------------- # ## MAIN MAKEFILE ------------------------------------------------------------- #
$(KOBJDIR)/%.o: %.c $(INCLUDEDIR)/*/*.h | $(KOBJDIR)
@mkdir -p $(shell dirname $@)
@$(KCC) $< -o $@
@echo ${CL2}[$@] ${CL}Compiled.${CL3}
test: all test: all
@qemu-system-x86_64 -m 4G -hda $(BUILDDIR)/bin/disk.img \ @qemu-system-x86_64 -m 4G -hda $(BUILDDIR)/bin/disk.img \
-d cpu_reset,guest_errors,pcall,int 2> $(BUILDDIR)/qemu.log & -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 @rmdir $(BINDIR)/disk
@echo ${CL2}[$@] ${CL}Success.${CL3} @echo ${CL2}[$@] ${CL}Success.${CL3}
dust:
-@$(MBRDIR)/umount.sh $(BINDIR)/disk || /bin/true
@rm -Rf $(OBJDIR)/*
@echo ${CL2}[$@] ${CL}Cleaned.${CL3}
clean: clean:
-@$(MBRDIR)/umount.sh $(BINDIR)/disk || /bin/true -@$(MBRDIR)/umount.sh $(BINDIR)/disk || /bin/true
@rm -Rvf ./ProjectTree $(BUILDDIR)/*.log @rm -Rvf ./ProjectTree $(BUILDDIR)/*.log
@rm -Rvf $(BINDIR)/* $(KernObj) $(LibCObj) $(OBJDIR)/* @rm -Rvf $(BINDIR)/* $(OBJDIR)/*
@echo ${CL2}[[$@]] ${CL}Cleaned.${CL3} @echo ${CL2}[$@] ${CL}Cleaned.${CL3}
$(BINDIR)/kaleid: $(LOBJDIR)/kaleid.x86_64 $(BINDIR)/kaleid: $(LOBJDIR)/kaleid.x86_64
@echo ${CL2}[$@] ${NC}Objcopy...${CL3} @echo ${CL2}[$@] ${NC}Objcopy...${CL3}
@ -220,7 +209,7 @@ $(BINDIR)/disk.img: $(MBRDIR)/create_disk.sh
OS/K: $(BINDIR)/kaleid $(BINDIR)/disk.img ./ProjectTree OS/K: $(BINDIR)/kaleid $(BINDIR)/disk.img ./ProjectTree
@mkdir -p $(BINDIR)/disk @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)/umount.sh $(BINDIR)/disk || /bin/true
@$(MBRDIR)/mount.sh $(BINDIR)/disk.img $(BINDIR)/disk @$(MBRDIR)/mount.sh $(BINDIR)/disk.img $(BINDIR)/disk
@cp $(BINDIR)/kaleid $(BINDIR)/disk/boot/kaleid @cp $(BINDIR)/kaleid $(BINDIR)/disk/boot/kaleid

View File

@ -55,6 +55,9 @@
│   │   │   ├── kaleid.x86_64 │   │   │   ├── kaleid.x86_64
│   │   │   └── loader.o │   │   │   └── loader.o
│   │   └── kaleid │   │   └── kaleid
│   │   ├── extras
│   │   │   ├── argv.o
│   │   │   └── prog.o
│   │   ├── kernel │   │   ├── kernel
│   │   │   ├── cpu │   │   │   ├── cpu
│   │   │   │   ├── cpuid.o │   │   │   │   ├── cpuid.o
@ -79,23 +82,24 @@
│   │   │   ├── bprint.o │   │   │   ├── bprint.o
│   │   │   ├── bput.o │   │   │   ├── bput.o
│   │   │   └── buf.o │   │   │   └── buf.o
│   │   ├── argv.o │   │   └── libc
│   │   ├── atoi.o │   │   ├── atoi.o
│   │   ├── atol.o │   │   ├── atoi.o.1
│   │   ├── atoul.o │   │   ├── atoi.o.2
│   │   ├── atou.o │   │   ├── atoi.o.3
│   │   ├── atoi.o.4
│   │   ├── ctype.o │   │   ├── ctype.o
│   │   ├── itoa.o │   │   ├── itoa.o
│   │   ├── ltoa.o │   │   ├── itoa.o.1
│   │   ├── itoa.o.2
│   │   ├── itoa.o.3
│   │   ├── itoa.o.4
│   │   ├── mem.o │   │   ├── mem.o
│   │   ├── prog.o
│   │   ├── rand.o │   │   ├── rand.o
│   │   ├── sprintf.o │   │   ├── sprintf.o
│   │   ├── status.o │   │   ├── status.o
│   │   ├── string.o │   │   ├── string.o
│   │   ├── strtol.o │   │   └── strtol.o
│   │   ├── ultoa.o
│   │   └── utoa.o
│   ├── grub.log │   ├── grub.log
│   └── kernel.ld │   └── kernel.ld
├── include ├── include
@ -174,4 +178,4 @@
├── ProjectTree ├── ProjectTree
└── README.md └── README.md
35 directories, 114 files 37 directories, 116 files

View File

@ -150,6 +150,8 @@ noreturn void BtStartKern(multiboot_info_t *mbInfo, uint mbMagic)
MmInitHeap(); MmInitHeap();
PsInitSched(); PsInitSched();
KalAssert(0);
KeStartPanic("Test Panic %d", 4); KeStartPanic("Test Panic %d", 4);
// End this machine's suffering // End this machine's suffering