Browse Source

Makefile: refactor subdirectory makefiles

Aaron Lindsay 7 years ago
parent
commit
c455b1eeb3
9 changed files with 75 additions and 24 deletions
  1. 9 5
      Makefile
  2. 0 3
      boot/Makefile.inc
  3. 10 0
      boot/kernel.mk
  4. 0 5
      devices/Makefile.inc
  5. 12 0
      devices/kernel.mk
  6. 12 0
      footer.mk
  7. 13 0
      header.mk
  8. 0 11
      kernel/Makefile.inc
  9. 19 0
      kernel/kernel.mk

+ 9 - 5
Makefile

@@ -22,11 +22,15 @@ KCFLAGS = -g -Wall -Wextra -Werror -nostdlib -nostartfiles -fno-builtin -std=gnu
22 22
 KLDFLAGS = -T link.ld -L /usr/lib/gcc/arm-elf/4.7.0/
23 23
 EXTRA_LIBS = -lgcc
24 24
 
25
-KOBJS =
26
-
27
-include boot/Makefile.inc
28
-include kernel/Makefile.inc
29
-include devices/Makefile.inc
25
+# Define KOBJS as a 'simply expanded' variable
26
+KOBJS :=
27
+
28
+# Initialize sub-directory Makefile inclusion
29
+BASEDIR = $(shell pwd)
30
+SUBDIRS := boot kernel devices
31
+ifneq (,$(SUBDIRS))
32
+	include $(patsubst %,%/kernel.mk,$(SUBDIRS))
33
+endif
30 34
 
31 35
 .PHONY: all clean boot boot-gdb
32 36
 

+ 0 - 3
boot/Makefile.inc

@@ -1,3 +0,0 @@
1
-BOOT_PREFIX = boot
2
-
3
-KOBJS += $(BOOT_PREFIX)/start.o

+ 10 - 0
boot/kernel.mk

@@ -0,0 +1,10 @@
1
+DIRNAME := boot
2
+SUBDIRS :=
3
+
4
+include $(BASEDIR)/header.mk
5
+
6
+OBJS_$(d) := $(d)/start.o
7
+
8
+KOBJS += $(OBJS_$(d))
9
+
10
+include $(BASEDIR)/footer.mk

+ 0 - 5
devices/Makefile.inc

@@ -1,5 +0,0 @@
1
-DEVICES_PREFIX = devices
2
-
3
-KOBJS += $(DEVICES_PREFIX)/pl011.o
4
-KOBJS += $(DEVICES_PREFIX)/pl110.o
5
-KOBJS += $(DEVICES_PREFIX)/pl111.o

+ 12 - 0
devices/kernel.mk

@@ -0,0 +1,12 @@
1
+DIRNAME := devices
2
+SUBDIRS :=
3
+
4
+include $(BASEDIR)/header.mk
5
+
6
+OBJS_$(d) := $(d)/pl011.o \
7
+	$(d)/pl110.o \
8
+	$(d)/pl111.o
9
+
10
+KOBJS += $(OBJS_$(d))
11
+
12
+include $(BASEDIR)/footer.mk

+ 12 - 0
footer.mk

@@ -0,0 +1,12 @@
1
+# Included at the bottom of each subdirectory Makefile
2
+
3
+# Include any subdirectory Makefiles
4
+ifneq (,$(SUBDIRS))
5
+	include $(patsubst %,$(d)/%/kernel.mk,$(SUBDIRS))
6
+endif
7
+
8
+# Pop the previous directory off the 'stack' 
9
+d := $(dirstack_$(sp))
10
+sp := $(basename $(sp))
11
+# Clear SUBDIRS so that it defaults to empty for the next directory
12
+SUBDIRS :=

+ 13 - 0
header.mk

@@ -0,0 +1,13 @@
1
+# Included at the top of each subdirectory Makefile, immediately
2
+# following the local re-definition of DIRNAME
3
+
4
+# Push the previous directory onto the 'stack'
5
+sp := $(sp).x
6
+dirstack_$(sp) := $(d)
7
+
8
+# Update $(d) to be the current directory
9
+ifneq (,$(d))
10
+	d := $(d)/$(DIRNAME)
11
+else
12
+	d := $(DIRNAME)
13
+endif

+ 0 - 11
kernel/Makefile.inc

@@ -1,11 +0,0 @@
1
-KERNEL_PREFIX = kernel
2
-
3
-KOBJS += $(KERNEL_PREFIX)/atags.o
4
-KOBJS += $(KERNEL_PREFIX)/console.o
5
-KOBJS += $(KERNEL_PREFIX)/font.o
6
-KOBJS += $(KERNEL_PREFIX)/framebuffer.o
7
-KOBJS += $(KERNEL_PREFIX)/list.o
8
-KOBJS += $(KERNEL_PREFIX)/mm.o
9
-KOBJS += $(KERNEL_PREFIX)/mmu.o
10
-KOBJS += $(KERNEL_PREFIX)/print.o
11
-KOBJS += $(KERNEL_PREFIX)/start_kernel.o

+ 19 - 0
kernel/kernel.mk

@@ -0,0 +1,19 @@
1
+DIRNAME := kernel
2
+SUBDIRS :=
3
+
4
+include $(BASEDIR)/header.mk
5
+
6
+OBJS_$(d) := $(d)/atags.o \
7
+	$(d)/console.o \
8
+	$(d)/font.o \
9
+	$(d)/framebuffer.o \
10
+	$(d)/kmalloc.o \
11
+	$(d)/list.o \
12
+	$(d)/mm.o \
13
+	$(d)/mmu.o \
14
+	$(d)/print.o \
15
+	$(d)/start_kernel.o
16
+
17
+KOBJS += $(OBJS_$(d))
18
+
19
+include $(BASEDIR)/footer.mk