XCOMM $XFree86: xc/config/cf/lnxdoc.rules,v 3.26 2001/12/19 23:07:24 dawes Exp $
XCOMM
XCOMM Rules for formatting Linuxdoc-SGML documentation
XCOMM

#include <lnxdoc.tmpl>

#ifdef DontInstallLinuxDoc
#define LinuxDocInstall(file,dest)	/* do nothing */
#define LinuxDocInstallMultiple(files,dest)	/* do nothing */
#else
#define LinuxDocInstall(file,dest)	InstallNonExecFile(file,dest)
#define LinuxDocInstallMultiple(files,dest)				@@\
InstallMultipleDest(install,files,dest)
#endif

/* Version for sgmlfmt */

#if BuildLinuxDocPS
#define LinuxDocSgmlToPs(sgmlfile,base) 				@@\
AllTarget(base.ps)							@@\
									@@\
base.ps: sgmlfile $(SGMLDEPENDS)					@@\
	RemoveFile(_$@ $@)						@@\
	@(BASE=`basename sgmlfile .sgml`;\				@@\
	  set -x;\							@@\
	  RemoveFile($$BASE.ps);\					@@\
	  $(SGMLFMTCMD) -f ps sgmlfile && \				@@\
		$(MV) $$BASE.ps _$@ && $(MV) _$@ $@)			@@\
									@@\
LinuxDocInstall(base.ps,$(XFREE86PSDOCDIR))				@@\
									@@\
clean::									@@\
	RemoveFile(Concat(_,base.ps) base.ps)
#else
#define LinuxDocSgmlToPs(sgmlfile,base) /**/
#endif

#if BuildLinuxDocText
#define LinuxDocSgmlToText(sgmlfile,textfile)				@@\
AllTarget(textfile)							@@\
									@@\
textfile: sgmlfile $(SGMLDEPENDS)					@@\
	RemoveFiles(_$@ $@)						@@\
	@(BASE=`basename sgmlfile .sgml`;\				@@\
	  set -x;\							@@\
	  RemoveFile($$BASE.latin1);\					@@\
	  $(SGMLFMTCMD) -f latin1 -b -n sgmlfile && \			@@\
	  $(XFREE86IDENTFIX) < $$BASE.latin1 > _$@ && $(MV) _$@ $@ && \	@@\
	  RemoveFile($$BASE.latin1))					@@\
									@@\
LinuxDocInstall(textfile,$(XFREE86DOCDIR))				@@\
									@@\
clean::									@@\
	@(file=textfile; set -x; RemoveFiles(_$$file $$file))
#else
#define LinuxDocSgmlToText(sgmlfile,textfile) /**/
#endif

#if BuildLinuxDocHtml
#define LinuxDocSgmlToHtml(sgmlfile,base)				@@\
AllTarget(base.html)							@@\
									@@\
base.html: sgmlfile $(SGMLDEPENDS)					@@\
	@if [ sgmlfile != base.sgml ]; then $(LN) sgmlfile base.sgml; fi @@\
	RemoveFiles(base*.html)						@@\
	$(SGMLFMTCMD) -f html base.sgml || RemoveFile($@)		@@\
	@if [ sgmlfile != base.sgml ]; then RemoveFile(base.sgml); fi	@@\
									@@\
LinuxDocInstallMultiple(base*.html,$(XFREE86HTMLDOCDIR))		@@\
									@@\
clean::									@@\
	RemoveFiles(base*.html)
#else
#define LinuxDocSgmlToHtml(sgmlfile,base) /**/
#endif

/*
 * Rule for maintainers to use to updated formatted copies of docs in the
 * source tree.  Use with care.
 */

#ifndef UpdateFormattedDoc
#define UpdateFormattedDoc(textfile,dstdir)				@@\
update.docs:: textfile							@@\
	-@if [ -f dstdir/textfile ]; then \				@@\
	    if [ "$(FORCEUPDATE)" = yes ]; then set -x; \		@@\
		if [ "$(FOLLOWLINK)" = no ]; then \			@@\
			$(RM) dstdir/textfile; \			@@\
		fi; \							@@\
		cp textfile dstdir/textfile; \				@@\
		echo "" >> dstdir/textfile; \				@@\
		echo "\$$XFree86\$$" >> dstdir/textfile; \		@@\
	    else \							@@\
		$(RM) __tmp1__ __tmp2__; \				@@\
		fgrep -v "\$$XFree86:" textfile > __tmp1__; \		@@\
		fgrep -v "\$$XFree86:" dstdir/textfile > __tmp2__; \	@@\
		if diff -B __tmp1__ __tmp2__ > /dev/null 2>&1; then :; \	@@\
		else set -x; \						@@\
			if [ "$(FOLLOWLINK)" = no ]; then \		@@\
				$(RM) dstdir/textfile; \		@@\
			fi; \						@@\
			cp textfile dstdir/textfile ; \			@@\
			echo "" >> dstdir/textfile; \			@@\
			echo "\$$XFree86"": \$$" >> dstdir/textfile; \	@@\
		fi; \							@@\
	    fi; \							@@\
	fi								@@\
	@$(RM) __tmp1__ __tmp2__
#endif

/*
 * Avoid using LinuxDocTargetLong with base != sgmlfile because HTML
 * index generation assumes that base == sgmlfile.
 */
#define LinuxDocTargetLong(sgmlfile,textfile,base)			@@\
LinuxDocSgmlToText(sgmlfile,textfile)					@@\
LinuxDocSgmlToHtml(sgmlfile,base)					@@\
LinuxDocSgmlToPs(sgmlfile,base)						@@\
UpdateFormattedDoc(textfile,$(FORMATTEDDIR))

#define LinuxDocReadmeTarget(base)					@@\
LinuxDocTargetLong(base.sgml,ReadmeFile(base),base)

#define LinuxDocTarget(base)						@@\
LinuxDocTargetLong(base.sgml,base,base)

