Makefile update

This commit is contained in:
Adrien Bourmault 2019-04-09 17:16:13 +02:00
parent 0addc2e952
commit ac626ae408
5 changed files with 111 additions and 151 deletions

219
Makefile
View File

@ -22,6 +22,9 @@
# along with OS/K. If not, see <https://www.gnu.org/licenses/>. #
#=----------------------------------------------------------------------------=#
.PHONY: all test test32 debug gdb install_mbr clean OS/K
all : OS/K
## VARIABLES ----------------------------------------------------------------- #
#Programs
@ -35,7 +38,7 @@ 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 -fno-strict-aliasing
CFLAGS2= -c -g -mno-red-zone -mno-mmx -mno-sse -mno-sse2
CFLAGS=$(CFLAGS1) $(CFLAGS2)
KCC=$(CCNAME) $(COPTIM) $(CWARNS) $(CFLAGS) $(CINCLUDES) -D_OSK_SOURCE -D_KALEID_KERNEL
@ -50,19 +53,16 @@ LOBJDIR=build/obj/boot
BINDIR=build/bin
BUILDDIR=build
vpath %.c $(KALEIDDIR)
#Color codes
CL='\033[0;32m'
CL2='\033[1;36m'
CL3='\033[0m'
NC='\033[1;37m'
.PHONY: all
all : OS/K
## KALEID MAKEFILE ----------------------------------------------------------- #
# Common objects
kal_com_obj= $(KOBJDIR)/atoi.o $(KOBJDIR)/ctype.o \
# 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 \
@ -72,118 +72,17 @@ kal_com_obj= $(KOBJDIR)/atoi.o $(KOBJDIR)/ctype.o \
$(KOBJDIR)/utoa.o $(KOBJDIR)/ltoa.o \
$(KOBJDIR)/ultoa.o
$(KOBJDIR)/atoi.o: $(KALEIDDIR)/libc/atoi.c $(INCLUDEDIR)/*/*.h
@$(KCC) -D_NEED_ATOI $< -o $@
@echo ${CL2}[$@] ${CL}Compiled.${CL3}
$(KOBJDIR)/atol.o: $(KALEIDDIR)/libc/atoi.c $(INCLUDEDIR)/*/*.h
@$(KCC) -D_NEED_ATOL $< -o $@
@echo ${CL2}[$@] ${CL}Compiled.${CL3}
$(KOBJDIR)/atou.o: $(KALEIDDIR)/libc/atoi.c $(INCLUDEDIR)/*/*.h
@$(KCC) -D_NEED_ATOU $< -o $@
@echo ${CL2}[$@] ${CL}Compiled.${CL3}
$(KOBJDIR)/atoul.o: $(KALEIDDIR)/libc/atoi.c $(INCLUDEDIR)/*/*.h
@$(KCC) -D_NEED_ATOUL $< -o $@
@echo ${CL2}[$@] ${CL}Compiled.${CL3}
$(KOBJDIR)/ctype.o: $(KALEIDDIR)/libc/ctype.c $(INCLUDEDIR)/*/*.h
@$(KCC) $< -o $@
@echo ${CL2}[$@] ${CL}Compiled.${CL3}
$(KOBJDIR)/itoa.o: $(KALEIDDIR)/libc/itoa.c $(INCLUDEDIR)/*/*.h
@$(KCC) -D_NEED_ITOA $< -o $@
@echo ${CL2}[$@] ${CL}Compiled.${CL3}
$(KOBJDIR)/ltoa.o: $(KALEIDDIR)/libc/itoa.c $(INCLUDEDIR)/*/*.h
@$(KCC) -D_NEED_LTOA $< -o $@
@echo ${CL2}[$@] ${CL}Compiled.${CL3}
$(KOBJDIR)/utoa.o: $(KALEIDDIR)/libc/itoa.c $(INCLUDEDIR)/*/*.h
@$(KCC) -D_NEED_UTOA $< -o $@
@echo ${CL2}[$@] ${CL}Compiled.${CL3}
$(KOBJDIR)/ultoa.o: $(KALEIDDIR)/libc/itoa.c $(INCLUDEDIR)/*/*.h
@$(KCC) -D_NEED_ULTOA $< -o $@
@echo ${CL2}[$@] ${CL}Compiled.${CL3}
$(KOBJDIR)/mem.o: $(KALEIDDIR)/libc/mem.c $(INCLUDEDIR)/*/*.h
@$(KCC) -fno-strict-aliasing $< -o $@
@echo ${CL2}[$@] ${CL}Compiled.${CL3}
$(KOBJDIR)/rand.o: $(KALEIDDIR)/libc/rand.c $(INCLUDEDIR)/*/*.h
@$(KCC) $< -o $@
@echo ${CL2}[$@] ${CL}Compiled.${CL3}
$(KOBJDIR)/sprintf.o: $(KALEIDDIR)/libc/sprintf.c $(INCLUDEDIR)/*/*.h
@$(KCC) $< -o $@
@echo ${CL2}[$@] ${CL}Compiled.${CL3}
$(KOBJDIR)/status.o: $(KALEIDDIR)/libc/status.c $(INCLUDEDIR)/*/*.h
@$(KCC) $< -o $@
@echo ${CL2}[$@] ${CL}Compiled.${CL3}
$(KOBJDIR)/string.o: $(KALEIDDIR)/libc/string.c $(INCLUDEDIR)/*/*.h
@$(KCC) $< -o $@
@echo ${CL2}[$@] ${CL}Compiled.${CL3}
$(KOBJDIR)/strtol.o: $(KALEIDDIR)/libc/strtol.c $(INCLUDEDIR)/*/*.h
@$(KCC) $< -o $@
@echo ${CL2}[$@] ${CL}Compiled.${CL3}
$(KOBJDIR)/argv.o: $(KALEIDDIR)/extras/argv.c $(INCLUDEDIR)/*/*.h
@$(KCC) $< -o $@
@echo ${CL2}[$@] ${CL}Compiled.${CL3}
$(KOBJDIR)/prog.o: $(KALEIDDIR)/extras/prog.c $(INCLUDEDIR)/*/*.h
@$(KCC) $< -o $@
@echo ${CL2}[$@] ${CL}Compiled.${CL3}
$(KOBJDIR)/kernel/buf.o: $(KALEIDDIR)/libbuf/buf.c $(INCLUDEDIR)/*/*.h
@$(KCC) $< -o $@
@echo ${CL2}[$@] ${CL}Compiled.${CL3}
$(KOBJDIR)/kernel/bput.o: $(KALEIDDIR)/libbuf/bput.c $(INCLUDEDIR)/*/*.h
@$(KCC) $< -o $@
@echo ${CL2}[$@] ${CL}Compiled.${CL3}
$(KOBJDIR)/kernel/bprint.o: $(KALEIDDIR)/libbuf/bprint.c $(INCLUDEDIR)/*/*.h
@$(KCC) $< -o $@
@echo ${CL2}[$@] ${CL}Compiled.${CL3}
# Kernel objects
kal_kern_obj= $(KOBJDIR)/kernel/cpuid.o $(KOBJDIR)/kernel/init.o \
$(KOBJDIR)/kernel/table.o $(KOBJDIR)/kernel/cursor.o \
$(KOBJDIR)/kernel/log.o $(KOBJDIR)/kernel/vga.o \
$(KOBJDIR)/kernel/panic.o $(KOBJDIR)/kernel/map.o \
$(KOBJDIR)/kernel/heap.o $(KOBJDIR)/kernel/malloc.o \
$(KOBJDIR)/kernel/buf.o $(KOBJDIR)/kernel/sched.o \
$(KOBJDIR)/kernel/bput.o $(KOBJDIR)/kernel/bprint.o \
$(KOBJDIR)/kernel/gdt.o
$(KOBJDIR)/kernel/cpuid.o: $(KALEIDDIR)/kernel/cpu/cpuid.c $(INCLUDEDIR)/*/*.h
@$(KCC) $< -o $@
@echo ${CL2}[$@] ${CL}Compiled.${CL3}
$(KOBJDIR)/kernel/idt.o: $(KALEIDDIR)/kernel/cpu/idt.c $(INCLUDEDIR)/*/*.h
@$(KCC) $< -o $@
@echo ${CL2}[$@] ${CL}Compiled.${CL3}
$(KOBJDIR)/kernel/init.o: $(KALEIDDIR)/kernel/init/init.c $(INCLUDEDIR)/*/*.h
@$(KCC) $< -o $@
@echo ${CL2}[$@] ${CL}Compiled.${CL3}
$(KOBJDIR)/kernel/table.o: $(KALEIDDIR)/kernel/init/table.c $(INCLUDEDIR)/*/*.h
@$(KCC) $< -o $@
@echo ${CL2}[$@] ${CL}Compiled.${CL3}
$(KOBJDIR)/kernel/cursor.o: $(KALEIDDIR)/kernel/io/cursor.c $(INCLUDEDIR)/*/*.h
@$(KCC) $< -o $@
@echo ${CL2}[$@] ${CL}Compiled.${CL3}
$(KOBJDIR)/kernel/log.o: $(KALEIDDIR)/kernel/ke/log.c $(INCLUDEDIR)/*/*.h
@$(KCC) $< -o $@
@echo ${CL2}[$@] ${CL}Compiled.${CL3}
$(KOBJDIR)/kernel/vga.o: $(KALEIDDIR)/kernel/io/vga.c $(INCLUDEDIR)/*/*.h
@$(KCC) $< -o $@
@echo ${CL2}[$@] ${CL}Compiled.${CL3}
$(KOBJDIR)/kernel/panic.o: $(KALEIDDIR)/kernel/ke/panic.c $(INCLUDEDIR)/*/*.h
@$(KCC) $< -o $@
@echo ${CL2}[$@] ${CL}Compiled.${CL3}
$(KOBJDIR)/kernel/map.o: $(KALEIDDIR)/kernel/mm/map.c $(INCLUDEDIR)/*/*.h
@$(KCC) $< -o $@
@echo ${CL2}[$@] ${CL}Compiled.${CL3}
$(KOBJDIR)/kernel/heap.o: $(KALEIDDIR)/kernel/mm/heap.c $(INCLUDEDIR)/*/*.h
@$(KCC) $< -o $@
@echo ${CL2}[$@] ${CL}Compiled.${CL3}
$(KOBJDIR)/kernel/malloc.o: $(KALEIDDIR)/kernel/mm/malloc.c $(INCLUDEDIR)/*/*.h
@$(KCC) $< -o $@
$(KOBJDIR)/kernel/gdt.o: $(KALEIDDIR)/kernel/mm/gdt.c $(INCLUDEDIR)/*/*.h
@$(KCC) $< -o $@
@echo ${CL2}[$@] ${CL}Compiled.${CL3}
$(KOBJDIR)/kernel/sched.o: $(KALEIDDIR)/kernel/ps/sched.c $(INCLUDEDIR)/*/*.h
@$(KCC) $< -o $@
@echo ${CL2}[$@] ${CL}Compiled.${CL3}
# 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 \
KernObj=$(patsubst %.c,$(KOBJDIR)/%.o,$(KernSources))
## MISC MAKEFILE ------------------------------------------------------------- #
./ProjectTree: ./.stylehlp_sh
@ -192,24 +91,83 @@ $(KOBJDIR)/kernel/sched.o: $(KALEIDDIR)/kernel/ps/sched.c $(INCLUDEDIR)/*/*.h
@tree --dirsfirst >> ./ProjectTree
@echo ${CL2}[$@] ${CL}Generated.${CL3}
$(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 $@
@echo ${CL2}[$@] ${CL}Compiled.${CL3}
## KERNEL MAKEFILE ----------------------------------------------------------- #
$(KOBJDIR)/%.o: %.c $(INCLUDEDIR)/*/*.h
@mkdir -p $(shell dirname $@)
@$(KCC) $< -o $@
@echo ${CL2}[$@] ${CL}Compiled.${CL3}
## MAIN MAKEFILE ------------------------------------------------------------- #
.PHONY: test
test: all
@qemu-system-x86_64 -m 4G -hda $(BUILDDIR)/bin/disk.img \
-d cpu_reset,guest_errors,pcall,int 2> $(BUILDDIR)/qemu.log &
.PHONY: test32
test32: all
@qemu-system-i386 -hda $(BUILDDIR)/bin/disk.img -d cpu_reset,guest_errors,pcall,int 2> $(BUILDDIR)/qemu.log &
.PHONY: debug
debug: all
@qemu-system-x86_64 -m 64M -hda $(BUILDDIR)/bin/disk.img -no-reboot \
-no-shutdown -d cpu_reset,guest_errors,pcall,int 2> $(BUILDDIR)/qemu.log &
@ndisasm $(BINDIR)/kaleid -o 0x00100000 -b 64 > $(BUILDDIR)/kaleid64_disasm.asm
@ndisasm $(BINDIR)/kaleid -o 0x00100000 -b 32 > $(BUILDDIR)/kaleid32_disasm.asm
.PHONY: gdb
gdb: all
@qemu-system-x86_64 -m 64M -hda $(BUILDDIR)/bin/disk.img -no-reboot \
-no-shutdown -d cpu_reset,guest_errors,pcall,int -s 2> $(BUILDDIR)/qemu.log &
@ -221,7 +179,6 @@ gdb: all
-ex "symbol-file $(BINDIR)/kaleid" \
-ex "break BtStartKern" \
.PHONY: install_mbr
install_mbr: $(BINDIR)/disk.img $(MBRDIR)/grub.cfg
@mkdir -p $(BINDIR)/disk
@echo ${CL2}[$@] ${NC}Installing MBR on image...${CL3}
@ -230,12 +187,10 @@ install_mbr: $(BINDIR)/disk.img $(MBRDIR)/grub.cfg
@rmdir $(BINDIR)/disk
@echo ${CL2}[$@] ${CL}Success.${CL3}
.PHONY: clean
clean:
-@$(MBRDIR)/umount.sh $(BINDIR)/disk || /bin/true
@rm -Rvf ./ProjectTree
@rm -Rvf $(BINDIR)/* $(OBJDIR)/*.o \
$(OBJDIR)/*/*.o $(OBJDIR)/*/*.x86_64 $(OBJDIR)/*/*/*.o
@rm -Rvf ./ProjectTree $(BUILDDIR)/*.log
@rm -Rvf $(BINDIR)/* $(KernObj) $(LibCObj) $(OBJDIR)/*
@echo ${CL2}[[$@]] ${CL}Cleaned.${CL3}
$(BINDIR)/kaleid: $(LOBJDIR)/kaleid.x86_64
@ -243,17 +198,16 @@ $(BINDIR)/kaleid: $(LOBJDIR)/kaleid.x86_64
@x86_64-elf-objcopy -I elf64-x86-64 -O elf32-i386 $(LOBJDIR)/kaleid.x86_64 $(BINDIR)/kaleid
@echo ${CL2}[$@] ${CL}Success.${CL3}
$(LOBJDIR)/kaleid.x86_64: $(kal_kern_obj) $(kal_com_obj) $(LOBJDIR)/loader.o
$(LOBJDIR)/kaleid.x86_64: $(LibCObj) $(KernObj) $(LOBJDIR)/loader.o
@echo ${CL2}[$@] ${NC}Linking kernel objects...${CL3}
@$(LD) $(LDFLAGS) -T $(BUILDDIR)/kernel.ld \
$(LOBJDIR)/loader.o \
$(KOBJDIR)/*.o \
$(KOBJDIR)/kernel/*.o \
$(LOBJDIR)/loader.o $(KernObj) $(LibCObj) \
-o $(LOBJDIR)/kaleid.x86_64
@echo ${CL2}[$@] ${CL}Success.${CL3}
$(LOBJDIR)/loader.o: $(LOADERDIR)/loader.asm $(LOADERDIR)/*/*.inc
@echo ${CL2}[$@] ${NC}Making loader...${CL3}
@mkdir -p $(shell dirname $@)
@$(ASM) $(ASMFLAGS) $(LOADERDIR)/loader.asm -o $(LOBJDIR)/loader.o > /dev/null
@echo ${CL2}[$@] ${CL}Success.${CL3}
@ -264,7 +218,6 @@ $(BINDIR)/disk.img: $(MBRDIR)/create_disk.sh
@make install_mbr
@echo ${CL2}[$@]${NC} Constructing disk image...${CL3}
.PHONY:OS/K
OS/K: $(BINDIR)/kaleid $(BINDIR)/disk.img ./ProjectTree
@mkdir -p $(BINDIR)/disk
@echo ${CL2}[[$@]] ${NC}Integrating kernel...${CL3}

View File

@ -56,21 +56,29 @@
│   │   │   └── loader.o
│   │   └── kaleid
│   │   ├── kernel
│   │   │   ├── cpu
│   │   │   │   ├── cpuid.o
│   │   │   │   └── idt.o
│   │   │   ├── init
│   │   │   │   ├── init.o
│   │   │   │   └── table.o
│   │   │   ├── io
│   │   │   │   ├── cursor.o
│   │   │   │   └── vga.o
│   │   │   ├── ke
│   │   │   │   ├── log.o
│   │   │   │   └── panic.o
│   │   │   ├── mm
│   │   │   │   ├── gdt.o
│   │   │   │   ├── heap.o
│   │   │   │   ├── malloc.o
│   │   │   │   └── map.o
│   │   │   └── ps
│   │   │   └── sched.o
│   │   ├── libbuf
│   │   │   ├── bprint.o
│   │   │   ├── bput.o
│   │   │   ├── buf.o
│   │   │   ├── cpuid.o
│   │   │   ├── cursor.o
│   │   │   ├── gdt.o
│   │   │   ├── heap.o
│   │   │   ├── init.o
│   │   │   ├── log.o
│   │   │   ├── malloc.o
│   │   │   ├── map.o
│   │   │   ├── panic.o
│   │   │   ├── sched.o
│   │   │   ├── table.o
│   │   │   └── vga.o
│   │   │   └── buf.o
│   │   ├── argv.o
│   │   ├── atoi.o
│   │   ├── atol.o
@ -89,8 +97,7 @@
│   │   ├── ultoa.o
│   │   └── utoa.o
│   ├── grub.log
│   ├── kernel.ld
│   └── qemu.log
│   └── kernel.ld
├── include
│   ├── base
│   │   ├── assert.h
@ -167,4 +174,4 @@
├── ProjectTree
└── README.md
28 directories, 114 files
35 directories, 114 files

View File

@ -21,7 +21,7 @@
// You should have received a copy of the GNU General Public License //
// along with OS/K. If not, see <https://www.gnu.org/licenses/>. //
//----------------------------------------------------------------------------//
#include <kernel/base.h>
//
// Registers the new idt in the idtr register.