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
35 EXTRA_CFLAGS_nostdinc := $(EXTRA_CFLAGS) $(kbuild_2_4_nostdinc)
43 both-m := $(filter $(mod-subdirs), $(subdir-y))
44 SUB_DIRS := $(subdir-y)
45 MOD_SUB_DIRS := $(sort $(subdir-m) $(both-m))
46 ALL_SUB_DIRS := $(sort $(subdir-y) $(subdir-m) $(subdir-n) $(subdir-))
54 $(CC) $(CFLAGS) $(EXTRA_CFLAGS_nostdinc) -DKBUILD_BASENAME=$(subst $(comma),_,$(subst -,_,$(*F))) $(CFLAGS_$@) -S $< -o $@
57 $(CPP) $(CFLAGS) $(EXTRA_CFLAGS_nostdinc) -DKBUILD_BASENAME=$(subst $(comma),_,$(subst -,_,$(*F))) $(CFLAGS_$@) $< > $@
60 $(CC) $(CFLAGS) $(EXTRA_CFLAGS_nostdinc) -DKBUILD_BASENAME=$(subst $(comma),_,$(subst -,_,$(*F))) $(CFLAGS_$@) -c -o $@ $<
62 echo 'ifeq ($(strip $(subst $(comma),:,$(CFLAGS) $(EXTRA_CFLAGS_nostdinc) $(CFLAGS_$@))),$$(strip $$(subst $$(comma),:,$$(CFLAGS) $$(EXTRA_CFLAGS_nostdinc) $$(CFLAGS_$@))))' ; \
63 echo 'FILES_FLAGS_UP_TO_DATE += $@' ; \
65 ) > $(dir $@)/.$(notdir $@).flags
68 $(AS) $(AFLAGS) $(EXTRA_CFLAGS) -o $@ $<
70 # Old makefiles define their own rules for compiling .S files,
71 # but these standard rules are available for any Makefile that
72 # wants to use them. Our plan is to incrementally convert all
73 # the Makefiles to these standard rules. -- rmk, mec
74 ifdef USE_STANDARD_AS_RULE
77 $(CPP) $(AFLAGS) $(EXTRA_AFLAGS) $(AFLAGS_$@) $< > $@
80 $(CC) $(AFLAGS) $(EXTRA_AFLAGS) $(AFLAGS_$@) -c -o $@ $<
85 $(CC) $(CFLAGS) $(EXTRA_CFLAGS_nostdinc) $(CFLAGS_$@) -g -c -o $*.o $<
86 $(TOPDIR)/scripts/makelst $* $(TOPDIR) $(OBJDUMP)
90 all_targets: $(O_TARGET) $(L_TARGET)
93 # Rule to compile a set of .o files into one .o file
98 ifneq "$(strip $(obj-y))" ""
99 $(LD) $(LDFLAGS) $(EXTRA_LDFLAGS) -r -o $@ $(filter $(obj-y), $^)
104 echo 'ifeq ($(strip $(subst $(comma),:,$(LDFLAGS) $(EXTRA_LDFLAGS) $(obj-y))),$$(strip $$(subst $$(comma),:,$$(LDFLAGS) $$(EXTRA_LDFLAGS) $$(obj-y))))' ; \
105 echo 'FILES_FLAGS_UP_TO_DATE += $@' ; \
107 ) > $(dir $@)/.$(notdir $@).flags
111 # Rule to compile a set of .o files into one .a file
114 $(L_TARGET): $(obj-y)
116 $(AR) $(EXTRA_ARFLAGS) rcs $@ $(obj-y)
118 echo 'ifeq ($(strip $(subst $(comma),:,$(EXTRA_ARFLAGS) $(obj-y))),$$(strip $$(subst $$(comma),:,$$(EXTRA_ARFLAGS) $$(obj-y))))' ; \
119 echo 'FILES_FLAGS_UP_TO_DATE += $@' ; \
121 ) > $(dir $@)/.$(notdir $@).flags
126 # This make dependencies quickly
129 $(TOPDIR)/scripts/mkdep $(CFLAGS) $(EXTRA_CFLAGS_nostdinc) -- $(wildcard *.[chS]) > .depend
131 $(MAKE) $(patsubst %,_sfdep_%,$(ALL_SUB_DIRS)) _FASTDEP_ALL_SUB_DIRS="$(ALL_SUB_DIRS)"
134 ifdef _FASTDEP_ALL_SUB_DIRS
135 $(patsubst %,_sfdep_%,$(_FASTDEP_ALL_SUB_DIRS)):
136 $(MAKE) -C $(patsubst _sfdep_%,%,$@) fastdep
141 # A rule to make subdirectories
143 subdir-list = $(sort $(patsubst %,_subdir_%,$(SUB_DIRS)))
144 sub_dirs: dummy $(subdir-list)
147 $(subdir-list) : dummy
148 $(MAKE) -C $(patsubst _subdir_%,%,$@)
152 # A rule to make modules
154 ALL_MOBJS = $(filter-out $(obj-y), $(obj-m))
155 ifneq "$(strip $(ALL_MOBJS))" ""
156 MOD_DESTDIR := $(shell $(CONFIG_SHELL) $(TOPDIR)/scripts/pathdown.sh)
160 MOD_DIRS := $(MOD_SUB_DIRS) $(MOD_IN_SUB_DIRS)
161 ifneq "$(strip $(MOD_DIRS))" ""
162 .PHONY: $(patsubst %,_modsubdir_%,$(MOD_DIRS))
163 $(patsubst %,_modsubdir_%,$(MOD_DIRS)) : dummy
164 $(MAKE) -C $(patsubst _modsubdir_%,%,$@) modules
166 .PHONY: $(patsubst %,_modinst_%,$(MOD_DIRS))
167 $(patsubst %,_modinst_%,$(MOD_DIRS)) : dummy
168 $(MAKE) -C $(patsubst _modinst_%,%,$@) modules_install
172 modules: $(ALL_MOBJS) dummy \
173 $(patsubst %,_modsubdir_%,$(MOD_DIRS))
177 ifneq "$(strip $(ALL_MOBJS))" ""
178 mkdir -p $(MODLIB)/kernel/$(MOD_DESTDIR)
179 cp $(sort $(ALL_MOBJS)) $(MODLIB)/kernel/$(MOD_DESTDIR)
182 .PHONY: modules_install
183 modules_install: _modinst__ \
184 $(patsubst %,_modinst_%,$(MOD_DIRS))
187 # A rule to do nothing
192 # This is useful for testing
198 # This sets version suffixes on exported symbols
199 # Separate the object into "normal" objects and "exporting" objects
200 # Exporting objects are: all objects that define symbol tables
204 multi-used := $(filter $(list-multi), $(obj-y) $(obj-m))
205 multi-objs := $(foreach m, $(multi-used), $($(basename $(m))-objs))
206 active-objs := $(sort $(multi-objs) $(obj-y) $(obj-m))
208 ifdef CONFIG_MODVERSIONS
209 ifneq "$(strip $(export-objs))" ""
211 MODINCL = $(TOPDIR)/include/linux/modules
213 # The -w option (enable warnings) for genksyms will return here in 2.1
214 # So where has it gone?
216 # Added the SMP separator to stop module accidents between uniprocessor
217 # and SMP Intel boxes - AC - from bits by Michael Chastain
221 genksyms_smp_prefix := -p smp_
223 genksyms_smp_prefix :=
226 $(MODINCL)/%.ver: %.c
227 @if [ ! -r $(MODINCL)/$*.stamp -o $(MODINCL)/$*.stamp -ot $< ]; then \
228 echo '$(CC) $(CFLAGS) $(EXTRA_CFLAGS_nostdinc) -E -D__GENKSYMS__ $<'; \
229 echo '| $(GENKSYMS) $(genksyms_smp_prefix) -k $(VERSION).$(PATCHLEVEL).$(SUBLEVEL) > $@.tmp'; \
230 $(CC) $(CFLAGS) $(EXTRA_CFLAGS_nostdinc) -E -D__GENKSYMS__ $< \
231 | $(GENKSYMS) $(genksyms_smp_prefix) -k $(VERSION).$(PATCHLEVEL).$(SUBLEVEL) > $@.tmp; \
232 if [ -r $@ ] && cmp -s $@ $@.tmp; then echo $@ is unchanged; rm -f $@.tmp; \
233 else echo mv $@.tmp $@; mv -f $@.tmp $@; fi; \
234 fi; touch $(MODINCL)/$*.stamp
236 $(addprefix $(MODINCL)/,$(export-objs:.o=.ver)): $(TOPDIR)/include/linux/autoconf.h
238 # updates .ver files but not modversions.h
239 fastdep: $(addprefix $(MODINCL)/,$(export-objs:.o=.ver))
241 # updates .ver files and modversions.h like before (is this needed?)
242 dep: fastdep update-modverfile
246 # update modversions.h, but only if it would change
248 @(echo "#ifndef _LINUX_MODVERSIONS_H";\
249 echo "#define _LINUX_MODVERSIONS_H"; \
250 echo "#include <linux/modsetver.h>"; \
251 cd $(TOPDIR)/include/linux/modules; \
253 if [ -f $$f ]; then echo "#include <linux/modules/$${f}>"; fi; \
256 ) > $(TOPDIR)/include/linux/modversions.h.tmp
257 @if [ -r $(TOPDIR)/include/linux/modversions.h ] && cmp -s $(TOPDIR)/include/linux/modversions.h $(TOPDIR)/include/linux/modversions.h.tmp; then \
258 echo $(TOPDIR)/include/linux/modversions.h was not updated; \
259 rm -f $(TOPDIR)/include/linux/modversions.h.tmp; \
261 echo $(TOPDIR)/include/linux/modversions.h was updated; \
262 mv -f $(TOPDIR)/include/linux/modversions.h.tmp $(TOPDIR)/include/linux/modversions.h; \
265 $(active-objs): $(TOPDIR)/include/linux/modversions.h
269 $(TOPDIR)/include/linux/modversions.h:
270 @echo "#include <linux/modsetver.h>" > $@
272 endif # CONFIG_MODVERSIONS
274 ifneq "$(strip $(export-objs))" ""
275 $(export-objs): $(export-objs:.o=.c) $(TOPDIR)/include/linux/modversions.h
276 $(CC) $(CFLAGS) $(EXTRA_CFLAGS_nostdinc) -DKBUILD_BASENAME=$(subst $(comma),_,$(subst -,_,$(*F))) $(CFLAGS_$@) -DEXPORT_SYMTAB -c $(@:.o=.c)
278 echo 'ifeq ($(strip $(subst $(comma),:,$(CFLAGS) $(EXTRA_CFLAGS_nostdinc) $(CFLAGS_$@) -DEXPORT_SYMTAB)),$$(strip $$(subst $$(comma),:,$$(CFLAGS) $$(EXTRA_CFLAGS_nostdinc) $$(CFLAGS_$@) -DEXPORT_SYMTAB)))' ; \
279 echo 'FILES_FLAGS_UP_TO_DATE += $@' ; \
281 ) > $(dir $@)/.$(notdir $@).flags
284 endif # CONFIG_MODULES
288 # include dependency files if they exist
290 ifneq ($(wildcard .depend),)
294 ifneq ($(wildcard $(TOPDIR)/.hdepend),)
295 include $(TOPDIR)/.hdepend
299 # Find files whose flags have changed and force recompilation.
300 # For safety, this works in the converse direction:
301 # every file is forced, except those whose flags are positively up-to-date.
303 FILES_FLAGS_UP_TO_DATE :=
305 # For use in expunging commas from flags, which mung our checking.
308 FILES_FLAGS_EXIST := $(wildcard .*.flags)
309 ifneq ($(FILES_FLAGS_EXIST),)
310 include $(FILES_FLAGS_EXIST)
313 FILES_FLAGS_CHANGED := $(strip \
314 $(filter-out $(FILES_FLAGS_UP_TO_DATE), \
315 $(O_TARGET) $(L_TARGET) $(active-objs) \
318 # A kludge: .S files don't get flag dependencies (yet),
319 # because that will involve changing a lot of Makefiles. Also
320 # suppress object files explicitly listed in $(IGNORE_FLAGS_OBJS).
321 # This allows handling of assembly files that get translated into
322 # multiple object files (see arch/ia64/lib/idiv.S, for example).
323 FILES_FLAGS_CHANGED := $(strip \
324 $(filter-out $(patsubst %.S, %.o, $(wildcard *.S) $(IGNORE_FLAGS_OBJS)), \
325 $(FILES_FLAGS_CHANGED)))
327 ifneq ($(FILES_FLAGS_CHANGED),)
328 $(FILES_FLAGS_CHANGED): dummy