2 # This file contains rules which are shared between multiple Makefiles.
11 # Special variables which should not be exported
14 #unexport EXTRA_CFLAGS
15 unexport EXTRA_LDFLAGS
16 unexport EXTRA_ARFLAGS
34 MAPPING_MODE= -DUSE_IO_OPS
35 EXTRA_CFLAGS := $(MAPPING_MODE)
36 EXTRA_CFLAGS := $(EXTRA_CFLAGS) -D_COMPAT_WITH_OLD_KERNEL
37 CFLAGS = -D__KERNEL__ -O -Wall -Wstrict-prototypes
40 EXTRA_CFLAGS_nostdinc := $(EXTRA_CFLAGS) $(kbuild_2_4_nostdinc)
48 both-m := $(filter $(mod-subdirs), $(subdir-y))
49 SUB_DIRS := $(subdir-y)
50 MOD_SUB_DIRS := $(sort $(subdir-m) $(both-m))
51 ALL_SUB_DIRS := $(sort $(subdir-y) $(subdir-m) $(subdir-n) $(subdir-))
59 $(CC) $(CFLAGS) $(EXTRA_CFLAGS_nostdinc) -DKBUILD_BASENAME=$(subst $(comma),_,$(subst -,_,$(*F))) $(CFLAGS_$@) -S $< -o $@
62 $(CPP) $(CFLAGS) $(EXTRA_CFLAGS_nostdinc) -DKBUILD_BASENAME=$(subst $(comma),_,$(subst -,_,$(*F))) $(CFLAGS_$@) $< > $@
65 $(CC) $(CFLAGS) $(EXTRA_CFLAGS_nostdinc) -DKBUILD_BASENAME=$(subst $(comma),_,$(subst -,_,$(*F))) $(CFLAGS_$@) -c -o $@ $<
67 echo 'ifeq ($(strip $(subst $(comma),:,$(CFLAGS) $(EXTRA_CFLAGS_nostdinc) $(CFLAGS_$@))),$$(strip $$(subst $$(comma),:,$$(CFLAGS) $$(EXTRA_CFLAGS_nostdinc) $$(CFLAGS_$@))))' ; \
68 echo 'FILES_FLAGS_UP_TO_DATE += $@' ; \
70 ) > $(dir $@)/.$(notdir $@).flags
73 $(AS) $(AFLAGS) $(EXTRA_CFLAGS) -o $@ $<
75 # Old makefiles define their own rules for compiling .S files,
76 # but these standard rules are available for any Makefile that
77 # wants to use them. Our plan is to incrementally convert all
78 # the Makefiles to these standard rules. -- rmk, mec
79 ifdef USE_STANDARD_AS_RULE
82 $(CPP) $(AFLAGS) $(EXTRA_AFLAGS) $(AFLAGS_$@) $< > $@
85 $(CC) $(AFLAGS) $(EXTRA_AFLAGS) $(AFLAGS_$@) -c -o $@ $<
90 $(CC) $(CFLAGS) $(EXTRA_CFLAGS_nostdinc) $(CFLAGS_$@) -g -c -o $*.o $<
91 $(TOPDIR)/scripts/makelst $* $(TOPDIR) $(OBJDUMP)
95 all_targets: $(O_TARGET) $(L_TARGET)
98 # Rule to compile a set of .o files into one .o file
101 $(O_TARGET): $(obj-y)
103 ifneq "$(strip $(obj-y))" ""
104 $(LD) $(EXTRA_LDFLAGS) -r -o $@ $(filter $(obj-y), $^)
109 echo 'ifeq ($(strip $(subst $(comma),:,$(EXTRA_LDFLAGS) $(obj-y))),$$(strip $$(subst $$(comma),:,$$(EXTRA_LDFLAGS) $$(obj-y))))' ; \
110 echo 'FILES_FLAGS_UP_TO_DATE += $@' ; \
112 ) > $(dir $@)/.$(notdir $@).flags
116 # Rule to compile a set of .o files into one .a file
119 $(L_TARGET): $(obj-y)
121 $(AR) $(EXTRA_ARFLAGS) rcs $@ $(obj-y)
123 echo 'ifeq ($(strip $(subst $(comma),:,$(EXTRA_ARFLAGS) $(obj-y))),$$(strip $$(subst $$(comma),:,$$(EXTRA_ARFLAGS) $$(obj-y))))' ; \
124 echo 'FILES_FLAGS_UP_TO_DATE += $@' ; \
126 ) > $(dir $@)/.$(notdir $@).flags
131 # This make dependencies quickly
134 $(TOPDIR)/scripts/mkdep $(CFLAGS) $(EXTRA_CFLAGS_nostdinc) -- $(wildcard *.[chS]) > .depend
136 $(MAKE) $(patsubst %,_sfdep_%,$(ALL_SUB_DIRS)) _FASTDEP_ALL_SUB_DIRS="$(ALL_SUB_DIRS)"
139 ifdef _FASTDEP_ALL_SUB_DIRS
140 $(patsubst %,_sfdep_%,$(_FASTDEP_ALL_SUB_DIRS)):
141 $(MAKE) -C $(patsubst _sfdep_%,%,$@) fastdep
146 # A rule to make subdirectories
148 subdir-list = $(sort $(patsubst %,_subdir_%,$(SUB_DIRS)))
149 sub_dirs: dummy $(subdir-list)
152 $(subdir-list) : dummy
153 $(MAKE) -C $(patsubst _subdir_%,%,$@)
157 # A rule to make modules
159 ALL_MOBJS = $(filter-out $(obj-y), $(obj-m))
160 ifneq "$(strip $(ALL_MOBJS))" ""
161 MOD_DESTDIR := $(shell $(CONFIG_SHELL) $(TOPDIR)/scripts/pathdown.sh)
165 MOD_DIRS := $(MOD_SUB_DIRS) $(MOD_IN_SUB_DIRS)
166 ifneq "$(strip $(MOD_DIRS))" ""
167 .PHONY: $(patsubst %,_modsubdir_%,$(MOD_DIRS))
168 $(patsubst %,_modsubdir_%,$(MOD_DIRS)) : dummy
169 $(MAKE) -C $(patsubst _modsubdir_%,%,$@) modules
171 .PHONY: $(patsubst %,_modinst_%,$(MOD_DIRS))
172 $(patsubst %,_modinst_%,$(MOD_DIRS)) : dummy
173 $(MAKE) -C $(patsubst _modinst_%,%,$@) modules_install
177 modules: $(ALL_MOBJS) dummy \
178 $(patsubst %,_modsubdir_%,$(MOD_DIRS))
182 ifneq "$(strip $(ALL_MOBJS))" ""
183 mkdir -p $(MODLIB)/kernel/$(MOD_DESTDIR)
184 cp $(sort $(ALL_MOBJS)) $(MODLIB)/kernel/$(MOD_DESTDIR)
187 .PHONY: modules_install
188 modules_install: _modinst__ \
189 $(patsubst %,_modinst_%,$(MOD_DIRS))
192 # A rule to do nothing
197 # This is useful for testing
203 # This sets version suffixes on exported symbols
204 # Separate the object into "normal" objects and "exporting" objects
205 # Exporting objects are: all objects that define symbol tables
209 multi-used := $(filter $(list-multi), $(obj-y) $(obj-m))
210 multi-objs := $(foreach m, $(multi-used), $($(basename $(m))-objs))
211 active-objs := $(sort $(multi-objs) $(obj-y) $(obj-m))
213 ifdef CONFIG_MODVERSIONS
214 ifneq "$(strip $(export-objs))" ""
216 MODINCL = $(TOPDIR)/include/linux/modules
219 # The -w option (enable warnings) for genksyms will return here in 2.1
220 # So where has it gone?
222 # Added the SMP separator to stop module accidents between uniprocessor
223 # and SMP Intel boxes - AC - from bits by Michael Chastain
227 genksyms_smp_prefix := -p smp_
229 genksyms_smp_prefix :=
232 $(MODINCL)/%.ver: %.c
233 @if [ ! -r $(MODINCL)/$*.stamp -o $(MODINCL)/$*.stamp -ot $< ]; then \
234 echo '$(CC) $(CFLAGS) $(EXTRA_CFLAGS_nostdinc) -E -D__GENKSYMS__ $<'; \
235 echo '| $(GENKSYMS) $(genksyms_smp_prefix) -k $(VERSION).$(PATCHLEVEL).$(SUBLEVEL) > $@.tmp'; \
236 $(CC) $(CFLAGS) $(EXTRA_CFLAGS_nostdinc) -E -D__GENKSYMS__ $< \
237 | $(GENKSYMS) $(genksyms_smp_prefix) -k $(VERSION).$(PATCHLEVEL).$(SUBLEVEL) > $@.tmp; \
238 if [ -r $@ ] && cmp -s $@ $@.tmp; then echo $@ is unchanged; rm -f $@.tmp; \
239 else echo mv $@.tmp $@; mv -f $@.tmp $@; fi; \
240 fi; touch $(MODINCL)/$*.stamp
242 $(addprefix $(MODINCL)/,$(export-objs:.o=.ver)): $(TOPDIR)/include/linux/autoconf.h
244 # updates .ver files but not modversions.h
245 fastdep: $(addprefix $(MODINCL)/,$(export-objs:.o=.ver))
247 # updates .ver files and modversions.h like before (is this needed?)
248 dep: fastdep update-modverfile
252 # update modversions.h, but only if it would change
254 @(echo "#ifndef _LINUX_MODVERSIONS_H";\
255 echo "#define _LINUX_MODVERSIONS_H"; \
256 echo "#include <linux/modsetver.h>"; \
257 cd $(TOPDIR)/include/linux/modules; \
259 if [ -f $$f ]; then echo "#include <linux/modules/$${f}>"; fi; \
262 ) > $(TOPDIR)/include/linux/modversions.h.tmp
263 @if [ -r $(TOPDIR)/include/linux/modversions.h ] && cmp -s $(TOPDIR)/include/linux/modversions.h $(TOPDIR)/include/linux/modversions.h.tmp; then \
264 echo $(TOPDIR)/include/linux/modversions.h was not updated; \
265 rm -f $(TOPDIR)/include/linux/modversions.h.tmp; \
267 echo $(TOPDIR)/include/linux/modversions.h was updated; \
268 mv -f $(TOPDIR)/include/linux/modversions.h.tmp $(TOPDIR)/include/linux/modversions.h; \
271 $(active-objs): $(TOPDIR)/include/linux/modversions.h
275 $(TOPDIR)/include/linux/modversions.h:
276 @echo "#include <linux/modsetver.h>" > $@
278 endif # CONFIG_MODVERSIONS
280 ifneq "$(strip $(export-objs))" ""
281 $(export-objs): $(export-objs:.o=.c) $(TOPDIR)/include/linux/modversions.h
282 $(CC) $(CFLAGS) $(EXTRA_CFLAGS_nostdinc) -DKBUILD_BASENAME=$(subst $(comma),_,$(subst -,_,$(*F))) $(CFLAGS_$@) -DEXPORT_SYMTAB -c $(@:.o=.c)
284 echo 'ifeq ($(strip $(subst $(comma),:,$(CFLAGS) $(EXTRA_CFLAGS_nostdinc) $(CFLAGS_$@) -DEXPORT_SYMTAB)),$$(strip $$(subst $$(comma),:,$$(CFLAGS) $$(EXTRA_CFLAGS_nostdinc) $$(CFLAGS_$@) -DEXPORT_SYMTAB)))' ; \
285 echo 'FILES_FLAGS_UP_TO_DATE += $@' ; \
287 ) > $(dir $@)/.$(notdir $@).flags
290 endif # CONFIG_MODULES
294 # include dependency files if they exist
296 ifneq ($(wildcard .depend),)
300 ifneq ($(wildcard $(TOPDIR)/.hdepend),)
301 include $(TOPDIR)/.hdepend
305 # Find files whose flags have changed and force recompilation.
306 # For safety, this works in the converse direction:
307 # every file is forced, except those whose flags are positively up-to-date.
309 FILES_FLAGS_UP_TO_DATE :=
311 # For use in expunging commas from flags, which mung our checking.
314 FILES_FLAGS_EXIST := $(wildcard .*.flags)
315 ifneq ($(FILES_FLAGS_EXIST),)
316 include $(FILES_FLAGS_EXIST)
320 FILES_FLAGS_CHANGED := $(strip \
321 $(filter-out $(FILES_FLAGS_UP_TO_DATE), \
322 $(O_TARGET) $(L_TARGET) $(active-objs) \
325 # A kludge: .S files don't get flag dependencies (yet),
326 # because that will involve changing a lot of Makefiles. Also
327 # suppress object files explicitly listed in $(IGNORE_FLAGS_OBJS).
328 # This allows handling of assembly files that get translated into
329 # multiple object files (see arch/ia64/lib/idiv.S, for example).
330 FILES_FLAGS_CHANGED := $(strip \
331 $(filter-out $(patsubst %.S, %.o, $(wildcard *.S) $(IGNORE_FLAGS_OBJS)), \
332 $(FILES_FLAGS_CHANGED)))
334 ifneq ($(FILES_FLAGS_CHANGED),)
335 $(FILES_FLAGS_CHANGED): dummy