- David Miller: sparc and net updates. Fix merge_segments.
[davej-history.git] / Rules.make
blobe12777d2ab65daad7816f46e0e9ad4ebc663761b
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
76 %.lst: %.c
77 $(CC) $(CFLAGS) $(EXTRA_CFLAGS) $(CFLAGS_$@) -g -c -o $*.o $<
78 $(TOPDIR)/scripts/makelst $* $(TOPDIR) $(OBJDUMP)
82 all_targets: $(O_TARGET) $(L_TARGET)
85 # Rule to compile a set of .o files into one .o file
87 ifdef O_TARGET
88 ALL_O = $(OX_OBJS) $(O_OBJS)
89 $(O_TARGET): $(ALL_O)
90 rm -f $@
91 ifneq "$(strip $(ALL_O))" ""
92 $(LD) $(EXTRA_LDFLAGS) -r -o $@ $(filter $(ALL_O), $^)
93 else
94 $(AR) rcs $@ $(filter $(ALL_O), $^)
95 endif
96 @ ( \
97 echo 'ifeq ($(strip $(subst $(comma),:,$(EXTRA_LDFLAGS) $(ALL_O))),$$(strip $$(subst $$(comma),:,$$(EXTRA_LDFLAGS) $$(ALL_O))))' ; \
98 echo 'FILES_FLAGS_UP_TO_DATE += $@' ; \
99 echo 'endif' \
100 ) > $(dir $@)/.$(notdir $@).flags
101 endif # O_TARGET
104 # Rule to compile a set of .o files into one .a file
106 ifdef L_TARGET
107 $(L_TARGET): $(LX_OBJS) $(L_OBJS)
108 rm -f $@
109 $(AR) $(EXTRA_ARFLAGS) rcs $@ $(LX_OBJS) $(L_OBJS)
110 @ ( \
111 echo 'ifeq ($(strip $(subst $(comma),:,$(EXTRA_ARFLAGS) $(LX_OBJS) $(L_OBJS))),$$(strip $$(subst $$(comma),:,$$(EXTRA_ARFLAGS) $$(LX_OBJS) $$(L_OBJS))))' ; \
112 echo 'FILES_FLAGS_UP_TO_DATE += $@' ; \
113 echo 'endif' \
114 ) > $(dir $@)/.$(notdir $@).flags
115 endif
118 # This make dependencies quickly
120 fastdep: dummy
121 $(TOPDIR)/scripts/mkdep $(wildcard *.[chS] local.h.master) > .depend
122 ifdef ALL_SUB_DIRS
123 $(MAKE) $(patsubst %,_sfdep_%,$(ALL_SUB_DIRS)) _FASTDEP_ALL_SUB_DIRS="$(ALL_SUB_DIRS)"
124 endif
126 ifdef _FASTDEP_ALL_SUB_DIRS
127 $(patsubst %,_sfdep_%,$(_FASTDEP_ALL_SUB_DIRS)):
128 $(MAKE) -C $(patsubst _sfdep_%,%,$@) fastdep
129 endif
133 # A rule to make subdirectories
135 sub_dirs: dummy $(patsubst %,_subdir_%,$(SUB_DIRS))
137 ifdef SUB_DIRS
138 $(patsubst %,_subdir_%,$(SUB_DIRS)) : dummy
139 $(MAKE) -C $(patsubst _subdir_%,%,$@)
140 endif
143 # A rule to make modules
145 ALL_MOBJS = $(MX_OBJS) $(M_OBJS)
146 ifneq "$(strip $(ALL_MOBJS))" ""
147 PDWN=$(shell $(CONFIG_SHELL) $(TOPDIR)/scripts/pathdown.sh)
148 endif
150 unexport MOD_DIRS
151 MOD_DIRS := $(MOD_SUB_DIRS) $(MOD_IN_SUB_DIRS)
152 ifneq "$(strip $(MOD_DIRS))" ""
153 .PHONY: $(patsubst %,_modsubdir_%,$(MOD_DIRS))
154 $(patsubst %,_modsubdir_%,$(MOD_DIRS)) : dummy
155 $(MAKE) -C $(patsubst _modsubdir_%,%,$@) modules
157 .PHONY: $(patsubst %,_modinst_%,$(MOD_DIRS))
158 $(patsubst %,_modinst_%,$(MOD_DIRS)) : dummy
159 $(MAKE) -C $(patsubst _modinst_%,%,$@) modules_install
160 endif
162 .PHONY: modules
163 modules: $(ALL_MOBJS) $(MIX_OBJS) $(MI_OBJS) dummy \
164 $(patsubst %,_modsubdir_%,$(MOD_DIRS))
166 .PHONY: _modinst__
167 _modinst__: dummy
168 ifneq "$(strip $(ALL_MOBJS))" ""
169 mkdir -p $(MODLIB)/kernel/$(PDWN)
170 cp $(ALL_MOBJS) $(MODLIB)/kernel/$(PDWN)
171 endif
173 .PHONY: modules_install
174 modules_install: _modinst__ \
175 $(patsubst %,_modinst_%,$(MOD_DIRS))
178 # A rule to do nothing
180 dummy:
183 # This is useful for testing
185 script:
186 $(SCRIPT)
189 # This sets version suffixes on exported symbols
190 # Uses SYMTAB_OBJS
191 # Separate the object into "normal" objects and "exporting" objects
192 # Exporting objects are: all objects that define symbol tables
194 ifdef CONFIG_MODULES
196 SYMTAB_OBJS = $(LX_OBJS) $(OX_OBJS) $(MX_OBJS) $(MIX_OBJS)
198 ifdef CONFIG_MODVERSIONS
199 ifneq "$(strip $(SYMTAB_OBJS))" ""
201 MODINCL = $(TOPDIR)/include/linux/modules
203 # The -w option (enable warnings) for genksyms will return here in 2.1
204 # So where has it gone?
206 # Added the SMP separator to stop module accidents between uniprocessor
207 # and SMP Intel boxes - AC - from bits by Michael Chastain
210 ifdef CONFIG_SMP
211 genksyms_smp_prefix := -p smp_
212 else
213 genksyms_smp_prefix :=
214 endif
216 $(MODINCL)/%.ver: %.c
217 @if [ ! -r $(MODINCL)/$*.stamp -o $(MODINCL)/$*.stamp -ot $< ]; then \
218 echo '$(CC) $(CFLAGS) -E -D__GENKSYMS__ $<'; \
219 echo '| $(GENKSYMS) $(genksyms_smp_prefix) -k $(VERSION).$(PATCHLEVEL).$(SUBLEVEL) > $@.tmp'; \
220 $(CC) $(CFLAGS) -E -D__GENKSYMS__ $< \
221 | $(GENKSYMS) $(genksyms_smp_prefix) -k $(VERSION).$(PATCHLEVEL).$(SUBLEVEL) > $@.tmp; \
222 if [ -r $@ ] && cmp -s $@ $@.tmp; then echo $@ is unchanged; rm -f $@.tmp; \
223 else echo mv $@.tmp $@; mv -f $@.tmp $@; fi; \
224 fi; touch $(MODINCL)/$*.stamp
226 $(addprefix $(MODINCL)/,$(SYMTAB_OBJS:.o=.ver)): $(TOPDIR)/include/linux/autoconf.h
228 # updates .ver files but not modversions.h
229 fastdep: $(addprefix $(MODINCL)/,$(SYMTAB_OBJS:.o=.ver))
231 # updates .ver files and modversions.h like before (is this needed?)
232 dep: fastdep update-modverfile
234 endif # SYMTAB_OBJS
236 # update modversions.h, but only if it would change
237 update-modverfile:
238 @(echo "#ifndef _LINUX_MODVERSIONS_H";\
239 echo "#define _LINUX_MODVERSIONS_H"; \
240 echo "#include <linux/modsetver.h>"; \
241 cd $(TOPDIR)/include/linux/modules; \
242 for f in *.ver; do \
243 if [ -f $$f ]; then echo "#include <linux/modules/$${f}>"; fi; \
244 done; \
245 echo "#endif"; \
246 ) > $(TOPDIR)/include/linux/modversions.h.tmp
247 @if [ -r $(TOPDIR)/include/linux/modversions.h ] && cmp -s $(TOPDIR)/include/linux/modversions.h $(TOPDIR)/include/linux/modversions.h.tmp; then \
248 echo $(TOPDIR)/include/linux/modversions.h was not updated; \
249 rm -f $(TOPDIR)/include/linux/modversions.h.tmp; \
250 else \
251 echo $(TOPDIR)/include/linux/modversions.h was updated; \
252 mv -f $(TOPDIR)/include/linux/modversions.h.tmp $(TOPDIR)/include/linux/modversions.h; \
255 $(M_OBJS): $(TOPDIR)/include/linux/modversions.h
256 ifdef MAKING_MODULES
257 $(O_OBJS) $(L_OBJS): $(TOPDIR)/include/linux/modversions.h
258 endif
260 else
262 $(TOPDIR)/include/linux/modversions.h:
263 @echo "#include <linux/modsetver.h>" > $@
265 endif # CONFIG_MODVERSIONS
267 ifneq "$(strip $(SYMTAB_OBJS))" ""
268 $(SYMTAB_OBJS): $(SYMTAB_OBJS:.o=.c) $(TOPDIR)/include/linux/modversions.h
269 $(CC) $(CFLAGS) $(EXTRA_CFLAGS) $(CFLAGS_$@) -DEXPORT_SYMTAB -c $(@:.o=.c)
270 @ ( \
271 echo 'ifeq ($(strip $(subst $(comma),:,$(CFLAGS) $(EXTRA_CFLAGS) $(CFLAGS_$@) -DEXPORT_SYMTAB)),$$(strip $$(subst $$(comma),:,$$(CFLAGS) $$(EXTRA_CFLAGS) $$(CFLAGS_$@) -DEXPORT_SYMTAB)))' ; \
272 echo 'FILES_FLAGS_UP_TO_DATE += $@' ; \
273 echo 'endif' \
274 ) > $(dir $@)/.$(notdir $@).flags
275 endif
277 endif # CONFIG_MODULES
281 # include dependency files if they exist
283 ifneq ($(wildcard .depend),)
284 include .depend
285 endif
287 ifneq ($(wildcard $(TOPDIR)/.hdepend),)
288 include $(TOPDIR)/.hdepend
289 endif
292 # Find files whose flags have changed and force recompilation.
293 # For safety, this works in the converse direction:
294 # every file is forced, except those whose flags are positively up-to-date.
296 FILES_FLAGS_UP_TO_DATE :=
298 # For use in expunging commas from flags, which mung our checking.
299 comma = ,
301 FILES_FLAGS_EXIST := $(wildcard .*.flags)
302 ifneq ($(FILES_FLAGS_EXIST),)
303 include $(FILES_FLAGS_EXIST)
304 endif
306 FILES_FLAGS_CHANGED := $(strip \
307 $(filter-out $(FILES_FLAGS_UP_TO_DATE), \
308 $(O_TARGET) $(O_OBJS) $(OX_OBJS) \
309 $(L_TARGET) $(L_OBJS) $(LX_OBJS) \
310 $(M_OBJS) $(MX_OBJS) \
311 $(MI_OBJS) $(MIX_OBJS) \
314 # A kludge: .S files don't get flag dependencies (yet),
315 # because that will involve changing a lot of Makefiles. Also
316 # suppress object files explicitly listed in $(IGNORE_FLAGS_OBJS).
317 # This allows handling of assembly files that get translated into
318 # multiple object files (see arch/ia64/lib/idiv.S, for example).
319 FILES_FLAGS_CHANGED := $(strip \
320 $(filter-out $(patsubst %.S, %.o, $(wildcard *.S) $(IGNORE_FLAGS_OBJS)), \
321 $(FILES_FLAGS_CHANGED)))
323 ifneq ($(FILES_FLAGS_CHANGED),)
324 $(FILES_FLAGS_CHANGED): dummy
325 endif