[PATCH] m68k: bitops update [3/20]
[linux-2.6/history.git] / Rules.make
blob8d93f2ba4e8d9c0237bf6991c05d237e51cf7119
2 # This file contains rules which are shared between multiple Makefiles.
6 # False targets.
8 .PHONY: dummy
11 # Special variables which should not be exported
13 unexport EXTRA_AFLAGS
14 unexport EXTRA_CFLAGS
15 unexport EXTRA_LDFLAGS
16 unexport EXTRA_ARFLAGS
17 unexport SUBDIRS
18 unexport SUB_DIRS
19 unexport ALL_SUB_DIRS
20 unexport MOD_SUB_DIRS
21 unexport O_TARGET
23 unexport obj-y
24 unexport obj-m
25 unexport obj-n
26 unexport obj-
27 unexport export-objs
28 unexport subdir-y
29 unexport subdir-m
30 unexport subdir-n
31 unexport subdir-
33 comma := ,
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))
42 # Get things started.
44 first_rule: sub_dirs
45 $(MAKE) all_targets
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-))
54 # Common rules
57 %.s: %.c
58 $(CC) $(CFLAGS) $(EXTRA_CFLAGS) -DKBUILD_BASENAME=$(subst $(comma),_,$(subst -,_,$(*F))) $(CFLAGS_$@) -S $< -o $@
60 %.i: %.c
61 $(CPP) $(CFLAGS) $(EXTRA_CFLAGS) -DKBUILD_BASENAME=$(subst $(comma),_,$(subst -,_,$(*F))) $(CFLAGS_$@) $< > $@
63 %.o: %.c
64 $(CC) $(CFLAGS) $(EXTRA_CFLAGS) -DKBUILD_BASENAME=$(subst $(comma),_,$(subst -,_,$(*F))) $(CFLAGS_$@) -c -o $@ $<
65 @ ( \
66 echo 'ifeq ($(strip $(subst $(comma),:,$(CFLAGS) $(EXTRA_CFLAGS) $(CFLAGS_$@))),$$(strip $$(subst $$(comma),:,$$(CFLAGS) $$(EXTRA_CFLAGS) $$(CFLAGS_$@))))' ; \
67 echo 'FILES_FLAGS_UP_TO_DATE += $@' ; \
68 echo 'endif' \
69 ) > $(dir $@)/.$(notdir $@).flags
71 %.o: %.s
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
80 %.s: %.S
81 $(CPP) $(AFLAGS) $(EXTRA_AFLAGS) $(AFLAGS_$@) $< > $@
83 %.o: %.S
84 $(CC) $(AFLAGS) $(EXTRA_AFLAGS) $(AFLAGS_$@) -c -o $@ $<
86 endif
88 %.lst: %.c
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
99 ifdef O_TARGET
100 $(O_TARGET): $(obj-y)
101 rm -f $@
102 ifneq "$(strip $(obj-y))" ""
103 $(LD) $(EXTRA_LDFLAGS) -r -o $@ $(filter $(obj-y), $^)
104 else
105 $(AR) rcs $@
106 endif
107 @ ( \
108 echo 'ifeq ($(strip $(subst $(comma),:,$(EXTRA_LDFLAGS) $(obj-y))),$$(strip $$(subst $$(comma),:,$$(EXTRA_LDFLAGS) $$(obj-y))))' ; \
109 echo 'FILES_FLAGS_UP_TO_DATE += $@' ; \
110 echo 'endif' \
111 ) > $(dir $@)/.$(notdir $@).flags
112 endif # O_TARGET
115 # Rule to compile a set of .o files into one .a file
117 ifdef L_TARGET
118 $(L_TARGET): $(obj-y)
119 rm -f $@
120 $(AR) $(EXTRA_ARFLAGS) rcs $@ $(obj-y)
121 @ ( \
122 echo 'ifeq ($(strip $(subst $(comma),:,$(EXTRA_ARFLAGS) $(obj-y))),$$(strip $$(subst $$(comma),:,$$(EXTRA_ARFLAGS) $$(obj-y))))' ; \
123 echo 'FILES_FLAGS_UP_TO_DATE += $@' ; \
124 echo 'endif' \
125 ) > $(dir $@)/.$(notdir $@).flags
126 endif
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)
144 rm -f $@
145 $(LD) $(EXTRA_LDFLAGS) -r -o $@ $(filter $($(basename $@)-objs), $^)
146 @ ( \
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 += $@' ; \
149 echo 'endif' \
150 ) > $(dir $@)/.$(notdir $@).flags
152 $(ld-multi-used-m) : %.o: $(ld-multi-objs-m)
153 rm -f $@
154 $(LD) $(EXTRA_LDFLAGS) -r -o $@ $(filter $($(basename $@)-objs), $^)
155 @ ( \
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 += $@' ; \
158 echo 'endif' \
159 ) > $(dir $@)/.$(notdir $@).flags
162 # This make dependencies quickly
164 fastdep: dummy
165 $(TOPDIR)/scripts/mkdep $(CFLAGS) $(EXTRA_CFLAGS) -- $(wildcard *.[chS]) > .depend
166 ifdef ALL_SUB_DIRS
167 $(MAKE) $(patsubst %,_sfdep_%,$(ALL_SUB_DIRS)) _FASTDEP_ALL_SUB_DIRS="$(ALL_SUB_DIRS)"
168 endif
170 ifdef _FASTDEP_ALL_SUB_DIRS
171 $(patsubst %,_sfdep_%,$(_FASTDEP_ALL_SUB_DIRS)):
172 $(MAKE) -C $(patsubst _sfdep_%,%,$@) fastdep
173 endif
177 # A rule to make subdirectories
179 subdir-list = $(sort $(patsubst %,_subdir_%,$(SUB_DIRS)))
180 sub_dirs: dummy $(subdir-list)
182 ifdef SUB_DIRS
183 $(subdir-list) : dummy
184 $(MAKE) -C $(patsubst _subdir_%,%,$@)
185 endif
188 # A rule to make modules
190 ifneq "$(strip $(obj-m))" ""
191 MOD_DESTDIR := $(shell $(CONFIG_SHELL) $(TOPDIR)/scripts/pathdown.sh)
192 endif
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
202 endif
204 .PHONY: modules
205 modules: $(obj-m) dummy \
206 $(patsubst %,_modsubdir_%,$(MOD_SUB_DIRS))
208 .PHONY: _modinst__
209 _modinst__: dummy
210 ifneq "$(strip $(obj-m))" ""
211 mkdir -p $(MODLIB)/kernel/$(MOD_DESTDIR)
212 cp $(obj-m) $(MODLIB)/kernel/$(MOD_DESTDIR)
213 endif
215 .PHONY: modules_install
216 modules_install: _modinst__ \
217 $(patsubst %,_modinst_%,$(MOD_SUB_DIRS))
220 # A rule to do nothing
222 dummy:
225 # This is useful for testing
227 script:
228 $(SCRIPT)
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
235 ifdef CONFIG_MODULES
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
254 ifdef CONFIG_SMP
255 genksyms_smp_prefix := -p smp_
256 else
257 genksyms_smp_prefix :=
258 endif
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
278 endif # export-objs
280 # update modversions.h, but only if it would change
281 update-modverfile:
282 @(echo "#ifndef _LINUX_MODVERSIONS_H";\
283 echo "#define _LINUX_MODVERSIONS_H"; \
284 echo "#include <linux/modsetver.h>"; \
285 cd $(TOPDIR)/include/linux/modules; \
286 for f in *.ver; do \
287 if [ -f $$f ]; then echo "#include <linux/modules/$${f}>"; fi; \
288 done; \
289 echo "#endif"; \
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; \
294 else \
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
301 else
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)
312 @ ( \
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 += $@' ; \
315 echo 'endif' \
316 ) > $(dir $@)/.$(notdir $@).flags
317 endif
319 endif # CONFIG_MODULES
323 # include dependency files if they exist
325 ifneq ($(wildcard .depend),)
326 include .depend
327 endif
329 ifneq ($(wildcard $(TOPDIR)/.hdepend),)
330 include $(TOPDIR)/.hdepend
331 endif
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.
341 comma = ,
343 FILES_FLAGS_EXIST := $(wildcard .*.flags)
344 ifneq ($(FILES_FLAGS_EXIST),)
345 include $(FILES_FLAGS_EXIST)
346 endif
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
364 endif