# Generated automatically from maintMakefile.in by configure.
#=============================================================================
#
# Maintainer stuff; don't even LOOK at this - and when you E-mail me
# about it you'll get blacklisted }:-).
#
# I added it only here for other GNU maintainers to look at.
# In order to use this as-is, you'll need the following utilities:
#
# GNU make
# GNU which-2.x
# GNU awk
# GNU date
# rpm-3.x (RedHat-6.x)
# texinfo2man.c (I'll make this available via my home page)
# texi2html
# cvs2html
# rcs2log
# cut
# grep
# egrep
# test
# sed
#
# This maintainer Makefile provides the following functionality:
#
# Targets
# -------
#
# - release
#	Creates everything and puts it all in the release directory $(WWWDIR)
#       This target calls all of the below targets.
#	Note: You must `cvs commit' *before* calling this target!
#
# The remaining targets can be used to test a part of the distribution process,
# but are not really useful on their own otherwise.
#
# - cvslog
#	Generates html-ized ChangeLog from the CVS repository log.
#
# - index.html
#	Generates the release front page index.html by replacing
#	"!VERSION!" in index.html.in by 2.2.0 and the word
#	"CHANGELOGLIST" by a list of links the cvslog change logs
#	(also from previous releases).
#
# - indent.lsm
#	Generates an LSM file for distribution via the web page.
#	It does this by simply replacing "!VERSION!" by 2.2.0.
#
# - rpm
#	Generates the $(TARGET).rpm and src.rpm files.
#	This target calls all of the below targets.
#
# - $(SPECFILE)
#	Generates the rpm spec file from the file `$(SPECFILE).in' by
#	replacing "!VERSION!" by 2.2.0 and "!CHANGELOG!" by an
#	rpm %changelog list generated from the CVS repository log.
#
# - tar
#	Generates the tar.gz distribution file.
#	This target calls all of the below targets (provided you added
#	README, indent.1, indent.html and ChangeLog to BUILT_SOURCES).
#
# - indent.html
#	Generates html-ized man page(s) (from indent.texinfo) and
#
# - README
#	Generate README file by replacing "!VERSION!" in README.in by
#	2.2.0.
#
# - indent.1
#	Generate man page from indent.texinfo.
#
# - ChangeLog
#	Generates the `ChangeLog' file from the CVS repository logs.

WWWDIR=/home/carlo/www/indent
REDHAT:=$(shell grep '^%_topdir' rpm/macros | cut -d \  -f 2)
SPECFILE=indent-${shell echo "2.2.0" | cut -d. -f1}.spec
TARGET=i386
REL=1
AUTHOR=Carlo Wood <carlo@gnu.org>
TAG:=${shell echo "V2.2.0" | sed -e 's/\./_/g'}
PREVTAG:=${shell test -f .prevtag && cat .prevtag}

test-values:
	@echo "WWWDIR   = \"$(WWWDIR)\""
	@echo "REDHAT   = \"$(REDHAT)\""
	@echo "SPECFILE = \"$(SPECFILE)\""
	@echo "TARGET   = \"$(TARGET)\""
	@echo "REL      = \"$(REL)\""
	@echo "AUTHOR   = \"$(AUTHOR)\""
	@echo "TAG      = \"$(TAG)\""
	@echo "PREVTAG  = \"$(PREVTAG)\""

.PHONY: release tar rpm cvslog gdb

indent.1: indent.1.in indent.texinfo texinfo2man configure.in
	texinfo2man indent.1.in indent.texinfo > indent.1

texinfo2man: texinfo2man.c
	$(CC) -g -o texinfo2man texinfo2man.c

indent.html: indent.texinfo version.texi
	texi2html -expandinfo -menu indent.texinfo

indent_%.html: indent.texinfo version.texi
	texi2html -expandinfo -menu indent.texinfo

index.html: index.html.in configure.in
	grep -B2000 '^CHANGELOGLIST' index.html.in \
	    | sed -e 's%!VERSION!%2.2.0%g' \
	    | grep -v '^CHANGELOGLIST' > index.html
	( \
	  VER=`echo "2.2.0" | cut -d. -f1-2`; \
	  PATCHLEVEL=`echo "2.2.0" | cut -d. -f3`; \
	  while test "$$PATCHLEVEL" != "-1" ; do \
	    echo "<LI><A HREF="cvslog-$$VER.$$PATCHLEVEL.html">Version $$VER.$$PATCHLEVEL</A>" >> index.html; \
	    PATCHLEVEL=`echo "$$PATCHLEVEL" | awk '{ printf("%d", $$1 - 1); }'`; \
	  done \
	)
	grep -A2000 '^CHANGELOGLIST' index.html.in | grep -v '^CHANGELOGLIST' >> index.html

README: README.in configure.in
	sed -e 's%!VERSION!%2.2.0%g' README.in > README

