#	Common rules for making SGML and HTML 

# BOOK_FILES is defined when it's an SGML book...
#if defined(BOOK_FILES)
SOURCES     = ${BOOK_FILES}
TARGETS     = ${BOOK_FILES:.doc=.sgm}

XXX_FILES   = ${BOOK_FILES:S/.doc$/.sgm/g}
SGM_FILES   = ${XXX_FILES:S/.mif$/.sgm/g}
VER_FILES   = ${SGM_FILES:S/.sgm$/.ver/g}
ERR_FILES   = ${SGM_FILES:S/.sgm$/.err/g}
DIRT_FILES  = ${SGM_FILES:S/.sgm$/.ctl/g} booklist.txt

MIF_FILES   = ${BOOK_FILES:S/.doc$/.mif/g}
#if ${BOOK_FILES:S/[     ]*/ /g} == "${MIF_FILES}"
MIF_FILES   =
#endif
#endif

# all the definitions based on the specific DTD in the Makefile
#if ${DTD} == "SGIDOC"
REAL_DTD = ${BOOK_LIB}/dtd/default.dtd
STYLES_DIR = ${BOOK_LIB}/styles
SRCH_TAGS = TITLE:Titles;CAPTION,FIGURE:Figure Captions:1;CAPTION,TABLE:Table Captions:1;TABLE:Tables;CODE EXAMPLE:Code Examples
HIDDEN ?= FALSE

#elif ${DTD} == "XHELP"
REAL_DTD = ${XHELP_LIB}/dtd/XHELP.dtd
STYLES_DIR = ${XHELP_LIB}/styles
SRCH_TAGS = HELPLABEL,HELPTOPIC TITLE:Titles:1;TITLE,FIGURE:Figure Captions:1;EXAMPLE:Code Examples
HIDDEN ?= TRUE

#elif ${DTD} == "DOCBOOK"
REAL_DTD = ${DOCBOOK_LIB}/dtd/docbook.dtd
STYLES_DIR = ${DOCBOOK_LIB}/styles
SRCH_TAGS = TITLE:Titles;TITLE,FIGURE:Figure Captions:1;TITLE,TABLE:Table Captions:1;TABLE:Tables;EXAMPLE:Code Examples
HIDDEN ?= FALSE

#else
REAL_DTD = ../../${BOOK}.dtd
STYLES_DIR = ../../styles
#endif


.SUFFIXES: .sgm .doc .mif .ver .err

## Rule for converting Frame files to MIF files
## if not SGIDOC DTD then don't use the conditional file
.doc.mif:
#if ${DTD} == "SGIDOC"
	@TMPFILE=${TMPDIR}/${@:.mif=.$$.tmp}; \
	echo "Open $<" > $${TMPFILE}; \
	echo "Open ${CONDITION_FILE}" >> $${TMPFILE}; \
	echo "UseFormatsFrom x $< ${CONDITION_FILE}" >> $${TMPFILE}; \
	echo "SaveAs m $< $*.mif.tmp" >> $${TMPFILE}; \
	echo "Quit $<" >> $${TMPFILE}; \
	${FMBATCH} $${TMPFILE}; \
	echo ${MIFHEADER} > $*.mif; \
	echo "#SGI=$*" >> $*.mif; \
	cat $*.mif.tmp >> $*.mif; \
	${RM} -f $${TMPFILE} $*.mif.tmp
#else
	@TMPFILE=${TMPDIR}/${@:.mif=.$$.tmp}; \
	echo "Open $<" > $${TMPFILE}; \
	echo "SaveAs m $< $*.mif" >> $${TMPFILE}; \
	echo "Quit $<" >> $${TMPFILE}; \
	${FMBATCH} $${TMPFILE}; \
	${RM} -f $${TMPFILE}
#endif

# Rule for converting MIF files to SGML files
# this also builds CGM figures if necessary
.mif.sgm:
#if ${DTD} == "SGIDOC"
#if defined(BOOK_LANG)
#if ${BOOK_LANG} == "ja_JP.EUC"
	@${MIF2SGML} ${CGM_NOTRAS} -i ${INTL_MAP_DIR}/${BOOK_LANG}.intl_map $<
#else
	@${MIF2SGML} ${CGM_NOTRAS} -i ${INTL_MAP_DIR}/${BOOK_LANG}.intl_map $<
