1
0

Makefile: refactor subdirectory makefiles

This commit is contained in:
Aaron Lindsay 2012-09-26 15:35:52 -04:00
parent f9244836e1
commit c455b1eeb3
9 changed files with 74 additions and 23 deletions

View File

@ -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

View File

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

10
boot/kernel.mk Normal file
View File

@ -0,0 +1,10 @@
DIRNAME := boot
SUBDIRS :=
include $(BASEDIR)/header.mk
OBJS_$(d) := $(d)/start.o
KOBJS += $(OBJS_$(d))
include $(BASEDIR)/footer.mk

View File

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

12
devices/kernel.mk Normal file
View File

@ -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

12
footer.mk Normal file
View File

@ -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 :=

13
header.mk Normal file
View File

@ -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

View File

@ -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

19
kernel/kernel.mk Normal file
View File

@ -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