Linux Headquarters
[ Register ]
[ About us ] [ Home Page ]

Advertisement
[ Kernel ] [ Documentation ] [ Links ] [ Books ]

Advertisement

Kernel v2.5.17 /Rules.make

Filename:/Rules.make
Lines Added:128
Lines Deleted:108
Also changed in: (Previous) 2.5.13  2.5.11  2.5.9  2.5.8  2.5.8-pre3  2.5.8-pre2 
(Following) 2.5.18  2.5.19  2.5.20  2.5.21  2.5.22  2.5.23 

Location
[  2.5.17
   o  Rules.make

Patch

diff -Nru a/Rules.make b/Rules.make
--- a/Rules.make   Mon May 20 22:07:17 2002
+++ b/Rules.make   Mon May 20 22:07:17 2002
@@ -41,35 +41,35 @@
 #
 # Get things started.
 #
-first_rule: sub_dirs
-   $(MAKE) all_targets
+first_rule: all_targets
 
 both-m          := $(filter $(mod-subdirs), $(subdir-y))
 SUB_DIRS   := $(subdir-y)
 MOD_SUB_DIRS   := $(sort $(subdir-m) $(both-m))
 ALL_SUB_DIRS   := $(sort $(subdir-y) $(subdir-m) $(subdir-n) $(subdir-))
 
-
 #
 # Common rules
 #
 
-%.s: %.c
-   $(CC) $(CFLAGS) $(EXTRA_CFLAGS) -DKBUILD_BASENAME=$(subst $(comma),_,$(subst -,_,$(*F))) $(CFLAGS_$@) -S $< -o $@
+# export_flags will be set to -DEXPORT_SYMBOL for objects in $(export-objs)
 
-%.i: %.c
-   $(CPP) $(CFLAGS) $(EXTRA_CFLAGS) -DKBUILD_BASENAME=$(subst $(comma),_,$(subst -,_,$(*F))) $(CFLAGS_$@) $< > $@
+c_flags = $(CFLAGS) $(EXTRA_CFLAGS) $(CFLAGS_$(*F).o) -DKBUILD_BASENAME=$(subst $(comma),_,$(subst -,_,$(*F))) $(export_flags)
 
-%.o: %.c
-   $(CC) $(CFLAGS) $(EXTRA_CFLAGS) -DKBUILD_BASENAME=$(subst $(comma),_,$(subst -,_,$(*F))) $(CFLAGS_$@) -c -o $@ $<
-   @ ( \
-       echo 'ifeq ($(strip $(subst $(comma),:,$(CFLAGS) $(EXTRA_CFLAGS) $(CFLAGS_$@))),$$(strip $$(subst $$(comma),:,$$(CFLAGS) $$(+
EXTRA_CFLAGS) $$(CFLAGS_$@))))' ; \
-       echo 'FILES_FLAGS_UP_TO_DATE += $@' ; \
-       echo 'endif' \
-   ) > $(dir $@)/.$(notdir $@).flags
+cmd_cc_s_c = $(CC) $(c_flags) -S $< -o $@
 
-%.o: %.s
-   $(AS) $(AFLAGS) $(EXTRA_CFLAGS) -o $@ $<
+%.s: %.c dummy
+   $(call if_changed,cmd_cc_s_c)
+
+cmd_cc_i_c = $(CPP) $(c_flags) $< > $@
+
+%.i: %.c dummy
+   $(call if_changed,cmd_cc_i_c)
+
+cmd_cc_o_c = $(CC) $(c_flags) -c -o $@ $<
+
+%.o: %.c dummy
+   $(call if_changed,cmd_cc_o_c)
 
 # Old makefiles define their own rules for compiling .S files,
 # but these standard rules are available for any Makefile that
@@ -77,86 +77,97 @@
 # the Makefiles to these standard rules.  -- rmk, mec
 ifdef USE_STANDARD_AS_RULE
 
-%.s: %.S
-   $(CPP) $(AFLAGS) $(EXTRA_AFLAGS) $(AFLAGS_$@) $< > $@
+a_flags = $(AFLAGS) $(EXTRA_AFLAGS) $(AFLAGS_$(*F).o)
+
+cmd_as_s_S = $(CPP) $(a_flags) $< > $@
 
-%.o: %.S
-   $(CC) $(AFLAGS) $(EXTRA_AFLAGS) $(AFLAGS_$@) -c -o $@ $<
+%.s: %.S dummy
+   $(call if_changed,cmd_as_s_S)
+
+cmd_as_o_S = $(CC) $(a_flags) -c -o $@ $<
+
+%.o: %.S dummy
+   $(call if_changed,cmd_as_o_S)
 
 endif
 
