;#
;# Copyright 1998, The University of Texas at Austin ("U. T. Austin").
;# All rights reserved.
;#
;# By using this software the USER indicates that he or she has read,
;# understood and will comply with the following:
;#
;# U. T. Austin hereby grants USER permission to use, copy, modify, and
;# distribute this software and its documentation for any purpose and
;# without fee, provided that:
;#
;# 1. the above copyright notice appears in all copies of the software
;#    and its documentation, or portions thereof, and 
;# 2. a full copy of this notice is included with the software and its
;#    documentation, or portions thereof, and 
;# 3. neither the software nor its documentation, nor portions thereof,
;#    is sold for profit. Any commercial sale or license of this software,
;#    copies of the software, its associated documentation and/or
;#    modifications of either is strictly prohibited without the prior
;#    consent of U. T. Austin. 
;# 
;# Title to copyright to this software and its associated documentation
;# shall at all times remain with U. T. Austin. No right is granted to
;# use in advertising, publicity or otherwise any trademark, service
;# mark, or the name of U. T. Austin.
;# 
;# This software and any associated documentation are provided "as is,"
;# and U. T. AUSTIN MAKES NO REPRESENTATIONS OR WARRANTIES, EXPRESSED OR
;# IMPLIED, INCLUDING THOSE OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR
;# PURPOSE, OR THAT USE OF THE SOFTWARE, MODIFICATIONS, OR ASSOCIATED
;# DOCUMENTATION WILL NOT INFRINGE ANY PATENTS, COPYRIGHTS, TRADEMARKS OR
;# OTHER INTELLECTUAL PROPERTY RIGHTS OF A THIRD PARTY. U. T. Austin, The
;# University of Texas System, its Regents, officers, and employees shall
;# not be liable under any circumstances for any direct, indirect, special,
;# incidental, or consequential damages with respect to any claim by USER
;# or any third party on account of or arising from the use, or inability
;# to use, this software or its associated documentation, even if U. T.
;# Austin has been advised of the possibility of those damages.
;# 
;# Submit commercialization requests to: Office of the Executive Vice
;# President and Provost, U. T. Austin, 201 Main Bldg., Austin, Texas,
;# 78712, ATTN: Technology Licensing Specialist.
;#
;# @(#)Jmakefile	1.13 10/01/98 (cc.utexas.edu)
;#
;# Makefile for npasswd documentation (mostly HTML docs)
;#

#include "../Jmake.local"

/* Implicit symbols needed from config.sh */
>CC
>RM

Initialize(DOCS, $p_docdir)

Describe(NROFF,	Nroff command)
Initialize(NROFF, $nroff)

/* Use lynx to convert HTML to text */
Describe(HTCONVERT,	Command to convert HTML to text (lynx -dump))
Initialize(HTCONVERT, lynx -dump)

