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

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

Advertisement

Kernel v2.5.22 /Rules.make

Filename:/Rules.make
Lines Added:165
Lines Deleted:128
Also changed in: (Previous) 2.5.21  2.5.20  2.5.19  2.5.18  2.5.17  2.5.13 
(Following) 2.5.23  2.5.24  2.5.25  2.5.30  2.5.35  2.5.40 

Location
[  2.5.22
   o  Rules.make

Patch

diff -Nru a/Rules.make b/Rules.make
--- a/Rules.make   Sun Jun 16 19:31:40 2002
+++ b/Rules.make   Sun Jun 16 19:31:40 2002
@@ -48,12 +48,9 @@
 obj-y      := $(patsubst %/, %/built-in.o, $(obj-y))
 obj-m      := $(filter-out %/, $(obj-m))
 
-# If a dir is selected in $(subdir-y) and also mentioned in $(mod-subdirs),
-# add it to $(subdir-m)
+# Subdirectories we need to descend into
 
-both-m          := $(filter $(mod-subdirs), $(subdir-y))
 subdir-ym   := $(sort $(subdir-y) $(subdir-m))
-subdir-ymn   := $(sort $(subdir-ym) $(subdir-n) $(subdir-))
 
 # export.o is never a composite object, since $(export-objs) has a
 # fixed meaning (== objects which EXPORT_SYMBOL())
@@ -85,8 +82,116 @@
 real-objs-y := $(foreach m, $(filter-out $(subdir-obj-y), $(obj-y)), $(if $($(m:.o=-objs)),$($(m:.o=-objs)),$(m))) $(EXTRA_TARGETS)
 real-objs-m := $(foreach m, $(obj-m), $(if $($(m:.o=-objs)),$($(m:.o=-objs)),$(m)))
 
-# Get things started.
+# Only build module versions for files which are selected to be built
+export-objs := $(filter $(export-objs),$(real-objs-y) $(real-objs-m))
+
+# The temporary file to save gcc -MD generated dependencies must not
+# contain a comma
+depfile = $(subst $(comma),_,$(@D)/.$(@F).d)
+
+# We're called for one of three purposes:
+# o fastdep: build module version files (.ver) for $(export-objs) in
+#   the current directory
+# o modules_install: install the modules in the current directory
+# o build: When no target is given, first_rule is the default and
+#   will build the built-in and modular objects in this dir
+#   (or a subset thereof, depending on $(KBUILD_MODULES),$(KBUILD_BUILTIN)
+#   When targets are given directly (like foo.o), we just build these
+#   targets (That happens when someone does make some/dir/foo.[ois])
+
+ifeq ($(MAKECMDGOALS),fastdep)
+
+# ===========================================================================
+# Module versions
+# ===========================================================================
+
+ifeq ($(strip $(export-objs)),)
+
+# If we don't export any symbols in this dir, just descend
+# ---------------------------------------------------------------------------
+
+fastdep: sub_dirs
+   @echo -n
+
+else
+
+# This sets version suffixes on exported symbols
+# ---------------------------------------------------------------------------
+
+MODVERDIR := $(TOPDIR)/include/linux/modules/$(RELDIR)
+
+#
+# Added the SMP separator to stop module accidents between uniprocessor
+# and SMP Intel boxes - AC - from bits by Michael Chastain
+#
+
+ifdef CONFIG_SMP
+   genksyms_smp_prefix := -p smp_
+else
+   genksyms_smp_prefix := 
+endif
+
+$(MODVERDIR)/$(real-objs-y:.o=.ver): modkern_cflags := $(CFLAGS_KERNEL)
+$(MODVERDIR)/$(real-objs-m:.o=.ver): modkern_cflags := $(CFLAGS_MODULE)
+$(MODVERDIR)/$(export-objs:.o=.ver): export_flags   := -D__GENKSYMS__
+
+c_flags = -Wp,-MD,$(depfile) $(CFLAGS) $(NOSTDINC_FLAGS) \
+     $(modkern_cflags) $(EXTRA_CFLAGS) $(CFLAGS_$(*F).o) \
+     -DKBUILD_BASENAME=$(subst $(comma),_,$(subst -,_,$(*F))) \
+     $(export_flags) 
+
+# Our objects only depend on modversions.h, not on the individual .ver
+# files (fix-dep filters them), so touch modversions.h if any of the .ver
+# files changes
+
+quiet_cmd_cc_ver_c = MKVER  include/linux/modules/$(RELDIR)/$*.ver
+define cmd_cc_ver_c
+   mkdir -p $(dir $@); \
+   $(CPP) $(c_flags) $< | $(GENKSYMS) $(genksyms_smp_prefix) \
+     -k $(VERSION).$(PATCHLEVEL).$(SUBLEVEL) > $@.tmp; \
+   if [ ! -r $@ ] || cmp -s $@ $@.tmp; then \
+     touch $(TOPDIR)/include/linux/modversions.h; \
+   fi; \
+   mv -f $@.tmp $@
+endef
+
+$(MODVERDIR)/%.ver: %.c FORCE
+   @$(call if_changed_dep,cc_ver_c)
+
+targets := $(addprefix $(MODVERDIR)/,$(export-objs:.o=.ver))
+
+fastdep: $(targets) sub_dirs
+   @mkdir -p $(TOPDIR)/.tmp_export-objs/modules/$(RELDIR)
+   @touch $(addprefix $(TOPDIR)/.tmp_export-objs/modules/$(RELDIR)/,$(export-objs:.o=.ver))
+
+endif # export-objs 
+
+else # ! fastdep
+ifeq ($(MAKECMDGOALS),modules_install)
+
+# ==========================================================================
+# Installing modules
+# ==========================================================================
+
+.PHONY: modules_install
+
+modules_install: sub_dirs
+ifneq ($(obj-m),)
+   @echo Installing modules in $(MODLIB)/kernel/$(RELDIR)
+   @mkdir -p $(MODLIB)/kernel/$(RELDIR)
+   @cp $(obj-m) $(MODLIB)/kernel/$(RELDIR)
+else
+   @echo -n
+endif
+
+else # ! modules_install
+
 # ==========================================================================
+# Building
+# ==========================================================================
+
+# If a Makefile does define neither O_TARGET nor L_TARGET,
+# use a standard O_TARGET named "built-in.o"
 
 ifndef O_TARGET
 ifndef L_TARGET
@@ -103,15 +208,9 @@
 # Compile C sources (.c)
 # ---------------------------------------------------------------------------
 
-# If we don't know if built-in or modular, assume built-in.
-# Only happens in Makefiles which override the default first_rule:
+# Default is built-in, unless we know otherwise
 modkern_cflags := $(CFLAGS_KERNEL)
 
-$(real-objs-y)        : modkern_cflags := $(CFLAGS_KERNEL)
-$(real-objs-y:.o=.i)  : modkern_cflags := $(CFLAGS_KERNEL)
-$(real-objs-y:.o=.s)  : modkern_cflags := $(CFLAGS_KERNEL)
-$(real-objs-y:.o=.lst): modkern_cflags := $(CFLAGS_KERNEL)
-
 $(real-objs-m)        : modkern_cflags := $(CFLAGS_MODULE)
 $(real-objs-m:.o=.i)  : modkern_cflags := $(CFLAGS_MODULE)
 $(real-objs-m:.o=.lst): modkern_cflags := $(CFLAGS_MODULE)
@@ -121,60 +220,59 @@
 $(export-objs:.o=.s)  : export_flags   := $(EXPORT_FLAGS)
 $(export-objs:.o=.lst): export_flags   := $(EXPORT_FLAGS)
 
-c_flags = $(CFLAGS) $(NOSTDINC_FLAGS) $(modkern_cflags) $(EXTRA_CFLAGS) $(CFLAGS_$(*F).o) -DKBUILD_BASENAME=$(subst $(comma),_,$(su+
bst -,_,$(*F))) $(export_flags) 
+c_flags = -Wp,-MD,$(depfile) $(CFLAGS) $(NOSTDINC_FLAGS) \
+     $(modkern_cflags) $(EXTRA_CFLAGS) $(CFLAGS_$(*F).o) \
+     -DKBUILD_BASENAME=$(subst $(comma),_,$(subst -,_,$(*F))) \
+     $(export_flags) 
 
 quiet_cmd_cc_s_c = CC     $(RELDIR)/$@
 cmd_cc_s_c       = $(CC) $(c_flags) -S -o $@ $< 
 
 %.s: %.c FORCE
-   $(call cmd,cmd_cc_s_c)
+   $(call if_changed_dep,cc_s_c)
 
 quiet_cmd_cc_i_c = CPP    $(RELDIR)/$@
 cmd_cc_i_c       = $(CPP) $(c_flags)   -o $@ $<
 
 %.i: %.c FORCE
-   $(call cmd,cmd_cc_i_c)
+   $(call if_changed_dep,cc_i_c)
 
 quiet_cmd_cc_o_c = CC     $(RELDIR)/$@
-cmd_cc_o_c       = $(CC) -Wp,-MD,.$(subst /,_,$@).d $(c_flags) -c -o $@ $<
+cmd_cc_o_c       = $(CC) $(c_flags) -c -o $@ $<
 
 %.o: %.c FORCE
    $(call if_changed_dep,cc_o_c)
 
-quiet_cmd_cc_lst_c = Generating $(RELDIR)/$@
+quiet_cmd_cc_lst_c = '  Generating $(RELDIR)/$@'
 cmd_cc_lst_c     = $(CC) $(c_flags) -g -c -o $*.o $< && $(TOPDIR)/scripts/makelst $*.o $(TOPDIR)/System.map $(OBJDUMP) > $@
 
 %.lst: %.c FORCE
-   $(call cmd,cmd_cc_lst_c)
+   $(call if_changed_dep,cc_lst_c)
 
 # Compile assembler sources (.S)
 # ---------------------------------------------------------------------------
 
-# FIXME (s.a.)
 modkern_aflags := $(AFLAGS_KERNEL)
 
-$(real-objs-y)      : modkern_aflags := $(AFLAGS_KERNEL)
-$(real-objs-y:.o=.s): modkern_aflags := $(AFLAGS_KERNEL)
-
 $(real-objs-m)      : modkern_aflags := $(AFLAGS_MODULE)
 $(real-objs-m:.o=.s): modkern_aflags := $(AFLAGS_MODULE)
 
-a_flags = $(AFLAGS) $(NOSTDINC_FLAGS) $(modkern_aflags) $(EXTRA_AFLAGS) $(AFLAGS_$(*F).o)
+a_flags = -Wp,-MD,$(depfile) $(AFLAGS) $(NOSTDINC_FLAGS) \
+     $(modkern_aflags) $(EXTRA_AFLAGS) $(AFLAGS_$(*F).o)
 
 quiet_cmd_as_s_S = CPP    $(RELDIR)/$@
 cmd_as_s_S       = $(CPP) $(a_flags)   -o $@ $< 
 
 %.s: %.S FORCE
-   $(call cmd,cmd_as_s_S)
+   $(call if_changed_dep,as_s_S)
 
 quiet_cmd_as_o_S = AS     $(RELDIR)/$@
-cmd_as_o_S       = $(CC) -Wp,-MD,.$(subst /,_,$@).d $(a_flags) -c -o $@ $<
+cmd_as_o_S       = $(CC) $(a_flags) -c -o $@ $<
 
 %.o: %.S FORCE
    $(call if_changed_dep,as_o_S)
 
-# If a Makefile does define neither O_TARGET nor L_TARGET,
-# use a standard O_TARGET named "built-in.o"
+targets += $(real-objs-y) $(real-objs-m) $(EXTRA_TARGETS) $(MAKECMDGOALS)
 
 # Build the compiled-in targets
 # ---------------------------------------------------------------------------
@@ -193,7 +291,9 @@
             rm -f $@; $(AR) rcs $@)
 
 $(O_TARGET): $(obj-y) FORCE
