Import changeset
[linux-flexiantxendom0-3.2.10.git] / Rules.make
1 #
2 # This file contains rules which are shared between multiple Makefiles.
3 #
4
5 #
6 # False targets.
7 #
8 .PHONY: dummy
9
10 #
11 # Special variables which should not be exported
12 #
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
23
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-
33
34 #
35 # Get things started.
36 #
37 first_rule: sub_dirs
38         $(MAKE) all_targets
39
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-))
44
45
46 #
47 # Common rules
48 #
49
50 %.s: %.c
51         $(CC) $(CFLAGS) $(EXTRA_CFLAGS) $(CFLAGS_$@) -S $< -o $@
52
53 %.i: %.c
54         $(CPP) $(CFLAGS) $(EXTRA_CFLAGS) $(CFLAGS_$@) $< > $@
55
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
63
64 %.o: %.s
65         $(AS) $(AFLAGS) $(EXTRA_CFLAGS) -o $@ $<
66
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
72
73 %.s: %.S
74         $(CPP) $(AFLAGS) $(EXTRA_AFLAGS) $(AFLAGS_$@) $< > $@
75
76 %.o: %.S
77         $(CC) $(AFLAGS) $(EXTRA_AFLAGS) $(AFLAGS_$@) -c -o $@ $<
78
79 endif
80
81 %.lst: %.c
82         $(CC) $(CFLAGS) $(EXTRA_CFLAGS) $(CFLAGS_$@) -g -c -o $*.o $<
83         $(TOPDIR)/scripts/makelst $* $(TOPDIR) $(OBJDUMP)
84 #
85 #
86 #
87 all_targets: $(O_TARGET) $(L_TARGET)
88
89 #
90 # Rule to compile a set of .o files into one .o file
91 #
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
106
107 #
108 # Rule to compile a set of .o files into one .a file
109 #
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
120
121
122 #
123 # This make dependencies quickly
124 #
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
130
131 ifdef _FASTDEP_ALL_SUB_DIRS
132 $(patsubst %,_sfdep_%,$(_FASTDEP_ALL_SUB_DIRS)):
133         $(MAKE) -C $(patsubst _sfdep_%,%,$@) fastdep
134 endif
135
136         
137 #
138 # A rule to make subdirectories
139 #
140 subdir-list = $(sort $(patsubst %,_subdir_%,$(SUB_DIRS)))
141 sub_dirs: dummy $(subdir-list)
142
143 ifdef SUB_DIRS
144 $(subdir-list) : dummy
145         $(MAKE) -C $(patsubst _subdir_%,%,$@)
146 endif
147
148 #
149 # A rule to make modules
150 #
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
155
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
162
163 .PHONY: $(patsubst %,_modinst_%,$(MOD_DIRS))
164 $(patsubst %,_modinst_%,$(MOD_DIRS)) : dummy
165         $(MAKE) -C $(patsubst _modinst_%,%,$@) modules_install
166 endif
167
168 .PHONY: modules
169 modules: $(ALL_MOBJS) dummy \
170          $(patsubst %,_modsubdir_%,$(MOD_DIRS))
171
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
178
179 .PHONY: modules_install
180 modules_install: _modinst__ \
181          $(patsubst %,_modinst_%,$(MOD_DIRS))
182
183 #
184 # A rule to do nothing
185 #
186 dummy:
187
188 #
189 # This is useful for testing
190 #
191 script:
192         $(SCRIPT)
193
194 #
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
198 #
199 ifdef CONFIG_MODULES
200
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))
204
205 ifdef CONFIG_MODVERSIONS
206 ifneq "$(strip $(export-objs))" ""
207
208 MODINCL = $(TOPDIR)/include/linux/modules
209
210 # The -w option (enable warnings) for genksyms will return here in 2.1
211 # So where has it gone?
212 #
213 # Added the SMP separator to stop module accidents between uniprocessor
214 # and SMP Intel boxes - AC - from bits by Michael Chastain
215 #
216
217 ifdef CONFIG_SMP
218         genksyms_smp_prefix := -p smp_
219 else
220         genksyms_smp_prefix := 
221 endif
222
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
232         
233 $(addprefix $(MODINCL)/,$(export-objs:.o=.ver)): $(TOPDIR)/include/linux/autoconf.h
234
235 # updates .ver files but not modversions.h
236 fastdep: $(addprefix $(MODINCL)/,$(export-objs:.o=.ver))
237
238 # updates .ver files and modversions.h like before (is this needed?)
239 dep: fastdep update-modverfile
240
241 endif # export-objs 
242
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; \
260         fi
261
262 $(active-objs): $(TOPDIR)/include/linux/modversions.h
263
264 else
265
266 $(TOPDIR)/include/linux/modversions.h:
267         @echo "#include <linux/modsetver.h>" > $@
268
269 endif # CONFIG_MODVERSIONS
270
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
280
281 endif # CONFIG_MODULES
282
283
284 #
285 # include dependency files if they exist
286 #
287 ifneq ($(wildcard .depend),)
288 include .depend
289 endif
290
291 ifneq ($(wildcard $(TOPDIR)/.hdepend),)
292 include $(TOPDIR)/.hdepend
293 endif
294
295 #
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.
299 #
300 FILES_FLAGS_UP_TO_DATE :=
301
302 # For use in expunging commas from flags, which mung our checking.
303 comma = ,
304
305 FILES_FLAGS_EXIST := $(wildcard .*.flags)
306 ifneq ($(FILES_FLAGS_EXIST),)
307 include $(FILES_FLAGS_EXIST)
308 endif
309
310 FILES_FLAGS_CHANGED := $(strip \
311     $(filter-out $(FILES_FLAGS_UP_TO_DATE), \
312         $(O_TARGET) $(L_TARGET) $(active-objs) \
313         ))
314
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)))
323
324 ifneq ($(FILES_FLAGS_CHANGED),)
325 $(FILES_FLAGS_CHANGED): dummy
326 endif