summaryrefslogtreecommitdiff
path: root/scripts/Makefile.modver
blob: 6f9c56dd32a8b569e126cdd0d01736bae36c4b37 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# ===========================================================================
# Module versions
# ===========================================================================

src := $(obj)

MODVERDIR := include/linux/modules

.PHONY: modver
modver:

include .config

include $(obj)/Makefile

include scripts/Makefile.lib

# ===========================================================================

ifeq ($(strip $(export-objs)),)

# If we don't export any symbols in this dir, just descend
# ---------------------------------------------------------------------------

modver: $(subdir-ym)
	@:

else

# This sets version suffixes on exported symbols
# ---------------------------------------------------------------------------

#
# Added the SMP separator to stop module accidents between uniprocessor
# and SMP Intel boxes - AC - from bits by Michael Chastain
#

ifdef CONFIG_SMP
	genksyms_smp_prefix := -p smp_
else
	genksyms_smp_prefix := 
endif

#	Don't include modversions.h, we're just about to generate it here.

CFLAGS_MODULE := $(filter-out -include include/linux/modversions.h,$(CFLAGS_MODULE))

$(addprefix $(MODVERDIR)/,$(real-objs-y:.o=.ver)): modkern_cflags := $(CFLAGS_KERNEL)
$(addprefix $(MODVERDIR)/,$(real-objs-m:.o=.ver)): modkern_cflags := $(CFLAGS_MODULE)
$(addprefix $(MODVERDIR)/,$(export-objs:.o=.ver)): export_flags   := -D__GENKSYMS__
# Default for not multi-part modules
modname = $(*F)

$(addprefix $(MODVERDIR)/,$(multi-objs:.o=.ver)) : modname = $(modname-multi)

# Our objects only depend on modversions.h, not on the individual .ver
# files (fix-dep filters them), so touch modversions.h if any of the .ver
# files changes

quiet_cmd_cc_ver_c = MKVER   include/linux/modules/$*.ver
cmd_cc_ver_c = $(CPP) $(c_flags) $< | $(GENKSYMS) $(genksyms_smp_prefix) \
		 -k $(VERSION).$(PATCHLEVEL).$(SUBLEVEL) > $@.tmp

# Okay, let's explain what's happening in rule_make_cc_ver_c:
# o echo the command
# o execute the command
# o If the $(CPP) fails, we won't notice because it's output is piped
#   to $(GENKSYMS) which does not fail. We recognize this case by
#   looking if the generated $(depfile) exists, though.
# o If the .ver file changed, touch modversions.h, which is our marker
#   of any changed .ver files.
# o Move command line and deps into their normal .*.cmd place.  

define rule_cc_ver_c
	$(if $($(quiet)cmd_cc_ver_c),echo '  $($(quiet)cmd_cc_ver_c)';) \
	$(cmd_cc_ver_c); \
	if [ ! -r $(depfile) ]; then exit 1; fi; \
	scripts/fixdep $(depfile) $@ '$(cmd_cc_ver_c)' > $(@D)/.$(@F).tmp; \
	rm -f $(depfile); \
	if [ ! -r $@ ] || cmp -s $@ $@.tmp; then \
	  touch include/linux/modversions.h; \
	fi; \
	mv -f $@.tmp $@
	mv -f $(@D)/.$(@F).tmp $(@D)/.$(@F).cmd
endef

targets := $(addprefix $(MODVERDIR)/,$(export-objs:.o=.ver))

$(MODVERDIR)/%.ver: %.c FORCE
	@$(call if_changed_rule,cc_ver_c)

modver: $(targets) $(subdir-ym)
	@mkdir -p $(dir $(addprefix .tmp_export-objs/modules/,$(export-objs:.o=.ver)))
	@touch $(addprefix .tmp_export-objs/modules/,$(export-objs:.o=.ver))

endif # export-objs 

# Descending
# ---------------------------------------------------------------------------

.PHONY: $(subdir-ym)
$(subdir-ym):
	$(Q)$(MAKE) -f scripts/Makefile.modver obj=$@

# Add FORCE to the prequisites of a target to force it to be always rebuilt.
# ---------------------------------------------------------------------------

.PHONY: FORCE

FORCE:

# Read all saved command lines and dependencies for the $(targets) we
# may be building above, using $(if_changed{,_dep}). As an
# optimization, we don't need to read them if the target does not
# exist, we will rebuild anyway in that case.

targets := $(wildcard $(sort $(targets)))
cmd_files := $(wildcard $(foreach f,$(targets),$(dir $(f)).$(notdir $(f)).cmd))

ifneq ($(cmd_files),)
  include $(cmd_files)
endif