[make] better modularize the build system
-Each module's rules.mk defines a seperate linkage unit. Each module can have a private set of CFLAGS, DEFINES, INCLUDES, and so forth. -Files to be compiled are now added by source, not object. Most rules.mk files can be converted easily by following these steps: 1) add 'MODULE := $(LOCAL_DIR)' near the top of the file 2) change OBJS += to MODULE_SRCS += and list source files instead of .os 3) add 'include make/module.mk' at the bottom of the file See make/module.mk for directions.
This commit is contained in:
97
make/module.mk
Normal file
97
make/module.mk
Normal file
@@ -0,0 +1,97 @@
|
||||
|
||||
# modules
|
||||
#
|
||||
# args:
|
||||
# MODULE : module name (required)
|
||||
# MODULE_SRCS : list of source files, local path (required)
|
||||
# MODULE_DEPS : other modules that this one depends on
|
||||
# MODULE_DEFINES : #defines local to this module
|
||||
# MODULE_OPTFLAGS : OPTFLAGS local to this module
|
||||
# MODULE_COMPILEFLAGS : COMPILEFLAGS local to this module
|
||||
# MODULE_CFLAGS : CFLAGS local to this module
|
||||
# MODULE_CPPFLAGS : CPPFLAGS local to this module
|
||||
# MODULE_ASMFLAGS : ASMFLAGS local to this module
|
||||
# MODULE_SRCDEPS : extra dependencies that all of this module's files depend on
|
||||
|
||||
# MODULE_ARM_OVERRIDE_SRCS : list of source files, local path that should be force compiled with ARM (if applicable)
|
||||
|
||||
# the minimum module rules.mk file is as follows:
|
||||
#
|
||||
# LOCAL_DIR := $(GET_LOCAL_DIR)
|
||||
# MODULE := $(LOCAL_DIR)
|
||||
#
|
||||
# MODULE_SRCS := $(LOCAL_DIR)/at_least_one_source_file.c
|
||||
#
|
||||
# include make/module.mk
|
||||
|
||||
# test for old style rules.mk
|
||||
ifneq ($(MODULE_OBJS),)
|
||||
$(warning MODULE_OBJS = $(MODULE_OBJS))
|
||||
$(error MODULE $(MODULE) is setting MODULE_OBJS, change to MODULE_SRCS)
|
||||
endif
|
||||
ifneq ($(OBJS),)
|
||||
$(warning OBJS = $(OBJS))
|
||||
$(error MODULE $(MODULE) is probably setting OBJS, change to MODULE_SRCS)
|
||||
endif
|
||||
|
||||
MODULE_SRCDIR := $(MODULE)
|
||||
MODULE_BUILDDIR := $(call TOBUILDDIR,$(MODULE_SRCDIR))
|
||||
|
||||
# add the listed module deps to the global list
|
||||
MODULES += $(MODULE_DEPS)
|
||||
|
||||
#$(info module $(MODULE))
|
||||
#$(info MODULE_SRCDIR $(MODULE_SRCDIR))
|
||||
#$(info MODULE_BUILDDIR $(MODULE_BUILDDIR))
|
||||
#$(info MODULE_DEPS $(MODULE_DEPS))
|
||||
#$(info MODULE_SRCS $(MODULE_SRCS))
|
||||
|
||||
# generate a per-module config.h file
|
||||
MODULE_CONFIG := $(MODULE_BUILDDIR)/module_config.h
|
||||
|
||||
$(MODULE_CONFIG): MODULE_DEFINES:=$(MODULE_DEFINES)
|
||||
$(MODULE_CONFIG): configheader
|
||||
$(call MAKECONFIGHEADER,$@,MODULE_DEFINES)
|
||||
|
||||
GENERATED += $(MODULE_CONFIG)
|
||||
|
||||
MODULE_COMPILEFLAGS += --include $(MODULE_CONFIG)
|
||||
|
||||
MODULE_SRCDEPS += $(MODULE_CONFIG)
|
||||
|
||||
# include the rules to compile the module's object files
|
||||
include make/compile.mk
|
||||
|
||||
# MODULE_OBJS is passed back from compile.mk
|
||||
#$(info MODULE_OBJS = $(MODULE_OBJS))
|
||||
|
||||
# build a ld -r style combined object
|
||||
MODULE_OBJECT := $(call TOBUILDDIR,$(MODULE_SRCDIR).mod.o)
|
||||
$(MODULE_OBJECT): $(MODULE_OBJS)
|
||||
@$(MKDIR)
|
||||
@echo linking $@
|
||||
$(NOECHO)$(LD) -r $^ -o $@
|
||||
|
||||
# track all the objects built
|
||||
ALLOBJS += $(MODULE_OBJS)
|
||||
|
||||
# make the rest of the build depend on our output
|
||||
ALLMODULE_OBJS := $(ALLMODULE_OBJS) $(MODULE_OBJECT)
|
||||
|
||||
# empty out any vars set here
|
||||
MODULE :=
|
||||
MODULE_SRCDIR :=
|
||||
MODULE_BUILDDIR :=
|
||||
MODULE_DEPS :=
|
||||
MODULE_SRCS :=
|
||||
MODULE_OBJS :=
|
||||
MODULE_DEFINES :=
|
||||
MODULE_OPTFLAGS :=
|
||||
MODULE_COMPILEFLAGS :=
|
||||
MODULE_CFLAGS :=
|
||||
MODULE_CPPFLAGS :=
|
||||
MODULE_ASMFLAGS :=
|
||||
MODULE_SRCDEPS :=
|
||||
MODULE_CONFIG :=
|
||||
MODULE_OBJECT :=
|
||||
MODULE_ARM_OVERRIDE_SRCS :=
|
||||
Reference in New Issue
Block a user