+# FIXME is anybody using this rule? Why does it have EXTRA_CFLAGS?
+%.o: %.s
+   $(AS) $(AFLAGS) $(EXTRA_CFLAGS) -o $@ $<
+
 %.lst: %.c
-   $(CC) $(CFLAGS) $(EXTRA_CFLAGS) $(CFLAGS_$@) -g -c -o $*.o $<
+   $(CC) $(c_flags) -g -c -o $*.o $<
    $(TOPDIR)/scripts/makelst $* $(TOPDIR) $(OBJDUMP)
 #
 #
 #
-all_targets: $(O_TARGET) $(L_TARGET)
+all_targets: $(O_TARGET) $(L_TARGET) sub_dirs
+
+# $(subdir-obj-y) is the list of objects in $(obj-y) which do not live
+# in the local directory
+subdir-obj-y := $(foreach o,$(obj-y),$(if $(filter-out $(o),$(notdir $(o))),$(o)))
+# Do build these objects, we need to descend into the directories
+$(subdir-obj-y): sub_dirs
 
 #
 # Rule to compile a set of .o files into one .o file
 #
 ifdef O_TARGET
-$(O_TARGET): $(obj-y)
-   rm -f $@
-    ifneq "$(strip $(obj-y))" ""
-   $(LD) $(EXTRA_LDFLAGS) -r -o $@ $(filter $(obj-y), $^)
-    else
-   $(AR) rcs $@
-    endif
-   @ ( \
-       echo 'ifeq ($(strip $(subst $(comma),:,$(EXTRA_LDFLAGS) $(obj-y))),$$(strip $$(subst $$(comma),:,$$(EXTRA_LDFLAGS) $$(obj-y)+
)))' ; \
-       echo 'FILES_FLAGS_UP_TO_DATE += $@' ; \
-       echo 'endif' \
-   ) > $(dir $@)/.$(notdir $@).flags
+# If the list of objects to link is empty, just create an empty O_TARGET
+cmd_link_o_target = $(if $(strip $(obj-y)),\
+            $(LD) $(EXTRA_LDFLAGS) -r -o $@ $(filter $(obj-y), $^),\
+            rm -f $@; $(AR) rcs $@)
+
+$(O_TARGET): $(obj-y) dummy
+   $(call if_changed,cmd_link_o_target)
 endif # O_TARGET
 
 #
 # Rule to compile a set of .o files into one .a file
 #
 ifdef L_TARGET
-$(L_TARGET): $(obj-y)
-   rm -f $@
-   $(AR) $(EXTRA_ARFLAGS) rcs $@ $(obj-y)
-   @ ( \
-       echo 'ifeq ($(strip $(subst $(comma),:,$(EXTRA_ARFLAGS) $(obj-y))),$$(strip $$(subst $$(comma),:,$$(EXTRA_ARFLAGS) $$(obj-y)+
)))' ; \
-       echo 'FILES_FLAGS_UP_TO_DATE += $@' ; \
-       echo 'endif' \
-   ) > $(dir $@)/.$(notdir $@).flags
+cmd_link_l_target = rm -f $@; $(AR) $(EXTRA_ARFLAGS) rcs $@ $(obj-y)
+
+$(L_TARGET): $(obj-y) dummy
+   $(call if_changed,cmd_link_l_target)
 endif
 
 #
 # Rule to link composite objects
 #
 
-# for make >= 3.78 the following is cleaner:
-# multi-used := $(foreach m,$(obj-y) $(obj-m), $(if $($(basename $(m))-objs), $(m)))
+# export.o is never a composite object, since $(export-objs) has a
+# fixed meaning (== objects which EXPORT_SYMBOL())
 __obj-y = $(filter-out export.o,$(obj-y))
 __obj-m = $(filter-out export.o,$(obj-m))
