BUG_DESCRIPTION = \
  "" \
  "**********************************************************************************" \
  "****************************** D E S C R I P T I O N *****************************" \
  "**********************************************************************************" \
  "" \
  "This single makefile purpose is to demonstrate what seems to be a bug in GNU make." \
  "" \
  "The following text excerpt from make.info:" \
  "" \
  "  > How Makefiles Are Remade" \
  "  > ========================" \
  "  > " \
  "  >    Sometimes makefiles can be remade from other files, such as RCS or" \
  "  > SCCS files.  If a makefile can be remade from other files, you probably" \
  "  > want `make' to get an up-to-date version of the makefile to read in." \
  "  > " \
  "  >    To this end, after reading in all makefiles, `make' will consider" \
  "  > each as a goal target and attempt to update it.  If a makefile has a" \
  "  > rule which says how to update it (found either in that very makefile or" \
  "  > in another one) or if an implicit rule applies to it (*note Using" \
  "  > Implicit Rules: Implicit Rules.), it will be updated if necessary." \
  "  > After all makefiles have been checked, if any have actually been" \
  "  > changed, `make' starts with a clean slate and reads all the makefiles" \
  "  > over again.  (It will also attempt to update each of them over again," \
  "  > but normally this will not change them again, since they are already up" \
  "  > to date.)" \
  "" \
  "While this was found to be correct under Solaris 2.6, this code demonstrates that" \
  "the process will fail to be done in a single make run under Linux RedHat 7.3..." \
  "" \
  "This Makefile includes make code from $(MAKEFILE_DEP), a dependency file created on the fly." \
  "Code is written in such a way that it takes 3 additional make internal runs to build $(MAKEFILE_DEP)" \
  "" \
  "Typing $(MAKE) under Solaris 2.6 yields" \
  "" \
  "  >   **DEBUG ** -include $$(MAKEFILE_DEP) = $(MAKEFILE_DEP) ->" \
  "  >   " \
  "  >   **DEBUG ** -include $$(MAKEFILE_DEP) = $(MAKEFILE_DEP) -> -r--r--r--   1 tgaillar      292 Jul 27 11:35 $(MAKEFILE_DEP)" \
  "  >   " \
  "  >   **DEBUG ** -include $$(MAKEFILE_DEP) = $(MAKEFILE_DEP) -> -r--r--r--   1 tgaillar      415 Jul 27 11:35 $(MAKEFILE_DEP)" \
  "  >   " \
  "  >   **DEBUG ** -include $$(MAKEFILE_DEP) = $(MAKEFILE_DEP) -> -r--r--r--   1 tgaillar      510 Jul 27 11:35 $(MAKEFILE_DEP)" \
  "  >   " \
  "" \
  "while it will take at least 2 make runs under GNU/Linux RedHat 7.3 to reach step 3" \
  "" \
  "  >   **DEBUG ** -include $$(MAKEFILE_DEP) = $(MAKEFILE_DEP) ->" \
  "  >   " \
  "  >   **DEBUG ** -include $$(MAKEFILE_DEP) = $(MAKEFILE_DEP) -> -r--r--r--   1 tgaillar      292 Jul 27 12:09 $(MAKEFILE_DEP)" \
  "  >   " \
  "  > GNU Make bug detected, please re-run $(MAKE) to complete and get bug description" \
  "  > $(MAKE): *** [all] Error 2" \
  "  >   " \
  "  > $(shell hostname):$(shell /bin/pwd) ( ) $(MAKE)" \
  "  >   " \
  "  >   **DEBUG ** -include $$(MAKEFILE_DEP) = $(MAKEFILE_DEP) -> -r--r--r--   1 tgaillar      415 Jul 27 12:09 $(MAKEFILE_DEP)" \
  "  >   " \
  "  >   **DEBUG ** -include $$(MAKEFILE_DEP) = $(MAKEFILE_DEP) -> -r--r--r--   1 tgaillar      510 Jul 27 12:09 $(MAKEFILE_DEP)" \
  "  >   " \
  "" \
  "Once you can read this text, it means the $(MAKEFILE_DEP) file has been fully built." \
  "It has now been removed so you can re-run $(MAKE) and see the problem again, if any." \
  "" \
  "Please have a look at $(MAKEFILE_DEP)-1, $(MAKEFILE_DEP)-2 and $(MAKEFILE_DEP)-3, they" \
  "show the contents of $(MAKEFILE_DEP) at $(MAKE) internal runs 1, 2 and 3." \
  ""