-   $(call if_changed,cmd_link_o_target)
+   $(call if_changed,link_o_target)
+
+targets += $(O_TARGET)
 endif # O_TARGET
 
 #
@@ -204,7 +304,9 @@
 cmd_link_l_target = rm -f $@; $(AR) $(EXTRA_ARFLAGS) rcs $@ $(obj-y)
 
 $(L_TARGET): $(obj-y) FORCE
-   $(call if_changed,cmd_link_l_target)
+   $(call if_changed,link_l_target)
+
+targets += $(L_TARGET)
 endif
 
 #
@@ -219,10 +321,12 @@
 # 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) FORCE
-   $(call if_changed,cmd_link_multi)
+   $(call if_changed,link_multi)
 
 $(multi-used-m) : %.o: $(multi-objs-m) FORCE
-   $(call if_changed,cmd_link_multi)
+   $(call if_changed,link_multi)
+
+targets += $(multi-used-y) $(multi-used-m)
 
 # Compile programs on the host
 # ===========================================================================
@@ -233,7 +337,8 @@
 
 quiet_cmd_host_cc__c  = HOSTCC $(RELDIR)/$@
 cmd_host_cc__c        = $(HOSTCC) -Wp,-MD,.$(subst /,_,$@).d \
-         $(HOSTCFLAGS) $(HOST_EXTRACFLAGS) -o $@ $<
+         $(HOSTCFLAGS) $(HOST_EXTRACFLAGS) \
+         $(HOST_LOADLIBES) -o $@ $<
 
 $(host-progs-single): %: %.c FORCE
    $(call if_changed_dep,host_cc__c)
@@ -250,51 +355,26 @@
          $(HOST_LOADLIBES)
 
 $(host-progs-multi): %: $(host-progs-multi-objs) FORCE
-   $(call if_changed,cmd_host_cc__o)
-
-
-# Descending when making module versions
-# ---------------------------------------------------------------------------
-
-fastdep-list := $(addprefix _sfdep_,$(subdir-ymn))
+   $(call if_changed,host_cc__o)
 
-.PHONY: fastdep $(fastdep-list)
+targets += $(host-progs-single) $(host-progs-multi-objs) $(host-progs-multi) 
 
-fastdep: $(fastdep-list)
+endif # ! modules_install
+endif # ! fastdep
 
-$(fastdep-list):
-   @$(MAKE) -C $(patsubst _sfdep_%,%,$@) fastdep
-
-# Descending when building
-# ---------------------------------------------------------------------------
-
-subdir-list := $(addprefix _subdir_,$(subdir-ym))
-
-.PHONY: sub_dirs $(subdir-list)
-
-sub_dirs: $(subdir-list)
-
-$(subdir-list):
-   @$(MAKE) -C $(patsubst _subdir_%,%,$@)
+# ===========================================================================
+# Generic stuff
+# ===========================================================================
 
-# Descending and installing modules
+# Descending
 # ---------------------------------------------------------------------------
 
-modinst-list := $(addprefix _modinst_,$(subdir-ym))
+.PHONY: sub_dirs $(subdir-ym)
 
-.PHONY: modules_install _modinst_ $(modinst-list)
+sub_dirs: $(subdir-ym)
 
-modules_install: $(modinst-list)
-ifneq ($(obj-m),)
-   @echo Installing modules in $(MODLIB)/kernel/$(RELDIR)
-   @mkdir -p $(MODLIB)/kernel/$(RELDIR)
-   @cp $(obj-m) $(MODLIB)/kernel/$(RELDIR)
-else
-   @echo -n
-endif
-
-$(modinst-list):
-   @$(MAKE) -C $(patsubst _modinst_%,%,$@) modules_install
+$(subdir-ym):
+   @$(MAKE) -C $@ $(MAKECMDGOALS)
 
 # Add FORCE to the prequisites of a target to force it to be always rebuilt.
 # ---------------------------------------------------------------------------
@@ -304,62 +384,11 @@
 FORCE:
 
 #
-# This is useful for testing
-# FIXME: really?
-script:
-   $(SCRIPT)
-
-#
 # This sets version suffixes on exported symbols
 # Separate the object into "normal" objects and "exporting" objects
 # Exporting objects are: all objects that define symbol tables
 #
 
-ifdef CONFIG_MODVERSIONS
-ifneq "$(strip $(export-objs))" ""
-
-MODVERDIR := $(TOPDIR)/include/linux/modules/$(RELDIR)
-
-#
-# Added the SMP separator to stop module accidents between uniprocessor
-# and SMP Intel boxes - AC - from bits by Michael Chastain
-#
-
-ifdef CONFIG_SMP
-   genksyms_smp_prefix := -p smp_
-else
-   genksyms_smp_prefix := 
-endif
-
-# We don't track dependencies for .ver files, so we FORCE to check
-# them always (i.e. always at "make dep" time).
-
-quiet_cmd_create_ver = Creating include/linux/modules/$(RELDIR)/$*.ver
-cmd_create_ver = $(CC) $(CFLAGS) $(EXTRA_CFLAGS) -E -D__GENKSYMS__ $< | \
-       $(GENKSYMS) $(genksyms_smp_prefix) -k $(VERSION).$(PATCHLEVEL).$(SUBLEVEL) > $@.tmp
-
-$(MODVERDIR)/%.ver: %.c FORCE
-   @mkdir -p $(dir $@)
-   @$(call cmd,cmd_create_ver)
-   @if [ -r $@ ] && cmp -s $@ $@.tmp; then \
-     rm -f $@.tmp; \
-   else \
-     touch $(TOPDIR)/include/linux/modversions.h; \
-     mv -f $@.tmp $@; \
-   fi
-
-# updates .ver files but not modversions.h
-fastdep: $(addprefix $(MODVERDIR)/,$(export-objs:.o=.ver))
-ifneq ($(export-objs),)
-   @mkdir -p $(TOPDIR)/.tmp_export-objs/modules/$(RELDIR)
-   @touch $(addprefix $(TOPDIR)/.tmp_export-objs/modules/$(RELDIR)/,$(export-objs:.o=.ver))
-endif
-
-
-endif # export-objs 
-
-endif # CONFIG_MODVERSIONS
-
 # ---------------------------------------------------------------------------
 # Check if command line has changed
 
@@ -391,9 +420,14 @@
 #   which is saved in .<target>.o, to the current command line using
 #   the two filter-out commands)
 
-# read all saved command lines and dependencies
+# Read all saved command lines and dependencies for the $(targets) we
+# may be building above, using $(if_changed{,_dep}). As an
+# optimization, we don't need to read them if the target does not
+# exist, we will rebuild anyway in that case.
+
+targets := $(wildcard $(sort $(targets)))
+cmd_files := $(wildcard $(foreach f,$(targets),$(dir $(f)).$(notdir $(f)).cmd))
 
-cmd_files := $(wildcard .*.cmd)
 ifneq ($(cmd_files),)
   include $(cmd_files)
 endif
@@ -401,9 +435,12 @@
 # function to only execute the passed command if necessary
 
 if_changed = $(if $(strip $? \
-                $(filter-out $($(1)),$(cmd_$(@F)))\
-           $(filter-out $(cmd_$(@F)),$($(1)))),\
-          @$(if $($(quiet)$(1)),echo '  $($(quiet)$(1))' &&) $($(1)) && echo 'cmd_$@ := $($(1))' > $(@D)/.$(@F).cmd)
+                $(filter-out $(cmd_$(1)),$(cmd_$@))\
+           $(filter-out $(cmd_$@),$(cmd_$(1)))),\
+   @set -e; \
+   $(if $($(quiet)cmd_$(1)),echo '  $($(quiet)cmd_$(1))';) \
+   $(cmd_$(1)); \
+   echo 'cmd_$@ := $(cmd_$(1))' > $(@D)/.$(@F).cmd)
 
 
 # execute the command and also postprocess generated .d dependencies
@@ -415,9 +452,9 @@
    @set -e; \
    $(if $($(quiet)cmd_$(1)),echo '  $($(quiet)cmd_$(1))';) \
    $(cmd_$(1)); \
-   $(TOPDIR)/scripts/fixdep $(subst /,_,$@) $(TOPDIR) '$(cmd_$(1))' > .$(subst /,_,$@).tmp; \
-   rm -f .$(subst /,_,$@).d; \
-   mv -f .$(subst /,_,$@).tmp .$(subst /,_,$@).cmd )
+   $(TOPDIR)/scripts/fixdep $(depfile) $@ $(TOPDIR) '$(cmd_$(1))' > $(@D)/.$(@F).tmp; \
+   rm -f $(depfile); \
+   mv -f $(@D)/.$(@F).tmp $(@D)/.$(@F).cmd)
 
 # If quiet is set, only print short version of command
 


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