+SrcMakefiles := $(filter %Makefile %Makefile.tests,\
+ $(wildcard $(PROJ_SRC_DIR)/Makefile*))
+ObjMakefiles := $(subst $(PROJ_SRC_DIR),$(PROJ_OBJ_DIR),$(SrcMakefiles))
+ConfigureScript := $(PROJ_SRC_ROOT)/configure
+ConfigStatusScript := $(PROJ_OBJ_ROOT)/config.status
+MakefileConfigIn := $(strip $(wildcard $(PROJ_SRC_ROOT)/Makefile.config.in))
+MakefileCommonIn := $(strip $(wildcard $(PROJ_SRC_ROOT)/Makefile.common.in))
+MakefileConfig := $(PROJ_OBJ_ROOT)/Makefile.config
+MakefileCommon := $(PROJ_OBJ_ROOT)/Makefile.common
+PreConditions := $(ConfigStatusScript) $(ObjMakefiles)
+ifneq ($(MakefileCommonIn),)
+PreConditions += $(MakefileCommon)
+endif
+ifneq ($(MakefileConfigIn),)
+PreConditions += $(MakefileConfig)
+endif
+
+preconditions : $(PreConditions)
+
+#------------------------------------------------------------------------
+# Make sure the BUILT_SOURCES are built first
+#------------------------------------------------------------------------
+$(filter-out clean clean-local,$(UserTargets)):: $(BUILT_SOURCES)
+
+clean-local::
+ifneq ($(strip $(BUILT_SOURCES)),)
+ -$(Verb) $(RM) -f $(BUILT_SOURCES)
+endif
+
+ifneq ($(PROJ_OBJ_ROOT),$(PROJ_SRC_ROOT))
+spotless:
+ $(Verb) if test -x config.status ; then \
+ $(EchoCmd) Wiping out $(PROJ_OBJ_ROOT) ; \
+ $(MKDIR) .spotless.save ; \
+ $(MV) config.status .spotless.save ; \
+ $(MV) mklib .spotless.save ; \
+ $(MV) projects .spotless.save ; \
+ $(RM) -rf * ; \
+ $(MV) .spotless.save/config.status . ; \
+ $(MV) .spotless.save/mklib . ; \
+ $(MV) .spotless.save/projects . ; \
+ $(RM) -rf .spotless.save ; \
+ $(EchoCmd) Rebuilding configuration of $(PROJ_OBJ_ROOT) ; \
+ $(ConfigStatusScript) --recheck $(ConfigureScriptFLAGS) && \
+ $(ConfigStatusScript) ; \
+ else \
+ $(EchoCmd) "make spotless" can only be run from $(PROJ_OBJ_ROOT); \
+ fi
+endif
+
+$(BUILT_SOURCES) : $(ObjMakefiles)
+
+#------------------------------------------------------------------------
+# Make sure we're not using a stale configuration
+#------------------------------------------------------------------------
+reconfigure:
+ $(Echo) Reconfiguring $(PROJ_OBJ_ROOT)
+ $(Verb) cd $(PROJ_OBJ_ROOT) && \
+ if test -w $(PROJ_OBJ_ROOT)/config.cache ; then \
+ $(RM) $(PROJ_OBJ_ROOT)/config.cache ; \
+ fi ; \
+ $(ConfigStatusScript) --recheck $(ConfigureScriptFLAGS) && \
+ $(ConfigStatusScript)
+
+.PRECIOUS: $(ConfigStatusScript)
+$(ConfigStatusScript): $(ConfigureScript)
+ $(Echo) Reconfiguring with $<
+ $(Verb) cd $(PROJ_OBJ_ROOT) && \
+ if test -w $(PROJ_OBJ_ROOT)/config.cache ; then \
+ $(RM) $(PROJ_OBJ_ROOT)/config.cache ; \
+ fi ; \
+ $(ConfigStatusScript) --recheck $(ConfigureScriptFLAGS) && \
+ $(ConfigStatusScript)
+
+#------------------------------------------------------------------------
+# Make sure the configuration makefile is up to date
+#------------------------------------------------------------------------
+ifneq ($(MakefileConfigIn),)
+$(MakefileConfig): $(MakefileConfigIn) $(ConfigStatusScript)
+ $(Echo) Regenerating $@
+ $(Verb) cd $(PROJ_OBJ_ROOT) ; $(ConfigStatusScript) Makefile.config
+endif
+
+ifneq ($(MakefileCommonIn),)
+$(MakefileCommon): $(MakefileCommonIn) $(ConfigStatusScript)
+ $(Echo) Regenerating $@
+ $(Verb) cd $(PROJ_OBJ_ROOT) ; $(ConfigStatusScript) Makefile.common
+endif
+
+#------------------------------------------------------------------------
+# If the Makefile in the source tree has been updated, copy it over into the
+# build tree. But, only do this if the source and object makefiles differ
+#------------------------------------------------------------------------
+ifneq ($(PROJ_OBJ_DIR),$(PROJ_SRC_DIR))
+
+Makefile: $(PROJ_SRC_DIR)/Makefile
+ $(Echo) "Updating Makefile"
+ $(Verb) $(MKDIR) $(@D)
+ $(Verb) $(CP) -f $< $@
+
+# Copy the Makefile.* files unless we're in the root directory which avoids
+# the copying of Makefile.config.in or other things that should be explicitly
+# taken care of.
+$(PROJ_OBJ_DIR)/Makefile% : $(PROJ_SRC_DIR)/Makefile%
+ @case '$?' in \
+ *Makefile.rules) ;; \
+ *.in) ;; \
+ *) $(Echo) "Updating $(@F)" ; \
+ $(MKDIR) $(@D) ; \
+ $(CP) -f $< $@ ;; \
+ esac
+
+endif
+
+#------------------------------------------------------------------------
+# Set up the basic dependencies
+#------------------------------------------------------------------------
+$(UserTargets):: $(PreConditions)
+
+all:: all-local
+clean:: clean-local
+clean-all:: clean-local clean-all-local
+install:: install-local
+uninstall:: uninstall-local
+install-local:: all-local
+install-bytecode:: install-bytecode-local