# #################################################################
# ######################### T E S T   C O D E #####################
# #################################################################

#
# Basic targets
#

.PHONY: all
all:

.PHONY: realclean
realclean:

.PHONY: __FORCE__
__FORCE__: ;


#
# Include (and "loudly" track) Makefile dependency
#

MAKEFILE_DEP = Makefile.dep
-include $(MAKEFILE_DEP)

$(shell echo "" 1>&2)
$(shell echo -n "  **DEBUG ** -include \$$(MAKEFILE_DEP) = $(MAKEFILE_DEP) -> " 1>&2)
$(shell [   -r "$(MAKEFILE_DEP)" ]  && ls -l $(MAKEFILE_DEP) 1>&2)
$(shell [ ! -r "$(MAKEFILE_DEP)" ]  && echo "" 1>&2)
$(shell [ -r "$(MAKEFILE_DEP)-2" ] && cp -f $(MAKEFILE_DEP)-2 $(MAKEFILE_DEP)-1 1>&2)
$(shell [ -r "$(MAKEFILE_DEP)-3" ] && cp -f $(MAKEFILE_DEP)-3 $(MAKEFILE_DEP)-2 1>&2)
$(shell [ -r "$(MAKEFILE_DEP)"   ] && cp -f $(MAKEFILE_DEP)   $(MAKEFILE_DEP)-3 1>&2)

$(MAKEFILE_DEP): __FORCE__
	@$(debug-target-wrt-dependencies-maybe)
	@$(create-tmp-target-automagic-header); \
	 (for line in $(MAKEFILE_DEP_STEP1) \
		      $(MAKEFILE_DEP_STEP2) \
		      $(MAKEFILE_DEP_STEP3); do \
	    echo "$${line}"; \
	  done; \
	  ) >> $(tmp-target); \
	 $(update-target-from-tmp-if-different-only)

realclean:
	@$(echo) ""
	 /bin/rm -f *~
	 /bin/rm -f $(MAKEFILE_DEP)
	 /bin/rm -f $(foreach ext,1 2 3,$(MAKEFILE_DEP)-$(ext))

#
# Dummy "all" target, run after included makefile dependency has been finalized
#

all:
	@$(echo) ""
	@if [ -z "$(NUM_LIST)" ]; then \
	   $(echo) 1>&2 "GNU Make bug detected, please re-run $(MAKE) to complete and get bug description"; \
	   $(echo) 1>&2 ""; \
	   exit 2; \
	 else \
	   for line in $(subst $(_BQUOTE_),\$(_BQUOTE_),$(subst $(_DOLLAR_),\$(_DOLLAR_),$(subst $(_BSLASH_),\$(_BSLASH_),$(BUG_DESCRIPTION)))); do \
	     echo 1>&2 "  | $${line}"; \
	   done; \
	   if [ -f Makefile.dep-expected ]; then \
	     if diff Makefile.dep-expected Makefile.dep > /dev/null 2>&1; then \
	       true; \
	     else \
	       echo "WARNING: final Makefile.dep does not match Makefile.dep-expected"; \
	     fi; \
	   fi; \
	   /bin/rm -f $(MAKEFILE_DEP); \
	 fi

#
# Dynamic Makefile.dep content variables
#

MAKEFILE_DEP_STEP1 = \
  "" \
  "\# This section content always output from step 1" \
  "ONE   = 1" \
  "TWO   = 2" \
  "THREE = 3" \
  "NAME_LIST = ONE TWO THREE"

