1
0
mirror of https://gitlab.os-k.eu/os-k-team/os-k.git synced 2023-08-25 14:03:10 +02:00
os-k/Makefile

263 lines
11 KiB
Makefile
Raw Normal View History

2019-02-06 15:41:24 +01:00
#=----------------------------------------------------------------------------=#
# GNU GPL OS/K #
# #
# Desc: Project Makefile #
# #
# #
# Copyright © 2018-2019 The OS/K Team #
# #
# This file is part of OS/K. #
# #
# OS/K is free software: you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by #
# the Free Software Foundation, either version 3 of the License, or #
# any later version. #
# #
# OS/K is distributed in the hope that it will be useful, #
# but WITHOUT ANY WARRANTY# without even the implied warranty of #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
# GNU General Public License for more details. #
# #
# You should have received a copy of the GNU General Public License #
# along with OS/K. If not, see <https://www.gnu.org/licenses/>. #
#=----------------------------------------------------------------------------=#
2019-03-17 22:32:52 +01:00
## VARIABLES ----------------------------------------------------------------- #
#Programs
2019-01-14 23:16:26 +01:00
ASM=nasm
LD=ld
2019-03-17 22:32:52 +01:00
CCNAME=x86_64-elf-gcc
ASMFLAGS=-f elf64
LDFLAGS=-melf_x86_64
2019-03-17 22:32:52 +01:00
COPTIM=-O2
2019-03-18 17:25:44 +01:00
CWARNS=-Wall -Wextra -Werror=implicit-function-declaration
2019-03-17 22:32:52 +01:00
CINCLUDES=-Ikaleid/include
2019-03-18 17:25:44 +01:00
CFLAGS1=-nostdlib -ffreestanding -mcmodel=large -std=gnu11
2019-03-17 22:32:52 +01:00
CFLAGS2= -c -mno-red-zone -mno-mmx -mno-sse -mno-sse2 -fno-strict-aliasing
2019-03-18 17:25:44 +01:00
CFLAGS=$(CFLAGS1) $(CFLAGS2)
2019-03-17 22:32:52 +01:00
KCC=$(CCNAME) $(COPTIM) $(CWARNS) $(CFLAGS) $(CINCLUDES) -D_OSK_SOURCE -D_KALEID_KERNEL
2019-01-14 23:16:26 +01:00
#Folders
MBRDIR=boot/grub
2019-01-16 11:01:18 +01:00
LOADERDIR=boot/loader
2019-03-17 22:32:52 +01:00
KERNELDIR=kaleid
2019-01-14 23:16:26 +01:00
OBJDIR=build/obj
2019-03-18 13:45:26 +01:00
KOBJDIR=build/obj/kaleid
LOBJDIR=build/obj/boot
2019-01-14 23:16:26 +01:00
BINDIR=build/bin
#Color codes
CL='\033[0;32m'
CL2='\033[1;36m'
CL3='\033[0m'
NC='\033[1;37m'
2019-03-17 22:47:21 +01:00
2019-03-17 22:32:52 +01:00
.PHONY: all
2019-03-17 22:47:21 +01:00
all : OS/K
## KALEID MAKEFILE ----------------------------------------------------------- #
# Common objects
2019-03-23 00:07:05 +01:00
kal_com_obj= $(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 \
2019-03-18 13:45:26 +01:00
$(KOBJDIR)/ultoa.o
2019-03-22 23:51:48 +01:00
$(KOBJDIR)/atoi.o: $(KERNELDIR)/crtlib/atoi.c $(KERNELDIR)/include/*/*.h
2019-03-17 22:47:21 +01:00
@$(KCC) -D_NEED_ATOI $< -o $@
2019-03-18 13:09:34 +01:00
@echo ${CL2}[$@] ${CL}Compiled.${CL3}
2019-03-22 23:51:48 +01:00
$(KOBJDIR)/atol.o: $(KERNELDIR)/crtlib/atoi.c $(KERNELDIR)/include/*/*.h
2019-03-17 22:47:21 +01:00
@$(KCC) -D_NEED_ATOL $< -o $@
2019-03-18 13:09:34 +01:00
@echo ${CL2}[$@] ${CL}Compiled.${CL3}
2019-03-22 23:51:48 +01:00
$(KOBJDIR)/atou.o: $(KERNELDIR)/crtlib/atoi.c $(KERNELDIR)/include/*/*.h
2019-03-17 22:47:21 +01:00
@$(KCC) -D_NEED_ATOU $< -o $@
2019-03-18 13:09:34 +01:00
@echo ${CL2}[$@] ${CL}Compiled.${CL3}
2019-03-22 23:51:48 +01:00
$(KOBJDIR)/atoul.o: $(KERNELDIR)/crtlib/atoi.c $(KERNELDIR)/include/*/*.h
2019-03-17 22:47:21 +01:00
@$(KCC) -D_NEED_ATOUL $< -o $@
2019-03-18 13:09:34 +01:00
@echo ${CL2}[$@] ${CL}Compiled.${CL3}
2019-03-22 23:51:48 +01:00
$(KOBJDIR)/ctype.o: $(KERNELDIR)/crtlib/ctype.c $(KERNELDIR)/include/*/*.h
2019-03-17 22:47:21 +01:00
@$(KCC) $< -o $@
2019-03-18 13:09:34 +01:00
@echo ${CL2}[$@] ${CL}Compiled.${CL3}
2019-03-22 23:51:48 +01:00
$(KOBJDIR)/itoa.o: $(KERNELDIR)/crtlib/itoa.c $(KERNELDIR)/include/*/*.h
2019-03-17 22:47:21 +01:00
@$(KCC) -D_NEED_ITOA $< -o $@
2019-03-18 13:09:34 +01:00
@echo ${CL2}[$@] ${CL}Compiled.${CL3}
2019-03-22 23:51:48 +01:00
$(KOBJDIR)/ltoa.o: $(KERNELDIR)/crtlib/itoa.c $(KERNELDIR)/include/*/*.h
2019-03-17 22:47:21 +01:00
@$(KCC) -D_NEED_LTOA $< -o $@
2019-03-18 13:09:34 +01:00
@echo ${CL2}[$@] ${CL}Compiled.${CL3}
2019-03-22 23:51:48 +01:00
$(KOBJDIR)/utoa.o: $(KERNELDIR)/crtlib/itoa.c $(KERNELDIR)/include/*/*.h
2019-03-17 22:47:21 +01:00
@$(KCC) -D_NEED_UTOA $< -o $@
2019-03-18 13:09:34 +01:00
@echo ${CL2}[$@] ${CL}Compiled.${CL3}
2019-03-22 23:51:48 +01:00
$(KOBJDIR)/ultoa.o: $(KERNELDIR)/crtlib/itoa.c $(KERNELDIR)/include/*/*.h
2019-03-17 22:47:21 +01:00
@$(KCC) -D_NEED_ULTOA $< -o $@
2019-03-18 13:09:34 +01:00
@echo ${CL2}[$@] ${CL}Compiled.${CL3}
2019-03-22 23:51:48 +01:00
$(KOBJDIR)/mem.o: $(KERNELDIR)/crtlib/mem.c $(KERNELDIR)/include/*/*.h
2019-03-17 22:47:21 +01:00
@$(KCC) -fno-strict-aliasing $< -o $@
2019-03-18 13:09:34 +01:00
@echo ${CL2}[$@] ${CL}Compiled.${CL3}
2019-03-22 23:51:48 +01:00
$(KOBJDIR)/rand.o: $(KERNELDIR)/crtlib/rand.c $(KERNELDIR)/include/*/*.h
2019-03-17 22:47:21 +01:00
@$(KCC) $< -o $@
2019-03-18 13:09:34 +01:00
@echo ${CL2}[$@] ${CL}Compiled.${CL3}
2019-03-22 23:51:48 +01:00
$(KOBJDIR)/sprintf.o: $(KERNELDIR)/crtlib/sprintf.c $(KERNELDIR)/include/*/*.h
2019-03-17 22:47:21 +01:00
@$(KCC) $< -o $@
2019-03-18 13:09:34 +01:00
@echo ${CL2}[$@] ${CL}Compiled.${CL3}
2019-03-22 23:51:48 +01:00
$(KOBJDIR)/status.o: $(KERNELDIR)/crtlib/status.c $(KERNELDIR)/include/*/*.h
2019-03-17 22:47:21 +01:00
@$(KCC) $< -o $@
2019-03-18 13:09:34 +01:00
@echo ${CL2}[$@] ${CL}Compiled.${CL3}
2019-03-22 23:51:48 +01:00
$(KOBJDIR)/string.o: $(KERNELDIR)/crtlib/string.c $(KERNELDIR)/include/*/*.h
2019-03-17 22:47:21 +01:00
@$(KCC) $< -o $@
2019-03-18 13:09:34 +01:00
@echo ${CL2}[$@] ${CL}Compiled.${CL3}
2019-03-22 23:51:48 +01:00
$(KOBJDIR)/strtol.o: $(KERNELDIR)/crtlib/strtol.c $(KERNELDIR)/include/*/*.h
2019-03-17 22:47:21 +01:00
@$(KCC) $< -o $@
2019-03-18 13:09:34 +01:00
@echo ${CL2}[$@] ${CL}Compiled.${CL3}
2019-03-22 23:51:48 +01:00
$(KOBJDIR)/argv.o: $(KERNELDIR)/extras/argv.c $(KERNELDIR)/include/*/*.h
2019-03-17 22:47:21 +01:00
@$(KCC) $< -o $@
2019-03-18 13:09:34 +01:00
@echo ${CL2}[$@] ${CL}Compiled.${CL3}
2019-03-22 23:51:48 +01:00
$(KOBJDIR)/prog.o: $(KERNELDIR)/extras/prog.c $(KERNELDIR)/include/*/*.h
2019-03-17 22:47:21 +01:00
@$(KCC) $< -o $@
2019-03-18 13:09:34 +01:00
@echo ${CL2}[$@] ${CL}Compiled.${CL3}
2019-03-17 22:47:21 +01:00
# Kernel objects
2019-03-23 00:07:05 +01:00
kal_kern_obj= $(KOBJDIR)/kernel/cpuid.o $(KOBJDIR)/kernel/init.o \
2019-03-26 17:50:03 +01:00
$(KOBJDIR)/kernel/table.o $(KOBJDIR)/kernel/cursor.o \
$(KOBJDIR)/kernel/term.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/gdt.o
2019-03-17 22:47:21 +01:00
2019-03-22 23:51:48 +01:00
$(KOBJDIR)/kernel/cpuid.o: $(KERNELDIR)/kernel/cpu/cpuid.c $(KERNELDIR)/include/*/*.h
2019-03-17 22:47:21 +01:00
@$(KCC) $< -o $@
2019-03-18 13:09:34 +01:00
@echo ${CL2}[$@] ${CL}Compiled.${CL3}
2019-03-26 17:50:03 +01:00
$(KOBJDIR)/kernel/idt.o: $(KERNELDIR)/kernel/cpu/idt.c $(KERNELDIR)/include/*/*.h
@$(KCC) $< -o $@
@echo ${CL2}[$@] ${CL}Compiled.${CL3}
2019-03-22 23:51:48 +01:00
$(KOBJDIR)/kernel/init.o: $(KERNELDIR)/kernel/init/init.c $(KERNELDIR)/include/*/*.h
2019-03-17 22:47:21 +01:00
@$(KCC) $< -o $@
2019-03-18 13:09:34 +01:00
@echo ${CL2}[$@] ${CL}Compiled.${CL3}
2019-03-22 23:51:48 +01:00
$(KOBJDIR)/kernel/table.o: $(KERNELDIR)/kernel/init/table.c $(KERNELDIR)/include/*/*.h
2019-03-17 22:47:21 +01:00
@$(KCC) $< -o $@
2019-03-18 13:09:34 +01:00
@echo ${CL2}[$@] ${CL}Compiled.${CL3}
2019-03-22 23:51:48 +01:00
$(KOBJDIR)/kernel/cursor.o: $(KERNELDIR)/kernel/io/cursor.c $(KERNELDIR)/include/*/*.h
2019-03-17 22:47:21 +01:00
@$(KCC) $< -o $@
2019-03-18 13:09:34 +01:00
@echo ${CL2}[$@] ${CL}Compiled.${CL3}
2019-03-22 23:51:48 +01:00
$(KOBJDIR)/kernel/term.o: $(KERNELDIR)/kernel/io/term.c $(KERNELDIR)/include/*/*.h
2019-03-17 22:47:21 +01:00
@$(KCC) $< -o $@
2019-03-18 13:09:34 +01:00
@echo ${CL2}[$@] ${CL}Compiled.${CL3}
2019-03-22 23:51:48 +01:00
$(KOBJDIR)/kernel/vga.o: $(KERNELDIR)/kernel/io/vga.c $(KERNELDIR)/include/*/*.h
2019-03-17 22:47:21 +01:00
@$(KCC) $< -o $@
2019-03-18 13:09:34 +01:00
@echo ${CL2}[$@] ${CL}Compiled.${CL3}
2019-03-22 23:51:48 +01:00
$(KOBJDIR)/kernel/panic.o: $(KERNELDIR)/kernel/ke/panic.c $(KERNELDIR)/include/*/*.h
2019-03-17 22:47:21 +01:00
@$(KCC) $< -o $@
2019-03-18 13:09:34 +01:00
@echo ${CL2}[$@] ${CL}Compiled.${CL3}
2019-03-22 23:51:48 +01:00
$(KOBJDIR)/kernel/map.o: $(KERNELDIR)/kernel/mm/map.c $(KERNELDIR)/include/*/*.h
2019-03-18 20:53:09 +01:00
@$(KCC) $< -o $@
@echo ${CL2}[$@] ${CL}Compiled.${CL3}
2019-03-22 23:51:48 +01:00
$(KOBJDIR)/kernel/heap.o: $(KERNELDIR)/kernel/mm/heap.c $(KERNELDIR)/include/*/*.h
2019-03-18 17:25:44 +01:00
@$(KCC) $< -o $@
@echo ${CL2}[$@] ${CL}Compiled.${CL3}
2019-03-22 23:51:48 +01:00
$(KOBJDIR)/kernel/malloc.o: $(KERNELDIR)/kernel/mm/malloc.c $(KERNELDIR)/include/*/*.h
2019-03-18 17:43:41 +01:00
@$(KCC) $< -o $@
2019-03-26 17:50:03 +01:00
$(KOBJDIR)/kernel/gdt.o: $(KERNELDIR)/kernel/mm/gdt.c $(KERNELDIR)/include/*/*.h
@$(KCC) $< -o $@
2019-03-18 17:43:41 +01:00
@echo ${CL2}[$@] ${CL}Compiled.${CL3}
2019-03-24 22:51:16 +01:00
$(KOBJDIR)/kernel/buf.o: $(KERNELDIR)/kernel/buf/buf.c $(KERNELDIR)/include/*/*.h
@$(KCC) $< -o $@
@echo ${CL2}[$@] ${CL}Compiled.${CL3}
2019-03-25 17:33:51 +01:00
$(KOBJDIR)/kernel/bput.o: $(KERNELDIR)/kernel/buf/bput.c $(KERNELDIR)/include/*/*.h
@$(KCC) $< -o $@
@echo ${CL2}[$@] ${CL}Compiled.${CL3}
$(KOBJDIR)/kernel/bprint.o: $(KERNELDIR)/kernel/buf/bprint.c $(KERNELDIR)/include/*/*.h
@$(KCC) $< -o $@
@echo ${CL2}[$@] ${CL}Compiled.${CL3}
$(KOBJDIR)/kernel/sched.o: $(KERNELDIR)/kernel/proc/sched.c $(KERNELDIR)/include/*/*.h
@$(KCC) $< -o $@
@echo ${CL2}[$@] ${CL}Compiled.${CL3}
2019-03-17 22:47:21 +01:00
2019-03-18 13:45:26 +01:00
## MISC MAKEFILE ------------------------------------------------------------- #
./ProjectTree: ./.stylehlp_sh
@cat ./.stylehlp_sh > ./ProjectTree
@echo "\n" >> ./ProjectTree
2019-03-21 13:30:17 +01:00
@tree --dirsfirst >> ./ProjectTree
2019-03-18 13:45:26 +01:00
@echo ${CL2}[$@] ${CL}Generated.${CL3}
2019-03-17 22:47:21 +01:00
## MAIN MAKEFILE ------------------------------------------------------------- #
2019-03-09 22:29:30 +01:00
2019-03-17 22:32:52 +01:00
.PHONY: test
test: all
2019-03-28 23:03:26 +01:00
@qemu-system-x86_64 -m 5G -mem-prealloc -hda build/bin/disk.img -d cpu_reset,guest_errors,pcall,int 2> qemu.log &
2019-03-08 09:44:09 +01:00
@ndisasm $(BINDIR)/kaleid -o 0x00100000 -b 64 > loader_disasm64.asm
@ndisasm $(BINDIR)/kaleid -o 0x00100000 -b 32 > loader_disasm32.asm
2019-03-17 22:32:52 +01:00
.PHONY: test32
test32: all
@qemu-system-i386 -hda build/bin/disk.img -d cpu_reset,guest_errors,pcall,int 2> qemu.log &
2019-03-08 09:44:09 +01:00
@ndisasm $(BINDIR)/kaleid -o 0x00100000 -b 64 > loader_disasm64.asm
@ndisasm $(BINDIR)/kaleid -o 0x00100000 -b 32 > loader_disasm32.asm
2019-03-17 22:32:52 +01:00
.PHONY: debug
debug: all
@qemu-system-x86_64 -m 5G -hda build/bin/disk.img -d cpu_reset,guest_errors,pcall,int -s -S 2> qemu.log &
2019-03-08 09:44:09 +01:00
@ndisasm $(BINDIR)/kaleid -o 0x00100000 -b 64 > loader_disasm64.asm
@ndisasm $(BINDIR)/kaleid -o 0x00100000 -b 32 > loader_disasm32.asm
2019-03-17 22:32:52 +01:00
.PHONY: install_mbr
install_mbr: $(BINDIR)/disk.img $(MBRDIR)/grub.cfg
@mkdir -p $(BINDIR)/disk
@echo ${CL2}[$@] ${NC}Installing MBR on image...${CL3}
2019-03-18 22:46:58 +01:00
-@$(MBRDIR)/umount.sh $(BINDIR)/disk || /bin/true
2019-03-17 22:32:52 +01:00
@$(MBRDIR)/grub-install.sh $(BINDIR)/disk.img $(BINDIR)/disk $(MBRDIR)/grub.cfg
@rmdir $(BINDIR)/disk
@echo ${CL2}[$@] ${CL}Success.${CL3}
2019-03-17 22:32:52 +01:00
.PHONY: clean
clean:
2019-03-18 22:46:58 +01:00
-@$(MBRDIR)/umount.sh $(BINDIR)/disk || /bin/true
2019-03-18 13:45:26 +01:00
@rm -Rvf ./ProjectTree
2019-03-18 22:46:58 +01:00
@rm -Rvf $(BINDIR)/* $(OBJDIR)/*.o \
$(OBJDIR)/*/*.o $(OBJDIR)/*/*.x86_64 $(OBJDIR)/*/*/*.o
2019-03-18 13:45:26 +01:00
@echo ${CL2}[[$@]] ${CL}Cleaned.${CL3}
2019-03-17 22:32:52 +01:00
2019-03-18 13:45:26 +01:00
$(BINDIR)/kaleid: $(LOBJDIR)/kaleid.x86_64
2019-03-17 22:32:52 +01:00
@echo ${CL2}[$@] ${NC}Objcopy...${CL3}
2019-03-18 13:45:26 +01:00
@x86_64-elf-objcopy -I elf64-x86-64 -O elf32-i386 $(LOBJDIR)/kaleid.x86_64 $(BINDIR)/kaleid
2019-03-17 22:32:52 +01:00
@echo ${CL2}[$@] ${CL}Success.${CL3}
2019-03-18 13:45:26 +01:00
$(LOBJDIR)/kaleid.x86_64: $(kal_kern_obj) $(kal_com_obj) $(LOBJDIR)/loader.o
2019-03-17 22:32:52 +01:00
@echo ${CL2}[$@] ${NC}Linking kernel objects...${CL3}
@$(LD) $(LDFLAGS) -T build/kernel.ld \
2019-03-18 13:45:26 +01:00
$(LOBJDIR)/loader.o \
$(KOBJDIR)/*.o \
$(KOBJDIR)/kernel/*.o \
-o $(LOBJDIR)/kaleid.x86_64
2019-03-17 22:32:52 +01:00
@echo ${CL2}[$@] ${CL}Success.${CL3}
2019-03-19 12:24:27 +01:00
$(LOBJDIR)/loader.o: $(LOADERDIR)/loader.asm $(LOADERDIR)/*/*.inc
2019-03-17 22:32:52 +01:00
@echo ${CL2}[$@] ${NC}Making loader...${CL3}
2019-03-18 13:45:26 +01:00
@$(ASM) $(ASMFLAGS) $(LOADERDIR)/loader.asm -o $(LOBJDIR)/loader.o > /dev/null
2019-03-17 22:32:52 +01:00
@echo ${CL2}[$@] ${CL}Success.${CL3}
2019-03-17 22:32:52 +01:00
$(BINDIR)/disk.img: $(MBRDIR)/create_disk.sh
@echo ${CL2}[$@]${NC} Constructing disk image...${CL3}
2019-03-18 22:46:58 +01:00
-@$(MBRDIR)/umount.sh $(BINDIR)/disk || /bin/true
2019-03-17 22:32:52 +01:00
@$(MBRDIR)/create_disk.sh $(BINDIR)/disk.img
@make install_mbr
@echo ${CL2}[$@]${NC} Constructing disk image...${CL3}
2019-03-18 13:45:26 +01:00
.PHONY:OS/K
OS/K: $(BINDIR)/kaleid $(BINDIR)/disk.img ./ProjectTree
@mkdir -p $(BINDIR)/disk
@echo ${CL2}[[$@]] ${NC}Integrating kernel...${CL3}
2019-03-18 22:46:58 +01:00
-@$(MBRDIR)/umount.sh $(BINDIR)/disk || /bin/true
2019-03-18 13:45:26 +01:00
@$(MBRDIR)/mount.sh $(BINDIR)/disk.img $(BINDIR)/disk
@cp $(BINDIR)/kaleid $(BINDIR)/disk/boot/kaleid
@$(MBRDIR)/umount.sh $(BINDIR)/disk
@echo ${CL2}[[$@]] ${CL}Success.${CL3}
@rmdir $(BINDIR)/disk