#endif
#else
	@${MIF2SGML} ${CGM_NOTRAS} $<
#endif
#elif ${DTD} == "XHELP"
	@echo "Frame to XHELP not supported at this time"; exit 1
#elif ${DTD} == "DOCBOOK"
	@echo "Generic Frame to DocBook requires Passage's translator"; exit 1
#else
	${OTHER_TRANSLATOR} $<
#endif
	-@ mkdir -p online 1> /dev/null 2>&1
	@if (`grep 'RASTERCONVERT' $*.sgm>/dev/null`) then \
	  echo "Creating CGM images..."; \
	  (CLHOME=${CLHOME}; MIFTOCGM_IP=${MIFTOCGM_IP}; \
		export CLHOME MIFTOCGM_IP; \
		${MIFTOCGM} ${CGM_VERBOSE} -c ${CLHOME}/data/kt.map -i $< -o online/$*.cgm ); \
	  TIFF_FILES=`grep '<!-- RASTERCONVERT:' $*.sgm |sed -e 's/.*<!-- RASTERCONVERT: \(.*\) -->.*/\1/'` ; \
	  for i in $${TIFF_FILES} ; do \
	        echo "Converting" $$i "to GIF"; \
		N_GIF=`echo $$i|sed 's/\.cgm$$/-1.gif/'|sed 's/\.cgm\([0-9][0-9]*\)/-\1\.gif/'`; \
	        (CLHOME=${CLHOME}; export CLHOME; \
			${CLTRANS} online/$$i online/$$i.out -of tiff \
			${CGM_VERBOSE} \
			-oo "${CGM_VERBOSE} -t palette -comp lzw -dpi 285"); \
	        ${TIFFTOPNM} online/$$i.out | ${PNMSCALE} .37 | ${PNMCROP} | \
		${PNMMARGIN} -white 10 | \
		${PPMQUANT} 256 > ${TMPDIR}/$$i.ppm; \
		/usr/sbin/fromppm ${TMPDIR}/$$i.ppm ${TMPDIR}/$$i.rgb; \
		/usr/sbin/hipass3 ${TMPDIR}/$$i.rgb ${TMPDIR}/$$i.rgb_sh .5; \
		${TOGIF} ${TMPDIR}/$$i.rgb_sh online/$${N_GIF} ; \
	        /bin/rm online/$$i.out online/$$i ${TMPDIR}/$$i.ppm ${TMPDIR}/$$i.rgb ${TMPDIR}/$$i.rgb_sh; \
	  done; \
	fi

# Rule for generating Exoterica report files for SGML files
.sgm.ver:
#if ${DTD} == "SGIDOC"
	-@TMPFILE=${TMPDIR}/${@:.ver=.$$.tmp}; \
	echo  "<SGIDOC LANG=$\"{BOOK_LANG}\">\c" > $${TMPFILE}; \
	cat $< >> $${TMPFILE}; \
	echo  "</SGIDOC>" >> $${TMPFILE}; \
	${OMNIR} $${TMPFILE} -env ${SGIDOC_ENV_FILE} -log $*.ver; \
	${RM} -f $${TMPFILE}
#elif ${DTD} == "XHELP"
	${OMNIR} $< -env ${XHELP_ENV_FILE} -log $*.ver
#else
	@echo "Exoterica Validation not supported at this time"; exit 1
#endif

# Rule for generating UNKNOWN errors report files for SGML files
.sgm.err:
	-@${EGREP} '<\!\-\- ERROR|<\!\-\- WARNING|<UNKNOWN.ERROR' $< > $*.err

EndPart:
	@echo "</PART>" > EndPart

EndPart.err:
	@touch EndPart.err

# Build the master SGML file which is concatenation of all individual
# SGML files with TITLE at the front and <SGIDOC> tag around either
# <MANUAL> or <SUPPORT> depending on the book type.

${MASTER_SGM}: ${SGM_FILES}
	@echo " ======== Building master sgml file ======== "
	@${RM} -f ${MASTER_SGM}
	@if [ "${SGM_FILES}" = "" ] ; then \
	  echo "error: No SGML files to process"; \
	  exit 1; \
	fi 
#if ${DTD} == "SGIDOC"
	@${RM} -f ${TMP_MASTER_SGM}
	@${RM} -f ${INDEXFILE}
	@for i in ${SGM_FILES}; do cat $$i >> ${TMP_MASTER_SGM}; done
