+endif
+
+###############################################################################
+# DISTRIBUTION: Handle construction of a distribution tarball
+###############################################################################
+
+#------------------------------------------------------------------------
+# Define distribution related variables
+#------------------------------------------------------------------------
+DistName := $(LLVM_TARBALL_NAME)
+DistDir := $(BUILD_OBJ_ROOT)/$(DistName)
+TopDistDir := $(BUILD_OBJ_ROOT)/$(DistName)
+DistTarGZip := $(BUILD_OBJ_ROOT)/$(DistName).tar.gz
+DistZip := $(BUILD_OBJ_ROOT)/$(DistName).zip
+DistTarBZ2 := $(BUILD_OBJ_ROOT)/$(DistName).tar.bz2
+DistAlways := CREDITS.TXT LICENSE.TXT README.txt README AUTHORS COPYING \
+ ChangeLog INSTALL NEWS Makefile Makefile.common Makefile.rules \
+ Makefile.config.in configure autoconf
+DistOther := $(notdir $(wildcard \
+ $(BUILD_SRC_DIR)/*.h \
+ $(BUILD_SRC_DIR)/*.td \
+ $(BUILD_SRC_DIR)/*.def \
+ $(BUILD_SRC_DIR)/*.ll \
+ $(BUILD_SRC_DIR)/*.in))
+DistSources := $(Sources) $(EXTRA_DIST)
+DistSubDirs := $(SubDirs)
+DistFiles := $(DistAlways) $(DistSources) $(DistOther)
+
+#------------------------------------------------------------------------
+# We MUST build distribution with OBJ_DIR != SRC_DIR
+#------------------------------------------------------------------------
+ifeq ($(BUILD_SRC_DIR),$(BUILD_OBJ_DIR))
+dist dist-check dist-clean dist-gzip dist-bzip2 dist-zip ::
+ $(Echo) ERROR: Target $@ only available with OBJ_DIR != SRC_DIR
+
+DistCheckTop :=
+else
+
+DistCheckTop := check
+
+#------------------------------------------------------------------------
+# Prevent catastrophic remove
+#------------------------------------------------------------------------
+ifeq ($(LLVM_TARBALL_NAME),)
+$(error LLVM_TARBALL_NAME is empty. Please rerun configure)
+endif
+
+#------------------------------------------------------------------------
+# Prevent attempt to run dist targets from anywhere but the top level
+#------------------------------------------------------------------------
+ifneq ($(LEVEL),.)
+
+dist dist-check dist-clean dist-gzip dist-bzip2 dist-zip ::
+ $(Echo) ERROR: You must run $@ from $(BUILD_OBJ_ROOT)
+
+else
+
+#------------------------------------------------------------------------
+# Provide the top level targets
+#------------------------------------------------------------------------
+
+dist-gzip:: $(DistTarGZip)
+
+$(DistTarGZip) : distdir
+ $(Echo) Packing gzipped distribution tar file.
+ $(Verb) cd $(BUILD_OBJ_ROOT) ; $(TAR) chf - "$(DistName)" | gzip -c > "$(DistTarGZip)"
+
+dist-bzip2:: $(DistTarBZ2)
+
+$(DistTarBZ2) : distdir
+ $(Echo) Packing bzipped distribution tar file.
+ $(Verb) cd $(BUILD_OBJ_ROOT) ; $(TAR) chf - $(DistName) | $(BZIP2) -c >$(DistTarBZ2)
+
+dist-zip:: $(DistZip)
+
+$(DistZip) : distdir
+ $(Echo) Packing zipped distribution file.
+ $(Verb) rm -f $(DistZip)
+ $(Verb) cd $(BUILD_OBJ_ROOT) ; $(ZIP) -rq $(DistZip) $(DistName)
+
+dist :: $(DistTarGZip) $(DistTarBZ2) $(DistZip)
+ $(Echo) ===== DISTRIBUTION PACKAGING SUCESSFUL =====
+
+DistCheckDir := $(LLVM_OBJ_ROOT)/_distcheckdir
+
+dist-check:: $(DistCheckTop) $(DistTarGZip)
+ $(Echo) Checking distribution tar file.
+ $(Verb) if test -d $(DistCheckDir) ; then \
+ $(RM) -rf $(DistCheckDir) ; \
+ fi
+ $(Verb) $(MKDIR) $(DistCheckDir)
+ $(Verb) cd $(DistCheckDir) && \
+ $(MKDIR) $(DistCheckDir)/build && \
+ $(MKDIR) $(DistCheckDir)/install && \
+ gunzip -c $(DistTarGZip) | $(TAR) xf - && \
+ cd build && \
+ ../$(DistName)/configure --prefix="$(DistCheckDir)/install" \
+ --srcdir=../$(DistName) --with-llvmgccdir="$(LLVMGCCDIR)" && \
+ $(MAKE) check && \
+ $(MAKE) install && \
+ $(MAKE) uninstall && \
+ $(MAKE) dist && \
+ $(MAKE) clean && \
+ $(MAKE) dist-clean && \
+ $(EchoCmd) ===== $(DistTarGZip) Ready For Distribution =====
+
+dist-clean::
+ $(Echo) Cleaning distribution files
+ -$(Verb) $(RM) -rf $(DistTarGZip) $(DistTarBZ2) $(DistZip) $(DistName) $(DistCheckDir)
+
+endif
+
+#------------------------------------------------------------------------
+# Provide the recursive distdir target for building the distribution directory
+#------------------------------------------------------------------------
+distdir : $(DistSources)
+ $(Echo) Building Distribution Directory $(DistDir)
+ $(Verb) if test "$(DistDir)" = "$(TopDistDir)" ; then \
+ if test -d "$(DistDir)" ; then \
+ find $(DistDir) -type d ! -perm -200 -exec chmod u+w {} ';' || \
+ exit 1 ; \
+ fi ; \
+ $(EchoCmd) Removing $(DistDir) ; \
+ $(RM) -rf $(DistDir); \
+ fi
+ $(Verb) $(MKDIR) $(DistDir)
+ $(Verb) srcdirstrip=`echo "$(BUILD_SRC_DIR)" | sed 's|.|.|g'`; \
+ srcrootstrip=`echo "$(BUILD_SRC_ROOT)" | sed 's|.|.|g'`; \
+ for file in $(DistFiles) ; do \
+ case "$$file" in \
+ $(BUILD_SRC_DIR)/*) file=`echo "$$file" | sed "s#^$$srcdirstrip/##"`;; \
+ $(BUILD_SRC_ROOT)/*) file=`echo "$$file" | sed "s#^$$srcrootstrip/#$(BUILD_OBJ_ROOT)/#"`;; \
+ esac; \
+ if test -f "$$file" || test -d "$$file" ; then \
+ from_dir=. ; \
+ else \
+ from_dir=$(BUILD_SRC_DIR); \
+ fi; \
+ to_dir=`echo "$$file" | sed -e 's#/[^/]*$$##'`; \
+ if test "$$to_dir" != "$$file" && test "$$to_dir" != "."; then \
+ to_dir="$(DistDir)/$$dir"; \
+ $(MKDIR) "$$to_dir" ; \
+ else \
+ to_dir="$(DistDir)"; \
+ fi; \
+ mid_dir=`echo "$$file" | sed -n -e 's#^\(.*\)/[^/]*$$#\1#p'`; \
+ if test -n "$$mid_dir" ; then \
+ $(MKDIR) "$$to_dir/$$mid_dir" || exit 1; \
+ fi ; \
+ if test -d "$$from_dir/$$file"; then \
+ if test -d "$(BUILD_SRC_DIR)/$$file" && \
+ test "$$from_dir" != "$(BUILD_SRC_DIR)" ; then \
+ cp -pR "$(BUILD_SRC_DIR)/$$file" "$$to_dir" || exit 1; \
+ fi; \
+ cp -pR $$from_dir/$$file $$to_dir || exit 1; \
+ elif test -f "$$from_dir/$$file" ; then \
+ cp -p "$$from_dir/$$file" "$(DistDir)/$$file" || exit 1; \
+ elif test -L "$$from_dir/$$file" ; then \
+ cp -pd "$$from_dir/$$file" $(DistDir)/$$file || exit 1; \
+ elif echo "$(DistAlways)" | grep -v "$$file" >/dev/null ; then \
+ $(EchoCmd) "===== WARNING: Distribution Source $$from_dir/$$file Not Found!" ; \
+ elif test "$(Verb)" != '@' ; then \
+ $(EchoCmd) "Skipping non-existent $$from_dir/$$file" ; \
+ fi; \
+ done
+ $(Verb) for subdir in $(DistSubDirs) ; do \
+ if test "$$subdir" \!= "." ; then \
+ new_distdir="$(DistDir)/$$subdir" ; \
+ test -d "$$new_distdir" || $(MKDIR) "$$new_distdir" || exit 1; \
+ ( cd $$subdir && $(MAKE) DistDir="$$new_distdir" distdir ) || exit 1; \
+ fi; \
+ done
+ $(Verb) $(MAKE) DistDir="$(DistDir)" dist-hook || exit 1
+ -$(Verb) find $(DistDir) -type d ! -perm -777 -exec chmod a+rwx {} \; -o \
+ ! -type d ! -perm -444 -links 1 -exec chmod a+r {} \; -o \
+ ! -type d ! -perm -400 -exec chmod a+r {} \; -o \
+ ! -type d ! -perm -444 -exec $(SHELL) $(INSTALL_SH) -c -m a+r {} {} \; \
+ || chmod -R a+r $(DistDir)
+
+# This is invoked by distdir target, define it as a no-op to avoid errors if not
+# defined by user.
+dist-hook::