aboutsummaryrefslogtreecommitdiff
path: root/compiler-rt/make
diff options
context:
space:
mode:
authorDaniel Dunbar <daniel@zuster.org>2010-01-18 06:48:33 +0000
committerDaniel Dunbar <daniel@zuster.org>2010-01-18 06:48:33 +0000
commit56e0eb9fc9080e31002aad8ce2d3c5ffefe6229a (patch)
tree100d96213ad5bc21be0282810b1d3cba862cf787 /compiler-rt/make
parent40d6f65ae10fadba067ef95b3242326bfd40195d (diff)
downloadllvm-56e0eb9fc9080e31002aad8ce2d3c5ffefe6229a.tar.gz
llvm-56e0eb9fc9080e31002aad8ce2d3c5ffefe6229a.tar.bz2
llvm-56e0eb9fc9080e31002aad8ce2d3c5ffefe6229a.zip
Simplify subdirectory makefiles, and be more robust by checking that they define the appropriate variables.
llvm-svn: 93714
Diffstat (limited to 'compiler-rt/make')
-rw-r--r--compiler-rt/make/config.mk5
-rw-r--r--compiler-rt/make/subdir.mk68
-rw-r--r--compiler-rt/make/util.mk12
3 files changed, 76 insertions, 9 deletions
diff --git a/compiler-rt/make/config.mk b/compiler-rt/make/config.mk
index 485119186951..903424d01b3d 100644
--- a/compiler-rt/make/config.mk
+++ b/compiler-rt/make/config.mk
@@ -11,7 +11,8 @@ ProjObjRoot := $(ProjSrcRoot)
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 @@ LIPO := lipo
CP := cp
VERBOSE := 0
-DEBUGMAKE := 0
+DEBUGMAKE :=
###
# Automatic and derived variables.
diff --git a/compiler-rt/make/subdir.mk b/compiler-rt/make/subdir.mk
index 81e29582097b..ccde0dc8d260 100644
--- a/compiler-rt/make/subdir.mk
+++ b/compiler-rt/make/subdir.mk
@@ -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 @@ $(foreach config,$(ConfigsToTraverse), \
###
# 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
diff --git a/compiler-rt/make/util.mk b/compiler-rt/make/util.mk
index 4f65790845ef..2ce9a46a20cb 100644
--- a/compiler-rt/make/util.mk
+++ b/compiler-rt/make/util.mk
@@ -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.