flatten the make system a little bit by providing only modules as a
compilation unit.
to add a module as a dependency of another, just add to the MODULE make
variable, instead of APPS/LIBS/DEVS
diff --git a/dev/rules.mk b/dev/rules.mk
index f03105e..cbc5ba7 100644
--- a/dev/rules.mk
+++ b/dev/rules.mk
@@ -1,5 +1,5 @@
LOCAL_DIR := $(GET_LOCAL_DIR)
-KOBJS += \
+OBJS += \
$(LOCAL_DIR)/dev.o
diff --git a/kernel/rules.mk b/kernel/rules.mk
index 33ca6c4..45cf94d 100644
--- a/kernel/rules.mk
+++ b/kernel/rules.mk
@@ -1,8 +1,11 @@
LOCAL_DIR := $(GET_LOCAL_DIR)
-LIBS += debug heap
+MODULES += \
+ lib/libc \
+ lib/debug \
+ lib/heap
-KOBJS += \
+OBJS += \
$(LOCAL_DIR)/debug.o \
$(LOCAL_DIR)/dpc.o \
$(LOCAL_DIR)/event.o \
diff --git a/makefile b/makefile
index 8223526..a40bda0 100644
--- a/makefile
+++ b/makefile
@@ -1,15 +1,15 @@
-include local.mk
include macros.mk
-PROJECT ?= armemu-test
-DEBUG ?= false
+PROJECT ?= beagle-test
+DEBUG ?= 1
BUILDDIR := build-$(PROJECT)
OUTBIN := $(BUILDDIR)/lk.bin
OUTELF := $(BUILDDIR)/lk
CONFIGHEADER := $(BUILDDIR)/config.h
-INCLUDES := -Iinclude
+INCLUDES := -I$(BUILDDIR) -Iinclude
CFLAGS := -O2 -g -fno-builtin -finline -W -Wall -Wno-multichar -Wno-unused-parameter -Wno-unused-function -include $(CONFIGHEADER)
#CFLAGS += -Werror
CPPFLAGS := -fno-exceptions -fno-rtti -fno-threadsafe-statics
@@ -21,12 +21,11 @@
LDFLAGS += -gc-sections
# top level rule
-all:: $(OUTBIN) $(OUTELF).lst $(OUTELF).debug.lst $(OUTELF).sym
+all:: $(OUTBIN) $(OUTELF).lst $(OUTELF).debug.lst $(OUTELF).sym $(OUTELF).size
# the following three object lists are identical except for the ordering
# which is bootobjs, kobjs, objs
BOOTOBJS :=
-KOBJS :=
OBJS :=
# a linker script needs to be declared in one of the project/target/platform files
@@ -46,15 +45,14 @@
TARGET :=
PLATFORM :=
ARCH :=
-LIBS := libc
-APPS :=
-DEVS :=
+ALLMODULES :=
+MODULES :=
# any rules you put here will also be built by the system before considered being complete
-EXTRA_BUILDDEPS :=
+EXTRA_BUILDDEPS :=
# any rules you put here will be depended on in clean builds
-EXTRA_CLEANDEPS :=
+EXTRA_CLEANDEPS :=
include project/$(PROJECT)/rules.mk
include target/$(TARGET)/rules.mk
@@ -65,20 +63,15 @@
include kernel/rules.mk
include dev/rules.mk
-DEVS := $(sort $(DEVS))
-LIBS := $(sort $(LIBS))
-APPS := $(sort $(APPS))
-
-include $(addsuffix /rules.mk,$(addprefix dev/,$(DEVS)))
-include $(addsuffix /rules.mk,$(addprefix lib/,$(LIBS)))
-include $(addsuffix /rules.mk,$(addprefix app/,$(APPS)))
+# recursively include any modules in the MODULE variable, leaving a trail of included
+# modules in the ALLMODULES list
+include module.mk
# any extra top level build dependencies that someone declared
all:: $(EXTRA_BUILDDEPS)
ALLOBJS := \
$(BOOTOBJS) \
- $(KOBJS) \
$(OBJS)
# add some automatic configuration defines
@@ -87,21 +80,21 @@
TARGET_$(TARGET)=1 \
PLATFORM_$(PLATFORM)=1 \
ARCH_$(ARCH)=1 \
- $(addsuffix =1,$(addprefix WITH_DEV_,$(DEVS))) \
- $(addsuffix =1,$(addprefix WITH_LIB_,$(LIBS))) \
- $(addsuffix =1,$(addprefix WITH_APP_,$(APPS)))
+ $(addsuffix =1,$(addprefix WITH_,$(ALLMODULES)))
# debug build?
-ifeq ($(DEBUG),true)
+ifneq ($(DEBUG),)
DEFINES += \
- DEBUG=1
+ DEBUG=$(DEBUG)
endif
ALLOBJS := $(addprefix $(BUILDDIR)/,$(ALLOBJS))
DEPS := $(ALLOBJS:%o=%d)
-CC := $(TOOLCHAIN_PREFIX)gcc
+# default to no ccache
+CCACHE ?=
+CC := $(CCACHE) $(TOOLCHAIN_PREFIX)gcc
LD := $(TOOLCHAIN_PREFIX)ld
OBJDUMP := $(TOOLCHAIN_PREFIX)objdump
OBJCOPY := $(TOOLCHAIN_PREFIX)objcopy
@@ -109,6 +102,10 @@
SIZE := $(TOOLCHAIN_PREFIX)size
NM := $(TOOLCHAIN_PREFIX)nm
+# comment out or override if you want to see the full output of each command
+NOECHO ?= @
+
+# the logic to compile and link stuff is in here
include build.mk
clean: $(EXTRA_CLEANDEPS)
@@ -152,4 +149,3 @@
endif
.PHONY: configheader
-
diff --git a/module.mk b/module.mk
new file mode 100644
index 0000000..3e07813
--- /dev/null
+++ b/module.mk
@@ -0,0 +1,21 @@
+# included from the main makefile to include a set of rules.mk to satisfy
+# the current MODULE list. If as a byproduct of including the rules.mk
+# more stuff shows up on the MODULE list, recurse
+
+# sort and filter out any modules that have already been included
+MODULES := $(sort $(MODULES))
+MODULES := $(filter-out $(ALLMODULES),$(MODULES))
+
+ifneq ($(MODULES),)
+
+ALLMODULES += $(MODULES)
+ALLMODULES := $(sort $(ALLMODULES))
+INCMODULES := $(MODULES)
+MODULES :=
+$(info including $(INCMODULES))
+include $(addsuffix /rules.mk,$(INCMODULES))
+
+include module.mk
+
+endif
+
diff --git a/project/armemu-test/rules.mk b/project/armemu-test/rules.mk
index 56eecca..eccbefb 100644
--- a/project/armemu-test/rules.mk
+++ b/project/armemu-test/rules.mk
@@ -3,8 +3,9 @@
LOCAL_DIR := $(GET_LOCAL_DIR)
TARGET := armemu
-APPS := tests \
- console
+MODULES += \
+ app/tests \
+ app/console
OBJS += \
$(LOCAL_DIR)/init.o
diff --git a/project/beagle-test/rules.mk b/project/beagle-test/rules.mk
index f20f613..336afe2 100644
--- a/project/beagle-test/rules.mk
+++ b/project/beagle-test/rules.mk
@@ -3,8 +3,11 @@
LOCAL_DIR := $(GET_LOCAL_DIR)
TARGET := beagle
-APPS := tests console stringtests
-DEVS :=
+
+MODULES += \
+ app/tests \
+ app/console \
+ app/stringtests
OBJS += \
$(LOCAL_DIR)/init.o
diff --git a/project/osk5912-test/rules.mk b/project/osk5912-test/rules.mk
index 80b76ac..353ddf2 100644
--- a/project/osk5912-test/rules.mk
+++ b/project/osk5912-test/rules.mk
@@ -3,7 +3,9 @@
LOCAL_DIR := $(GET_LOCAL_DIR)
TARGET := osk5912
-APPS := tests console
+MODULES += \
+ app/tests \
+ app/console
OBJS += \
$(LOCAL_DIR)/init.o
diff --git a/project/qemu-arm-test/rules.mk b/project/qemu-arm-test/rules.mk
index 71a300f..a3bfe8c 100644
--- a/project/qemu-arm-test/rules.mk
+++ b/project/qemu-arm-test/rules.mk
@@ -3,7 +3,8 @@
LOCAL_DIR := $(GET_LOCAL_DIR)
TARGET := qemu-arm
-APPS := tests
+MODULES += \
+ app/tests
OBJS += \
$(LOCAL_DIR)/init.o
diff --git a/project/sam7ex256-test/rules.mk b/project/sam7ex256-test/rules.mk
index 1c775f3..ecf391a 100644
--- a/project/sam7ex256-test/rules.mk
+++ b/project/sam7ex256-test/rules.mk
@@ -3,7 +3,8 @@
LOCAL_DIR := $(GET_LOCAL_DIR)
TARGET := sam7ex256
-APPS := tests
+MODULES += \
+ app/tests
OBJS += \
$(LOCAL_DIR)/init.o
diff --git a/target/osk5912/rules.mk b/target/osk5912/rules.mk
index f7f1e48..1fe75de 100644
--- a/target/osk5912/rules.mk
+++ b/target/osk5912/rules.mk
@@ -2,7 +2,8 @@
PLATFORM := omap5912
-DEVS := net/smc91c96
+MODULES += \
+ dev/net/smc91c96
OBJS += \
$(LOCAL_DIR)/init.o