Version:  2.0.40 2.2.26 2.4.37 3.13 3.14 3.15 3.16 3.17 3.18 3.19 4.0 4.1 4.2 4.3 4.4 4.5 4.6 4.7 4.8 4.9 4.10

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

This page was automatically generated by LXR 0.3.1 (source).  •  Linux is a registered trademark of Linus Torvalds  •  Contact us