added profiling support
[linux-2.6/linux-mips.git] / Rules.make
blobbcd55b4760793d125e7406122dda55390c1a1f48
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_ASFLAGS
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
35 unexport MOD_LIST_NAME
38 # Get things started.
40 first_rule: sub_dirs
41 $(MAKE) all_targets
44 # Common rules
47 %.s: %.c
48 $(CC) $(CFLAGS) $(EXTRA_CFLAGS) $(CFLAGS_$@) -S $< -o $@
50 %.i: %.c
51 $(CC) $(CFLAGS) $(EXTRA_CFLAGS) $(CFLAGS_$@) -E $< > $@
53 %.o: %.c
54 $(CC) $(CFLAGS) $(EXTRA_CFLAGS) $(CFLAGS_$@) -c -o $@ $<
55 @ ( \
56 echo 'ifeq ($(strip $(CFLAGS) $(EXTRA_CFLAGS) $(CFLAGS_$@)),$$(strip $$(CFLAGS) $$(EXTRA_CFLAGS) $$(CFLAGS_$@)))' ; \
57 echo 'FILES_FLAGS_UP_TO_DATE += $@' ; \
58 echo 'endif' \
59 ) > $(dir $@)/.$(notdir $@).flags
61 %.o: %.s
62 $(AS) $(ASFLAGS) $(EXTRA_CFLAGS) -o $@ $<
67 all_targets: $(O_TARGET) $(L_TARGET)
70 # Rule to compile a set of .o files into one .o file
72 ifdef O_TARGET
73 ALL_O = $(OX_OBJS) $(O_OBJS)
74 $(O_TARGET): $(ALL_O)
75 rm -f $@
76 ifneq "$(strip $(ALL_O))" ""
77 $(LD) $(EXTRA_LDFLAGS) -r -o $@ $(ALL_O)
78 else
79 $(AR) rcs $@
80 endif
81 @ ( \
82 echo 'ifeq ($(strip $(EXTRA_LDFLAGS) $(ALL_O)),$$(strip $$(EXTRA_LDFLAGS) $$(ALL_O)))' ; \
83 echo 'FILES_FLAGS_UP_TO_DATE += $@' ; \
84 echo 'endif' \
85 ) > $(dir $@)/.$(notdir $@).flags
86 endif # O_TARGET
89 # Rule to compile a set of .o files into one .a file
91 ifdef L_TARGET
92 $(L_TARGET): $(LX_OBJS) $(L_OBJS)
93 rm -f $@
94 $(AR) $(EXTRA_ARFLAGS) rcs $@ $(LX_OBJS) $(L_OBJS)
95 @ ( \
96 echo 'ifeq ($(strip $(EXTRA_ARFLAGS) $(LX_OBJS) $(L_OBJS)),$$(strip $$(EXTRA_ARFLAGS) $$(LX_OBJS) $$(L_OBJS)))' ; \
97 echo 'FILES_FLAGS_UP_TO_DATE += $@' ; \
98 echo 'endif' \
99 ) > $(dir $@)/.$(notdir $@).flags
100 endif
103 # This make dependencies quickly
105 fastdep: dummy
106 $(TOPDIR)/scripts/mkdep $(wildcard *.[chS] local.h.master) > .depend
107 ifdef ALL_SUB_DIRS
108 set -e; for i in $(ALL_SUB_DIRS); do $(MAKE) -C $$i fastdep; done
109 endif
112 # A rule to make subdirectories
114 sub_dirs: dummy
115 ifdef SUB_DIRS
116 set -e; for i in $(SUB_DIRS); do $(MAKE) -C $$i; done
117 endif
120 # A rule to make modules
122 ALL_MOBJS = $(MX_OBJS) $(M_OBJS)
123 ifneq "$(strip $(ALL_MOBJS))" ""
124 PDWN=$(shell $(CONFIG_SHELL) $(TOPDIR)/scripts/pathdown.sh)
125 endif
126 modules: $(ALL_MOBJS) $(MIX_OBJS) $(MI_OBJS) dummy
127 ifdef MOD_SUB_DIRS
128 set -e; for i in $(MOD_SUB_DIRS); do $(MAKE) -C $$i modules; done
129 endif
130 ifdef MOD_IN_SUB_DIRS
131 set -e; for i in $(MOD_IN_SUB_DIRS); do $(MAKE) -C $$i modules; done
132 endif
133 ifneq "$(strip $(MOD_LIST_NAME))" ""
134 rm -f $$TOPDIR/modules/$(MOD_LIST_NAME)
135 ifdef MOD_SUB_DIRS
136 for i in $(MOD_SUB_DIRS); do \
137 echo `basename $$i`.o >> $$TOPDIR/modules/$(MOD_LIST_NAME); done
138 endif
139 ifneq "$(strip $(ALL_MOBJS))" ""
140 echo $(ALL_MOBJS) >> $$TOPDIR/modules/$(MOD_LIST_NAME)
141 endif
142 ifneq "$(strip $(MOD_TO_LIST))" ""
143 echo $(MOD_TO_LIST) >> $$TOPDIR/modules/$(MOD_LIST_NAME)
144 endif
145 endif
146 ifneq "$(strip $(ALL_MOBJS))" ""
147 echo $(PDWN)
148 cd $$TOPDIR/modules; for i in $(ALL_MOBJS); do \
149 ln -sf ../$(PDWN)/$$i $$i; done
150 endif
153 # A rule to do nothing
155 dummy:
158 # This is useful for testing
160 script:
161 $(SCRIPT)
164 # This sets version suffixes on exported symbols
165 # Uses SYMTAB_OBJS
166 # Separate the object into "normal" objects and "exporting" objects
167 # Exporting objects are: all objects that define symbol tables
169 ifdef CONFIG_MODULES
171 SYMTAB_OBJS = $(LX_OBJS) $(OX_OBJS) $(MX_OBJS) $(MIX_OBJS)
173 ifdef CONFIG_MODVERSIONS
174 ifneq "$(strip $(SYMTAB_OBJS))" ""
176 MODINCL = $(TOPDIR)/include/linux/modules
178 # The -w option (enable warnings) for genksyms will return here in 2.1
179 # So where has it gone ???
181 # Added the SMP seperator to stop module accidents between uniproc/smp
182 # intel boxes - AC - from bits by Michael Chastain
185 ifdef SMP
186 genksyms_smp_prefix := -p smp_
187 else
188 genksyms_smp_prefix :=
189 endif
191 $(MODINCL)/%.ver: %.c
192 $(CC) $(CFLAGS) -E -D__GENKSYMS__ $<\
193 | $(GENKSYMS) $(genksyms_smp_prefix) -k $(VERSION).$(PATCHLEVEL).$(SUBLEVEL) > $@.tmp
194 mv $@.tmp $@
196 $(addprefix $(MODINCL)/,$(SYMTAB_OBJS:.o=.ver)): $(TOPDIR)/include/linux/autoconf.h
198 $(TOPDIR)/include/linux/modversions.h: $(addprefix $(MODINCL)/,$(SYMTAB_OBJS:.o=.ver))
199 @echo updating $(TOPDIR)/include/linux/modversions.h
200 @(echo "#ifndef _LINUX_MODVERSIONS_H";\
201 echo "#define _LINUX_MODVERSIONS_H"; \
202 echo "#include <linux/modsetver.h>"; \
203 cd $(TOPDIR)/include/linux/modules; \
204 for f in *.ver; do \
205 if [ -f $$f ]; then echo "#include <linux/modules/$${f}>"; fi; \
206 done; \
207 echo "#endif"; \
208 ) > $@
210 dep fastdep: $(TOPDIR)/include/linux/modversions.h
212 endif # SYMTAB_OBJS
214 $(M_OBJS): $(TOPDIR)/include/linux/modversions.h
215 ifdef MAKING_MODULES
216 $(O_OBJS) $(L_OBJS): $(TOPDIR)/include/linux/modversions.h
217 endif
219 else
221 $(TOPDIR)/include/linux/modversions.h:
222 @echo "#include <linux/modsetver.h>" > $@
224 endif # CONFIG_MODVERSIONS
226 ifneq "$(strip $(SYMTAB_OBJS))" ""
227 $(SYMTAB_OBJS): $(TOPDIR)/include/linux/modversions.h $(SYMTAB_OBJS:.o=.c)
228 $(CC) $(CFLAGS) $(EXTRA_CFLAGS) $(CFLAGS_$@) -DEXPORT_SYMTAB -c $(@:.o=.c)
229 @ ( \
230 echo 'ifeq ($(strip $(CFLAGS) $(EXTRA_CFLAGS) $(CFLAGS_$@) -DEXPORT_SYMTAB),$$(strip $$(CFLAGS) $$(EXTRA_CFLAGS) $$(CFLAGS_$@) -DEXPORT_SYMTAB))' ; \
231 echo 'FILES_FLAGS_UP_TO_DATE += $@' ; \
232 echo 'endif' \
233 ) > $(dir $@)/.$(notdir $@).flags
234 endif
236 endif # CONFIG_MODULES
240 # include dependency files if they exist
242 ifneq ($(wildcard .depend),)
243 include .depend
244 endif
246 ifneq ($(wildcard $(TOPDIR)/.hdepend),)
247 include $(TOPDIR)/.hdepend
248 endif
251 # Find files whose flags have changed and force recompilation.
252 # For safety, this works in the converse direction:
253 # every file is forced, except those whose flags are positively up-to-date.
255 FILES_FLAGS_UP_TO_DATE :=
257 FILES_FLAGS_EXIST := $(wildcard .*.flags)
258 ifneq ($(FILES_FLAGS_EXIST),)
259 include $(FILES_FLAGS_EXIST)
260 endif
262 FILES_FLAGS_CHANGED := $(strip \
263 $(filter-out $(FILES_FLAGS_UP_TO_DATE), \
264 $(O_TARGET) $(O_OBJS) $(OX_OBJS) \
265 $(L_TARGET) $(L_OBJS) $(LX_OBJS) \
266 $(M_OBJS) $(MX_OBJS) \
267 $(MI_OBJS) $(MIX_OBJS) \
270 # A kludge: .S files don't get flag dependencies (yet),
271 # because that will involve changing a lot of Makefiles.
272 FILES_FLAGS_CHANGED := $(strip \
273 $(filter-out $(patsubst %.S, %.o, $(wildcard *.S)), \
274 $(FILES_FLAGS_CHANGED)))
276 ifneq ($(FILES_FLAGS_CHANGED),)
277 $(FILES_FLAGS_CHANGED): dummy
278 endif