-multi-used-y := $(sort $(foreach m,$(__obj-y),$(patsubst %,$(m),$($(basename $(m))-objs))))
-multi-used-m := $(sort $(foreach m,$(__obj-m),$(patsubst %,$(m),$($(basename $(m))-objs))))
-ld-multi-used-y := $(filter-out $(list-multi),$(multi-used-y))
-ld-multi-used-m := $(filter-out $(list-multi),$(multi-used-m))
-ld-multi-objs-y := $(foreach m, $(ld-multi-used-y), $($(basename $(m))-objs))
-ld-multi-objs-m := $(foreach m, $(ld-multi-used-m), $($(basename $(m))-objs))
-
-$(ld-multi-used-y) : %.o: $(ld-multi-objs-y)
-   rm -f $@
-   $(LD) $(EXTRA_LDFLAGS) -r -o $@ $(filter $($(basename $@)-objs), $^)
-   @ ( \
-       echo 'ifeq ($(strip $(subst $(comma),:,$(LD) $(EXTRA_LDFLAGS) $($(basename $@)-objs)),$$(strip $$(subst $$(comma),:,$$(LD) $+
$(EXTRA_LDFLAGS) $$($(basename $@)-objs)))))' ; \
-       echo 'FILES_FLAGS_UP_TO_DATE += $@' ; \
-       echo 'endif' \
-   ) > $(dir $@)/.$(notdir $@).flags
-
-$(ld-multi-used-m) : %.o: $(ld-multi-objs-m)
-   rm -f $@
-   $(LD) $(EXTRA_LDFLAGS) -r -o $@ $(filter $($(basename $@)-objs), $^)
-   @ ( \
-       echo 'ifeq ($(strip $(subst $(comma),:,$(LD) $(EXTRA_LDFLAGS) $($(basename $@)-objs)),$$(strip $$(subst $$(comma),:,$$(LD) $+
$(EXTRA_LDFLAGS) $$($(basename $@)-objs)))))' ; \
-       echo 'FILES_FLAGS_UP_TO_DATE += $@' ; \
-       echo 'endif' \
-   ) > $(dir $@)/.$(notdir $@).flags
+
+# if $(foo-objs) exists, foo.o is a composite object 
+__multi-used-y := $(sort $(foreach m,$(__obj-y), $(if $($(basename $(m))-objs), $(m))))
+__multi-used-m := $(sort $(foreach m,$(__obj-m), $(if $($(basename $(m))-objs), $(m))))
+
+# Backwards compatibility: if a composite object is listed in
+# $(list-multi), skip it here, since the Makefile will have an explicit
+# link rule for it
+
+multi-used-y := $(filter-out $(list-multi),$(__multi-used-y))
+multi-used-m := $(filter-out $(list-multi),$(__multi-used-m))
+
+# Build list of the parts of our composite objects, our composite
+# objects depend on those (obviously)
+multi-objs-y := $(foreach m, $(multi-used-y), $($(basename $(m))-objs))
+multi-objs-m := $(foreach m, $(multi-used-m), $($(basename $(m))-objs))
+
+cmd_link_multi = $(LD) $(EXTRA_LDFLAGS) -r -o $@ $(filter $($(basename $@)-objs),$^)
+
+# We would rather have a list of rules like
+#    foo.o: $(foo-objs)
+# but that's not so easy, so we rather make all composite objects depend
+# on the set of all their parts
+$(multi-used-y) : %.o: $(multi-objs-y) dummy
+   $(call if_changed,cmd_link_multi)
+
+$(multi-used-m) : %.o: $(multi-objs-m) dummy
+   $(call if_changed,cmd_link_multi)
 
 #
 # This make dependencies quickly
@@ -169,7 +180,7 @@
 
 ifdef _FASTDEP_ALL_SUB_DIRS
 $(patsubst %,_sfdep_%,$(_FASTDEP_ALL_SUB_DIRS)):
-   $(MAKE) -C $(patsubst _sfdep_%,%,$@) fastdep
+   @$(MAKE) -C $(patsubst _sfdep_%,%,$@) fastdep
 endif
 
 
@@ -181,7 +192,7 @@
 
 ifdef SUB_DIRS
 $(subdir-list) : dummy
-   $(MAKE) -C $(patsubst _subdir_%,%,$@)
+   @$(MAKE) -C $(patsubst _subdir_%,%,$@)
 endif
 
 #
@@ -194,11 +205,11 @@
 ifneq "$(strip $(MOD_SUB_DIRS))" ""
 .PHONY: $(patsubst %,_modsubdir_%,$(MOD_SUB_DIRS))
 $(patsubst %,_modsubdir_%,$(MOD_SUB_DIRS)) : dummy
-   $(MAKE) -C $(patsubst _modsubdir_%,%,$@) modules
+   @$(MAKE) -C $(patsubst _modsubdir_%,%,$@) modules
 
 .PHONY: $(patsubst %,_modinst_%,$(MOD_SUB_DIRS))
 $(patsubst %,_modinst_%,$(MOD_SUB_DIRS)) : dummy