MAKEFILE_DEP_STEP2 = \
  "" \
  "\# This section content always output from step 2" \
  $(foreach name,$(NAME_LIST), \
  "VAR_$(name) = \$$($(name))" \
  "  VAR_LIST += VAR_$(name)")

MAKEFILE_DEP_STEP3 =  \
  "" \
  "\# This section content always output from step 3" \
  $(foreach var,$(VAR_LIST), \
  "  \# $(var) = $($(var))" \
  "  NUM_LIST += $($(var))")



# #################################################################
# ################### S U P P O R T   S T U F F ###################
# #################################################################

#
# Standard Unix commands
#

cat	= cat /dev/null
echo    = echo
touch	= touch -f
rm	= /bin/rm -f
mv	= /bin/mv -f
ln	= /bin/ln -s
cp	= /bin/cp
mkdir	= /bin/mkdir -p
rmdir	= /bin/rm -rf
chmod	= /bin/chmod
sed     = /bin/sed

#
# Make automatic variables shortcuts
#

target            = $(@)
tmp-target        = $(@).tmp
target-log        = $(@).log
target-file       = $(@F)
target-directory  = $(@D)

stem              = $(*)
stem-file         = $(*F)
stem-dir          = $(*D)

dependency-list   = $(^)
dependency-new    = $(?)
dependency-first  = $(<)

#
# Useful shell code macros
#

make-target-not-precious = \
  $(rm) $(target) $(tmp-target) $(target-log)
make-target-not-writable = \
  $(chmod) a-w $(target)
update-target-from-tmp = \
  $(rm) $(target); \
  $(mv) $(tmp-target) $(target); \
  $(make-target-not-writable)
remove-tmp-target = \
  $(rm) $(tmp-target)
update-target-from-tmp-if-different-only = \
  if [ ! -f $(target) ]; then \
    $(echodebug) "Creating $(target)..."; \
    $(update-target-from-tmp); \
  elif diff $(tmp-target) $(target) > /dev/null 2>&1; then \
    $(echodebug) "$(target) is OK..."; \
    $(remove-tmp-target); \
  else \
    $(echodebug) "Recreating $(target)..."; \
    $(update-target-from-tmp); \
  fi

#
# Automagic header related commands/variables
#

AUTOMAGIC_HEADER_LINES = \
  "\# WARNING, THIS FILE AUTOMAGICALLY GENERATED" \
  "\#" \
  "\# PLEASE DO NEVER MODIFY IT BY HAND" \
  "\#" \
  ""

echo-automagic-header = \
  (for line in $(AUTOMAGIC_HEADER_LINES); do \
     echo "$$line"; \
   done)

create-tmp-target-automagic-header = \
  $(echo-automagic-header) > $(tmp-target)

#
# Debug macros
#

ifdef DEBUG
  echodebug = echo
else
  echodebug = true
endif

ifndef DEBUG
  debug-target-wrt-dependencies-maybe = true
else
  EXPLAIN = 1
  debug-target-wrt-dependencies-maybe = \
    $(echo) " "; \
    $(echo) " >> Target       : " $(target); \
    $(echo) " >> -------------- "; \
    $(echo) " >>   Stem       : " $(stem); \
    $(echo) " >>   Reason     : " $(dependency-new); \
    $(echo) " >>   Dependency : " $(dependency-list)
endif

#
# Explicit or inaccessible characters (_EMPTY_ intentionally left undefined...)
#

_COLON_  := :
_COMMA_  := ,
_SPACE_  := $(_EMPTY_) $(_EMPTY_)
_DOLLAR_ := $$
_BSLASH_ := $(_EMPTY_)\$(_EMPTY_)
_LANGLE_ := <
_RANGLE_ := >
_QUOTE_  := '
_BQUOTE_ := `
_DQUOTE_ := "
# Dummy comment to overcome Emacs font-lock problem... "`'
