cleanup
[linux-2.4.21-pre4.git] / Rules1.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 MAPPING_MODE= -DUSE_IO_OPS
35 EXTRA_CFLAGS := $(MAPPING_MODE) 
36 EXTRA_CFLAGS := $(EXTRA_CFLAGS) -D_COMPAT_WITH_OLD_KERNEL
37 CFLAGS = -D__KERNEL__ -O -Wall -Wstrict-prototypes
38
39 comma   := ,
40 EXTRA_CFLAGS_nostdinc := $(EXTRA_CFLAGS) $(kbuild_2_4_nostdinc)
41
42 #
43 # Get things started.
44 #
45 first_rule: sub_dirs
46         $(MAKE) all_targets
47
48 both-m          := $(filter $(mod-subdirs), $(subdir-y))
49 SUB_DIRS        := $(subdir-y)
50 MOD_SUB_DIRS    := $(sort $(subdir-m) $(both-m))
51 ALL_SUB_DIRS    := $(sort $(subdir-y) $(subdir-m) $(subdir-n) $(subdir-))
52
53
54 #
55 # Common rules
56 #
57
58 %.s: %.c
59         $(CC) $(CFLAGS) $(EXTRA_CFLAGS_nostdinc) -DKBUILD_BASENAME=$(subst $(comma),_,$(subst -,_,$(*F))) $(CFLAGS_$@) -S $< -o $@
60
61 %.i: %.c
62         $(CPP) $(CFLAGS) $(EXTRA_CFLAGS_nostdinc) -DKBUILD_BASENAME=$(subst $(comma),_,$(subst -,_,$(*F))) $(CFLAGS_$@) $< > $@
63
64 %.o: %.c
65         $(CC) $(CFLAGS) $(EXTRA_CFLAGS_nostdinc) -DKBUILD_BASENAME=$(subst $(comma),_,$(subst -,_,$(*F))) $(CFLAGS_$@) -c -o $@ $<
66         @ ( \
67             echo 'ifeq ($(strip $(subst $(comma),:,$(CFLAGS) $(EXTRA_CFLAGS_nostdinc) $(CFLAGS_$@))),$$(strip $$(subst $$(comma),:,$$(CFLAGS) $$(EXTRA_CFLAGS_nostdinc) $$(CFLAGS_$@))))' ; \
68             echo 'FILES_FLAGS_UP_TO_DATE += $@' ; \
69             echo 'endif' \
70         ) > $(dir $@)/.$(notdir $@).flags
71
72 %.o: %.s
73         $(AS) $(AFLAGS) $(EXTRA_CFLAGS) -o $@ $<
74
75 # Old makefiles define their own rules for compiling .S files,
76 # but these standard rules are available for any Makefile that
77 # wants to use them.  Our plan is to incrementally convert all
78 # the Makefiles to these standard rules.  -- rmk, mec
79 ifdef USE_STANDARD_AS_RULE
80
81 %.s: %.S
82         $(CPP) $(AFLAGS) $(EXTRA_AFLAGS) $(AFLAGS_$@) $< > $@
83
84 %.o: %.S
85         $(CC) $(AFLAGS) $(EXTRA_AFLAGS) $(AFLAGS_$@) -c -o $@ $<
86
87 endif
88
89 %.lst: %.c
90         $(CC) $(CFLAGS) $(EXTRA_CFLAGS_nostdinc) $(CFLAGS_$@) -g -c -o $*.o $<
91         $(TOPDIR)/scripts/makelst $* $(TOPDIR) $(OBJDUMP)
92 #
93 #
94 #
95 all_targets: $(O_TARGET) $(L_TARGET)
96
97 #
98 # Rule to compile a set of .o files into one .o file
99 #
100 ifdef O_TARGET
101 $(O_TARGET): $(obj-y)
102         rm -f $@
103     ifneq "$(strip $(obj-y))" ""
104         $(LD) $(EXTRA_LDFLAGS) -r -o $@ $(filter $(obj-y), $^)
105     else
106         $(AR) rcs $@
107     endif
108         @ ( \
109             echo 'ifeq ($(strip $(subst $(comma),:,$(EXTRA_LDFLAGS) $(obj-y))),$$(strip $$(subst $$(comma),:,$$(EXTRA_LDFLAGS) $$(obj-y))))' ; \
110             echo 'FILES_FLAGS_UP_TO_DATE += $@' ; \
111             echo 'endif' \
112         ) > $(dir $@)/.$(notdir $@).flags
113 endif # O_TARGET
114
115 #
116 # Rule to compile a set of .o files into one .a file
117 #
118 ifdef L_TARGET
119 $(L_TARGET): $(obj-y)
120         rm -f $@
121         $(AR) $(EXTRA_ARFLAGS) rcs $@ $(obj-y)
122         @ ( \
123             echo 'ifeq ($(strip $(subst $(comma),:,$(EXTRA_ARFLAGS) $(obj-y))),$$(strip $$(subst $$(comma),:,$$(EXTRA_ARFLAGS) $$(obj-y))))' ; \
124             echo 'FILES_FLAGS_UP_TO_DATE += $@' ; \
125             echo 'endif' \
126         ) > $(dir $@)/.$(notdir $@).flags
127 endif
128
129
130 #
131 # This make dependencies quickly
132 #
133 fastdep: dummy
134         $(TOPDIR)/scripts/mkdep $(CFLAGS) $(EXTRA_CFLAGS_nostdinc) -- $(wildcard *.[chS]) > .depend
135 ifdef ALL_SUB_DIRS
136         $(MAKE) $(patsubst %,_sfdep_%,$(ALL_SUB_DIRS)) _FASTDEP_ALL_SUB_DIRS="$(ALL_SUB_DIRS)"
137 endif
138
139 ifdef _FASTDEP_ALL_SUB_DIRS
140 $(patsubst %,_sfdep_%,$(_FASTDEP_ALL_SUB_DIRS)):
141         $(MAKE) -C $(patsubst _sfdep_%,%,$@) fastdep
142 endif
143
144         
145 #
146 # A rule to make subdirectories
147 #
148 subdir-list = $(sort $(patsubst %,_subdir_%,$(SUB_DIRS)))
149 sub_dirs: dummy $(subdir-list)
150
151 ifdef SUB_DIRS
152 $(subdir-list) : dummy
153         $(MAKE) -C $(patsubst _subdir_%,%,$@)
154 endif
155
156 #
157 # A rule to make modules
158 #
159 ALL_MOBJS = $(filter-out $(obj-y), $(obj-m))
160 ifneq "$(strip $(ALL_MOBJS))" ""
161 MOD_DESTDIR := $(shell $(CONFIG_SHELL) $(TOPDIR)/scripts/pathdown.sh)
162 endif
163
164 unexport MOD_DIRS
165 MOD_DIRS := $(MOD_SUB_DIRS) $(MOD_IN_SUB_DIRS)
166 ifneq "$(strip $(MOD_DIRS))" ""
167 .PHONY: $(patsubst %,_modsubdir_%,$(MOD_DIRS))
168 $(patsubst %,_modsubdir_%,$(MOD_DIRS)) : dummy
169         $(MAKE) -C $(patsubst _modsubdir_%,%,$@) modules
170
171 .PHONY: $(patsubst %,_modinst_%,$(MOD_DIRS))
172 $(patsubst %,_modinst_%,$(MOD_DIRS)) : dummy
173         $(MAKE) -C $(patsubst _modinst_%,%,$@) modules_install
174 endif
175
176 .PHONY: modules
177 modules: $(ALL_MOBJS) dummy \
178          $(patsubst %,_modsubdir_%,$(MOD_DIRS))
179
180 .PHONY: _modinst__
181 _modinst__: dummy
182 ifneq "$(strip $(ALL_MOBJS))" ""
183         mkdir -p $(MODLIB)/kernel/$(MOD_DESTDIR)
184         cp $(sort $(ALL_MOBJS)) $(MODLIB)/kernel/$(MOD_DESTDIR)
185 endif
186
187 .PHONY: modules_install
188 modules_install: _modinst__ \
189          $(patsubst %,_modinst_%,$(MOD_DIRS))
190
191 #
192 # A rule to do nothing
193 #
194 dummy:
195
196 #
197 # This is useful for testing
198 #
199 script:
200         $(SCRIPT)
201
202 #
203 # This sets version suffixes on exported symbols
204 # Separate the object into "normal" objects and "exporting" objects
205 # Exporting objects are: all objects that define symbol tables
206 #
207 ifdef CONFIG_MODULES
208
209 multi-used      := $(filter $(list-multi), $(obj-y) $(obj-m))
210 multi-objs      := $(foreach m, $(multi-used), $($(basename $(m))-objs))
211 active-objs     := $(sort $(multi-objs) $(obj-y) $(obj-m))
212
213 ifdef CONFIG_MODVERSIONS
214 ifneq "$(strip $(export-objs))" ""
215
216 MODINCL = $(TOPDIR)/include/linux/modules
217
218
219 # The -w option (enable warnings) for genksyms will return here in 2.1
220 # So where has it gone?
221 #
222 # Added the SMP separator to stop module accidents between uniprocessor
223 # and SMP Intel boxes - AC - from bits by Michael Chastain
224 #
225
226 ifdef CONFIG_SMP
227         genksyms_smp_prefix := -p smp_
228 else
229         genksyms_smp_prefix := 
230 endif
231
232 $(MODINCL)/%.ver: %.c
233         @if [ ! -r $(MODINCL)/$*.stamp -o $(MODINCL)/$*.stamp -ot $< ]; then \
234                 echo '$(CC) $(CFLAGS) $(EXTRA_CFLAGS_nostdinc) -E -D__GENKSYMS__ $<'; \
235                 echo '| $(GENKSYMS) $(genksyms_smp_prefix) -k $(VERSION).$(PATCHLEVEL).$(SUBLEVEL) > $@.tmp'; \
236                 $(CC) $(CFLAGS) $(EXTRA_CFLAGS_nostdinc) -E -D__GENKSYMS__ $< \
237                 | $(GENKSYMS) $(genksyms_smp_prefix) -k $(VERSION).$(PATCHLEVEL).$(SUBLEVEL) > $@.tmp; \
238                 if [ -r $@ ] && cmp -s $@ $@.tmp; then echo $@ is unchanged; rm -f $@.tmp; \
239                 else echo mv $@.tmp $@; mv -f $@.tmp $@; fi; \
240         fi; touch $(MODINCL)/$*.stamp
241         
242 $(addprefix $(MODINCL)/,$(export-objs:.o=.ver)): $(TOPDIR)/include/linux/autoconf.h
243
244 # updates .ver files but not modversions.h
245 fastdep: $(addprefix $(MODINCL)/,$(export-objs:.o=.ver))
246
247 # updates .ver files and modversions.h like before (is this needed?)
248 dep: fastdep update-modverfile
249
250 endif # export-objs 
251
252 # update modversions.h, but only if it would change
253 update-modverfile:
254         @(echo "#ifndef _LINUX_MODVERSIONS_H";\
255           echo "#define _LINUX_MODVERSIONS_H"; \
256           echo "#include <linux/modsetver.h>"; \
257           cd $(TOPDIR)/include/linux/modules; \
258           for f in *.ver; do \
259             if [ -f $$f ]; then echo "#include <linux/modules/$${f}>"; fi; \
260           done; \
261           echo "#endif"; \
262         ) > $(TOPDIR)/include/linux/modversions.h.tmp
263         @if [ -r $(TOPDIR)/include/linux/modversions.h ] && cmp -s $(TOPDIR)/include/linux/modversions.h $(TOPDIR)/include/linux/modversions.h.tmp; then \
264                 echo $(TOPDIR)/include/linux/modversions.h was not updated; \
265                 rm -f $(TOPDIR)/include/linux/modversions.h.tmp; \
266         else \
267                 echo $(TOPDIR)/include/linux/modversions.h was updated; \
268                 mv -f $(TOPDIR)/include/linux/modversions.h.tmp $(TOPDIR)/include/linux/modversions.h; \
269         fi
270
271 $(active-objs): $(TOPDIR)/include/linux/modversions.h
272
273 else
274
275 $(TOPDIR)/include/linux/modversions.h:
276         @echo "#include <linux/modsetver.h>" > $@
277
278 endif # CONFIG_MODVERSIONS
279
280 ifneq "$(strip $(export-objs))" ""
281 $(export-objs): $(export-objs:.o=.c) $(TOPDIR)/include/linux/modversions.h
282         $(CC) $(CFLAGS) $(EXTRA_CFLAGS_nostdinc) -DKBUILD_BASENAME=$(subst $(comma),_,$(subst -,_,$(*F))) $(CFLAGS_$@) -DEXPORT_SYMTAB -c $(@:.o=.c)
283         @ ( \
284             echo 'ifeq ($(strip $(subst $(comma),:,$(CFLAGS) $(EXTRA_CFLAGS_nostdinc) $(CFLAGS_$@) -DEXPORT_SYMTAB)),$$(strip $$(subst $$(comma),:,$$(CFLAGS) $$(EXTRA_CFLAGS_nostdinc) $$(CFLAGS_$@) -DEXPORT_SYMTAB)))' ; \
285             echo 'FILES_FLAGS_UP_TO_DATE += $@' ; \
286             echo 'endif' \
287         ) > $(dir $@)/.$(notdir $@).flags
288 endif
289
290 endif # CONFIG_MODULES
291
292
293 #
294 # include dependency files if they exist
295 #
296 ifneq ($(wildcard .depend),)
297 include .depend
298 endif
299
300 ifneq ($(wildcard $(TOPDIR)/.hdepend),)
301 include $(TOPDIR)/.hdepend
302 endif
303
304 #
305 # Find files whose flags have changed and force recompilation.
306 # For safety, this works in the converse direction:
307 #   every file is forced, except those whose flags are positively up-to-date.
308 #
309 FILES_FLAGS_UP_TO_DATE :=
310
311 # For use in expunging commas from flags, which mung our checking.
312 comma = ,
313
314 FILES_FLAGS_EXIST := $(wildcard .*.flags)
315 ifneq ($(FILES_FLAGS_EXIST),)
316 include $(FILES_FLAGS_EXIST)
317 endif
318
319
320 FILES_FLAGS_CHANGED := $(strip \
321     $(filter-out $(FILES_FLAGS_UP_TO_DATE), \
322         $(O_TARGET) $(L_TARGET) $(active-objs) \
323         ))
324
325 # A kludge: .S files don't get flag dependencies (yet),
326 #   because that will involve changing a lot of Makefiles.  Also
327 #   suppress object files explicitly listed in $(IGNORE_FLAGS_OBJS).
328 #   This allows handling of assembly files that get translated into
329 #   multiple object files (see arch/ia64/lib/idiv.S, for example).
330 FILES_FLAGS_CHANGED := $(strip \
331     $(filter-out $(patsubst %.S, %.o, $(wildcard *.S) $(IGNORE_FLAGS_OBJS)), \
332     $(FILES_FLAGS_CHANGED)))
333
334 ifneq ($(FILES_FLAGS_CHANGED),)
335 $(FILES_FLAGS_CHANGED): dummy
336 endif