#if ${BOOK_LANG} != "ja_JP.EUC"
	@cat ${TMP_MASTER_SGM} | ${INDEXGEN} -s -o ${INDEXFILE}
#endif
	@if [ "${DOC_TYPE}" = "" ] ; then \
	  echo "<SGIDOC LANG=\"${BOOK_LANG}\"><MANUAL>" > ${MASTER_SGM}; \
	else \
	  echo "<SGIDOC LANG=\"${BOOK_LANG}\"><${DOC_TYPE}>" > ${MASTER_SGM}; \
	fi 
#endif
	@for i in ${SGM_FILES}; do cat $$i >> ${MASTER_SGM}; done
#if ${DTD} == "SGIDOC"
#if ${BOOK_LANG} != "ja_JP.EUC"
	@cat ${INDEXFILE} >> ${MASTER_SGM}
#endif
	@if [ "${DOC_TYPE}" = "" ] ; then \
	  echo "</MANUAL></SGIDOC>" >> ${MASTER_SGM} ; \
	else \
	  echo "</${DOC_TYPE}></SGIDOC>" >> ${MASTER_SGM} ; \
	fi
	@${RM} -f ${TMP_MASTER_SGM}
#endif

${BOOKDIR}/${BOOK}.sgm: ${MASTER_SGM}
	-@mkdir -p ${BOOKDIR} 1> /dev/null 2>&1
	@${RM} -f ${BOOKDIR}/${BOOK}.sgm
	@${CP} ${MASTER_SGM} ${BOOKDIR}/${BOOK}.sgm

# Branch for ruled for making a book out of 'compiled' sgm files, or HTML
#if ${DTD} != "HTML"
default book help xhelp: mk_book figures

#else
default book help xhelp:
	@echo "operation not supported with HTML books"

clobber clean rmtargets fluff tags:
	@echo "operation not supported with HTML books"

#if defined(RAWIDB)
install: booklist.txt
#	Generate booklist.txt idb
	$(INSTALL) -m 644 -f ${BOOKSHELF}/${BOOKDIR} \
	    -idb '${BOOKSUBSYSTEM} exitop("(chroot \$$rbase /usr/sbin/insightAdmin -avf ${BOOKSHELF}>>\$$rbase/var/share/Insight/install.insight.log)2>>\$$rbase/var/share/Insight/install.insight.log")' \
	    booklist.txt
#       Generate helpmap idbs 
	if [ -d help ] ; then \
	    (cd help; \
	    if [ "${BOOK_LANG}" = "C" ] ; then \
	        $(INSTALL) -m 644 -idb $(HELPSUBSYSTEM) \
	 	    -f ${HELPDIR}/help *.helpmap; \
	    else \
		$(INSTALL) -m 644 -idb $(HELPSUBSYSTEM) \
		    -f ${HELPDIR}/help/${BOOK_LANG} *.helpmap; \
	    fi; \
	    cd ..); \
	fi
#       Generate book directory idb
	$(INSTALL) -u root -g sys  -m 755 \
	    -idb '${BOOKSUBSYSTEM} removeop("if [ -r $$rbase/usr/sbin/insightAdmin ]; then chroot \$$rbase /usr/sbin/insightAdmin -avf ${BOOKSHELF}>>\$$rbase/var/share/Insight/install.insight.log 2>&1; fi")' \
	    -dir ${BOOKSHELF}/${BOOKDIR}
#       Generate subdirectory idbs, if any
	for d in $(BOOK_DIRS); do \
	    if [ "$$d" != "." ]; then \
		$(INSTALL) -m 755 -idb $(BOOKSUBSYSTEM) \
			-dir ${BOOKSHELF}/${BOOKDIR}/$$d; \
	    fi; \
	done
