blob: 634eaafec58efd9da8c51e6eb9246efac8e43bda [file] [log] [blame]
rjw1f884582022-01-06 17:20:42 +08001
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))\"
63
64# generate a per-module config.h file
65MODULE_CONFIG := $(MODULE_BUILDDIR)/module_config.h
66
67$(MODULE_CONFIG): MODULE_DEFINES:=$(MODULE_DEFINES)
68$(MODULE_CONFIG): configheader
69 @$(call MAKECONFIGHEADER,$@,MODULE_DEFINES)
70
71GENERATED += $(MODULE_CONFIG)
72
73MODULE_COMPILEFLAGS += --include $(MODULE_CONFIG)
74
75MODULE_SRCDEPS += $(MODULE_CONFIG)
76
77MODULE_INCLUDES := $(addprefix -I,$(MODULE_INCLUDES))
78
79# include the rules to compile the module's object files
80include make/compile.mk
81
82# MODULE_OBJS is passed back from compile.mk
83#$(info MODULE_OBJS = $(MODULE_OBJS))
84
85# build a ld -r style combined object
86MODULE_OBJECT := $(call TOBUILDDIR,$(MODULE_SRCDIR).mod.o)
87$(MODULE_OBJECT): $(MODULE_OBJS) $(MODULE_EXTRA_OBJS)
88 @$(MKDIR)
89 @echo linking $@
90 $(NOECHO)$(LD) $(GLOBAL_MODULE_LDFLAGS) -r $^ -o $@
91
92# track all of the source files compiled
93ALLSRCS += $(MODULE_SRCS)
94
95# track all the objects built
96ALLOBJS += $(MODULE_OBJS)
97
98# track the module object for make clean
99GENERATED += $(MODULE_OBJECT)
100
101# make the rest of the build depend on our output
102ALLMODULE_OBJS := $(ALLMODULE_OBJS) $(MODULE_OBJECT)
103
104# empty out any vars set here
105MODULE :=
106MODULE_SRCDIR :=
107MODULE_BUILDDIR :=
108MODULE_DEPS :=
109MODULE_SRCS :=
110MODULE_OBJS :=
111MODULE_DEFINES :=
112MODULE_OPTFLAGS :=
113MODULE_COMPILEFLAGS :=
114MODULE_CFLAGS :=
115MODULE_CPPFLAGS :=
116MODULE_ASMFLAGS :=
117MODULE_SRCDEPS :=
118MODULE_INCLUDES :=
119MODULE_EXTRA_OBJS :=
120MODULE_CONFIG :=
121MODULE_OBJECT :=
122MODULE_ARM_OVERRIDE_SRCS :=