1 # ===========================================================================
3 # ===========================================================================
9 include scripts/Makefile.lib
13 __modules := $(shell head -q -n1 /dev/null $(wildcard $(MODVERDIR)/*.mod))
14 modules := $(patsubst %.o,%.ko,$(wildcard $(__modules:.ko=.o)))
16 ifneq ($(filter-out $(modules),$(__modules)),)
17 $(warning Trouble: $(filter-out $(modules),$(__modules)))
18 $(warning *** Uh-oh, you have stale module entries. You messed with SUBDIRS,)
19 $(warning do not complain if something goes wrong.)
22 __modversions: $(modules)
25 # The final module link
27 quiet_cmd_ld_ko_o = LD [M] $@
28 cmd_ld_ko_o = $(LD) $(LDFLAGS) $(LDFLAGS_MODULE) -o $@ \
29 $(filter-out FORCE,$^)
31 $(modules): %.ko :%.o %.mod.o FORCE
32 $(call if_changed,ld_ko_o)
36 # Compile version info for unresolved symbols
38 quiet_cmd_cc_o_c = CC $@
39 cmd_cc_o_c = $(CC) $(c_flags) $(CFLAGS_MODULE) \
42 $(modules:.ko=.mod.o): %.mod.o: %.mod.c FORCE
43 $(call if_changed_dep,cc_o_c)
45 targets += $(modules:.ko=.mod.o)
47 # All the .mod.c files are generated using the helper "modpost"
51 $(modules:.ko=.mod.c): __modpost ;
53 # Extract all checksums for all exported symbols
55 # Are we building out-of-tree modules?
57 ifeq ($(filter ../% /%,$(SUBDIRS)),)
58 modver_file := modversions-$(shell echo $(ARCH)-$(CONFIG_CFGNAME))
59 quiet_cmd_modpost = MODPOST
60 cmd_modpost = scripts/modpost $(filter-out FORCE,$^) $(if $(CONFIG_MODVERSIONS),-o $(modver_file))
61 __modpost: $(wildcard vmlinux) $(modules:.ko=.o) FORCE
62 $(call if_changed,modpost)
64 modver_file := $(wildcard $(srctree)/modversions-$(shell echo $(ARCH)-$(CONFIG_CFGNAME)))
65 quiet_cmd_modpost = MODPOST
66 cmd_modpost = scripts/modpost $(if $(modver_file),-i $(modver_file)) $^
67 __modpost: $(modules:.ko=.o)
73 # Add FORCE to the prequisites of a target to force it to be always rebuilt.
74 # ---------------------------------------------------------------------------
80 # Read all saved command lines and dependencies for the $(targets) we
81 # may be building above, using $(if_changed{,_dep}). As an
82 # optimization, we don't need to read them if the target does not
83 # exist, we will rebuild anyway in that case.
85 targets := $(wildcard $(sort $(targets)))
86 cmd_files := $(wildcard $(foreach f,$(targets),$(dir $(f)).$(notdir $(f)).cmd))