# This Makefile is included from the other Makefiles
# It contains some overall targets...

# refresh Makefile and other stuff

PROGRAMS_WITH_GIT_HASH := hmc_tm invert

.SUFFIXES:

Makefile: ${top_srcdir}/Makefile.global $(srcdir)/Makefile.in $(abs_top_builddir)/config.status 
	cd $(abs_top_builddir) \
	  && CONFIG_FILES=$(subdir)/$@ CONFIG_HEADERS= $(SHELL) ./config.status

$(abs_top_builddir)/config.status: $(top_srcdir)/configure
	( cd ${abs_top_builddir} && $(SHELL) ./config.status --recheck ) 

$(abs_top_builddir)/config.h: $(top_srcdir)/config.h.in $(abs_top_builddir)/config.status $(top_srcdir)/configure
	( cd ${abs_top_builddir} && $(SHELL) ./config.status --header=config.h )

# rebuild configure if configure.in changes but ignore errors
# on many machines some of the macros fail to be recognized
# but the resulting configure still works
$(top_srcdir)/configure: $(top_srcdir)/configure.in 
	-( cd $(top_srcdir) && $(AUTOCONF) )

#dep rules

# PROGRAMS_WITH_GIT_HASH require git_hash.h which is dynamically built by a phony make target
# to prevent too frequent building of git_hash (slowing down the build)
# we filter the list of all objects and treat these separately
$(addsuffix .d, $(filter-out ${PROGRAMS_WITH_GIT_HASH},${ALLOBJ})): %.d: ${srcdir}/%.c Makefile
	@ $(CCDEP) ${DEPFLAGS} ${DEFS} ${INCLUDES} $< > $@

# dirty hack to prevent make from entering an infinite loop because a phony target is given as a real
# dependency (make will build invert.d and hmc_tm.d indefinitely)
# when git_hash.h does not exist (as checked using wildcard) it is given as a dependency of invert.d and hmc_tm.d
# once it exists, this is no longer the case
# while this does break updating of git_hash.h while the dependencies are built, this is quite
# irrelevant because it will be rebuilt during the compilation of either invert or hmc_tm
ifneq (git_hash.h, $(findstring git_hash.h,$(wildcard $(top_srcdir)/git_has*.h)))
$(addsuffix .d, $(filter ${PROGRAMS_WITH_GIT_HASH},${ALLOBJ})): %.d: ${srcdir}/%.c ${top_srcdir}/git_hash.h Makefile
	@ $(CCDEP) ${DEPFLAGS} ${DEFS} ${INCLUDES} $< > $@
else
$(addsuffix .d, $(filter ${PROGRAMS_WITH_GIT_HASH},${ALLOBJ})): %.d: ${srcdir}/%.c Makefile
	@ $(CCDEP) ${DEPFLAGS} ${DEFS} ${INCLUDES} $< > $@
endif

${top_builddir}/fixed_volume.h: ${top_srcdir}/fixed_volume.h.in ${top_builddir}/config.status
	cd ${abs_top_builddir} && CONFIG_FILES=fixed_volume.h CONFIG_HEADERS= $(SHELL) ${top_builddir}/config.status

all-recursive all-debug-recursive all-profile-recursive clean-recursive distclean-recursive compile-clean-recursive: Makefile
	@set fnord ${MAKEFLAGS}; amf=$$2; \
	dot_seen=no; \
	target=`echo $@ | sed s/-recursive//`; \
	list='$(SUBDIRS)'; for subdir in $$list; do \
	  echo "Making $$target in $$subdir"; \
	  local_target="$$target"; \
	  ( cd $$subdir && $(MAKE) $$local_target ) \
	    || case "$$amf" in *=*) exit 1;; *k*) fail=yes;; *) exit 1;; esac; \
	done; test -z "$$fail";
