Makefile: add module support
Signed-off-by: Michael Shaw <m@michaelsshaw.com>
This commit is contained in:
parent
7cc7da0f54
commit
9fed595abc
7 changed files with 50 additions and 17 deletions
|
|
@ -11,6 +11,7 @@
|
|||
export
|
||||
|
||||
obj-y :=
|
||||
obj-m :=
|
||||
subdir-y :=
|
||||
|
||||
include $(obj)/Makefile
|
||||
|
|
@ -20,7 +21,14 @@ real-objs-y :=
|
|||
subdir-y := $(patsubst %/,%,$(filter %/, $(obj-y)))
|
||||
real-objs-y := $(addprefix $(obj)/, $(filter-out %/, $(obj-y)))
|
||||
subdir-objs-y := $(foreach d,$(subdir-y),$(obj)/$(d)/built-in.o)
|
||||
deps := $(real-objs-y:.o=.d)
|
||||
|
||||
subdir-m := $(patsubst %/,%,$(filter %/, $(obj-m)))
|
||||
mod-names := $(basename $(filter-out %/, $(obj-m)))
|
||||
mod-targets := $(addprefix $(obj)/, $(addsuffix .ko, $(mod-names)))
|
||||
mod-objs := $(foreach m,$(mod-names), \
|
||||
$(addprefix $(obj)/, $(or $($(m)-objs),$($(m)-y),$(m).o)))
|
||||
|
||||
deps := $(real-objs-y:.o=.d) $(mod-objs:.o=.d)
|
||||
|
||||
ifeq ($(obj),.)
|
||||
_all: $(subdir-objs-y)
|
||||
|
|
@ -40,15 +48,36 @@ $(obj)/built-in.o: $(real-objs-y) $(subdir-objs-y)
|
|||
$(Q)echo " LD $@"
|
||||
$(Q)$(LD) -r -o $@ $(real-objs-y) $(foreach d,$(subdir-y),$(obj)/$(d)/built-in.o)
|
||||
|
||||
# --- Module support ---
|
||||
|
||||
define mod_rule
|
||||
$(obj)/$(1).ko: $(addprefix $(obj)/, $(or $($(1)-objs),$($(1)-y),$(1).o))
|
||||
$$(Q)echo " MODLD $$@"
|
||||
$$(Q)$$(LD) -r -o $$@ $$^
|
||||
endef
|
||||
|
||||
$(foreach m,$(mod-names),$(eval $(call mod_rule,$(m))))
|
||||
|
||||
define mod_cflags
|
||||
$(addprefix $(obj)/, $(or $($(1)-objs),$($(1)-y),$(1).o)): CFLAGS += $(MODULE_CFLAGS)
|
||||
endef
|
||||
|
||||
$(foreach m,$(mod-names),$(eval $(call mod_cflags,$(m))))
|
||||
|
||||
.PHONY: _modules
|
||||
_modules: $(mod-targets) $(subdir-m)
|
||||
|
||||
.PHONY: _clean
|
||||
_clean: $(subdir-y)
|
||||
_clean: $(subdir-y) $(subdir-m)
|
||||
$(Q)echo " CLEAN $(obj)"
|
||||
@rm -rf $(obj)/built-in.o $(real-objs-y) $(deps)
|
||||
|
||||
@rm -rf $(obj)/built-in.o $(real-objs-y) $(deps) $(mod-objs) $(mod-targets)
|
||||
|
||||
$(subdir-y): FORCE
|
||||
$(Q)$(MAKE) --no-print-directory -f scripts/Makefile.build $(MAKECMDGOALS) obj=$(obj)/$@
|
||||
|
||||
$(subdir-m): FORCE
|
||||
$(Q)$(MAKE) --no-print-directory -f scripts/Makefile.build $(if $(filter _clean,$(MAKECMDGOALS)),_clean,_modules) obj=$(obj)/$@
|
||||
|
||||
$(obj)/%/built-in.o: FORCE
|
||||
$(Q)$(MAKE) --no-print-directory -f scripts/Makefile.build obj=$(patsubst %/,%,$(dir $@))
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue