[llvm-commits] [compiler-rt] r93714 - in /compiler-rt/trunk: Makefile lib/Makefile.mk lib/arm/Makefile.mk lib/i386/Makefile.mk lib/ppc/Makefile.mk lib/x86_64/Makefile.mk make/config.mk make/subdir.mk make/util.mk

Daniel Dunbar daniel at zuster.org
Sun Jan 17 22:48:33 PST 2010


Author: ddunbar
Date: Mon Jan 18 00:48:33 2010
New Revision: 93714

URL: http://llvm.org/viewvc/llvm-project?rev=93714&view=rev
Log:
Simplify subdirectory makefiles, and be more robust by checking that they define the appropriate variables.

Modified:
    compiler-rt/trunk/Makefile
    compiler-rt/trunk/lib/Makefile.mk
    compiler-rt/trunk/lib/arm/Makefile.mk
    compiler-rt/trunk/lib/i386/Makefile.mk
    compiler-rt/trunk/lib/ppc/Makefile.mk
    compiler-rt/trunk/lib/x86_64/Makefile.mk
    compiler-rt/trunk/make/config.mk
    compiler-rt/trunk/make/subdir.mk
    compiler-rt/trunk/make/util.mk

Modified: compiler-rt/trunk/Makefile
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/Makefile?rev=93714&r1=93713&r2=93714&view=diff

==============================================================================
--- compiler-rt/trunk/Makefile (original)
+++ compiler-rt/trunk/Makefile Mon Jan 18 00:48:33 2010
@@ -39,7 +39,8 @@
 
 help-hidden: help
 	@echo "Debugging variables:"
-	@echo "  DEBUGMAKE=1: enable some Makefile logging [default=0]"
+	@echo "  DEBUGMAKE=1: enable some Makefile logging [default=]"
+	@echo "           =2: enable more Makefile logging"
 	@echo
 	@echo "Debugging targets:"
 	@echo "  make-print-FOO: print information on the variable 'FOO'"
@@ -201,7 +202,8 @@
 ###
 # Include child makefile fragments
 
-$(foreach subdir,$(SubDirs),$(eval include $(subdir)/Makefile.mk))
+Dir := .
+include make/subdir.mk
 
 ###
 # Determine the actual inputs for an optimized library.
@@ -223,3 +225,8 @@
 $(foreach config,$(Configs), \
   $(foreach arch,$(Archs), \
     $(eval $(call Final_CNA_template,$(config),$(arch)))))
+
+ifneq ($(DEBUGMAKE),)
+  $(info MAKE: Done processing Makefile)
+  $(info  )
+endif

Modified: compiler-rt/trunk/lib/Makefile.mk
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/Makefile.mk?rev=93714&r1=93713&r2=93714&view=diff

==============================================================================
--- compiler-rt/trunk/lib/Makefile.mk (original)
+++ compiler-rt/trunk/lib/Makefile.mk Mon Jan 18 00:48:33 2010
@@ -7,7 +7,6 @@
 #
 #===------------------------------------------------------------------------===#
 
-Dir := lib
 SubDirs := i386 ppc x86_64 arm
 
 Sources := $(foreach file,$(wildcard $(Dir)/*.c),$(notdir $(file)))
@@ -16,5 +15,3 @@
 
 # FIXME: use automatic dependencies?
 Dependencies := $(wildcard $(Dir)/*.h)
-
-include make/subdir.mk

Modified: compiler-rt/trunk/lib/arm/Makefile.mk
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/arm/Makefile.mk?rev=93714&r1=93713&r2=93714&view=diff

==============================================================================
--- compiler-rt/trunk/lib/arm/Makefile.mk (original)
+++ compiler-rt/trunk/lib/arm/Makefile.mk Mon Jan 18 00:48:33 2010
@@ -7,7 +7,6 @@
 #
 #===------------------------------------------------------------------------===#
 
-Dir := lib/arm
 SubDirs := 
 OnlyArchs := armv6 armv7
 
@@ -18,5 +17,3 @@
 
 # FIXME: use automatic dependencies?
 Dependencies := $(wildcard lib/*.h $(Dir)/*.h)
-
-include make/subdir.mk

Modified: compiler-rt/trunk/lib/i386/Makefile.mk
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/i386/Makefile.mk?rev=93714&r1=93713&r2=93714&view=diff

==============================================================================
--- compiler-rt/trunk/lib/i386/Makefile.mk (original)
+++ compiler-rt/trunk/lib/i386/Makefile.mk Mon Jan 18 00:48:33 2010
@@ -7,7 +7,6 @@
 #
 #===------------------------------------------------------------------------===#
 
-Dir := lib/i386
 SubDirs := 
 OnlyArchs := i386
 
@@ -18,5 +17,3 @@
 
 # FIXME: use automatic dependencies?
 Dependencies := $(wildcard lib/*.h $(Dir)/*.h)
-
-include make/subdir.mk

Modified: compiler-rt/trunk/lib/ppc/Makefile.mk
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/ppc/Makefile.mk?rev=93714&r1=93713&r2=93714&view=diff

==============================================================================
--- compiler-rt/trunk/lib/ppc/Makefile.mk (original)
+++ compiler-rt/trunk/lib/ppc/Makefile.mk Mon Jan 18 00:48:33 2010
@@ -7,7 +7,6 @@
 #
 #===------------------------------------------------------------------------===#
 
-Dir := lib/ppc
 SubDirs := 
 OnlyArchs := ppc
 
@@ -18,5 +17,3 @@
 
 # FIXME: use automatic dependencies?
 Dependencies := $(wildcard lib/*.h $(Dir)/*.h)
-
-include make/subdir.mk

Modified: compiler-rt/trunk/lib/x86_64/Makefile.mk
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/x86_64/Makefile.mk?rev=93714&r1=93713&r2=93714&view=diff

==============================================================================
--- compiler-rt/trunk/lib/x86_64/Makefile.mk (original)
+++ compiler-rt/trunk/lib/x86_64/Makefile.mk Mon Jan 18 00:48:33 2010
@@ -7,7 +7,6 @@
 #
 #===------------------------------------------------------------------------===#
 
-Dir := lib/x86_64
 SubDirs := 
 OnlyArchs := x86_64
 
@@ -18,5 +17,3 @@
 
 # FIXME: use automatic dependencies?
 Dependencies := $(wildcard lib/*.h $(Dir)/*.h)
-
-include make/subdir.mk

Modified: compiler-rt/trunk/make/config.mk
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/make/config.mk?rev=93714&r1=93713&r2=93714&view=diff

==============================================================================
--- compiler-rt/trunk/make/config.mk (original)
+++ compiler-rt/trunk/make/config.mk Mon Jan 18 00:48:33 2010
@@ -11,7 +11,8 @@
 Configs := Debug Release Profile
 
 # The full list of architectures we support.
-Archs := i386 ppc x86_64 armv6 armv7
+Archs := i386 ppc x86_64
+# armv6 armv7
 
 # If TargetArch is defined, only build for that architecture (and don't use
 # -arch).
@@ -66,7 +67,7 @@
 CP := cp
 
 VERBOSE := 0
-DEBUGMAKE := 0
+DEBUGMAKE :=
 
 ###
 # Automatic and derived variables.

Modified: compiler-rt/trunk/make/subdir.mk
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/make/subdir.mk?rev=93714&r1=93713&r2=93714&view=diff

==============================================================================
--- compiler-rt/trunk/make/subdir.mk (original)
+++ compiler-rt/trunk/make/subdir.mk Mon Jan 18 00:48:33 2010
@@ -1,13 +1,20 @@
 # This file is intended to be included from each subdirectory makefile.
+#
+# Subdirectory makefiles must define:
+#   SubDirs - The subdirectories to traverse.
+#   ObjNames - The objects available in that directory.
+#   Target - The library configuration the objects should go in (Generic or
+#            Optimized)
+#   Dependencies - Any dependences for the object files.
+#
+# Subdirectory makefiles may define:
+#   OnlyArchs - Only build the objects for the listed archs.
+#   OnlyConfigs - Only build the objects for the listed configurations.
 
 ifeq ($(Dir),)
   $(error "No Dir variable defined.")
 endif
 
-ifeq ($(DEBUGMAKE),1)
-  $(info MAKE: $(Dir): Processing subdirectory)
-endif
-
 # Expand template for each configuration and architecture.
 #
 # FIXME: This level of logic should be in primary Makefile?
@@ -35,13 +42,60 @@
 ###
 # Include child makefile fragments
 
+# The list of variables which are intended to be overridden in a subdirectory
+# makefile.
+RequiredSubdirVariables := SubDirs ObjNames Target Dependencies
+OptionalSubdirVariables := OnlyArchs OnlyConfigs
+
+# Template: subdir_traverse_template subdir
+define subdir_traverse_template
+$(call Set,Dir,$(1))
+ifneq ($(DEBUGMAKE),)
+  $$(info MAKE: $(Dir): Processing subdirectory)
+endif
+
+# Reset subdirectory specific variables to sentinel value.
+$$(foreach var,$$(RequiredSubdirVariables) $$(OptionalSubdirVariables),\
+  $$(call Set,$$(var),UNDEFINED))
+
+# Get the subdirectory variables.
+include $(1)/Makefile.mk
+
+ifeq ($(DEBUGMAKE),2)
+$$(foreach var,$(RequiredSubdirVariables) $(OptionalSubdirVariables),\
+  $$(if $$(call strneq UNDEFINED,$$($$(var))), \
+	$$(info MAKE: $(Dir): $$(var) is defined), \
+	$$(info MAKE: $(Dir): $$(var) is undefined)))
+endif
+
+# Check for undefined required variables, and unset sentinel value from optional
+# variables.
+$$(foreach var,$(RequiredSubdirVariables),\
+  $$(if $$(call strneq UNDEFINED,$$($$(var))), \
+	$$(error $(Dir): variable '$$(var)' was not undefined)))
+$$(foreach var,$(OptionalSubdirVariables),\
+  $$(if $$(call strneq UNDEFINED,$$($$(var))),, \
+	$$(call Set,$$(var),)))
+
+# Recurse.
+include make/subdir.mk
+
+# Restore directory variable.
+$$(call Set,Dir,$(1))
+
+ifneq ($(DEBUGMAKE),)
+  $$(info MAKE: $$(Dir): Done processing subdirectory)
+endif
+endef
+
 # Evaluate this now so we do not have to worry about order of evaluation.
 SubDirsList := $(SubDirs:%=$(Dir)/%)
 ifeq ($(SubDirsList),)
 else
-  ifeq ($(DEBUGMAKE),1)
+  ifneq ($(DEBUGMAKE),)
     $(info MAKE: Descending into subdirs: $(SubDirsList))
   endif
-  $(foreach subdir,$(SubDirsList),$(eval include $(subdir)/Makefile.mk))
-endif
 
+  $(foreach subdir,$(SubDirsList),\
+	$(eval $(call subdir_traverse_template,$(subdir))))
+endif

Modified: compiler-rt/trunk/make/util.mk
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/make/util.mk?rev=93714&r1=93713&r2=93714&view=diff

==============================================================================
--- compiler-rt/trunk/make/util.mk (original)
+++ compiler-rt/trunk/make/util.mk Mon Jan 18 00:48:33 2010
@@ -3,6 +3,18 @@
 ###
 # Utility functions
 
+# Function: streq LHS RHS
+#
+# Return "true" if LHS == RHS, otherwise "".
+#
+# LHS == RHS <=> (LHS subst RHS is empty) and (RHS subst LHS is empty)
+streq = $(if $(1),$(if $(subst $(1),,$(2))$(subst $(2),,$(1)),,true),$(if $(2),,true))
+
+# Function: strneq LHS RHS
+#
+# Return "true" if LHS != RHS, otherwise "".
+strneq = $(if $(call streq,$(1),$(2)),,true)
+
 # Function: Set variable value
 #
 # Set the given make variable to the given value.





More information about the llvm-commits mailing list