From 2e23f70e6f62d9fe5fca6a29df31a08e679d09c1 Mon Sep 17 00:00:00 2001 From: Braiden Vasco Date: Wed, 8 Nov 2017 09:38:55 +0000 Subject: [PATCH] Build kernel in root directory --- Makefile | 27 ++++++++++++++++++++++----- arch/x86/Makefile | 12 +++++------- libk/Makefile | 5 +---- 3 files changed, 28 insertions(+), 16 deletions(-) diff --git a/Makefile b/Makefile index 949361c..648b0d1 100644 --- a/Makefile +++ b/Makefile @@ -1,14 +1,20 @@ include config.mk +export AR = $(CCPREFIX)ar +export AS = $(CCPREFIX)as +export CC = $(CCPREFIX)gcc + export INCLUDE = $(shell pwd)/include -export KERNEL = $(shell pwd)/arch/$(ARCH)/kernel.multiboot +export KERNEL = $(shell pwd)/kernelmq.multiboot export LIBK = $(shell pwd)/libk/libk.a +export LIBARCH = $(shell pwd)/arch/$(ARCH)/libarch.a +export LINKER = $(shell pwd)/arch/$(ARCH)/linker.ld export MODULES = $(addprefix $(shell pwd)/modules/, dummy1.bin dummy2.bin) run: run-iso -all: all-kernel all-iso all-libk all-test all-modules -clean: clean-kernel clean-iso clean-libk clean-test clean-modules +all: all-kernel all-iso all-libk all-arch all-test all-modules +clean: clean-kernel clean-iso clean-libk clean-arch clean-test clean-modules test: run-test @@ -16,10 +22,21 @@ test: run-test # Kernel # ########## -all-kernel: all-libk - make all -C arch +all-kernel: all-arch all-libk + $(CC) -T $(LINKER) -o $(KERNEL) -ffreestanding -nostdlib -lgcc $(LIBARCH) $(LIBK) + grub-file --is-x86-multiboot2 $(KERNEL) clean-kernel: + rm -f $(KERNEL) + +######## +# arch # +######## + +all-arch: + make all -C arch + +clean-arch: make clean -C arch ####### diff --git a/arch/x86/Makefile b/arch/x86/Makefile index ef3f328..7d59921 100644 --- a/arch/x86/Makefile +++ b/arch/x86/Makefile @@ -1,5 +1,4 @@ -AS = $(CCPREFIX)as -CC = $(CCPREFIX)gcc +OUTPUT = libarch.a # Architecture-dependent OBJS = start.s.o @@ -33,14 +32,13 @@ OBJS += exception.c.o OBJS += hwint.c.o OBJS += syscall.c.o -all: kernel.multiboot +all: $(OUTPUT) clean: - rm -f kernel.multiboot $(OBJS) + rm -f $(OUTPUT) $(OBJS) -kernel.multiboot: $(OBJS) - $(CC) -T linker.ld -o $@ -ffreestanding -nostdlib -lgcc $(OBJS) $(LIBK) - grub-file --is-x86-multiboot2 $@ +$(OUTPUT): $(OBJS) + $(AR) -rcs $@ $(OBJS) %.c.o: %.c $(CC) -c $< -o $@ -std=gnu99 -ffreestanding -nostdinc -fno-builtin -fno-stack-protector -Wall -Wextra -I "$(INCLUDE)" diff --git a/libk/Makefile b/libk/Makefile index e27b89e..45097ac 100644 --- a/libk/Makefile +++ b/libk/Makefile @@ -1,10 +1,7 @@ -AR = $(CCPREFIX)ar -CC = $(CCPREFIX)gcc +OUTPUT = libk.a CFLAGS = -std=gnu99 -ffreestanding -nostdinc -fno-builtin -fno-stack-protector -Wall -Wextra -OUTPUT = libk.a - OBJS = memset.o strlen.o itoa.o strncpy.o all: $(OUTPUT)