Ok, there's a test13-pre6 out there now, which does a partial sync with
[davej-history.git] / Rules.make
blob3093254217ea7f0b08f9d802914c8d706fb54800
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 ALL_MOBJS
24 unexport obj-y
25 unexport obj-m
26 unexport obj-n
27 unexport obj-
28 unexport export-objs
29 unexport subdir-y
30 unexport subdir-m
31 unexport subdir-n
32 unexport subdir-
35 # Get things started.
37 first_rule: sub_dirs
38 $(MAKE) all_targets
40 both-m := $(filter $(mod-subdirs), $(subdir-y))
41 SUB_DIRS := $(subdir-y)
42 MOD_SUB_DIRS := $(sort $(subdir-m) $(both-m))
43 ALL_SUB_DIRS := $(sort $(subdir-y) $(subdir-m) $(subdir-n) $(subdir-))
47 # Common rules
50 %.s: %.c
51 $(CC) $(CFLAGS) $(EXTRA_CFLAGS) $(CFLAGS_$@) -S $< -o $@
53 %.i: %.c
54 $(CPP) $(CFLAGS) $(EXTRA_CFLAGS) $(CFLAGS_$@) $< > $@
56 %.o: %.c
57 $(CC) $(CFLAGS) $(EXTRA_CFLAGS) $(CFLAGS_$@) -c -o $@ $<
58 @ ( \
59 echo 'ifeq ($(strip $(subst $(comma),:,$(CFLAGS) $(EXTRA_CFLAGS) $(CFLAGS_$@))),$$(strip $$(subst $$(comma),:,$$(CFLAGS) $$(EXTRA_CFLAGS) $$(CFLAGS_$@))))' ; \
60 echo 'FILES_FLAGS_UP_TO_DATE += $@' ; \
61 echo 'endif' \
62 ) > $(dir $@)/.$(notdir $@).flags
64 %.o: %.s
65 $(AS) $(AFLAGS) $(EXTRA_CFLAGS) -o $@ $<
67 # Old makefiles define their own rules for compiling .S files,
68 # but these standard rules are available for any Makefile that
69 # wants to use them. Our plan is to incrementally convert all
70 # the Makefiles to these standard rules. -- rmk, mec
71 ifdef USE_STANDARD_AS_RULE
73 %.s: %.S
74 $(CPP) $(AFLAGS) $(EXTRA_AFLAGS) $(AFLAGS_$@) $< > $@
76 %.o: %.S
77 $(CC) $(AFLAGS) $(EXTRA_AFLAGS) $(AFLAGS_$@) -c -o $@ $<
79 endif
81 %.lst: %.c
82 $(CC) $(CFLAGS) $(EXTRA_CFLAGS) $(CFLAGS_$@) -g -c -o $*.o $<
83 $(TOPDIR)/scripts/makelst $* $(TOPDIR) $(OBJDUMP)
87 all_targets: $(O_TARGET) $(L_TARGET)
90 # Rule to compile a set of .o files into one .o file
92 ifdef O_TARGET
93 $(O_TARGET): $(obj-y)
94 rm -f $@
95 ifneq "$(strip $(obj-y))" ""
96 $(LD) $(EXTRA_LDFLAGS) -r -o $@ $(filter $(obj-y), $^)
97 else
98 $(AR) rcs $@
99 endif
100 @ ( \
101 echo 'ifeq ($(strip $(subst $(comma),:,$(EXTRA_LDFLAGS) $(obj-y))),$$(strip $$(subst $$(comma),:,$$(EXTRA_LDFLAGS) $$(obj-y))))' ; \
102 echo 'FILES_FLAGS_UP_TO_DATE += $@' ; \
103 echo 'endif' \
104 ) > $(dir $@)/.$(notdir $@).flags
105 endif # O_TARGET
108 # Rule to compile a set of .o files into one .a file
110 ifdef L_TARGET
111 $(L_TARGET): $(obj-y)
112 rm -f $@
113 $(AR) $(EXTRA_ARFLAGS) rcs $@ $(obj-y)
114 @ ( \
115 echo 'ifeq ($(strip $(subst $(comma),:,$(EXTRA_ARFLAGS) $(obj-y))),$$(strip $$(subst $$(comma),:,$$(EXTRA_ARFLAGS) $$(obj-y))))' ; \
116 echo 'FILES_FLAGS_UP_TO_DATE += $@' ; \
117 echo 'endif' \
118 ) > $(dir $@)/.$(notdir $@).flags
119 endif
123 # This make dependencies quickly
125 fastdep: dummy
126 $(TOPDIR)/scripts/mkdep $(wildcard *.[chS] local.h.master) > .depend
127 ifdef ALL_SUB_DIRS
128 $(MAKE) $(patsubst %,_sfdep_%,$(ALL_SUB_DIRS)) _FASTDEP_ALL_SUB_DIRS="$(ALL_SUB_DIRS)"
129 endif
131 ifdef _FASTDEP_ALL_SUB_DIRS
132 $(patsubst %,_sfdep_%,$(_FASTDEP_ALL_SUB_DIRS)):
133 $(MAKE) -C $(patsubst _sfdep_%,%,$@) fastdep
134 endif
138 # A rule to make subdirectories
140 subdir-list = $(sort $(patsubst %,_subdir_%,$(SUB_DIRS)))
141 sub_dirs: dummy $(subdir-list)
143 ifdef SUB_DIRS
144 $(subdir-list) : dummy
145 $(MAKE) -C $(patsubst _subdir_%,%,$@)
146 endif
149 # A rule to make modules
151 ALL_MOBJS = $(filter-out $(obj-y), $(obj-m))
152 ifneq "$(strip $(ALL_MOBJS))" ""
153 PDWN=$(shell $(CONFIG_SHELL) $(TOPDIR)/scripts/pathdown.sh)
154 endif
156 unexport MOD_DIRS
157 MOD_DIRS := $(MOD_SUB_DIRS) $(MOD_IN_SUB_DIRS)
158 ifneq "$(strip $(MOD_DIRS))" ""
159 .PHONY: $(patsubst %,_modsubdir_%,$(MOD_DIRS))
160 $(patsubst %,_modsubdir_%,$(MOD_DIRS)) : dummy
161 $(MAKE) -C $(patsubst _modsubdir_%,%,$@) modules
163 .PHONY: $(patsubst %,_modinst_%,$(MOD_DIRS))
164 $(patsubst %,_modinst_%,$(MOD_DIRS)) : dummy
165 $(MAKE) -C $(patsubst _modinst_%,%,$@) modules_install
166 endif
168 .PHONY: modules
169 modules: $(ALL_MOBJS) dummy \
170 $(patsubst %,_modsubdir_%,$(MOD_DIRS))
172 .PHONY: _modinst__
173 _modinst__: dummy
174 ifneq "$(strip $(ALL_MOBJS))" ""
175 mkdir -p $(MODLIB)/kernel/$(PDWN)
176 cp $(ALL_MOBJS) $(MODLIB)/kernel/$(PDWN)
177 endif
179 .PHONY: modules_install
180 modules_install: _modinst__ \
181 $(patsubst %,_modinst_%,$(MOD_DIRS))
184 # A rule to do nothing
186 dummy:
189 # This is useful for testing
191 script:
192 $(SCRIPT)
195 # This sets version suffixes on exported symbols
196 # Separate the object into "normal" objects and "exporting" objects
197 # Exporting objects are: all objects that define symbol tables
199 ifdef CONFIG_MODULES
201 multi-used := $(filter $(list-multi), $(obj-y) $(obj-m))
202 multi-objs := $(foreach m, $(multi-used), $($(basename $(m))-objs))
203 active-objs := $(sort $(multi-objs) $(obj-y) $(obj-m))
205 ifdef CONFIG_MODVERSIONS
206 ifneq "$(strip $(export-objs))" ""
208 MODINCL = $(TOPDIR)/include/linux/modules
210 # The -w option (enable warnings) for genksyms will return here in 2.1
211 # So where has it gone?
213 # Added the SMP separator to stop module accidents between uniprocessor
214 # and SMP Intel boxes - AC - from bits by Michael Chastain
217 ifdef CONFIG_SMP
218 genksyms_smp_prefix := -p smp_
219 else
220 genksyms_smp_prefix :=
221 endif
223 $(MODINCL)/%.ver: %.c
224 @if [ ! -r $(MODINCL)/$*.stamp -o $(MODINCL)/$*.stamp -ot $< ]; then \
225 echo '$(CC) $(CFLAGS) -E -D__GENKSYMS__ $<'; \
226 echo '| $(GENKSYMS) $(genksyms_smp_prefix) -k $(VERSION).$(PATCHLEVEL).$(SUBLEVEL) > $@.tmp'; \
227 $(CC) $(CFLAGS) -E -D__GENKSYMS__ $< \
228 | $(GENKSYMS) $(genksyms_smp_prefix) -k $(VERSION).$(PATCHLEVEL).$(SUBLEVEL) > $@.tmp; \
229 if [ -r $@ ] && cmp -s $@ $@.tmp; then echo $@ is unchanged; rm -f $@.tmp; \
230 else echo mv $@.tmp $@; mv -f $@.tmp $@; fi; \
231 fi; touch $(MODINCL)/$*.stamp
233 $(addprefix $(MODINCL)/,$(export-objs:.o=.ver)): $(TOPDIR)/include/linux/autoconf.h
235 # updates .ver files but not modversions.h
236 fastdep: $(addprefix $(MODINCL)/,$(export-objs:.o=.ver))
238 # updates .ver files and modversions.h like before (is this needed?)
239 dep: fastdep update-modverfile
241 endif # export-objs
243 # update modversions.h, but only if it would change
244 update-modverfile:
245 @(echo "#ifndef _LINUX_MODVERSIONS_H";\
246 echo "#define _LINUX_MODVERSIONS_H"; \
247 echo "#include <linux/modsetver.h>"; \
248 cd $(TOPDIR)/include/linux/modules; \
249 for f in *.ver; do \
250 if [ -f $$f ]; then echo "#include <linux/modules/$${f}>"; fi; \
251 done; \
252 echo "#endif"; \
253 ) > $(TOPDIR)/include/linux/modversions.h.tmp
254 @if [ -r $(TOPDIR)/include/linux/modversions.h ] && cmp -s $(TOPDIR)/include/linux/modversions.h $(TOPDIR)/include/linux/modversions.h.tmp; then \
255 echo $(TOPDIR)/include/linux/modversions.h was not updated; \
256 rm -f $(TOPDIR)/include/linux/modversions.h.tmp; \
257 else \
258 echo $(TOPDIR)/include/linux/modversions.h was updated; \
259 mv -f $(TOPDIR)/include/linux/modversions.h.tmp $(TOPDIR)/include/linux/modversions.h; \
262 $(active-objs): $(TOPDIR)/include/linux/modversions.h
264 else
266 $(TOPDIR)/include/linux/modversions.h:
267 @echo "#include <linux/modsetver.h>" > $@
269 endif # CONFIG_MODVERSIONS
271 ifneq "$(strip $(export-objs))" ""
272 $(export-objs): $(export-objs:.o=.c) $(TOPDIR)/include/linux/modversions.h
273 $(CC) $(CFLAGS) $(EXTRA_CFLAGS) $(CFLAGS_$@) -DEXPORT_SYMTAB -c $(@:.o=.c)
274 @ ( \
275 echo 'ifeq ($(strip $(subst $(comma),:,$(CFLAGS) $(EXTRA_CFLAGS) $(CFLAGS_$@) -DEXPORT_SYMTAB)),$$(strip $$(subst $$(comma),:,$$(CFLAGS) $$(EXTRA_CFLAGS) $$(CFLAGS_$@) -DEXPORT_SYMTAB)))' ; \
276 echo 'FILES_FLAGS_UP_TO_DATE += $@' ; \
277 echo 'endif' \
278 ) > $(dir $@)/.$(notdir $@).flags
279 endif
281 endif # CONFIG_MODULES
285 # include dependency files if they exist
287 ifneq ($(wildcard .depend),)
288 include .depend
289 endif
291 ifneq ($(wildcard $(TOPDIR)/.hdepend),)
292 include $(TOPDIR)/.hdepend
293 endif
296 # Find files whose flags have changed and force recompilation.
297 # For safety, this works in the converse direction:
298 # every file is forced, except those whose flags are positively up-to-date.
300 FILES_FLAGS_UP_TO_DATE :=
302 # For use in expunging commas from flags, which mung our checking.
303 comma = ,
305 FILES_FLAGS_EXIST := $(wildcard .*.flags)
306 ifneq ($(FILES_FLAGS_EXIST),)
307 include $(FILES_FLAGS_EXIST)
308 endif
310 FILES_FLAGS_CHANGED := $(strip \
311 $(filter-out $(FILES_FLAGS_UP_TO_DATE), \
312 $(O_TARGET) $(L_TARGET) $(active-objs) \
315 # A kludge: .S files don't get flag dependencies (yet),
316 # because that will involve changing a lot of Makefiles. Also
317 # suppress object files explicitly listed in $(IGNORE_FLAGS_OBJS).
318 # This allows handling of assembly files that get translated into
319 # multiple object files (see arch/ia64/lib/idiv.S, for example).
320 FILES_FLAGS_CHANGED := $(strip \
321 $(filter-out $(patsubst %.S, %.o, $(wildcard *.S) $(IGNORE_FLAGS_OBJS)), \
322 $(FILES_FLAGS_CHANGED)))
324 ifneq ($(FILES_FLAGS_CHANGED),)
325 $(FILES_FLAGS_CHANGED): dummy
326 endif