1 2# modules 3# 4# args: 5# MODULE : module name (required) 6# MODULE_SRCS : list of source files, local path (required) 7# MODULE_FLOAT_SRCS : list of source files compiled with floating point support (if available) 8# MODULE_DEPS : other modules that this one depends on 9# MODULE_DEFINES : #defines local to this module 10# MODULE_OPTFLAGS : OPTFLAGS local to this module 11# MODULE_COMPILEFLAGS : COMPILEFLAGS local to this module 12# MODULE_CFLAGS : CFLAGS local to this module 13# MODULE_CPPFLAGS : CPPFLAGS local to this module 14# MODULE_ASMFLAGS : ASMFLAGS local to this module 15# MODULE_INCLUDES : include directories local to this module 16# MODULE_SRCDEPS : extra dependencies that all of this module's files depend on 17# MODULE_EXTRA_OBJS : extra .o files that should be linked with the module 18 19# MODULE_ARM_OVERRIDE_SRCS : list of source files, local path that should be force compiled with ARM (if applicable) 20 21# MODULE_OPTIONS : space delimited list of options 22# currently defined options: 23# extra_warnings - add additional warnings to the front of the module deps 24# float - module uses floating point instructions/code 25 26# the minimum module rules.mk file is as follows: 27# 28# LOCAL_DIR := $(GET_LOCAL_DIR) 29# MODULE := $(LOCAL_DIR) 30# 31# MODULE_SRCS := $(LOCAL_DIR)/at_least_one_source_file.c 32# 33# include make/module.mk 34 35# test for old style rules.mk 36ifneq ($(flavor MODULE_OBJS),undefined) 37ifneq ($(MODULE_OBJS),) 38$(warning MODULE_OBJS = $(MODULE_OBJS)) 39$(error MODULE $(MODULE) is setting MODULE_OBJS, change to MODULE_SRCS) 40endif 41endif 42ifneq ($(flavor OBJS),undefined) 43ifneq ($(OBJS),) 44$(warning OBJS = $(OBJS)) 45$(error MODULE $(MODULE) is probably setting OBJS, change to MODULE_SRCS) 46endif 47endif 48 49ifneq ($(filter $(MODULE),$(DENY_MODULES)),) 50$(error MODULE $(MODULE) is not allowed by PROJECT $(PROJECT)'s DENY_MODULES list) 51endif 52 53MODULE_SRCDIR := $(MODULE) 54MODULE_BUILDDIR := $(call TOBUILDDIR,$(MODULE_SRCDIR)) 55 56# add a local include dir to the global include path 57GLOBAL_INCLUDES += $(MODULE_SRCDIR)/include 58 59# add the listed module deps to the global list 60MODULES += $(MODULE_DEPS) 61 62# parse options 63MODULE_OPTIONS_COPY := $(sort $(MODULE_OPTIONS)) 64ifneq (,$(findstring float,$(MODULE_OPTIONS))) 65# floating point option just forces all files in the module to be 66# compiled with floating point compiler flags. 67#$(info MODULE $(MODULE) has float option) 68MODULE_FLOAT_SRCS := $(sort $(MODULE_FLOAT_SRCS) $(MODULE_SRCS)) 69MODULE_SRCS := 70MODULE_OPTIONS_COPY := $(filter-out float,$(MODULE_OPTIONS_COPY)) 71endif 72ifneq (,$(findstring extra_warnings,$(MODULE_OPTIONS))) 73# add some extra warnings to the various module compiler switches. 74# add these extra switches first so it's possible for the rules.mk file 75# that invoked us to override with a -Wno-... 76MODULE_COMPILEFLAGS := $(EXTRA_MODULE_COMPILEFLAGS) $(MODULE_COMPILEFLAGS) 77MODULE_CFLAGS := $(EXTRA_MODULE_CFLAGS) $(MODULE_CFLAGS) 78MODULE_CPPFLAGS := $(EXTRA_MODULE_CPPFLAGS) $(MODULE_CPPFLAGS) 79MODULE_ASMFLAGS := $(EXTRA_MODULE_ASMFLAGS) $(MODULE_ASMFLAGS) 80MODULE_OPTIONS_COPY := $(filter-out extra_warnings,$(MODULE_OPTIONS_COPY)) 81endif 82 83ifneq ($(MODULE_OPTIONS_COPY),) 84$(error MODULE $(MODULE) has unrecognized option(s) $(MODULE_OPTIONS_COPY)) 85endif 86 87 88#$(info module $(MODULE)) 89#$(info MODULE_COMPILEFLAGS = $(MODULE_COMPILEFLAGS)) 90#$(info MODULE_SRCDIR $(MODULE_SRCDIR)) 91#$(info MODULE_BUILDDIR $(MODULE_BUILDDIR)) 92#$(info MODULE_DEPS $(MODULE_DEPS)) 93#$(info MODULE_SRCS $(MODULE_SRCS)) 94#$(info MODULE_FLOAT_SRCS $(MODULE_FLOAT_SRCS)) 95#$(info MODULE_OPTIONS $(MODULE_OPTIONS)) 96 97MODULE_DEFINES += MODULE_NAME=\"$(subst $(SPACE),_,$(MODULE))\" 98MODULE_DEFINES += MODULE_OPTIONS=\"$(subst $(SPACE),_,$(MODULE_OPTIONS))\" 99MODULE_DEFINES += MODULE_COMPILEFLAGS=\"$(subst $(SPACE),_,$(MODULE_COMPILEFLAGS))\" 100MODULE_DEFINES += MODULE_CFLAGS=\"$(subst $(SPACE),_,$(MODULE_CFLAGS))\" 101MODULE_DEFINES += MODULE_CPPFLAGS=\"$(subst $(SPACE),_,$(MODULE_CPPFLAGS))\" 102MODULE_DEFINES += MODULE_ASMFLAGS=\"$(subst $(SPACE),_,$(MODULE_ASMFLAGS))\" 103MODULE_DEFINES += MODULE_OPTFLAGS=\"$(subst $(SPACE),_,$(MODULE_OPTFLAGS))\" 104MODULE_DEFINES += MODULE_INCLUDES=\"$(subst $(SPACE),_,$(MODULE_INCLUDES))\" 105MODULE_DEFINES += MODULE_SRCDEPS=\"$(subst $(SPACE),_,$(MODULE_SRCDEPS))\" 106MODULE_DEFINES += MODULE_DEPS=\"$(subst $(SPACE),_,$(MODULE_DEPS))\" 107MODULE_DEFINES += MODULE_SRCS=\"$(subst $(SPACE),_,$(MODULE_SRCS))\" 108MODULE_DEFINES += MODULE_FLOAT_SRCS=\"$(subst $(SPACE),_,$(MODULE_FLOAT_SRCS))\" 109 110# generate a per-module config.h file 111MODULE_CONFIG := $(MODULE_BUILDDIR)/module_config.h 112 113$(MODULE_CONFIG): MODULE_DEFINES:=$(MODULE_DEFINES) 114$(MODULE_CONFIG): configheader 115 @$(call MAKECONFIGHEADER,$@,MODULE_DEFINES) 116 117GENERATED += $(MODULE_CONFIG) 118 119MODULE_COMPILEFLAGS += -include $(MODULE_CONFIG) 120 121MODULE_SRCDEPS += $(MODULE_CONFIG) 122 123MODULE_INCLUDES := $(addprefix -I,$(MODULE_INCLUDES)) 124 125# include the rules to compile the module's object files 126include make/compile.mk 127 128# MODULE_OBJS is passed back from compile.mk 129#$(info MODULE_OBJS = $(MODULE_OBJS)) 130 131# build a ld -r style combined object 132MODULE_OBJECT := $(call TOBUILDDIR,$(MODULE_SRCDIR).mod.o) 133$(MODULE_OBJECT): $(MODULE_OBJS) $(MODULE_EXTRA_OBJS) 134 @$(MKDIR) 135 $(info linking $@) 136 $(NOECHO)$(LD) $(GLOBAL_MODULE_LDFLAGS) -r $^ -o $@ 137 138# track all of the source files compiled 139ALLSRCS += $(MODULE_SRCS) 140 141# track all the objects built 142ALLOBJS += $(MODULE_OBJS) 143 144# track the module object for make clean 145GENERATED += $(MODULE_OBJECT) 146 147# make the rest of the build depend on our output 148ALLMODULE_OBJS := $(ALLMODULE_OBJS) $(MODULE_OBJECT) 149 150# empty out any vars set here 151MODULE := 152MODULE_SRCDIR := 153MODULE_BUILDDIR := 154MODULE_DEPS := 155MODULE_SRCS := 156MODULE_FLOAT_SRCS := 157MODULE_OBJS := 158MODULE_DEFINES := 159MODULE_OPTFLAGS := 160MODULE_COMPILEFLAGS := 161MODULE_CFLAGS := 162MODULE_CPPFLAGS := 163MODULE_ASMFLAGS := 164MODULE_SRCDEPS := 165MODULE_INCLUDES := 166MODULE_EXTRA_OBJS := 167MODULE_CONFIG := 168MODULE_OBJECT := 169MODULE_ARM_OVERRIDE_SRCS := 170MODULE_OPTIONS := 171