From c455b1eeb36b1a93be28265dd3b68c646fc6a06d Mon Sep 17 00:00:00 2001 From: Aaron Lindsay Date: Wed, 26 Sep 2012 15:35:52 -0400 Subject: [PATCH] Makefile: refactor subdirectory makefiles --- Makefile | 12 ++++++++---- boot/Makefile.inc | 3 --- boot/kernel.mk | 10 ++++++++++ devices/Makefile.inc | 5 ----- devices/kernel.mk | 12 ++++++++++++ footer.mk | 12 ++++++++++++ header.mk | 13 +++++++++++++ kernel/Makefile.inc | 11 ----------- kernel/kernel.mk | 19 +++++++++++++++++++ 9 files changed, 74 insertions(+), 23 deletions(-) delete mode 100644 boot/Makefile.inc create mode 100644 boot/kernel.mk delete mode 100644 devices/Makefile.inc create mode 100644 devices/kernel.mk create mode 100644 footer.mk create mode 100644 header.mk delete mode 100644 kernel/Makefile.inc create mode 100644 kernel/kernel.mk diff --git a/Makefile b/Makefile index 769086a..ec118d1 100644 --- a/Makefile +++ b/Makefile @@ -22,11 +22,15 @@ KCFLAGS = -g -Wall -Wextra -Werror -nostdlib -nostartfiles -fno-builtin -std=gnu KLDFLAGS = -T link.ld -L /usr/lib/gcc/arm-elf/4.7.0/ EXTRA_LIBS = -lgcc -KOBJS = +# Define KOBJS as a 'simply expanded' variable +KOBJS := -include boot/Makefile.inc -include kernel/Makefile.inc -include devices/Makefile.inc +# Initialize sub-directory Makefile inclusion +BASEDIR = $(shell pwd) +SUBDIRS := boot kernel devices +ifneq (,$(SUBDIRS)) + include $(patsubst %,%/kernel.mk,$(SUBDIRS)) +endif .PHONY: all clean boot boot-gdb diff --git a/boot/Makefile.inc b/boot/Makefile.inc deleted file mode 100644 index d9df028..0000000 --- a/boot/Makefile.inc +++ /dev/null @@ -1,3 +0,0 @@ -BOOT_PREFIX = boot - -KOBJS += $(BOOT_PREFIX)/start.o diff --git a/boot/kernel.mk b/boot/kernel.mk new file mode 100644 index 0000000..b4f1b32 --- /dev/null +++ b/boot/kernel.mk @@ -0,0 +1,10 @@ +DIRNAME := boot +SUBDIRS := + +include $(BASEDIR)/header.mk + +OBJS_$(d) := $(d)/start.o + +KOBJS += $(OBJS_$(d)) + +include $(BASEDIR)/footer.mk diff --git a/devices/Makefile.inc b/devices/Makefile.inc deleted file mode 100644 index 4e19edb..0000000 --- a/devices/Makefile.inc +++ /dev/null @@ -1,5 +0,0 @@ -DEVICES_PREFIX = devices - -KOBJS += $(DEVICES_PREFIX)/pl011.o -KOBJS += $(DEVICES_PREFIX)/pl110.o -KOBJS += $(DEVICES_PREFIX)/pl111.o diff --git a/devices/kernel.mk b/devices/kernel.mk new file mode 100644 index 0000000..a0451c7 --- /dev/null +++ b/devices/kernel.mk @@ -0,0 +1,12 @@ +DIRNAME := devices +SUBDIRS := + +include $(BASEDIR)/header.mk + +OBJS_$(d) := $(d)/pl011.o \ + $(d)/pl110.o \ + $(d)/pl111.o + +KOBJS += $(OBJS_$(d)) + +include $(BASEDIR)/footer.mk diff --git a/footer.mk b/footer.mk new file mode 100644 index 0000000..15077d7 --- /dev/null +++ b/footer.mk @@ -0,0 +1,12 @@ +# Included at the bottom of each subdirectory Makefile + +# Include any subdirectory Makefiles +ifneq (,$(SUBDIRS)) + include $(patsubst %,$(d)/%/kernel.mk,$(SUBDIRS)) +endif + +# Pop the previous directory off the 'stack' +d := $(dirstack_$(sp)) +sp := $(basename $(sp)) +# Clear SUBDIRS so that it defaults to empty for the next directory +SUBDIRS := diff --git a/header.mk b/header.mk new file mode 100644 index 0000000..95dceb5 --- /dev/null +++ b/header.mk @@ -0,0 +1,13 @@ +# Included at the top of each subdirectory Makefile, immediately +# following the local re-definition of DIRNAME + +# Push the previous directory onto the 'stack' +sp := $(sp).x +dirstack_$(sp) := $(d) + +# Update $(d) to be the current directory +ifneq (,$(d)) + d := $(d)/$(DIRNAME) +else + d := $(DIRNAME) +endif diff --git a/kernel/Makefile.inc b/kernel/Makefile.inc deleted file mode 100644 index 8870cbd..0000000 --- a/kernel/Makefile.inc +++ /dev/null @@ -1,11 +0,0 @@ -KERNEL_PREFIX = kernel - -KOBJS += $(KERNEL_PREFIX)/atags.o -KOBJS += $(KERNEL_PREFIX)/console.o -KOBJS += $(KERNEL_PREFIX)/font.o -KOBJS += $(KERNEL_PREFIX)/framebuffer.o -KOBJS += $(KERNEL_PREFIX)/list.o -KOBJS += $(KERNEL_PREFIX)/mm.o -KOBJS += $(KERNEL_PREFIX)/mmu.o -KOBJS += $(KERNEL_PREFIX)/print.o -KOBJS += $(KERNEL_PREFIX)/start_kernel.o diff --git a/kernel/kernel.mk b/kernel/kernel.mk new file mode 100644 index 0000000..1e0f065 --- /dev/null +++ b/kernel/kernel.mk @@ -0,0 +1,19 @@ +DIRNAME := kernel +SUBDIRS := + +include $(BASEDIR)/header.mk + +OBJS_$(d) := $(d)/atags.o \ + $(d)/console.o \ + $(d)/font.o \ + $(d)/framebuffer.o \ + $(d)/kmalloc.o \ + $(d)/list.o \ + $(d)/mm.o \ + $(d)/mmu.o \ + $(d)/print.o \ + $(d)/start_kernel.o + +KOBJS += $(OBJS_$(d)) + +include $(BASEDIR)/footer.mk