# Makefile for auto-H4-ifying the Pratchett FAQs.


# Location of the txt2html program, and its link dictionaries.

TXT2HTML = ./txt2html/txt2html.pl

TXT2HTML_DEFAULT_DIC = ./txt2html/txt2html.dict
TXT2HTML_FAQS_DIC = ./faqs.dict

# Install directory for the HTMLified FAQs
WWWDIR	= ./www-faqs

# Install directory for the original FAQs
FTPDIR	= ./ftp-faqs

SOURCES = abp-guide acronym-faq \
	afp-faq afp-recipes-faq afpa-faq afpmeet-faq \
	 daftpabank lspace-faq \
	mini-faq subject-tags-faq \
	history-monks-faq
#	bibliography welcome-to-afp-1 welcome-to-afp-2


# Nothing to customise below this point.

SOURCES := $(sort $(SOURCES))
H4FILES = $(SOURCES:%=%.g.h4)

WWWINSTALLS = $(H4FILES:%=$(WWWDIR)/%) $(WWWDIR)/index.h4
FTPINSTALLS = $(SOURCES:%=$(FTPDIR)/%)


all:		$(H4FILES) index.h4



# Leo: FAQs are now deprecated. To help avoid link rot, htmlify, but
# do not actually create any links anymore.
#
# %.g.h4:		% %-metatags.g.tmp $(TXT2HTML_FAQS_DIC)
#		@echo -n "H4-ifying $<... ";
#		@$(TXT2HTML) \
#		-l $(TXT2HTML_FAQS_DIC) \
#		-l $(TXT2HTML_DEFAULT_DIC) \
#		-t "`sed -n -e '21q;1,20s/^Subject: //p' $<`" \
#		-ah $*-metatags.g.tmp \
#		-pb -666 $< \
#		| sed -e 's@"http://www.lspace.org@"_LSPACE_WWW@g' \
#		     -e 's@"ftp://ftp.lspace.org/pub/pratchett@"_LSPACE_FTP@g' > $@;
#		@echo " Done."
#
#
%.g.h4:		% %-metatags.g.tmp $(TXT2HTML_FAQS_DIC)
		@echo -n "H4-ifying $<... ";
		@$(TXT2HTML) \
		-t "`sed -n -e '21q;1,20s/^Subject: //p' $<`" \
		-ah $*-metatags.g.tmp \
		-pb -666 $< \
		| sed -e 's@"http://www.lspace.org@"_LSPACE_WWW@g' \
		     -e 's@"ftp://ftp.lspace.org/pub/pratchett@"_LSPACE_FTP@g' > $@;
		@echo " Done."



%-metatags.g.tmp: %
		@echo -n "<meta name=\"keywords\" content=\"" > $@
		@echo -n "`sed -n -e '21q;1,20s/^Keywords: //p' $*`" >> $@;
		@echo    "\" />" >> $@;
		@echo -n "<meta name=\"author\" content=\"" >> $@
		@echo -n "`sed -n -e '16q;1,15s/^From: *\"\?\([^\".]*\)\"\? *<.*>/\1/p' $*`" >> $@;
		@echo    "\" />" >> $@;
		@echo -n "<meta name=\"description\" content=\"" >> $@
		@echo -n "`sed -n -e '16q;1,15s/^Summary: //p;s/^	/ /p' $*`" >> $@;
		@echo    "\" />" >> $@;
		@echo -n "<link rev=\"made\" href=\"mailto:" >> $@;
		@echo -n "`sed -n -e '21q;1,20s/^From:.*<\(.*\)>/\1/p' $*`" >> $@;
		@echo    "\" />" >> $@;
		@echo    "<link rel=\"stylesheet\" title=\"Default Stylesheet\" href=\"_CSS/default.css\" type=\"text/css\" />" >> $@;



index.h4:	maintainer-info.g.sed index.h4.in
		@echo -n "Creating $@... "
		@sed -f $< index.h4.in > $@
		@echo " Done."

maintainer-info.g.sed: $(SOURCES)
		@rm -f $@;
		@( for i in $(SOURCES);\
		do\
			echo -n "s@<$$i-meta>@" >> $@;\
			echo -n "`sed -n -e '21q;1,20s/^From: \(.*\) <.*>/Maintained by \1/p' $$i`" >> $@;\
			echo -n ";  " >> $@;\
			echo -n "`sed -n -e '21q;1,20s/^Last-[Mm]odified/Last updated/p' $$i`" >> $@;\
			echo    "@"  >> $@;\
		done )


install:	$(WWWINSTALLS)# $(FTPINSTALLS)


$(WWWDIR)/%:	%
		cp $< $@
#		cp $< $(HOME)/hex/lspace/faqs


$(FTPDIR)/%:	%
		cp $< $@


.PHONY: clean empty

clean:	
	rm -f $(H4FILES)

empty:	clean
	rm -f index.h4 *.g.*