indent.lsm: indent.lsm.in configure.in
	sed -e 's%!VERSION!%2.2.0%g' indent.lsm.in > indent.lsm

tar:
	@# Make sure the ChangeLog is up to date in maintainer mode
	@rm -f ChangeLog
	$(MAKE) dist
	mv indent-2.2.0.tar.gz $(REDHAT)/SOURCES

rpm: tar $(SPECFILE)
	rpm --rcfile /usr/lib/rpm/rpmrc:rpm/rpmrc --target $(TARGET) --sign --clean -ba $(SPECFILE)

cvslog:
	@( \
	   D1=`cat .release_day`; \
	   D2=`date +%j`; \
	   DD=`echo "$$D1 $$D2" | awk '{ printf("%d\n", $$2 - $$1) }'`; \
	   echo "Last release was $$DD days ago."; \
	   cvs2html -e -r$(PREVTAG):HEAD -o cvslog-2.2.0; \
	 )

$(SPECFILE): $(SPECFILE).in configure.in
	cvs commit $(SPECFILE).in
	sed -e 's/!VERSION!/2.2.0/g' $(SPECFILE).in | grep -B2000 '!CHANGELOG!' | grep -v '!CHANGELOG!' > $(SPECFILE)
	echo -n "%changelog" >> $(SPECFILE)
	cvs log $(SPECFILE).in | \
	  grep -A2000 '^-----' | \
	  egrep -v '^-----|^=====|^revision' | \
	  awk -F'[ ;]' --assign lastdate="" '{ if ($$0~/^date: /) { \
	    if (lastdate != $$2) { \
	      lastdate=$$2; \
	      printf("\n* "); \
	      system("echo -n `date --date \""$$2" "$$3"\" \"+%a %b %d %Y\"`"); \
	      printf(" $(AUTHOR)\n"); \
	    } \
	  } else if ($$0~/^[A-Z]/) { printf("- %s\n", $$0); } else if ($$0~/./) { printf("  %s\n", $$0); } else {print} }' >> $(SPECFILE)
	grep -A2000 '!CHANGELOG!' $(SPECFILE).in | grep -v '!CHANGELOG!' >> $(SPECFILE)

ChangeLog:
	@( echo "`which --skip-dot cvs` \`echo \"\$$*\" | sed -e 's%1970%1990%'\`" > cvs; \
	chmod 755 cvs; )
	PATH=.:$$PATH rcs2log > ChangeLog
	@rm cvs

release: cvslog tar index.html indent.lsm rpm
	install -m 644 $(REDHAT)/SRPMS/indent-2.2.0-$(REL).src.rpm $(WWWDIR)
	install -m 644 $(REDHAT)/RPMS/$(TARGET)/indent-2.2.0-$(REL).$(TARGET).rpm $(WWWDIR)
	install -m 644 $(REDHAT)/SOURCES/indent-2.2.0.tar.gz $(WWWDIR)
	install -m 644 index.html $(WWWDIR)
	install -m 644 indent.lsm $(WWWDIR)
	install -m 644 cvslog-2.2.0*.html $(WWWDIR)
	install -m 644 indent*.html $(WWWDIR)
	rm cvslog-2.2.0*.html
	cvs tag $(TAG)
	echo "$(TAG)" > .prevtag
	date +%j > .release_day

##----------------------------------------------------------------------------
## indent specific stuff:
##

gdb:
	$(MAKE) CFLAGS=-g
	@(egrep -v '^#|^WATCH' .gdbinit.in > .gdbinit; \
	  what=`grep '^WATCH' .gdbinit.in | cut -d\  -f2`; \
	  ptrs=`echo "$$what" | grep -- '->' | cut -d- -f1 | sort | uniq`; \
	  nonptrs=`echo "$$what" | grep -v -- '->'`; \
	  for p in $$ptrs; do \
	    lines=`grep -n GDB_HOOK_$$p *.c | cut -d: -f1,2`; \
	    for i in $$lines; do \
	      echo -e "b "$$i"\ncommands" >> .gdbinit; \
	      vars=`grep '^WATCH '$$p'->' .gdbinit.in | cut -d'>' -f2`; \
	      for j in $$vars; do \
		echo "watch $$p->$$j" >> .gdbinit; \
	      done; \
	      echo "end" >> .gdbinit; \
	    done; \
	  done; \
	  for np in $$nonptrs; do \
	    func=`echo "$$np" | cut -d: -f1`; \
	    var=`echo "$$np" | cut -d: -f2`; \
	    lines=`grep -n "GDB_HOOK_$$func()" *.c | cut -d: -f1,2`; \
	    for i in $$lines; do \
	      echo -e "b "$$i"\ncommands\nwatch $$var\nend" >> .gdbinit; \
	    done; \
	  done)
