Browse Source

Makefile: Generalize flags and tools in preparation for i386 arch

Aaron Lindsay 7 years ago
parent
commit
c76991b1b5
2 changed files with 30 additions and 14 deletions
  1. 23 14
      Makefile
  2. 7 0
      arch/arm/kernel.mk

+ 23 - 14
Makefile

@@ -2,25 +2,26 @@
2 2
 # Copyright (C) 2012, Aaron Lindsay <aaron@aclindsay.com>
3 3
 
4 4
 # Config options for the code itself (should be separated from the Makefile sometime)
5
-ARCH = arm
5
+ARCH ?= arm
6
+#ARCH_KCFLAGS defined (if at all) in arch/$(ARCH)/kernel.mk
7
+#CROSS_COMPILE defined (if at all) in arch/$(ARCH)/kernel.mk
6 8
 
7 9
 # Config options concerning the build process itself
8 10
 VERBOSE ?= 0 # 1 shows all compiler flags, 0 shows cleaner output
9 11
 V = $(if $(VERBOSE:1=),@) # Use this to prefix commands that should only be shown when VERBOSE==1
10 12
 
11 13
 # Define the tools to be used
12
-TOOL_PREFIX = arm-elf-
13
-AS = $(TOOL_PREFIX)as
14
-CC = $(TOOL_PREFIX)gcc
15
-LD = $(TOOL_PREFIX)ld
16
-OBJCOPY = $(TOOL_PREFIX)objcopy
17
-OBJDUMP = $(TOOL_PREFIX)objdump
14
+AS = $(CROSS_COMPILE)as
15
+CC = $(CROSS_COMPILE)gcc
16
+LD = $(CROSS_COMPILE)ld
17
+OBJCOPY = $(CROSS_COMPILE)objcopy
18
+OBJDUMP = $(CROSS_COMPILE)objdump
18 19
 
19 20
 # Define the flags we'll need for our tools
20 21
 INCLUDES = -I include -I arch/$(ARCH)/include
21
-KCFLAGS = -g -Wall -Wextra -Werror -nostdlib -nostartfiles -fno-builtin -std=gnu99 -include config.h $(INCLUDES)
22
-KLDFLAGS = -T arch/$(ARCH)/kernel.ld -L /usr/lib/gcc/arm-elf/4.7.0/
23
-EXTRA_LIBS = -lgcc
22
+KCFLAGS = -g -Wall -Wextra -Werror -nostdlib -nostartfiles -fno-builtin -std=gnu99 $(ARCH_KCFLAGS) -include config.h $(INCLUDES)
23
+KLDFLAGS = -T arch/$(ARCH)/kernel.ld -L /usr/lib/gcc/arm-elf/4.7.0/ $(ARCH_KLDFLAGS)
24
+EXTRA_LIBS = $(ARCH_EXTRA_LIBS)
24 25
 
25 26
 # Include the config file so we don't compile/link unnecessary objects
26 27
 include config
@@ -92,10 +93,18 @@ clean:
92 93
 	@echo '  CLEAN   aedrix-kernel.img'
93 94
 	$(V)rm -f aedrix-kernel.img
94 95
 
95
-boot: aedrix-kernel.img
96
-	$(V)qemu-system-arm -m 1024 -M vexpress-a9 -kernel aedrix-kernel.img -serial stdio
97
-boot-gdb: aedrix-kernel.img
98
-	$(V)qemu-system-arm -m 1024 -M vexpress-a9 -kernel aedrix-kernel.img -serial stdio -S -s
96
+boot-elf: aedrix-kernel.elf
97
+	$(V)$(ARCH_QEMU_CMD) -kernel aedrix-kernel.elf -serial stdio
98
+boot-img: aedrix-kernel.img
99
+	$(V)$(ARCH_QEMU_CMD) -kernel aedrix-kernel.img -serial stdio
100
+boot-hda: aedrix-boot.img
101
+	$(V)$(ARCH_QEMU_CMD) -hda aedrix-boot.img -serial stdio
102
+boot-elf-gdb: aedrix-kernel.elf
103
+	$(V)$(ARCH_QEMU_CMD) -kernel aedrix-kernel.elf -serial stdio -S -s
104
+boot-img-gdb: aedrix-kernel.img
105
+	$(V)$(ARCH_QEMU_CMD) -kernel aedrix-kernel.img -serial stdio -S -s
106
+boot-hda-gdb: aedrix-boot.img
107
+	$(V)$(ARCH_QEMU_CMD) -hda aedrix-boot.img -serial stdio -S -s
99 108
 
100 109
 DEPENDENCY_FILES = $(foreach file,$(KOBJS), $(dir $(file)).$(notdir $(basename $(file))).d)
101 110
 -include $(DEPENDENCY_FILES)

+ 7 - 0
arch/arm/kernel.mk

@@ -3,8 +3,15 @@ SUBDIRS := kernel
3 3
 
4 4
 include $(BASEDIR)/header.mk
5 5
 
6
+# Architecture-specific definitions
7
+CROSS_COMPILE ?= arm-elf-
8
+ARCH_KCFLAGS =
9
+ARCH_EXTRA_LIBS = -lgcc
10
+
6 11
 OBJS_$(d) := $(d)/start.o
7 12
 
8 13
 KOBJS += $(OBJS_$(d))
9 14
 
10 15
 include $(BASEDIR)/footer.mk
16
+
17
+ARCH_QEMU_CMD = qemu-system-arm -m 1024 -M vexpress-a9