1
2# modules
3#
4# args:
5# MODULE : module name (required)
6# MODULE_SRCS : list of source files, local path (required)
7# MODULE_DEPS : other modules that this one depends on
8# MODULE_DEFINES : #defines local to this module
9# MODULE_OPTFLAGS : OPTFLAGS local to this module
10# MODULE_COMPILEFLAGS : COMPILEFLAGS local to this module
11# MODULE_CFLAGS : CFLAGS local to this module
12# MODULE_CPPFLAGS : CPPFLAGS local to this module
13# MODULE_ASMFLAGS : ASMFLAGS local to this module
14# MODULE_INCLUDES : include directories local to this module
15# MODULE_SRCDEPS : extra dependencies that all of this module's files depend on
16# MODULE_EXTRA_OBJS : extra .o files that should be linked with the module
17
18# MODULE_ARM_OVERRIDE_SRCS : list of source files, local path that should be force compiled with ARM (if applicable)
19
20# the minimum module rules.mk file is as follows:
21#
22# LOCAL_DIR := $(GET_LOCAL_DIR)
23# MODULE := $(LOCAL_DIR)
24#
25# MODULE_SRCS := $(LOCAL_DIR)/at_least_one_source_file.c
26#
27# include make/module.mk
28
29# test for old style rules.mk
30ifneq ($(MODULE_OBJS),)
31$(warning MODULE_OBJS = $(MODULE_OBJS))
32$(error MODULE $(MODULE) is setting MODULE_OBJS, change to MODULE_SRCS)
33endif
34ifneq ($(OBJS),)
35$(warning OBJS = $(OBJS))
36$(error MODULE $(MODULE) is probably setting OBJS, change to MODULE_SRCS)
37endif
38
39MODULE_SRCDIR := $(MODULE)
40MODULE_BUILDDIR := $(call TOBUILDDIR,$(MODULE_SRCDIR))
41
42# add a local include dir to the global include path
43GLOBAL_INCLUDES += $(MODULE_SRCDIR)/include
44
45# add the listed module deps to the global list
46MODULES += $(MODULE_DEPS)
47
48#$(info module $(MODULE))
49#$(info MODULE_SRCDIR $(MODULE_SRCDIR))
50#$(info MODULE_BUILDDIR $(MODULE_BUILDDIR))
51#$(info MODULE_DEPS $(MODULE_DEPS))
52#$(info MODULE_SRCS $(MODULE_SRCS))
53
54MODULE_DEFINES += MODULE_COMPILEFLAGS=\"$(subst $(SPACE),_,$(MODULE_COMPILEFLAGS))\"
55MODULE_DEFINES += MODULE_CFLAGS=\"$(subst $(SPACE),_,$(MODULE_CFLAGS))\"
56MODULE_DEFINES += MODULE_CPPFLAGS=\"$(subst $(SPACE),_,$(MODULE_CPPFLAGS))\"
57MODULE_DEFINES += MODULE_ASMFLAGS=\"$(subst $(SPACE),_,$(MODULE_ASMFLAGS))\"
58MODULE_DEFINES += MODULE_LDFLAGS=\"$(subst $(SPACE),_,$(MODULE_LDFLAGS))\"
59MODULE_DEFINES += MODULE_OPTFLAGS=\"$(subst $(SPACE),_,$(MODULE_OPTFLAGS))\"
60MODULE_DEFINES += MODULE_INCLUDES=\"$(subst $(SPACE),_,$(MODULE_INCLUDES))\"
61MODULE_DEFINES += MODULE_SRCDEPS=\"$(subst $(SPACE),_,$(MODULE_SRCDEPS))\"
62MODULE_DEFINES += MODULE_DEPS=\"$(subst $(SPACE),_,$(MODULE_DEPS))\"
63MODULE_DEFINES += MODULE_SRCS=\"$(subst $(SPACE),_,$(MODULE_SRCS))\"
64
65# generate a per-module config.h file
66MODULE_CONFIG := $(MODULE_BUILDDIR)/module_config.h
67
68$(MODULE_CONFIG): MODULE_DEFINES:=$(MODULE_DEFINES)
69$(MODULE_CONFIG): configheader
70	@$(call MAKECONFIGHEADER,$@,MODULE_DEFINES)
71
72GENERATED += $(MODULE_CONFIG)
73
74MODULE_COMPILEFLAGS += -include $(MODULE_CONFIG)
75
76MODULE_SRCDEPS += $(MODULE_CONFIG)
77
78MODULE_INCLUDES := $(addprefix -I,$(MODULE_INCLUDES))
79
80# include the rules to compile the module's object files
81include make/compile.mk
82
83# MODULE_OBJS is passed back from compile.mk
84#$(info MODULE_OBJS = $(MODULE_OBJS))
85
86# build a ld -r style combined object
87MODULE_OBJECT := $(call TOBUILDDIR,$(MODULE_SRCDIR).mod.o)
88$(MODULE_OBJECT): $(MODULE_OBJS) $(MODULE_EXTRA_OBJS)
89	@$(MKDIR)
90	$(info linking $@)
91	$(NOECHO)$(LD) $(GLOBAL_MODULE_LDFLAGS) -r $^ -o $@
92
93# track all of the source files compiled
94ALLSRCS += $(MODULE_SRCS)
95
96# track all the objects built
97ALLOBJS += $(MODULE_OBJS)
98
99# track the module object for make clean
100GENERATED += $(MODULE_OBJECT)
101
102# make the rest of the build depend on our output
103ALLMODULE_OBJS := $(ALLMODULE_OBJS) $(MODULE_OBJECT)
104
105# empty out any vars set here
106MODULE :=
107MODULE_SRCDIR :=
108MODULE_BUILDDIR :=
109MODULE_DEPS :=
110MODULE_SRCS :=
111MODULE_OBJS :=
112MODULE_DEFINES :=
113MODULE_OPTFLAGS :=
114MODULE_COMPILEFLAGS :=
115MODULE_CFLAGS :=
116MODULE_CPPFLAGS :=
117MODULE_ASMFLAGS :=
118MODULE_SRCDEPS :=
119MODULE_INCLUDES :=
120MODULE_EXTRA_OBJS :=
121MODULE_CONFIG :=
122MODULE_OBJECT :=
123MODULE_ARM_OVERRIDE_SRCS :=
124