rjw | 1f88458 | 2022-01-06 17:20:42 +0800 | [diff] [blame^] | 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 |
| 30 | ifneq ($(MODULE_OBJS),) |
| 31 | $(warning MODULE_OBJS = $(MODULE_OBJS)) |
| 32 | $(error MODULE $(MODULE) is setting MODULE_OBJS, change to MODULE_SRCS) |
| 33 | endif |
| 34 | ifneq ($(OBJS),) |
| 35 | $(warning OBJS = $(OBJS)) |
| 36 | $(error MODULE $(MODULE) is probably setting OBJS, change to MODULE_SRCS) |
| 37 | endif |
| 38 | |
| 39 | MODULE_SRCDIR := $(MODULE) |
| 40 | MODULE_BUILDDIR := $(call TOBUILDDIR,$(MODULE_SRCDIR)) |
| 41 | |
| 42 | # add a local include dir to the global include path |
| 43 | GLOBAL_INCLUDES += $(MODULE_SRCDIR)/include |
| 44 | |
| 45 | # add the listed module deps to the global list |
| 46 | MODULES += $(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 | |
| 54 | MODULE_DEFINES += MODULE_COMPILEFLAGS=\"$(subst $(SPACE),_,$(MODULE_COMPILEFLAGS))\" |
| 55 | MODULE_DEFINES += MODULE_CFLAGS=\"$(subst $(SPACE),_,$(MODULE_CFLAGS))\" |
| 56 | MODULE_DEFINES += MODULE_CPPFLAGS=\"$(subst $(SPACE),_,$(MODULE_CPPFLAGS))\" |
| 57 | MODULE_DEFINES += MODULE_ASMFLAGS=\"$(subst $(SPACE),_,$(MODULE_ASMFLAGS))\" |
| 58 | MODULE_DEFINES += MODULE_LDFLAGS=\"$(subst $(SPACE),_,$(MODULE_LDFLAGS))\" |
| 59 | MODULE_DEFINES += MODULE_OPTFLAGS=\"$(subst $(SPACE),_,$(MODULE_OPTFLAGS))\" |
| 60 | MODULE_DEFINES += MODULE_INCLUDES=\"$(subst $(SPACE),_,$(MODULE_INCLUDES))\" |
| 61 | MODULE_DEFINES += MODULE_SRCDEPS=\"$(subst $(SPACE),_,$(MODULE_SRCDEPS))\" |
| 62 | MODULE_DEFINES += MODULE_DEPS=\"$(subst $(SPACE),_,$(MODULE_DEPS))\" |
| 63 | |
| 64 | # generate a per-module config.h file |
| 65 | MODULE_CONFIG := $(MODULE_BUILDDIR)/module_config.h |
| 66 | |
| 67 | $(MODULE_CONFIG): MODULE_DEFINES:=$(MODULE_DEFINES) |
| 68 | $(MODULE_CONFIG): configheader |
| 69 | @$(call MAKECONFIGHEADER,$@,MODULE_DEFINES) |
| 70 | |
| 71 | GENERATED += $(MODULE_CONFIG) |
| 72 | |
| 73 | MODULE_COMPILEFLAGS += --include $(MODULE_CONFIG) |
| 74 | |
| 75 | MODULE_SRCDEPS += $(MODULE_CONFIG) |
| 76 | |
| 77 | MODULE_INCLUDES := $(addprefix -I,$(MODULE_INCLUDES)) |
| 78 | |
| 79 | # include the rules to compile the module's object files |
| 80 | include 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 |
| 86 | MODULE_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 |
| 93 | ALLSRCS += $(MODULE_SRCS) |
| 94 | |
| 95 | # track all the objects built |
| 96 | ALLOBJS += $(MODULE_OBJS) |
| 97 | |
| 98 | # track the module object for make clean |
| 99 | GENERATED += $(MODULE_OBJECT) |
| 100 | |
| 101 | # make the rest of the build depend on our output |
| 102 | ALLMODULE_OBJS := $(ALLMODULE_OBJS) $(MODULE_OBJECT) |
| 103 | |
| 104 | # empty out any vars set here |
| 105 | MODULE := |
| 106 | MODULE_SRCDIR := |
| 107 | MODULE_BUILDDIR := |
| 108 | MODULE_DEPS := |
| 109 | MODULE_SRCS := |
| 110 | MODULE_OBJS := |
| 111 | MODULE_DEFINES := |
| 112 | MODULE_OPTFLAGS := |
| 113 | MODULE_COMPILEFLAGS := |
| 114 | MODULE_CFLAGS := |
| 115 | MODULE_CPPFLAGS := |
| 116 | MODULE_ASMFLAGS := |
| 117 | MODULE_SRCDEPS := |
| 118 | MODULE_INCLUDES := |
| 119 | MODULE_EXTRA_OBJS := |
| 120 | MODULE_CONFIG := |
| 121 | MODULE_OBJECT := |
| 122 | MODULE_ARM_OVERRIDE_SRCS := |