2 # This file contains rules which are shared between multiple Makefiles.
11 # Special variables which should not be exported
15 unexport EXTRA_LDFLAGS
16 unexport EXTRA_ARFLAGS
36 # When an object is listed to be built compiled-in and modular,
37 # only build the compiled-in version
39 obj-m
:= $(filter-out $(obj-y
),$(obj-m
))
47 both-m
:= $(filter $(mod-subdirs
), $(subdir-y
))
48 SUB_DIRS
:= $(subdir-y
)
49 MOD_SUB_DIRS
:= $(sort $(subdir-m
) $(both-m
))
50 ALL_SUB_DIRS
:= $(sort $(subdir-y
) $(subdir-m
) $(subdir-n
) $(subdir-
))
58 $(CC
) $(CFLAGS
) $(EXTRA_CFLAGS
) -DKBUILD_BASENAME
=$(subst $(comma
),_
,$(subst -,_
,$(*F
))) $(CFLAGS_
$@
) -S
$< -o
$@
61 $(CPP
) $(CFLAGS
) $(EXTRA_CFLAGS
) -DKBUILD_BASENAME
=$(subst $(comma
),_
,$(subst -,_
,$(*F
))) $(CFLAGS_
$@
) $< > $@
64 $(CC
) $(CFLAGS
) $(EXTRA_CFLAGS
) -DKBUILD_BASENAME
=$(subst $(comma
),_
,$(subst -,_
,$(*F
))) $(CFLAGS_
$@
) -c
-o
$@
$<
66 echo
'ifeq ($(strip $(subst $(comma),:,$(CFLAGS) $(EXTRA_CFLAGS) $(CFLAGS_$@))),$$(strip $$(subst $$(comma),:,$$(CFLAGS) $$(EXTRA_CFLAGS) $$(CFLAGS_$@))))' ; \
67 echo
'FILES_FLAGS_UP_TO_DATE += $@' ; \
69 ) > $(dir $@
)/.
$(notdir $@
).flags
72 $(AS
) $(AFLAGS
) $(EXTRA_CFLAGS
) -o
$@
$<
74 # Old makefiles define their own rules for compiling .S files,
75 # but these standard rules are available for any Makefile that
76 # wants to use them. Our plan is to incrementally convert all
77 # the Makefiles to these standard rules. -- rmk, mec
78 ifdef USE_STANDARD_AS_RULE
81 $(CPP
) $(AFLAGS
) $(EXTRA_AFLAGS
) $(AFLAGS_
$@
) $< > $@
84 $(CC
) $(AFLAGS
) $(EXTRA_AFLAGS
) $(AFLAGS_
$@
) -c
-o
$@
$<
89 $(CC
) $(CFLAGS
) $(EXTRA_CFLAGS
) $(CFLAGS_
$@
) -g
-c
-o
$*.o
$<
90 $(TOPDIR
)/scripts
/makelst
$* $(TOPDIR
) $(OBJDUMP
)
94 all_targets
: $(O_TARGET
) $(L_TARGET
)
97 # Rule to compile a set of .o files into one .o file
100 $(O_TARGET
): $(obj-y
)
102 ifneq "$(strip $(obj-y))" ""
103 $(LD
) $(EXTRA_LDFLAGS
) -r
-o
$@
$(filter $(obj-y
), $^
)
108 echo
'ifeq ($(strip $(subst $(comma),:,$(EXTRA_LDFLAGS) $(obj-y))),$$(strip $$(subst $$(comma),:,$$(EXTRA_LDFLAGS) $$(obj-y))))' ; \
109 echo
'FILES_FLAGS_UP_TO_DATE += $@' ; \
111 ) > $(dir $@
)/.
$(notdir $@
).flags
115 # Rule to compile a set of .o files into one .a file
118 $(L_TARGET
): $(obj-y
)
120 $(AR
) $(EXTRA_ARFLAGS
) rcs
$@
$(obj-y
)
122 echo
'ifeq ($(strip $(subst $(comma),:,$(EXTRA_ARFLAGS) $(obj-y))),$$(strip $$(subst $$(comma),:,$$(EXTRA_ARFLAGS) $$(obj-y))))' ; \
123 echo
'FILES_FLAGS_UP_TO_DATE += $@' ; \
125 ) > $(dir $@
)/.
$(notdir $@
).flags
129 # Rule to link composite objects
132 # for make >= 3.78 the following is cleaner:
133 # multi-used := $(foreach m,$(obj-y) $(obj-m), $(if $($(basename $(m))-objs), $(m)))
134 __obj-y
= $(filter-out export.o
,$(obj-y
))
135 __obj-m
= $(filter-out export.o
,$(obj-m
))
136 multi-used-y
:= $(sort $(foreach m
,$(__obj-y
),$(patsubst %,$(m
),$($(basename $(m
))-objs
))))
137 multi-used-m
:= $(sort $(foreach m
,$(__obj-m
),$(patsubst %,$(m
),$($(basename $(m
))-objs
))))
138 ld-multi-used-y
:= $(filter-out $(list-multi
),$(multi-used-y
))
139 ld-multi-used-m
:= $(filter-out $(list-multi
),$(multi-used-m
))
140 ld-multi-objs-y
:= $(foreach m
, $(ld-multi-used-y
), $($(basename $(m
))-objs
))
141 ld-multi-objs-m
:= $(foreach m
, $(ld-multi-used-m
), $($(basename $(m
))-objs
))
143 $(ld-multi-used-y
) : %.o
: $(ld-multi-objs-y
)
145 $(LD
) $(EXTRA_LDFLAGS
) -r
-o
$@
$(filter $($(basename $@
)-objs
), $^
)
147 echo
'ifeq ($(strip $(subst $(comma),:,$(LD) $(EXTRA_LDFLAGS) $($(basename $@)-objs)),$$(strip $$(subst $$(comma),:,$$(LD) $$(EXTRA_LDFLAGS) $$($(basename $@)-objs)))))' ; \
148 echo
'FILES_FLAGS_UP_TO_DATE += $@' ; \
150 ) > $(dir $@
)/.
$(notdir $@
).flags
152 $(ld-multi-used-m
) : %.o
: $(ld-multi-objs-m
)
154 $(LD
) $(EXTRA_LDFLAGS
) -r
-o
$@
$(filter $($(basename $@
)-objs
), $^
)
156 echo
'ifeq ($(strip $(subst $(comma),:,$(LD) $(EXTRA_LDFLAGS) $($(basename $@)-objs)),$$(strip $$(subst $$(comma),:,$$(LD) $$(EXTRA_LDFLAGS) $$($(basename $@)-objs)))))' ; \
157 echo
'FILES_FLAGS_UP_TO_DATE += $@' ; \
159 ) > $(dir $@
)/.
$(notdir $@
).flags
162 # This make dependencies quickly
165 $(TOPDIR
)/scripts
/mkdep
$(CFLAGS
) $(EXTRA_CFLAGS
) -- $(wildcard *.
[chS
]) > .depend
167 $(MAKE
) $(patsubst %,_sfdep_
%,$(ALL_SUB_DIRS
)) _FASTDEP_ALL_SUB_DIRS
="$(ALL_SUB_DIRS)"
170 ifdef _FASTDEP_ALL_SUB_DIRS
171 $(patsubst %,_sfdep_
%,$(_FASTDEP_ALL_SUB_DIRS
)):
172 $(MAKE
) -C
$(patsubst _sfdep_
%,%,$@
) fastdep
177 # A rule to make subdirectories
179 subdir-list
= $(sort $(patsubst %,_subdir_
%,$(SUB_DIRS
)))
180 sub_dirs
: dummy
$(subdir-list
)
183 $(subdir-list
) : dummy
184 $(MAKE
) -C
$(patsubst _subdir_
%,%,$@
)
188 # A rule to make modules
190 ifneq "$(strip $(obj-m))" ""
191 MOD_DESTDIR
:= $(shell $(CONFIG_SHELL
) $(TOPDIR
)/scripts
/pathdown.sh
)
194 ifneq "$(strip $(MOD_SUB_DIRS))" ""
195 .PHONY
: $(patsubst %,_modsubdir_
%,$(MOD_SUB_DIRS
))
196 $(patsubst %,_modsubdir_
%,$(MOD_SUB_DIRS
)) : dummy
197 $(MAKE
) -C
$(patsubst _modsubdir_
%,%,$@
) modules
199 .PHONY
: $(patsubst %,_modinst_
%,$(MOD_SUB_DIRS
))
200 $(patsubst %,_modinst_
%,$(MOD_SUB_DIRS
)) : dummy
201 $(MAKE
) -C
$(patsubst _modinst_
%,%,$@
) modules_install
205 modules
: $(obj-m
) dummy \
206 $(patsubst %,_modsubdir_
%,$(MOD_SUB_DIRS
))
210 ifneq "$(strip $(obj-m))" ""
211 mkdir
-p
$(MODLIB
)/kernel
/$(MOD_DESTDIR
)
212 cp
$(obj-m
) $(MODLIB
)/kernel
/$(MOD_DESTDIR
)
215 .PHONY
: modules_install
216 modules_install
: _modinst__ \
217 $(patsubst %,_modinst_
%,$(MOD_SUB_DIRS
))
220 # A rule to do nothing
225 # This is useful for testing
231 # This sets version suffixes on exported symbols
232 # Separate the object into "normal" objects and "exporting" objects
233 # Exporting objects are: all objects that define symbol tables
237 multi-objs
:= $(foreach m
, $(obj-y
) $(obj-m
), $($(basename $(m
))-objs
))
238 active-objs
:= $(sort $(multi-objs
) $(obj-y
) $(obj-m
))
240 ifdef CONFIG_MODVERSIONS
241 ifneq "$(strip $(export-objs))" ""
243 MODINCL
= $(TOPDIR
)/include/linux
/modules
244 MODCURDIR
= $(subst $(TOPDIR
)/,,$(shell /bin
/pwd
))
245 MODPREFIX
= $(subst /,-,$(MODCURDIR
))__
247 # The -w option (enable warnings) for genksyms will return here in 2.1
248 # So where has it gone?
250 # Added the SMP separator to stop module accidents between uniprocessor
251 # and SMP Intel boxes - AC - from bits by Michael Chastain
255 genksyms_smp_prefix
:= -p smp_
257 genksyms_smp_prefix
:=
260 $(MODINCL
)/$(MODPREFIX
)%.ver
: %.c
261 @if
[ ! -r
$(MODINCL
)/$(MODPREFIX
)$*.stamp
-o
$(MODINCL
)/$(MODPREFIX
)$*.stamp
-ot
$< ]; then \
262 echo
'$(CC) $(CFLAGS) $(EXTRA_CFLAGS) -E -D__GENKSYMS__ $<'; \
263 echo
'| $(GENKSYMS) $(genksyms_smp_prefix) -k $(VERSION).$(PATCHLEVEL).$(SUBLEVEL) > $@.tmp'; \
264 $(CC
) $(CFLAGS
) $(EXTRA_CFLAGS
) -E
-D__GENKSYMS__
$< \
265 |
$(GENKSYMS
) $(genksyms_smp_prefix
) -k
$(VERSION
).
$(PATCHLEVEL
).
$(SUBLEVEL
) > $@.tmp
; \
266 if
[ -r
$@
] && cmp
-s
$@
$@.tmp
; then echo
$@ is unchanged
; rm -f
$@.tmp
; \
267 else echo mv
$@.tmp
$@
; mv
-f
$@.tmp
$@
; fi
; \
268 fi
; touch
$(MODINCL
)/$(MODPREFIX
)$*.stamp
270 $(addprefix $(MODINCL
)/$(MODPREFIX
),$(export-objs
:.o
=.ver
)): $(TOPDIR
)/include/linux
/autoconf.h
272 # updates .ver files but not modversions.h
273 fastdep
: $(addprefix $(MODINCL
)/$(MODPREFIX
),$(export-objs
:.o
=.ver
))
275 # updates .ver files and modversions.h like before (is this needed?)
276 dep
: fastdep update-modverfile
280 # update modversions.h, but only if it would change
282 @
(echo
"#ifndef _LINUX_MODVERSIONS_H";\
283 echo
"#define _LINUX_MODVERSIONS_H"; \
284 echo
"#include <linux/modsetver.h>"; \
285 cd
$(TOPDIR
)/include/linux
/modules
; \
287 if
[ -f
$$f ]; then echo
"#include <linux/modules/$${f}>"; fi
; \
290 ) > $(TOPDIR
)/include/linux
/modversions.h.tmp
291 @if
[ -r
$(TOPDIR
)/include/linux
/modversions.h
] && cmp
-s
$(TOPDIR
)/include/linux
/modversions.h
$(TOPDIR
)/include/linux
/modversions.h.tmp
; then \
292 echo
$(TOPDIR
)/include/linux
/modversions.h was not updated
; \
293 rm -f
$(TOPDIR
)/include/linux
/modversions.h.tmp
; \
295 echo
$(TOPDIR
)/include/linux
/modversions.h was updated
; \
296 mv
-f
$(TOPDIR
)/include/linux
/modversions.h.tmp
$(TOPDIR
)/include/linux
/modversions.h
; \
299 $(active-objs
): $(TOPDIR
)/include/linux
/modversions.h
303 $(TOPDIR
)/include/linux
/modversions.h
:
304 @echo
"#include <linux/modsetver.h>" > $@
306 endif # CONFIG_MODVERSIONS
308 ifneq "$(strip $(export-objs))" ""
309 $(export-objs
): $(TOPDIR
)/include/linux
/modversions.h
310 $(export-objs
): %.o
: %.c
311 $(CC
) $(CFLAGS
) $(EXTRA_CFLAGS
) -DKBUILD_BASENAME
=$(subst $(comma
),_
,$(subst -,_
,$(*F
))) $(CFLAGS_
$@
) -DEXPORT_SYMTAB
-c
$(@
:.o
=.c
)
313 echo
'ifeq ($(strip $(subst $(comma),:,$(CFLAGS) $(EXTRA_CFLAGS) $(CFLAGS_$@) -DEXPORT_SYMTAB)),$$(strip $$(subst $$(comma),:,$$(CFLAGS) $$(EXTRA_CFLAGS) $$(CFLAGS_$@) -DEXPORT_SYMTAB)))' ; \
314 echo
'FILES_FLAGS_UP_TO_DATE += $@' ; \
316 ) > $(dir $@
)/.
$(notdir $@
).flags
319 endif # CONFIG_MODULES
323 # include dependency files if they exist
325 ifneq ($(wildcard .depend
),)
329 ifneq ($(wildcard $(TOPDIR
)/.hdepend
),)
330 include $(TOPDIR
)/.hdepend
334 # Find files whose flags have changed and force recompilation.
335 # For safety, this works in the converse direction:
336 # every file is forced, except those whose flags are positively up-to-date.
338 FILES_FLAGS_UP_TO_DATE
:=
340 # For use in expunging commas from flags, which mung our checking.
343 FILES_FLAGS_EXIST
:= $(wildcard .
*.flags
)
344 ifneq ($(FILES_FLAGS_EXIST
),)
345 include $(FILES_FLAGS_EXIST
)
348 FILES_FLAGS_CHANGED
:= $(strip \
349 $(filter-out $(FILES_FLAGS_UP_TO_DATE
), \
350 $(O_TARGET
) $(L_TARGET
) $(active-objs
) \
353 # A kludge: .S files don't get flag dependencies (yet),
354 # because that will involve changing a lot of Makefiles. Also
355 # suppress object files explicitly listed in $(IGNORE_FLAGS_OBJS).
356 # This allows handling of assembly files that get translated into
357 # multiple object files (see arch/ia64/lib/idiv.S, for example).
358 FILES_FLAGS_CHANGED
:= $(strip \
359 $(filter-out $(patsubst %.S
, %.o
, $(wildcard *.S
) $(IGNORE_FLAGS_OBJS
)), \
360 $(FILES_FLAGS_CHANGED
)))
362 ifneq ($(FILES_FLAGS_CHANGED
),)
363 $(FILES_FLAGS_CHANGED
): dummy