From c76991b1b548980e39c75c3e9eb4ac244ef20a54 Mon Sep 17 00:00:00 2001 From: Aaron Lindsay Date: Thu, 15 Nov 2012 00:30:17 -0500 Subject: [PATCH] Makefile: Generalize flags and tools in preparation for i386 arch --- Makefile | 37 +++++++++++++++++++++++-------------- arch/arm/kernel.mk | 7 +++++++ 2 files changed, 30 insertions(+), 14 deletions(-) diff --git a/Makefile b/Makefile index 7de14ea..b0af286 100644 --- a/Makefile +++ b/Makefile @@ -2,25 +2,26 @@ # Copyright (C) 2012, Aaron Lindsay # Config options for the code itself (should be separated from the Makefile sometime) -ARCH = arm +ARCH ?= arm +#ARCH_KCFLAGS defined (if at all) in arch/$(ARCH)/kernel.mk +#CROSS_COMPILE defined (if at all) in arch/$(ARCH)/kernel.mk # Config options concerning the build process itself VERBOSE ?= 0 # 1 shows all compiler flags, 0 shows cleaner output V = $(if $(VERBOSE:1=),@) # Use this to prefix commands that should only be shown when VERBOSE==1 # Define the tools to be used -TOOL_PREFIX = arm-elf- -AS = $(TOOL_PREFIX)as -CC = $(TOOL_PREFIX)gcc -LD = $(TOOL_PREFIX)ld -OBJCOPY = $(TOOL_PREFIX)objcopy -OBJDUMP = $(TOOL_PREFIX)objdump +AS = $(CROSS_COMPILE)as +CC = $(CROSS_COMPILE)gcc +LD = $(CROSS_COMPILE)ld +OBJCOPY = $(CROSS_COMPILE)objcopy +OBJDUMP = $(CROSS_COMPILE)objdump # Define the flags we'll need for our tools INCLUDES = -I include -I arch/$(ARCH)/include -KCFLAGS = -g -Wall -Wextra -Werror -nostdlib -nostartfiles -fno-builtin -std=gnu99 -include config.h $(INCLUDES) -KLDFLAGS = -T arch/$(ARCH)/kernel.ld -L /usr/lib/gcc/arm-elf/4.7.0/ -EXTRA_LIBS = -lgcc +KCFLAGS = -g -Wall -Wextra -Werror -nostdlib -nostartfiles -fno-builtin -std=gnu99 $(ARCH_KCFLAGS) -include config.h $(INCLUDES) +KLDFLAGS = -T arch/$(ARCH)/kernel.ld -L /usr/lib/gcc/arm-elf/4.7.0/ $(ARCH_KLDFLAGS) +EXTRA_LIBS = $(ARCH_EXTRA_LIBS) # Include the config file so we don't compile/link unnecessary objects include config @@ -92,10 +93,18 @@ clean: @echo ' CLEAN aedrix-kernel.img' $(V)rm -f aedrix-kernel.img -boot: aedrix-kernel.img - $(V)qemu-system-arm -m 1024 -M vexpress-a9 -kernel aedrix-kernel.img -serial stdio -boot-gdb: aedrix-kernel.img - $(V)qemu-system-arm -m 1024 -M vexpress-a9 -kernel aedrix-kernel.img -serial stdio -S -s +boot-elf: aedrix-kernel.elf + $(V)$(ARCH_QEMU_CMD) -kernel aedrix-kernel.elf -serial stdio +boot-img: aedrix-kernel.img + $(V)$(ARCH_QEMU_CMD) -kernel aedrix-kernel.img -serial stdio +boot-hda: aedrix-boot.img + $(V)$(ARCH_QEMU_CMD) -hda aedrix-boot.img -serial stdio +boot-elf-gdb: aedrix-kernel.elf + $(V)$(ARCH_QEMU_CMD) -kernel aedrix-kernel.elf -serial stdio -S -s +boot-img-gdb: aedrix-kernel.img + $(V)$(ARCH_QEMU_CMD) -kernel aedrix-kernel.img -serial stdio -S -s +boot-hda-gdb: aedrix-boot.img + $(V)$(ARCH_QEMU_CMD) -hda aedrix-boot.img -serial stdio -S -s DEPENDENCY_FILES = $(foreach file,$(KOBJS), $(dir $(file)).$(notdir $(basename $(file))).d) -include $(DEPENDENCY_FILES) diff --git a/arch/arm/kernel.mk b/arch/arm/kernel.mk index c8dab6d..b2b748b 100644 --- a/arch/arm/kernel.mk +++ b/arch/arm/kernel.mk @@ -3,8 +3,15 @@ SUBDIRS := kernel include $(BASEDIR)/header.mk +# Architecture-specific definitions +CROSS_COMPILE ?= arm-elf- +ARCH_KCFLAGS = +ARCH_EXTRA_LIBS = -lgcc + OBJS_$(d) := $(d)/start.o KOBJS += $(OBJS_$(d)) include $(BASEDIR)/footer.mk + +ARCH_QEMU_CMD = qemu-system-arm -m 1024 -M vexpress-a9