/* Command to post-process lynx output */
Initialize(HTFILTER,  sed -e s@file://localhost`pwd`@file://localhost/.@) 

/*
 * Roff2HTML
 *	Convert nroff documents to HTML.
 */
#define	Roff2HTML(_mac,_src,_dst) 	@!\
>RM		@!\
>NROFF		@!\
_dst: _src @@\
	-@if [ -f $(NROFF) ]; then \	@@\
		$(RM) _dst; \	@@\
		$(NROFF) -m^^_mac _src |./docfilter |./nroff2html > _dst ;\ @@\
		echo "_src -> _dst"; \  @@\
	else \ @@\
		echo "Cannot make _dst ($(NROFF) not found)"; \ @@\
	fi

/*
 * Roff2Text
 *	Convert nroff documents to Text.
 */
#define	Roff2Text(_mac,_src,_dst) 	@!\
>RM		@!\
>NROFF		@!\
_dst: _src @@\
	-@if [ -f $(NROFF) ]; then \	@@\
		$(RM) _dst; \	@@\
		$(NROFF) -m^^_mac _src | ./docfilter > _dst ;\ @@\
		echo "_src -> _dst"; \  @@\
	else \ @@\
		echo "Cannot make _dst ($(NROFF) not found)"; \ @@\
	fi

/*
 * HTML2Text
 *	Convert HTML documents to text.
 */
#define	HTML2Text(_src,_dst)	@!\
>RM		@!\
_dst: _src @@\
	@test -f _src 	@@\
        -@$(HTCONVERT) _src | ./docfilter | $(HTFILTER) > _dst.tmp; \ @@\
	 if [ -s _dst.tmp ]; then \ @@\
		$(MV) _dst.tmp _dst; \	@@\
		echo "_src -> _dst"; \ @@\
	else \ @@\
		echo "Cannot make _dst ('$(HTCONVERT)' failed)"; \ @@\
		$(RM) _dst.tmp; \ @@\
	fi

HTML	= \
	AdminGuide.html \
	BuildInstall.html \
	BugReport.html \
	Copyright.html \
	QNA.html \
	Main.html \
	ManPages.html \
	MiscNotes.html \
	Support.html \
	Reference.html \
	Reference_TOC.html \
	Reference_index.html \
	TOC_frame.html \
	TOC_std.html \
	index.html


HTML_TXT = \
	AdminGuide.txt \
	BuildInstall.txt \
	BugReport.txt \
	Copyright.txt \
	QNA.txt \
	Main.txt \
	ManPages.txt \
	MiscNotes.txt \
	Support.txt \
	Reference.txt \
	TOC_std.txt

PS	= \
	PasswordSecurity.ps \
	Worm-MIT.ps \
	Worm-Utah.ps

IMG	= \
	top.gif \
	home.gif

MAN	= \
	checkpassword.1 \
	checkpassword.3 \
	history_admin.1 \
	makedict.1 \
	npasswd.1

MAN_HTML = \
	checkpassword_1.html \
	checkpassword_3.html \
	history_admin_1.html \
	makedict_1.html \
	npasswd_1.html

MAN_CAT = \
	checkpassword.cat1 \
	checkpassword.cat3 \
	history_admin.cat1 \
	makedict.cat1 \
	npasswd.cat1

Describe(all,	Make everything: nroff2html docfilter man-html man-txt hmtl-txt)
all::	nroff2html docfilter man-html man-txt html-txt

Describe(dist,	Prepare for distribution)
dist:	man-html man-txt html-txt

Describe(install,	Install everything: install-html install-man install-txt)
Describe(deinstall,	Remove everything: deinstall-html deinstall-man deinstall-txt)

MakeInstallDirectories($(DOCS))

HelpTarget()

;#
;#  Program to "convert" nroff output to HTML
;#

nroff2html: nroff2html.c
	$(CC) -o nroff2html nroff2html.c

docfilter: docfilter.SH
	$(RM) docfilter
	sh docfilter.SH

;#
;# Transform manual pages to HTML documents
;#
Describe(man-html,	Make HTML versions of man pages)
man-html:	$(MAN_HTML) docfilter nroff2html

Roff2HTML(an,checkpassword.1,checkpassword_1.html)
Roff2HTML(an,checkpassword.3,checkpassword_3.html)
Roff2HTML(an,history_admin.1,history_admin_1.html)
Roff2HTML(an,makedict.1,makedict_1.html)
Roff2HTML(an,npasswd.1,npasswd_1.html)

;#
;# Transform manual pages to text documents
;#
Describe(man-txt,	Make text (cat) versions of man pages)
man-txt:	$(MAN_CAT) docfilter

Roff2Text(an,checkpassword.1,checkpassword.cat1)
Roff2Text(an,checkpassword.3,checkpassword.cat3)
Roff2Text(an,history_admin.1,history_admin.cat1)
Roff2Text(an,makedict.1,makedict.cat1)
Roff2Text(an,npasswd.1,npasswd.cat1)

;#
;# Transform HTML documents to text
;#
Describe(html-txt,	Make text versions of HTML files)
html-txt:	$(HTML_TXT) docfilter

|expand d!$(HTML_TXT)!
HTML2Text(!d:\.txt=\.html, !d)

-expand

;#
;# Install targets
;#
|expand d!html man txt!
install::	install-!d

deinstall::	deinstall-!d

-expand

/*
 * Install documentation files
 */
Describe(install-html,	Install HTML documents)
Describe(deinstall-html,	Remove HTML documents)

InstallMultipleDestFlags(install-html,$(PS) $(IMG), $(DOCS), -m 0444)

#define InstallDoc(_target_,_src_,_dst_) @!\
>RM		@!\
install-^^_target_^^:: _src_ docfilter	@@\
	@case '${MFLAGS}' in *[i]*) set +e;; esac; \	@@\
	for f in _src_ ; do \		@@\
		$(RM) /tmp/$$f.temp; \	@@\
		./docfilter $$f > /tmp/$$f.temp; \	@@\
		(set -x; $(INSTALL) -m 444 /tmp/$$f.temp _dst_/$$f; ); \  @@\
		$(RM) /tmp/$$f.temp;	\	@@\
	done

#define DeinstallDoc(_target_,_src_,_dst_) @!\
>RM		@!\
deinstall-^^_target_^^::		@@\
	@case '${MFLAGS}' in *[i]*) set +e;; esac; \	@@\
	for f in _src_ ; do \ 		@@\
		$(RM) $(DOCS)/$$f; \	@@\
	done

InstallDoc(html, $(HTML), $(DOCS))
DeinstallDoc(html, $(HTML), $(DOCS))

Describe(install-man,	Install man pages)
Describe(deinstall-man,	Remove man pages)
InstallMultipleDestFlags(install-man, $(MAN_HTML) $(MAN_CAT), $(DOCS), -m 0444)

InstallDoc(man, $(MAN), $(DOCS))
DeinstallDoc(man, $(MAN), $(DOCS))

Describe(install-txt,	Install text versions of HTML documents)
Describe(deinstall-txt,	Remove text versions of HTML documents)
InstallMultipleDestFlags(install-txt, $(HTML_TXT), $(DOCS), -m 0444)

;#
;# Dependancies for HTML documents
;#
TerminalDependancy($(HTML) $(PS) $(IMG))

;#
;# Clean the HTML docs created from man pages
;#
local_clobber::
	$(RM) $(MAN_HTML) $(HTML_TXT) nroff2html docfilter

NoDebug()
NoLint()
NoDepend()

;#
;# End Makefile