-   $(MAKE) -C $(patsubst _modinst_%,%,$@) modules_install
+   @$(MAKE) -C $(patsubst _modinst_%,%,$@) modules_install
 endif
 
 .PHONY: modules
@@ -306,14 +317,10 @@
 endif # CONFIG_MODVERSIONS
 
 ifneq "$(strip $(export-objs))" ""
+
 $(export-objs): $(TOPDIR)/include/linux/modversions.h
-$(export-objs): %.o: %.c
-   $(CC) $(CFLAGS) $(EXTRA_CFLAGS) -DKBUILD_BASENAME=$(subst $(comma),_,$(subst -,_,$(*F))) $(CFLAGS_$@) -DEXPORT_SYMTAB -c $(@:.o=+
.c)
-   @ ( \
-       echo 'ifeq ($(strip $(subst $(comma),:,$(CFLAGS) $(EXTRA_CFLAGS) $(CFLAGS_$@) -DEXPORT_SYMTAB)),$$(strip $$(subst $$(comma),+
:,$$(CFLAGS) $$(EXTRA_CFLAGS) $$(CFLAGS_$@) -DEXPORT_SYMTAB)))' ; \
-       echo 'FILES_FLAGS_UP_TO_DATE += $@' ; \
-       echo 'endif' \
-   ) > $(dir $@)/.$(notdir $@).flags
+$(export-objs): export_flags := -DEXPORT_SYMTAB
+
 endif
 
 endif # CONFIG_MODULES
@@ -330,35 +337,48 @@
 include $(TOPDIR)/.hdepend
 endif
 
+# ---------------------------------------------------------------------------
+# Check if command line has changed
+
+# Usage:
+# normally one uses rules like
+#
+# %.o: %.c
+#    <command line>
+#
+# However, these only rebuild the target when the source has changed,
+# but not when e.g. the command or the flags on the command line changed.
+#
+# This extension allows to do the following:
 #
-# Find files whose flags have changed and force recompilation.
-# For safety, this works in the converse direction:
-#   every file is forced, except those whose flags are positively up-to-date.
-#
-FILES_FLAGS_UP_TO_DATE :=
-
-# For use in expunging commas from flags, which mung our checking.
-comma = ,
-
-FILES_FLAGS_EXIST := $(wildcard .*.flags)
-ifneq ($(FILES_FLAGS_EXIST),)
-include $(FILES_FLAGS_EXIST)
-endif
-
-FILES_FLAGS_CHANGED := $(strip \
-    $(filter-out $(FILES_FLAGS_UP_TO_DATE), \
-   $(O_TARGET) $(L_TARGET) $(active-objs) \
-   ))
-
-# A kludge: .S files don't get flag dependencies (yet),
-#   because that will involve changing a lot of Makefiles.  Also
-#   suppress object files explicitly listed in $(IGNORE_FLAGS_OBJS).
-#   This allows handling of assembly files that get translated into
-#   multiple object files (see arch/ia64/lib/idiv.S, for example).
-FILES_FLAGS_CHANGED := $(strip \
-    $(filter-out $(patsubst %.S, %.o, $(wildcard *.S) $(IGNORE_FLAGS_OBJS)), \
-    $(FILES_FLAGS_CHANGED)))
+# command = <command line>
+#
+# %.o: %.c dummy
+#   $(call if_changed,command)
+#
+# which will make sure to rebuild the target when either its prerequisites
+# change or the command line changes
+#
+# The magic works as follows:
+# The addition of dummy to the dependencies causes the rule for rebuilding
+# to be always executed. However, the if_changed function will generate
+# an empty command when 
+# o none of the prequesites changed (i.e $? is empty)
+# o the command line did not change (we compare the old command line,
+#   which is saved in .<target>.o, to the current command line using
+#   the two filter-out commands)
+
+# read all saved command lines
 
-ifneq ($(FILES_FLAGS_CHANGED),)
-$(FILES_FLAGS_CHANGED): dummy
+cmd_files := $(wildcard .*.cmd)
+ifneq ($(cmd_files),)
+  include $(cmd_files)
 endif
+
+# function to only execute the passed command if necessary
+
+if_changed = $(if $(strip $? \
+                $(filter-out $($(1)),$(cmd_$@))\
+           $(filter-out $(cmd_$@),$($(1)))),\
+          @echo $($(1)); $($(1)); echo 'cmd_$@ := $($(1))' > .$@.cmd)
+


Comments: webmaster (at) linuxhq.com.
Advertising: banners (at) linuxhq.com.
Compilation ©1998-2008 Linux Headquarters, Inc.