Import 2.4.0-test6pre6
[davej-history.git] / Rules.make
blobc2d795f241851bcdd4bcc06bc0bfd2e5933d4b9e
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_ASFLAGS
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
22 unexport O_OBJS
23 unexport L_OBJS
24 unexport M_OBJS
25 # intermediate objects that form part of a module
26 unexport MI_OBJS
27 unexport ALL_MOBJS
28 # objects that export symbol tables
29 unexport OX_OBJS
30 unexport LX_OBJS
31 unexport MX_OBJS
32 unexport MIX_OBJS
33 unexport SYMTAB_OBJS
36 # Get things started.
38 first_rule: sub_dirs
39 $(MAKE) all_targets
42 # Common rules
45 %.s: %.c
46 $(CC) $(CFLAGS) $(EXTRA_CFLAGS) $(CFLAGS_$@) -S $< -o $@
48 %.i: %.c
49 $(CPP) $(CFLAGS) $(EXTRA_CFLAGS) $(CFLAGS_$@) $< > $@
51 %.o: %.c
52 $(CC) $(CFLAGS) $(EXTRA_CFLAGS) $(CFLAGS_$@) -c -o $@ $<
53 @ ( \
54 echo 'ifeq ($(strip $(subst $(comma),:,$(CFLAGS) $(EXTRA_CFLAGS) $(CFLAGS_$@))),$$(strip $$(subst $$(comma),:,$$(CFLAGS) $$(EXTRA_CFLAGS) $$(CFLAGS_$@))))' ; \
55 echo 'FILES_FLAGS_UP_TO_DATE += $@' ; \
56 echo 'endif' \
57 ) > $(dir $@)/.$(notdir $@).flags
59 %.o: %.s
60 $(AS) $(ASFLAGS) $(EXTRA_CFLAGS) -o $@ $<
65 all_targets: $(O_TARGET) $(L_TARGET)
68 # Rule to compile a set of .o files into one .o file
70 ifdef O_TARGET
71 ALL_O = $(OX_OBJS) $(O_OBJS)
72 $(O_TARGET): $(ALL_O)
73 rm -f $@
74 ifneq "$(strip $(ALL_O))" ""
75 $(LD) $(EXTRA_LDFLAGS) -r -o $@ $(filter $(ALL_O), $^)
76 else
77 $(AR) rcs $@ $(filter $(ALL_O), $^)
78 endif
79 @ ( \
80 echo 'ifeq ($(strip $(subst $(comma),:,$(EXTRA_LDFLAGS) $(ALL_O))),$$(strip $$(subst $$(comma),:,$$(EXTRA_LDFLAGS) $$(ALL_O))))' ; \
81 echo 'FILES_FLAGS_UP_TO_DATE += $@' ; \
82 echo 'endif' \
83 ) > $(dir $@)/.$(notdir $@).flags
84 endif # O_TARGET
87 # Rule to compile a set of .o files into one .a file
89 ifdef L_TARGET
90 $(L_TARGET): $(LX_OBJS) $(L_OBJS)
91 rm -f $@
92 $(AR) $(EXTRA_ARFLAGS) rcs $@ $(LX_OBJS) $(L_OBJS)
93 @ ( \
94 echo 'ifeq ($(strip $(subst $(comma),:,$(EXTRA_ARFLAGS) $(LX_OBJS) $(L_OBJS))),$$(strip $$(subst $$(comma),:,$$(EXTRA_ARFLAGS) $$(LX_OBJS) $$(L_OBJS))))' ; \
95 echo 'FILES_FLAGS_UP_TO_DATE += $@' ; \
96 echo 'endif' \
97 ) > $(dir $@)/.$(notdir $@).flags
98 endif
101 # This make dependencies quickly
103 fastdep: dummy
104 $(TOPDIR)/scripts/mkdep $(wildcard *.[chS] local.h.master) > .depend
105 ifdef ALL_SUB_DIRS
106 $(MAKE) $(patsubst %,_sfdep_%,$(ALL_SUB_DIRS)) _FASTDEP_ALL_SUB_DIRS="$(ALL_SUB_DIRS)"
107 endif
109 ifdef _FASTDEP_ALL_SUB_DIRS
110 $(patsubst %,_sfdep_%,$(_FASTDEP_ALL_SUB_DIRS)):
111 $(MAKE) -C $(patsubst _sfdep_%,%,$@) fastdep
112 endif
116 # A rule to make subdirectories
118 sub_dirs: dummy $(patsubst %,_subdir_%,$(SUB_DIRS))
120 ifdef SUB_DIRS
121 $(patsubst %,_subdir_%,$(SUB_DIRS)) : dummy
122 $(MAKE) -C $(patsubst _subdir_%,%,$@)
123 endif
126 # A rule to make modules
128 ALL_MOBJS = $(MX_OBJS) $(M_OBJS)
129 ifneq "$(strip $(ALL_MOBJS))" ""
130 PDWN=$(shell $(CONFIG_SHELL) $(TOPDIR)/scripts/pathdown.sh)
131 endif
133 unexport MOD_DIRS
134 MOD_DIRS := $(MOD_SUB_DIRS) $(MOD_IN_SUB_DIRS)
135 ifneq "$(strip $(MOD_DIRS))" ""
136 .PHONY: $(patsubst %,_modsubdir_%,$(MOD_DIRS))
137 $(patsubst %,_modsubdir_%,$(MOD_DIRS)) : dummy
138 $(MAKE) -C $(patsubst _modsubdir_%,%,$@) modules
140 .PHONY: $(patsubst %,_modinst_%,$(MOD_DIRS))
141 $(patsubst %,_modinst_%,$(MOD_DIRS)) : dummy
142 $(MAKE) -C $(patsubst _modinst_%,%,$@) modules_install
143 endif
145 .PHONY: modules
146 modules: $(ALL_MOBJS) $(MIX_OBJS) $(MI_OBJS) dummy \
147 $(patsubst %,_modsubdir_%,$(MOD_DIRS))
149 .PHONY: _modinst__
150 _modinst__: dummy
151 ifneq "$(strip $(ALL_MOBJS))" ""
152 mkdir -p $(MODLIB)/kernel/$(PDWN)
153 cp $(ALL_MOBJS) $(MODLIB)/kernel/$(PDWN)
154 endif
156 .PHONY: modules_install
157 modules_install: _modinst__ \
158 $(patsubst %,_modinst_%,$(MOD_DIRS))
161 # A rule to do nothing
163 dummy:
166 # This is useful for testing
168 script:
169 $(SCRIPT)
172 # This sets version suffixes on exported symbols
173 # Uses SYMTAB_OBJS
174 # Separate the object into "normal" objects and "exporting" objects
175 # Exporting objects are: all objects that define symbol tables
177 ifdef CONFIG_MODULES
179 SYMTAB_OBJS = $(LX_OBJS) $(OX_OBJS) $(MX_OBJS) $(MIX_OBJS)
181 ifdef CONFIG_MODVERSIONS
182 ifneq "$(strip $(SYMTAB_OBJS))" ""
184 MODINCL = $(TOPDIR)/include/linux/modules
186 # The -w option (enable warnings) for genksyms will return here in 2.1
187 # So where has it gone?
189 # Added the SMP separator to stop module accidents between uniprocessor
190 # and SMP Intel boxes - AC - from bits by Michael Chastain
193 ifdef CONFIG_SMP
194 genksyms_smp_prefix := -p smp_
195 else
196 genksyms_smp_prefix :=
197 endif
199 $(MODINCL)/%.ver: %.c
200 @if [ ! -r $(MODINCL)/$*.stamp -o $(MODINCL)/$*.stamp -ot $< ]; then \
201 echo '$(CC) $(CFLAGS) -E -D__GENKSYMS__ $<'; \
202 echo '| $(GENKSYMS) $(genksyms_smp_prefix) -k $(VERSION).$(PATCHLEVEL).$(SUBLEVEL) > $@.tmp'; \
203 $(CC) $(CFLAGS) -E -D__GENKSYMS__ $< \
204 | $(GENKSYMS) $(genksyms_smp_prefix) -k $(VERSION).$(PATCHLEVEL).$(SUBLEVEL) > $@.tmp; \
205 if [ -r $@ ] && cmp -s $@ $@.tmp; then echo $@ is unchanged; rm -f $@.tmp; \
206 else echo mv $@.tmp $@; mv -f $@.tmp $@; fi; \
207 fi; touch $(MODINCL)/$*.stamp
209 $(addprefix $(MODINCL)/,$(SYMTAB_OBJS:.o=.ver)): $(TOPDIR)/include/linux/autoconf.h
211 $(TOPDIR)/include/linux/modversions.h: $(addprefix $(MODINCL)/,$(SYMTAB_OBJS:.o=.ver))
212 @echo updating $(TOPDIR)/include/linux/modversions.h
213 @(echo "#ifndef _LINUX_MODVERSIONS_H";\
214 echo "#define _LINUX_MODVERSIONS_H"; \
215 echo "#include <linux/modsetver.h>"; \
216 cd $(TOPDIR)/include/linux/modules; \
217 for f in *.ver; do \
218 if [ -f $$f ]; then echo "#include <linux/modules/$${f}>"; fi; \
219 done; \
220 echo "#endif"; \
221 ) > $@
223 dep fastdep: $(TOPDIR)/include/linux/modversions.h
225 endif # SYMTAB_OBJS
227 $(M_OBJS): $(TOPDIR)/include/linux/modversions.h
228 ifdef MAKING_MODULES
229 $(O_OBJS) $(L_OBJS): $(TOPDIR)/include/linux/modversions.h
230 endif
232 else
234 $(TOPDIR)/include/linux/modversions.h:
235 @echo "#include <linux/modsetver.h>" > $@
237 endif # CONFIG_MODVERSIONS
239 ifneq "$(strip $(SYMTAB_OBJS))" ""
240 $(SYMTAB_OBJS): $(SYMTAB_OBJS:.o=.c) $(TOPDIR)/include/linux/modversions.h
241 $(CC) $(CFLAGS) $(EXTRA_CFLAGS) $(CFLAGS_$@) -DEXPORT_SYMTAB -c $(@:.o=.c)
242 @ ( \
243 echo 'ifeq ($(strip $(subst $(comma),:,$(CFLAGS) $(EXTRA_CFLAGS) $(CFLAGS_$@) -DEXPORT_SYMTAB)),$$(strip $$(subst $$(comma),:,$$(CFLAGS) $$(EXTRA_CFLAGS) $$(CFLAGS_$@) -DEXPORT_SYMTAB)))' ; \
244 echo 'FILES_FLAGS_UP_TO_DATE += $@' ; \
245 echo 'endif' \
246 ) > $(dir $@)/.$(notdir $@).flags
247 endif
249 endif # CONFIG_MODULES
253 # include dependency files if they exist
255 ifneq ($(wildcard .depend),)
256 include .depend
257 endif
259 ifneq ($(wildcard $(TOPDIR)/.hdepend),)
260 include $(TOPDIR)/.hdepend
261 endif
264 # Find files whose flags have changed and force recompilation.
265 # For safety, this works in the converse direction:
266 # every file is forced, except those whose flags are positively up-to-date.
268 FILES_FLAGS_UP_TO_DATE :=
270 # For use in expunging commas from flags, which mung our checking.
271 comma = ,
273 FILES_FLAGS_EXIST := $(wildcard .*.flags)
274 ifneq ($(FILES_FLAGS_EXIST),)
275 include $(FILES_FLAGS_EXIST)
276 endif
278 FILES_FLAGS_CHANGED := $(strip \
279 $(filter-out $(FILES_FLAGS_UP_TO_DATE), \
280 $(O_TARGET) $(O_OBJS) $(OX_OBJS) \
281 $(L_TARGET) $(L_OBJS) $(LX_OBJS) \
282 $(M_OBJS) $(MX_OBJS) \
283 $(MI_OBJS) $(MIX_OBJS) \
286 # A kludge: .S files don't get flag dependencies (yet),
287 # because that will involve changing a lot of Makefiles. Also
288 # suppress object files explicitly listed in $(IGNORE_FLAGS_OBJS).
289 # This allows handling of assembly files that get translated into
290 # multiple object files (see arch/ia64/lib/idiv.S, for example).
291 FILES_FLAGS_CHANGED := $(strip \
292 $(filter-out $(patsubst %.S, %.o, $(wildcard *.S) $(IGNORE_FLAGS_OBJS)), \
293 $(FILES_FLAGS_CHANGED)))
295 ifneq ($(FILES_FLAGS_CHANGED),)
296 $(FILES_FLAGS_CHANGED): dummy
297 endif