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

364 lines
13 KiB
Makefile
Raw Normal View History

2019-02-06 15:41:24 +01:00
#=----------------------------------------------------------------------------=#
# GNU GPL OS/K #
# #
# Desc: Project Makefile #
# #
# #
# Copyright © 2018-2020 The OS/K Team #
2019-02-06 15:41:24 +01:00
# #
# 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/>. #
#=----------------------------------------------------------------------------=#
2020-01-05 20:13:53 +01:00
.PHONY: all test testnokvm testnosnd test32 debug gdb ddd gdbnokvm dddnokvm installonimage dust clean OS/K run
2019-05-12 20:30:53 +02:00
.DELETE_ON_ERROR: $(BINDIR)/kaleid
2019-11-11 23:57:31 +01:00
.DEFAULT_GOAL := all
2019-11-08 15:41:51 +01:00
2019-03-17 22:32:52 +01:00
## VARIABLES ----------------------------------------------------------------- #
2019-04-09 23:35:31 +02:00
# Debug
mode ?= debug
2019-05-16 23:56:23 +02:00
ram ?= 4G
2019-11-15 21:31:10 +01:00
cpu ?= core2duo
2019-04-09 23:35:31 +02:00
# Programs
2019-01-14 23:16:26 +01:00
ASM=nasm
2019-04-10 10:55:22 +02:00
LD=x86_64-elf-ld
OBJCOPY=x86_64-elf-objcopy
2019-03-17 22:32:52 +01:00
CCNAME=x86_64-elf-gcc
2020-02-19 22:19:58 +01:00
# Flags
ASMFLAGS=-f elf64
LDFLAGS=-melf_x86_64
2019-03-17 22:32:52 +01:00
COPTIM=-O2
2020-01-08 21:10:24 +01:00
CWARNS=-Wall -Wextra -Wno-unused-parameter -Wno-implicit-fallthrough -Werror=implicit-function-declaration -Werror=return-type #-Wpadded
2020-02-19 22:19:58 +01:00
CINCLUDES=-Iinclude -Iinclude/drivers -Iinclude/kernel
2019-05-27 20:45:05 +02:00
CFLAGS1=-nostdlib -ffreestanding -mcmodel=large -std=gnu11 -fstack-protector-all -fdump-rtl-expand
2019-04-09 23:35:31 +02:00
CFLAGS2= -c -mno-red-zone -mno-mmx -mno-sse -mno-sse2
2019-05-22 23:32:44 +02:00
CFLAGS= $(CFLAGS1) $(CFLAGS2)
CFLAGS_MATHS= $(CFLAGS1) -c -mno-red-zone -mno-mmx
2019-04-09 23:35:31 +02:00
ifeq ($(mode), release)
CFLAGS += -D_NO_DEBUG
2020-02-19 22:19:58 +01:00
CFLAGS_MATHS += -D_NO_DEBUG
2019-04-09 23:35:31 +02:00
dep += dust
endif
ifeq ($(mode), debug)
CFLAGS += -g
2020-02-19 22:19:58 +01:00
CFLAGS_MATHS += -g
2019-04-09 23:35:31 +02:00
endif
2020-02-19 22:19:58 +01:00
# GCC
2019-05-22 23:32:44 +02:00
KCC=$(CCNAME) $(COPTIM) $(CWARNS) $(CFLAGS) $(CINCLUDES) \
2019-05-27 20:45:05 +02:00
-D_OSK_SOURCE -D_KALEID_KERNEL
2019-05-22 23:32:44 +02:00
KCC_MATHS=$(CCNAME) $(COPTIM) $(CWARNS) $(CFLAGS_MATHS) $(CINCLUDES) \
2019-05-27 20:45:05 +02:00
-D_OSK_SOURCE -D_KALEID_KERNEL
2019-01-14 23:16:26 +01:00
2019-04-09 23:35:31 +02:00
# Folders
MBRDIR=boot/grub
2019-01-16 11:01:18 +01:00
LOADERDIR=boot/loader
2019-04-06 07:53:58 +02:00
KALEIDDIR=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
BUILDDIR=build
2019-04-09 17:16:13 +02:00
vpath %.c $(KALEIDDIR)
2019-11-11 18:32:22 +01:00
# Installation parameters
installdisk ?= $(BINDIR)/disk.img
2019-04-09 23:35:31 +02:00
# Color codes
CL='\033[0;32m'
CL2='\033[1;36m'
CL3='\033[0m'
NC='\033[1;37m'
2019-04-09 23:35:31 +02:00
## SOURCES INSCRIPTION-------------------------------------------------------- #
2019-05-07 23:16:56 +02:00
# Lib C sources + libbuf source
2019-11-28 13:02:47 +01:00
LibCSources = libc/mem.c libc/ctype.c \
libc/rand.c libc/sprintf.c \
libc/errno.c libc/string.c \
libc/strtol.c \
libbuf/bopen.c libbuf/bputc.c libbuf/bscroll.c \
libbuf/bprint.c libbuf/bgetc.c libbuf/bscan.c \
libbuf/bflush.c libbuf/bwrite.c libbuf/bread.c \
libbuf/bmisc.c libbuf/bclose.c \
2019-03-18 13:45:26 +01:00
2019-05-11 00:16:40 +02:00
LibCObj=$(patsubst %.c,$(KOBJDIR)/%.o,$(LibCSources))
LibCDep=$(patsubst %.c,$(KOBJDIR)/%.d,$(LibCSources))
LibCObj += $(KOBJDIR)/libc/atoi.o $(KOBJDIR)/libc/itoa.o
2019-04-09 23:36:30 +02:00
2019-04-09 17:16:13 +02:00
# Kernel sources
2019-11-28 13:02:47 +01:00
KernSources = kernel/ke/cpuid.c kernel/mm/paging.c \
kernel/ke/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 \
kernel/init/info.c kernel/init/ssp.c \
kernel/ke/rtc.c kernel/io/keyb.c \
kernel/io/spkr.c kernel/po/shtdwn.c \
kernel/sh/shell.c kernel/sh/shcmds.c \
2020-02-19 22:19:58 +01:00
kernel/sh/musage.c kernel/sh/argv.c \
kernel/ke/pit.c kernel/sh/testcmds.c \
kernel/mm/palloc.c kernel/io/acpi.c \
kernel/io/pci.c
2019-04-09 17:16:13 +02:00
2019-05-11 00:16:40 +02:00
KernObj=$(patsubst %.c,$(KOBJDIR)/%.o,$(KernSources))
KernDep=$(patsubst %.c,$(KOBJDIR)/%.d,$(KernSources))
2019-04-09 23:35:31 +02:00
2020-02-19 22:19:58 +01:00
# Drivers sources
2020-02-19 22:33:05 +01:00
DriverSources = drivers/ata.c drivers/rtl8139.c
2020-02-19 22:19:58 +01:00
DriverObj=$(patsubst %.c,$(KOBJDIR)/%.o,$(DriverSources))
DriverDep=$(patsubst %.c,$(KOBJDIR)/%.d,$(DriverSources))
-include $(LibCDep)
-include $(KernDep)
-include $(DriverDep)
2019-04-09 17:16:13 +02:00
## MISC MAKEFILE ------------------------------------------------------------- #
2019-11-08 15:41:51 +01:00
2019-04-09 17:16:13 +02:00
./ProjectTree: ./.stylehlp_sh
@cat ./.stylehlp_sh > ./ProjectTree
@echo "\n" >> ./ProjectTree
2019-11-11 18:37:18 +01:00
@tree --dirsfirst -I "bin|obj">> ./ProjectTree
2019-04-09 17:16:13 +02:00
@echo ${CL2}[$@] ${CL}Generated.${CL3}
$(KOBJDIR):
@mkdir -p $(KOBJDIR)
2019-06-15 13:44:49 +02:00
wc:
@rm -f build/kaleid*_disasm.asm
@cat $(shell find -name *.[ch]) $(shell find -name *.asm) $(shell find -name *.inc) | wc -l
2019-11-08 15:41:51 +01:00
egypt: CFLAGS := -DNDEBUG $(filter-out -fstack-protector-all,$(CFLAGS))
2020-02-19 22:19:58 +01:00
egypt: dust $(LibCObj) $(KernObj) $(DriverObj)
2019-11-08 15:41:51 +01:00
@find -name '*.expand' -o -name '*.expand' | xargs cat > rtl_exp.out
@egypt < rtl_exp.out | dot -Tps -o osk-graph.ps
@rm -f rtl_exp.out
@evince osk-graph.ps &
2019-04-09 23:35:31 +02:00
## LIB C MAKEFILE ------------------------------------------------------------ #
2019-11-08 15:41:51 +01:00
2019-05-13 23:22:27 +02:00
$(KOBJDIR)/libc/atoi.o: $(KALEIDDIR)/libc/atoi.c | $(KOBJDIR)
2019-04-09 23:35:31 +02:00
@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
2019-04-22 20:15:32 +02:00
@$(LD) $(LDFLAGS) -r $@.1 $@.2 $@.3 $@.4 -o $@
2019-04-10 10:59:13 +02:00
@rm -f $@.1 $@.2 $@.3 $@.4
2019-03-18 13:09:34 +01:00
@echo ${CL2}[$@] ${CL}Compiled.${CL3}
2019-04-09 23:35:31 +02:00
2019-05-13 23:22:27 +02:00
$(KOBJDIR)/libc/itoa.o: $(KALEIDDIR)/libc/itoa.c | $(KOBJDIR)
2019-04-09 23:35:31 +02:00
@mkdir -p $(shell dirname $@)
@$(KCC) -D_NEED_ITOA $< -o $@.1
@$(KCC) -D_NEED_LTOA $< -o $@.2
@$(KCC) -D_NEED_UTOA $< -o $@.3
@$(KCC) -D_NEED_ULTOA $< -o $@.4
2019-04-22 20:15:32 +02:00
@$(LD) $(LDFLAGS) -r $@.1 $@.2 $@.3 $@.4 -o $@
2019-04-10 10:59:13 +02:00
@rm -f $@.1 $@.2 $@.3 $@.4
2019-03-18 13:09:34 +01:00
@echo ${CL2}[$@] ${CL}Compiled.${CL3}
2019-04-09 23:35:31 +02:00
2019-05-11 00:16:40 +02:00
$(KOBJDIR)/libc/mem.o: $(KALEIDDIR)/libc/mem.c | $(KOBJDIR)
2019-04-09 23:35:31 +02:00
@mkdir -p $(shell dirname $@)
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-17 22:47:21 +01:00
2019-11-08 15:41:51 +01:00
2020-02-19 22:19:58 +01:00
## KERNEL SPECIAL RECIPES MAKEFILE ------------------------------------------- #
2019-05-08 17:49:30 +02:00
2019-05-14 13:17:24 +02:00
$(KOBJDIR)/kernel/ke/idt.o: $(KALEIDDIR)/kernel/ke/idt.c \
$(KALEIDDIR)/kernel/ke/isr.asm | $(KOBJDIR)
2019-04-22 20:15:32 +02:00
@mkdir -p $(shell dirname $@)
2019-05-14 13:17:24 +02:00
@$(ASM) $(ASMFLAGS) $(KALEIDDIR)/kernel/ke/isr.asm -o $@.1
2019-04-22 20:15:32 +02:00
@$(KCC) $< -o $@.2
@$(LD) $(LDFLAGS) -r $@.1 $@.2 -o $@
@rm -f $@.1 $@.2
@echo ${CL2}[$@] ${CL}Compiled.${CL3}
2019-05-23 14:50:05 +02:00
$(KOBJDIR)/kernel/ke/cpuid.o: $(KALEIDDIR)/kernel/ke/cpuid.c \
$(KALEIDDIR)/kernel/ke/cpuf.asm | $(KOBJDIR)
@mkdir -p $(shell dirname $@)
@$(ASM) $(ASMFLAGS) $(KALEIDDIR)/kernel/ke/cpuf.asm -o $@.1
@$(KCC_MATHS) $< -o $@.2
@$(LD) $(LDFLAGS) -r $@.1 $@.2 -o $@
@rm -f $@.1 $@.2
@echo ${CL2}[$@] ${CL}Compiled.${CL3}
2019-11-26 17:23:55 +01:00
$(KOBJDIR)/kernel/ke/shcmds.o: $(KALEIDDIR)/kernel/sh/shcmds.c | $(KOBJDIR)
@mkdir -p $(shell dirname $@)
@$(KCC_MATHS) -MM -MT $(@:%.d=%.o) -MF $@ $<
@echo ${CL2}[$@] ${CL}Compiled.${CL3}
2019-05-14 14:39:35 +02:00
$(KOBJDIR)/kernel/mm/paging.o: $(KALEIDDIR)/kernel/mm/paging.c \
$(KALEIDDIR)/kernel/mm/paging.asm | $(KOBJDIR)
@mkdir -p $(shell dirname $@)
@$(ASM) $(ASMFLAGS) $(KALEIDDIR)/kernel/mm/paging.asm -o $@.1
@$(KCC) $< -o $@.2
@$(LD) $(LDFLAGS) -r $@.1 $@.2 -o $@
@rm -f $@.1 $@.2
@echo ${CL2}[$@] ${CL}Compiled.${CL3}
2019-05-13 18:07:45 +02:00
$(KOBJDIR)/kernel/mm/gdt.o: $(KALEIDDIR)/kernel/mm/gdt.c \
$(KALEIDDIR)/kernel/mm/gdt.asm | $(KOBJDIR)
@mkdir -p $(shell dirname $@)
@$(ASM) $(ASMFLAGS) $(KALEIDDIR)/kernel/mm/gdt.asm -o $@.1
@$(KCC) $< -o $@.2
@$(LD) $(LDFLAGS) -r $@.1 $@.2 -o $@
@rm -f $@.1 $@.2
@echo ${CL2}[$@] ${CL}Compiled.${CL3}
2020-02-19 22:19:58 +01:00
## DRIVERS SPECIAL RECIPES MAKEFILE ------------------------------------------ #
$(KOBJDIR)/drivers/ata.o: $(KALEIDDIR)/drivers/ata.c $(KALEIDDIR)/drivers/ata.asm | $(KOBJDIR)
2019-05-08 17:49:30 +02:00
@mkdir -p $(shell dirname $@)
2020-02-19 22:19:58 +01:00
@$(ASM) $(ASMFLAGS) $(KALEIDDIR)/drivers/ata.asm -o $@.1
2019-05-23 14:50:05 +02:00
@$(KCC) $< -o $@.2
2019-05-08 17:49:30 +02:00
@$(LD) $(LDFLAGS) -r $@.1 $@.2 -o $@
@rm -f $@.1 $@.2
@echo ${CL2}[$@] ${CL}Compiled.${CL3}
2020-02-19 22:19:58 +01:00
2019-05-11 00:16:40 +02:00
## DEPENDENCIES MAKEFILE ----------------------------------------------------- #
2019-11-08 15:41:51 +01:00
2019-05-11 00:16:40 +02:00
$(KOBJDIR)/%.d: %.c | $(KOBJDIR)
@mkdir -p $(shell dirname $@)
@$(KCC) -MM -MT $(@:%.d=%.o) -MF $@ $<
@echo ${CL2}[$@] ${CL}Dependencies generated.${CL3}
2019-04-09 23:35:31 +02:00
## MAIN MAKEFILE ------------------------------------------------------------- #
2019-05-11 00:16:40 +02:00
$(KOBJDIR)/%.o: %.c | $(KOBJDIR)
2019-04-09 17:16:13 +02:00
@mkdir -p $(shell dirname $@)
2019-03-17 22:47:21 +01:00
@$(KCC) $< -o $@
2019-03-18 13:09:34 +01:00
@echo ${CL2}[$@] ${CL}Compiled.${CL3}
2019-04-06 07:53:58 +02:00
2019-11-08 15:41:51 +01:00
$(BINDIR)/kaleid: $(LOBJDIR)/kaleid.x86_64
@echo ${CL2}[$@] ${NC}Objcopy...${CL3}
2019-11-13 20:43:02 +01:00
@mkdir -p $(shell dirname $@)
2020-02-19 22:19:58 +01:00
@$(OBJCOPY) -I elf64-x86-64 -O elf32-i386 $(LOBJDIR)/kaleid.x86_64 \
$(BINDIR)/kaleid
2019-11-08 15:41:51 +01:00
@echo ${CL2}[$@] ${CL}Success.${CL3}
2020-02-19 22:19:58 +01:00
$(LOBJDIR)/kaleid.x86_64: $(LibCObj) $(KernObj) $(DriverObj) \
$(LOBJDIR)/loader.o $(BUILDDIR)/kernel.ld
2019-11-08 15:41:51 +01:00
@echo ${CL2}[$@] ${NC}Linking kernel objects...${CL3}
2019-11-13 20:43:02 +01:00
@mkdir -p $(shell dirname $@)
2019-11-08 15:41:51 +01:00
@$(LD) $(LDFLAGS) -T $(BUILDDIR)/kernel.ld \
2020-02-19 22:19:58 +01:00
$(LOBJDIR)/loader.o $(KernObj) $(DriverObj) $(LibCObj) \
2019-11-08 15:41:51 +01:00
-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}
OS/K: $(dep) ./ProjectTree $(BINDIR)/kaleid
@echo ${CL2}[[$@]] ${NC} OS/K successfully made, $(mode) mode.${CL3}
2019-11-18 00:15:39 +01:00
all :
@make OS/K -j 8
2019-11-08 15:41:51 +01:00
## QEMU/DEBUG RELATED
2019-12-13 23:22:57 +01:00
test: all installonimage
2020-02-10 13:24:20 +01:00
@qemu-system-x86_64 -vga std -enable-kvm -machine type=q35 -soundhw pcspk -cpu host -s \
2020-02-12 13:15:10 +01:00
-rtc base=localtime -m $(ram) -hda $(installdisk) -net nic,model=rtl8139 \
2019-05-15 02:26:55 +02:00
-d cpu_reset,guest_errors,pcall,int 2> $(BUILDDIR)/qemu.log &
2019-04-09 17:16:13 +02:00
2019-11-18 00:15:39 +01:00
run: test
2019-12-13 23:22:57 +01:00
testnokvm: all installonimage
2019-11-15 21:31:10 +01:00
@qemu-system-x86_64 -vga std -cpu $(cpu) -soundhw pcspk -s \
2019-11-15 00:09:20 +01:00
-rtc base=localtime -m $(ram) -hda $(installdisk) \
-d cpu_reset,guest_errors,pcall,int 2> $(BUILDDIR)/qemu.log &
2019-12-13 23:22:57 +01:00
testnosnd: all installonimage
@qemu-system-x86_64 -vga std -enable-kvm -cpu host -s \
-rtc base=localtime -m $(ram) -hda $(installdisk) \
-d cpu_reset,guest_errors,pcall,int 2> $(BUILDDIR)/qemu.log &
test32: all installonimage
@qemu-system-i386 -m $(ram) -hda $(installdisk) -d \
2019-05-15 02:26:55 +02:00
cpu_reset,guest_errors,pcall,int 2> $(BUILDDIR)/qemu.log &
gdb: all installonimage
2020-01-05 20:13:53 +01:00
@setsid qemu-system-x86_64 -m $(ram) -enable-kvm -rtc base=localtime \
-hda $(installdisk) -no-reboot -no-shutdown -d \
2019-05-15 02:26:55 +02:00
cpu_reset,guest_errors,pcall,int -s -S 2> $(BUILDDIR)/qemu.log &
2019-03-29 13:45:24 +01:00
@gdb \
-ex "set arch i386:x86-64:intel" \
-ex "target remote localhost:1234" \
-ex "symbol-file $(BINDIR)/kaleid" \
-ex "break BtStartKern" \
ddd: all installonimage
2020-01-05 20:13:53 +01:00
@setsid qemu-system-x86_64 -m $(ram) -enable-kvm -rtc base=localtime \
-hda $(installdisk) -no-reboot -no-shutdown -d \
cpu_reset,guest_errors,pcall,int -s -S 2> $(BUILDDIR)/qemu.log &
@ddd -n
gdbnokvm: all installonimage
@setsid qemu-system-x86_64 -m $(ram) -rtc base=localtime \
-hda $(installdisk) -no-reboot -no-shutdown -d \
cpu_reset,guest_errors,pcall,int -s -S 2> $(BUILDDIR)/qemu.log &
@gdb \
-ex "set arch i386:x86-64:intel" \
-ex "target remote localhost:1234" \
-ex "symbol-file $(BINDIR)/kaleid" \
-ex "break BtStartKern" \
dddnokvm: all installonimage
@setsid qemu-system-x86_64 -m $(ram) -rtc base=localtime \
-hda $(installdisk) -no-reboot -no-shutdown -d \
cpu_reset,guest_errors,pcall,int -s -S 2> $(BUILDDIR)/qemu.log &
@ddd -n
2019-04-24 21:08:44 +02:00
2019-11-08 15:41:51 +01:00
## HD IMAGE RELATED ---------------------------------------------------------- #
installonimage: $(installdisk) $(MBRDIR)/grub.cfg
@echo ${CL2}[$@] ${NC}Installing boot configuration on image...${CL3}
2019-11-11 18:32:22 +01:00
@$(BUILDDIR)/install-os-k.sh $(installdisk) $(MBRDIR)/grub.cfg $(BINDIR)/kaleid
2019-05-11 10:04:36 +02:00
@echo ${CL2}[$@] ${CL}Success.${CL3}
$(installdisk): $(BUILDDIR)/create_disk.sh
2019-11-13 22:21:56 +01:00
@echo ${CL2}[$@]${NC} Constructing disk image $@...${CL3}
@mkdir -p $(shell dirname $@)
@$(BUILDDIR)/create_disk.sh $(installdisk)
2019-11-08 15:41:51 +01:00
@echo ${CL2}[$@]${NC} Constructing disk image...${CL3}
## CLEANUP RELATED ----------------------------------------------------------- #
2019-05-27 20:15:22 +02:00
2019-04-09 23:35:31 +02:00
dust:
@rm -Rf $(OBJDIR)/*
@echo ${CL2}[$@] ${CL}Cleaned.${CL3}
2019-05-27 20:15:22 +02:00
2019-03-17 22:32:52 +01:00
clean:
2019-04-09 17:16:13 +02:00
@rm -Rvf ./ProjectTree $(BUILDDIR)/*.log
2019-11-13 20:43:02 +01:00
@rm -Rvf $(BINDIR) $(OBJDIR)
2019-04-09 23:35:31 +02:00
@echo ${CL2}[$@] ${CL}Cleaned.${CL3}