- pre4:
[davej-history.git] / Rules.make
blobdd79396c666c1aaffb76600d9863b218e4816eda
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
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) $(AFLAGS) $(EXTRA_CFLAGS) -o $@ $<
62 # Old makefiles define their own rules for compiling .S files,
63 # but these standard rules are available for any Makefile that
64 # wants to use them. Our plan is to incrementally convert all
65 # the Makefiles to these standard rules. -- rmk, mec
66 ifdef USE_STANDARD_AS_RULE
68 %.s: %.S
69 $(CPP) $(AFLAGS) $(EXTRA_AFLAGS) $(AFLAGS_$@) $< > $@
71 %.o: %.S
72 $(CC) $(AFLAGS) $(EXTRA_AFLAGS) $(AFLAGS_$@) -c -o $@ $<
74 endif
79 all_targets: $(O_TARGET) $(L_TARGET)
82 # Rule to compile a set of .o files into one .o file
84 ifdef O_TARGET
85 ALL_O = $(OX_OBJS) $(O_OBJS)
86 $(O_TARGET): $(ALL_O)
87 rm -f $@
88 ifneq "$(strip $(ALL_O))" ""
89 $(LD) $(EXTRA_LDFLAGS) -r -o $@ $(filter $(ALL_O), $^)
90 else
91 $(AR) rcs $@ $(filter $(ALL_O), $^)
92 endif
93 @ ( \
94 echo 'ifeq ($(strip $(subst $(comma),:,$(EXTRA_LDFLAGS) $(ALL_O))),$$(strip $$(subst $$(comma),:,$$(EXTRA_LDFLAGS) $$(ALL_O))))' ; \
95 echo 'FILES_FLAGS_UP_TO_DATE += $@' ; \
96 echo 'endif' \
97 ) > $(dir $@)/.$(notdir $@).flags
98 endif # O_TARGET
101 # Rule to compile a set of .o files into one .a file
103 ifdef L_TARGET
104 $(L_TARGET): $(LX_OBJS) $(L_OBJS)
105 rm -f $@
106 $(AR) $(EXTRA_ARFLAGS) rcs $@ $(LX_OBJS) $(L_OBJS)
107 @ ( \
108 echo 'ifeq ($(strip $(subst $(comma),:,$(EXTRA_ARFLAGS) $(LX_OBJS) $(L_OBJS))),$$(strip $$(subst $$(comma),:,$$(EXTRA_ARFLAGS) $$(LX_OBJS) $$(L_OBJS))))' ; \
109 echo 'FILES_FLAGS_UP_TO_DATE += $@' ; \
110 echo 'endif' \
111 ) > $(dir $@)/.$(notdir $@).flags
112 endif
115 # This make dependencies quickly
117 fastdep: dummy
118 $(TOPDIR)/scripts/mkdep $(wildcard *.[chS] local.h.master) > .depend
119 ifdef ALL_SUB_DIRS
120 $(MAKE) $(patsubst %,_sfdep_%,$(ALL_SUB_DIRS)) _FASTDEP_ALL_SUB_DIRS="$(ALL_SUB_DIRS)"
121 endif
123 ifdef _FASTDEP_ALL_SUB_DIRS
124 $(patsubst %,_sfdep_%,$(_FASTDEP_ALL_SUB_DIRS)):
125 $(MAKE) -C $(patsubst _sfdep_%,%,$@) fastdep
126 endif
130 # A rule to make subdirectories
132 sub_dirs: dummy $(patsubst %,_subdir_%,$(SUB_DIRS))
134 ifdef SUB_DIRS
135 $(patsubst %,_subdir_%,$(SUB_DIRS)) : dummy
136 $(MAKE) -C $(patsubst _subdir_%,%,$@)
137 endif
140 # A rule to make modules
142 ALL_MOBJS = $(MX_OBJS) $(M_OBJS)
143 ifneq "$(strip $(ALL_MOBJS))" ""
144 PDWN=$(shell $(CONFIG_SHELL) $(TOPDIR)/scripts/pathdown.sh)
145 endif
147 unexport MOD_DIRS
148 MOD_DIRS := $(MOD_SUB_DIRS) $(MOD_IN_SUB_DIRS)
149 ifneq "$(strip $(MOD_DIRS))" ""
150 .PHONY: $(patsubst %,_modsubdir_%,$(MOD_DIRS))
151 $(patsubst %,_modsubdir_%,$(MOD_DIRS)) : dummy
152 $(MAKE) -C $(patsubst _modsubdir_%,%,$@) modules
154 .PHONY: $(patsubst %,_modinst_%,$(MOD_DIRS))
155 $(patsubst %,_modinst_%,$(MOD_DIRS)) : dummy
156 $(MAKE) -C $(patsubst _modinst_%,%,$@) modules_install
157 endif
159 .PHONY: modules
160 modules: $(ALL_MOBJS) $(MIX_OBJS) $(MI_OBJS) dummy \
161 $(patsubst %,_modsubdir_%,$(MOD_DIRS))
163 .PHONY: _modinst__
164 _modinst__: dummy
165 ifneq "$(strip $(ALL_MOBJS))" ""
166 mkdir -p $(MODLIB)/kernel/$(PDWN)
167 cp $(ALL_MOBJS) $(MODLIB)/kernel/$(PDWN)
168 endif
170 .PHONY: modules_install
171 modules_install: _modinst__ \
172 $(patsubst %,_modinst_%,$(MOD_DIRS))
175 # A rule to do nothing
177 dummy:
180 # This is useful for testing
182 script:
183 $(SCRIPT)
186 # This sets version suffixes on exported symbols
187 # Uses SYMTAB_OBJS
188 # Separate the object into "normal" objects and "exporting" objects
189 # Exporting objects are: all objects that define symbol tables
191 ifdef CONFIG_MODULES
193 SYMTAB_OBJS = $(LX_OBJS) $(OX_OBJS) $(MX_OBJS) $(MIX_OBJS)
195 ifdef CONFIG_MODVERSIONS
196 ifneq "$(strip $(SYMTAB_OBJS))" ""
198 MODINCL = $(TOPDIR)/include/linux/modules
200 # The -w option (enable warnings) for genksyms will return here in 2.1
201 # So where has it gone?
203 # Added the SMP separator to stop module accidents between uniprocessor
204 # and SMP Intel boxes - AC - from bits by Michael Chastain
207 ifdef CONFIG_SMP
208 genksyms_smp_prefix := -p smp_
209 else
210 genksyms_smp_prefix :=
211 endif
213 $(MODINCL)/%.ver: %.c
214 @if [ ! -r $(MODINCL)/$*.stamp -o $(MODINCL)/$*.stamp -ot $< ]; then \
215 echo '$(CC) $(CFLAGS) -E -D__GENKSYMS__ $<'; \
216 echo '| $(GENKSYMS) $(genksyms_smp_prefix) -k $(VERSION).$(PATCHLEVEL).$(SUBLEVEL) > $@.tmp'; \
217 $(CC) $(CFLAGS) -E -D__GENKSYMS__ $< \
218 | $(GENKSYMS) $(genksyms_smp_prefix) -k $(VERSION).$(PATCHLEVEL).$(SUBLEVEL) > $@.tmp; \
219 if [ -r $@ ] && cmp -s $@ $@.tmp; then echo $@ is unchanged; rm -f $@.tmp; \
220 else echo mv $@.tmp $@; mv -f $@.tmp $@; fi; \
221 fi; touch $(MODINCL)/$*.stamp
223 $(addprefix $(MODINCL)/,$(SYMTAB_OBJS:.o=.ver)): $(TOPDIR)/include/linux/autoconf.h
225 # updates .ver files but not modversions.h
226 fastdep: $(addprefix $(MODINCL)/,$(SYMTAB_OBJS:.o=.ver))
228 # updates .ver files and modversions.h like before (is this needed?)
229 dep: fastdep update-modverfile
231 endif # SYMTAB_OBJS
233 # update modversions.h, but only if it would change
234 update-modverfile:
235 @(echo "#ifndef _LINUX_MODVERSIONS_H";\
236 echo "#define _LINUX_MODVERSIONS_H"; \
237 echo "#include <linux/modsetver.h>"; \
238 cd $(TOPDIR)/include/linux/modules; \
239 for f in *.ver; do \
240 if [ -f $$f ]; then echo "#include <linux/modules/$${f}>"; fi; \
241 done; \
242 echo "#endif"; \
243 ) > $(TOPDIR)/include/linux/modversions.h.tmp
244 @if [ -r $(TOPDIR)/include/linux/modversions.h ] && cmp -s $(TOPDIR)/include/linux/modversions.h $(TOPDIR)/include/linux/modversions.h.tmp; then \
245 echo $(TOPDIR)/include/linux/modversions.h was not updated; \
246 rm -f $(TOPDIR)/include/linux/modversions.h.tmp; \
247 else \
248 echo $(TOPDIR)/include/linux/modversions.h was updated; \
249 mv -f $(TOPDIR)/include/linux/modversions.h.tmp $(TOPDIR)/include/linux/modversions.h; \
252 $(M_OBJS): $(TOPDIR)/include/linux/modversions.h
253 ifdef MAKING_MODULES
254 $(O_OBJS) $(L_OBJS): $(TOPDIR)/include/linux/modversions.h
255 endif
257 else
259 $(TOPDIR)/include/linux/modversions.h:
260 @echo "#include <linux/modsetver.h>" > $@
262 endif # CONFIG_MODVERSIONS
264 ifneq "$(strip $(SYMTAB_OBJS))" ""
265 $(SYMTAB_OBJS): $(SYMTAB_OBJS:.o=.c) $(TOPDIR)/include/linux/modversions.h
266 $(CC) $(CFLAGS) $(EXTRA_CFLAGS) $(CFLAGS_$@) -DEXPORT_SYMTAB -c $(@:.o=.c)
267 @ ( \
268 echo 'ifeq ($(strip $(subst $(comma),:,$(CFLAGS) $(EXTRA_CFLAGS) $(CFLAGS_$@) -DEXPORT_SYMTAB)),$$(strip $$(subst $$(comma),:,$$(CFLAGS) $$(EXTRA_CFLAGS) $$(CFLAGS_$@) -DEXPORT_SYMTAB)))' ; \
269 echo 'FILES_FLAGS_UP_TO_DATE += $@' ; \
270 echo 'endif' \
271 ) > $(dir $@)/.$(notdir $@).flags
272 endif
274 endif # CONFIG_MODULES
278 # include dependency files if they exist
280 ifneq ($(wildcard .depend),)
281 include .depend
282 endif
284 ifneq ($(wildcard $(TOPDIR)/.hdepend),)
285 include $(TOPDIR)/.hdepend
286 endif
289 # Find files whose flags have changed and force recompilation.
290 # For safety, this works in the converse direction:
291 # every file is forced, except those whose flags are positively up-to-date.
293 FILES_FLAGS_UP_TO_DATE :=
295 # For use in expunging commas from flags, which mung our checking.
296 comma = ,
298 FILES_FLAGS_EXIST := $(wildcard .*.flags)
299 ifneq ($(FILES_FLAGS_EXIST),)
300 include $(FILES_FLAGS_EXIST)
301 endif
303 FILES_FLAGS_CHANGED := $(strip \
304 $(filter-out $(FILES_FLAGS_UP_TO_DATE), \
305 $(O_TARGET) $(O_OBJS) $(OX_OBJS) \
306 $(L_TARGET) $(L_OBJS) $(LX_OBJS) \
307 $(M_OBJS) $(MX_OBJS) \
308 $(MI_OBJS) $(MIX_OBJS) \
311 # A kludge: .S files don't get flag dependencies (yet),
312 # because that will involve changing a lot of Makefiles. Also
313 # suppress object files explicitly listed in $(IGNORE_FLAGS_OBJS).
314 # This allows handling of assembly files that get translated into
315 # multiple object files (see arch/ia64/lib/idiv.S, for example).
316 FILES_FLAGS_CHANGED := $(strip \
317 $(filter-out $(patsubst %.S, %.o, $(wildcard *.S) $(IGNORE_FLAGS_OBJS)), \
318 $(FILES_FLAGS_CHANGED)))
320 ifneq ($(FILES_FLAGS_CHANGED),)
321 $(FILES_FLAGS_CHANGED): dummy
322 endif