#       Generate files idbs 
	for d in $(BOOK_DIRS); do \
	    if [ "$$d" = "." ]; then \
		for f in *.html *.htm *.gif *.jpg *.jpeg; do \
		    if [ -f $$f ]; then \
			$(INSTALL) -m 644 -idb $(BOOKSUBSYSTEM) \
				-f ${BOOKSHELF}/${BOOKDIR} $$f; \
		    fi; \
		done; \
	    else \
		for f in $$d/*.html $$d/*.htm $$d/*.gif $$d/*.jpg $$d/*.jpeg; \
		do \
		    if [ -f $$f ]; then \
			$(INSTALL) -m 644 -idb $(BOOKSUBSYSTEM) \
				-f ${BOOKSHELF}/${BOOKDIR} $$f; \
		    fi; \
		done; \
	    fi; \
	done
#	Generate idb for dummy edr file, and dir to hold it
	$(INSTALL) -u root -g sys  -m 755 -idb ${BOOKSUBSYSTEM} \
            -dir ${BOOKSHELF}/${BOOKDIR}/ebt
	$(INSTALL) -f $(BOOKSHELF)/books/$(TITLE)/ebt -idb $(BOOKSUBSYSTEM) $(TITLE).edr

#else
install:
	@echo "warning: 'install' not supported if RAWIDB not defined"

#endif
#endif

# notice that any tdr files less than 62 in length are being removed
.ORDER: prep_book ${BOOKDIR}/ebt/${BOOK}.edr
mk_book: prep_book ${BOOKDIR}/ebt/${BOOK}.edr

${BOOKDIR}/ebt/${BOOK}.edr: ${MASTER_SGM}
#if ${DTD} == "XHELP"
	@(EBTRC=${EBTRC}; TOOLROOT=${ITOOLROOT}; export EBTRC TOOLROOT; \
		${MKHELP} -col . ${BOOK})
#else
#if ${BOOK_LANG} == "ja_JP.EUC"
	@(EBTRC=${EBTRC}; TOOLROOT=${ITOOLROOT}; LANG=${BOOK_LANG}; \
		export EBTRC TOOLROOT LANG; \
		${MKBOOK} ${MKBOOK_FLAGS} -col `pwd` ${BOOK})
#else
#if ${DTD} == "SGIDOC"
#if exists(${MKSGIDOC})
	@(EBTRC=${EBTRC}; TOOLROOT=${ITOOLROOT}; export EBTRC TOOLROOT; \
		${MKSGIDOC} ${MKBOOK_FLAGS} -col `pwd` ${BOOK})
#else
	@(EBTRC=${EBTRC}; TOOLROOT=${ITOOLROOT}; export EBTRC TOOLROOT; \
		${MKBOOK} ${MKBOOK_FLAGS} -col `pwd` ${BOOK})
#endif
#else
	@(EBTRC=${EBTRC}; TOOLROOT=${ITOOLROOT}; export EBTRC TOOLROOT; \
		${MKBOOK} ${MKBOOK_FLAGS} -col `pwd` ${BOOK})
#endif
#endif
#endif
	-@${RM} -f `${LS} -l ${BOOKDIR}/ebt/*.tdr | ${AWK} '{if ($$5 < 62) print $$9}'`

pub_book: mk_book
#if ${DTD} == "XHELP"

#else
#if ${BOOK_LANG} == "ja_JP.EUC"
	@(EBTRC=${EBTRC}; TOOLROOT=${ITOOLROOT}; LANG=${BOOK_LANG}; \
		export EBTRC TOOLROOT LANG; \
		${PUBBOOK} -col . ${BOOK})
#else
#if ${DTD} == "SGIDOC"
#if ! exists(${MKSGIDOC})
	@(EBTRC=${EBTRC}; TOOLROOT=${ITOOLROOT}; export EBTRC TOOLROOT; \
		${PUBBOOK} -col . ${BOOK})
#endif
#else
	@(EBTRC=${EBTRC}; TOOLROOT=${ITOOLROOT}; export EBTRC TOOLROOT; \
		${PUBBOOK} -col . ${BOOK})
#endif
#endif
#endif

booklist.txt: Makefile
#if ${DTD} != "OTHER"
	@if [ -f booklist.txt ] ; then \
	    ${MV} booklist.txt booklist.txt.old; \
	fi
	@echo '<BOOK NAME="${TITLE}" ALIAS="'${FULL_TITLE}'" TYPE="${BOOK_ICON}" HIDE="${HIDDEN}" VERSION="${VERSION}" SGITYPE="${BOOK_ICON}" SGIHIDE="${HIDDEN}" SGIVERSION="${VERSION}" \c' > booklist.txt
	@if [ ${SORT_ORDER} != "" ] ; then \
		echo 'SGISORT="${SORT_ORDER}" \c' >> booklist.txt; \
	fi
	@echo 'SGISRCHRES="${HIDDEN}" SGISRCHTAGS="$(SRCH_TAGS)" SGIGROUP="${DTD}">' >> booklist.txt
#endif

prep_book: ${BOOKDIR}/${BOOK}.sgm booklist.txt
	-@mkdir -p ${BOOKDIR}/ebt 1> /dev/null 2>&1
	-@mkdir -p ${BOOKDIR}/index 1> /dev/null 2>&1
	@if [ ! -f ${BOOKDIR}/${BOOK}.dtd ] ; then \
	    if [ -f ${BOOK}.dtd ] ; then \
		ln -s ../../${BOOK}.dtd ${BOOKDIR}/${BOOK}.dtd; \
	    else \
		ln -s ${REAL_DTD} ${BOOKDIR}/${BOOK}.dtd; \
	    fi \
	fi
	@if [ ! -d  ${BOOKDIR}/styles ] ; then \
	    if [ -d styles ] ; then \
		ln -s ../../styles ${BOOKDIR}/styles; \
	    else \
		ln -s ${STYLES_DIR} ${BOOKDIR}/styles; \
	    fi \
	fi
	@if [ ! -d  ${BOOKDIR}/entities ] ; then \
	    if [ -d entities ] ; then \
		ln -s ../../entities ${BOOKDIR}/entities; \
	    else \
		ln -s ${BOOK_LIB}/entities ${BOOKDIR}/entities; \
	    fi \
	fi
	@if [ ! -f ${BOOKDIR}/${BOOK}.ctl ] ; then \
	    if [ -f ${BOOK}.ctl ] ; then \
		ln -s ../../${BOOK}.ctl ${BOOKDIR}/${BOOK}.ctl; \
	    fi \
	fi

book.ver ${BOOK}.ver: ${MASTER_SGM}
	@${RM} -f ${BOOK}.ver
#if ${DTD} == "SGIDOC"
	-@${OMNIR} ${MASTER_SGM} -env ${SGIDOC_ENV_FILE} -log ${BOOK}.ver
#elif ${DTD} == "XHELP"
	-@${OMNIR} ${MASTER_SGM} -env ${XHELP_ENV_FILE} -log ${BOOK}.ver
#else
	@echo "Exoterica Validation not supported"; exit 1
#endif

verify: ${MASTER_SGM}
	-@(EBTRC=${EBTRC}; TOOLROOT=${ITOOLROOT}; export EBTRC TOOLROOT; \
	  if [ ! -d entities ] ; then \
	    if [ -d ${BOOK_LIB}/entities ] ; then \
		ln -s ${BOOK_LIB}/entities entities; \
		REMOVE_ENTS=TRUE; export REMOVE_ENTS; \
	    else \
		REMOVE_ENTS=FALSE; export REMOVE_ENTS; \
	    fi \
	fi; \
	${SGMLRVW} -quiet -verifyMore -dtd ${REAL_DTD} -f ${MASTER_SGM} ; \
	if [ $$REMOVE_ENTS = "TRUE" ] ; then \
	    ${RM} -f entities ; \
	fi)

book.err ${BOOK}.err: ${ERR_FILES}
	@${RM} -f ${BOOK}.err
	@for i in ${ERR_FILES}; do \
	  echo "=== $$i Translation Error/Warning report ===" >> ${BOOK}.err; \
	  cat $$i >> ${BOOK}.err; \
	  echo "" >> ${BOOK}.err; \
	done

book.full ${BOOK}.full: ${ERR_FILES} ${MASTER_SGM} book
	@echo " ======== Building master report file ======== "
	@${RM} -f ${BOOK}.full
	@for i in ${SGM_FILES}; do \
	  base=`basename $$i .sgm`; \
	  if [ -f $$base.err ] ; then \
	      echo "=== $$base.err Translation Error/Warning report ===" >> ${BOOK}.full; \
	      cat $$base.err >> ${BOOK}.full; \
	  fi; \
	  echo "" >> ${BOOK}.full; \
	done
#if exists(/usr/sbin/perl)
#if defined (SGI_QA)
	@echo "=== ${BOOK} Internal SGI Doc report ===" >> ${BOOK}.full
	@${SGIBOOK_QA} >> ${BOOK}.full
#endif
	@echo "=== ${BOOK} Link QA report file ===" >> ${BOOK}.full
	@(TOOLROOT=${ITOOLROOT}; export TOOLROOT; \
	  ${XREF} ${MASTER_SGM} >> ${BOOK}.full)
	@echo "" >> ${BOOK}.full
	@echo "=== ${BOOK} Glossary QA report file ===" >> ${BOOK}.full
	@${GLOSSQA} ${MASTER_SGM} >> ${BOOK}.full
	@echo "" >> ${BOOK}.full
#else
	@echo "WARNING: Link QA and Glossary QA reports require /usr/sbin/perl...skipped" >> ${BOOK}.full
	@echo "" >> ${BOOK}.full
#endif
#if defined(VALIDATE)
	@echo "=== ${BOOK} EBT validation report file ===" >> ${BOOK}.full
	-@(EBTRC=${EBTRC}; TOOLROOT=${ITOOLROOT}; export EBTRC TOOLROOT; \
	   if [ ! -d entities ] ; then \
	    if [ -d ${BOOK_LIB}/entities ] ; then \
		ln -s ${BOOK_LIB}/entities entities; \
		REMOVE_ENTS=TRUE; \
	    else \
		REMOVE_ENTS=FALSE; export REMOVE_ENTS; \
	    fi \
	fi ; \
	${SGMLRVW} -quiet -verifyMore -dtd ${REAL_DTD} -f ${MASTER_SGM} >> ${BOOK}.full 2>&1 ; \
	if [ $$REMOVE_ENTS = "TRUE" ] ; then \
	    ${RM} -f entities; \
	fi)
	@echo "" >> ${BOOK}.full
#endif


.ORDER: _online copy_figures
figures: _online copy_figures

localfigrules: Makefile
	@smake -J 1 -r -f Makefile XXX=$$$$ rules

_online: localfigrules
	-@mkdir -p online 1> /dev/null 2>&1
	@if [ -d orig ] ; then \
	  (TOOLROOT=${ITOOLROOT}; export TOOLROOT; \
	  make -r -f Makefile COMMONPREPRULES=${COMMONFIGRULES} online_figs) ;\
	fi

copy_figures: ${SGM_FILES} ${MASTER_SGM}
	-@mkdir -p ${BOOKDIR}/figures 1> /dev/null 2>&1
	-@if [ -d online ] ; then \
	  (for i in ${BOOKDIR}/figures/*; do \
		${RM} -f $$i ; done ) ; \
	fi
#if defined(MISC_FILES)
#if ! empty(MISC_FILES)
	@(cd orig; ${CP} ${MISC_FILES} ../${BOOKDIR}/figures ; cd ..)
#endif
#endif
#if ${DTD} == "SGIDOC"
	@if [ -d online ] ; then \
	  ${CLEAN_CGMS} ${MASTER_SGM} online ; \
	  (for i in `${COPY_SGIDOC_FIGS} ${MASTER_SGM}` ; do \
		  ${CP} online/$$i ${BOOKDIR}/figures/$$i ; \
	  done) ; \
	fi
#else
	@if [ -d online ] ; then \
	(cd online; for i in *; do \
		${CP} $$i ../${BOOKDIR}/figures/$$i ; \
	done; cd ..) ; \
	fi

#endif
	-@rmdir ${BOOKDIR}/figures 1> /dev/null 2>&1

_print print: localfigrules
	-@mkdir -p print 1> /dev/null 2>&1
	@make -r -f Makefile COMMONPREPRULES=${COMMONFIGRULES} print_figs

#if ${DTD} != "HTML"
#if ! defined(RAWIDB)
install::
	  @echo "warning: 'install' not supported if RAWIDB not defined"
#else
.ORDER: pub_book copy_figures common_install
install:: pub_book  copy_figures common_install
#endif
#endif

#if ! defined(RAWIDB)
booksinstall::
	  @echo "warning: 'install' not supported if RAWIDB not defined"
#else
.ORDER: pub_book figures copy_figures common_install
booksinstall:: pub_book figures copy_figures common_install
#endif

common_install:
	$(INSTALL) -u root -g sys  -m 755 \
	    -idb '${BOOKSUBSYSTEM} removeop("if [ -r $$rbase/usr/sbin/insightAdmin ]; then chroot \$$rbase /usr/sbin/insightAdmin -avf ${BOOKSHELF}>>\$$rbase/var/share/Insight/install.insight.log 2>&1; fi")' \
	    -dir ${BOOKSHELF}/${BOOKDIR}
	$(INSTALL) -u root -g sys  -m 755 -idb ${BOOKSUBSYSTEM} \
	    -dir ${BOOKSHELF}/${BOOKDIR}/ebt
	$(INSTALL) -m 644 -f ${BOOKSHELF} -idb \
	    ${BOOKSUBSYSTEM} ${BOOKDIR}/ebt/*
	$(INSTALL) -u root -g sys  -m 755 -idb ${BOOKSUBSYSTEM} \
	    -dir ${BOOKSHELF}/${BOOKDIR}/index
	$(INSTALL) -m 644 -f ${BOOKSHELF} -idb \
	    ${BOOKSUBSYSTEM} ${BOOKDIR}/index/*
	$(INSTALL) -u root -g sys  -m 755 -idb ${BOOKSUBSYSTEM} \
	    -dir ${BOOKSHELF}/${BOOKDIR}/styles
	$(INSTALL) -m 644 -f ${BOOKSHELF} -idb \
	    ${BOOKSUBSYSTEM} ${BOOKDIR}/styles/*
	if [ -d online ] ; then \
		$(INSTALL) -u root -g sys  -m 755 -idb ${BOOKSUBSYSTEM} \
			-dir ${BOOKSHELF}/${BOOKDIR}/figures ; \
		(for i in ${BOOKDIR}/figures/*; do \
			$(INSTALL) -m 644 -f ${BOOKSHELF} -idb \
			${BOOKSUBSYSTEM} $$i ; done ) \
	; fi
	if [ -d help ] ; then \
		if [ "${BOOK_LANG}" = "C" ] ; then \
		     $(INSTALL) -m 644 -f ${HELPDIR} -idb ${HELPSUBSYSTEM}  \
			`${COPY_HELPMAPS} ${MASTER_SGM} help` ; \
		else \
		      (cd help; \
			$(INSTALL) -m 644 -f ${HELPDIR}/help/${BOOK_LANG}\
			-idb ${HELPSUBSYSTEM} \
			`${COPY_HELPMAPS} ../${MASTER_SGM} .` ; \
		       cd ..) ; \
		fi \
	; fi
	$(INSTALL) -m 644 -f ${BOOKSHELF}/${BOOKDIR} \
	    -idb '${BOOKSUBSYSTEM} exitop("(chroot \$$rbase /usr/sbin/insightAdmin -avf ${BOOKSHELF}>>\$$rbase/var/share/Insight/install.insight.log)2>>\$$rbase/var/share/Insight/install.insight.log")' \
	    booklist.txt

#if ${DTD} != "HTML"
clean:: clean_book clean_reports
	${RM} -rf $(DIRT)

clobber:: clean clean_figures clean_sgm
clobber_all: clobber clean_print 
#endif

# Remove the master sgml file and files in the 'books' sub directory.
clean_book::
	${RM} -f ${MASTER_SGM} ${INDEXFILE} ${MIF_FILES}
	${RM} -rf ${BOOKDIR}/ebt ${BOOKDIR}/index ${BOOKDIR}/styles
	${RM} -rf ${BOOKDIR}/entities ${BOOKDIR}/figures
	${RM} -f ${BOOKDIR}/${BOOK}.dtd ${BOOKDIR}/${BOOK}.sgm ${BOOKDIR}/${BOOK}.ctl

# Remove the report files
clean_reports::
	${RM} -f ${VER_FILES} ${ERR_FILES}
	${RM} -f ${BOOK}.err ${BOOK}.ver ${BOOK}.full

# Remove the generated figures
clean_figures::
	${RM} -f online/* ${LOCALFIGRULES}

#if defined(BOOK_FILES)
# Remove all sgml files - only if NONE of the sources are .sgm files
#if ${BOOK_FILES:S/[	 ]*/ /g} == "${BOOK_FILES:S/.sgm$/.skip/g}"
clean_sgm::
	${RM} -f ${SGM_FILES}
#else
clean_sgm::

#endif
#endif

clean_print::
	${RM} -f print/*

# Remove any crufty files
XDIRT = printFiles.* onlineFiles.* localFigs.* ${DIRT_FILES} ${BOOK}.sgml.tmp \
	*.bak *.backup booklist.txt.old EndPart.err EndPart
