# ~jhs/public_html/bin/Makefile by Julian H. Stacey

SUBDIR += .other
SUBDIR += .sh
SUBDIR += .csh

all:	index.lmth index.html

FILES!= find -s . -type f				\
	\(	\! -name ./index.html		-and	\
		\! -name ./index.html.tmp	-and	\
		\! -name ./index.lmth			\
	\)		-print | \
	grep -v index.html | grep -v index.lmth
# JJLATER why do I need above grep -v

files_show:
	@echo ${FILES}

index.lmth:	${FILES}
	echo "<HTML><HEAD><TITLE>"				>  ${.CURDIR}/$@
	echo "Julian H. Stacey's ~/bin/</TITLE></HEAD>"		>> ${.CURDIR}/$@
	echo "<BODY><H1><a href=../>Julian H. Stacey</a>'s"	>> ${.CURDIR}/$@
	echo "<BR>Index of ~jhs/bin/</H1>"			>> ${.CURDIR}/$@
	echo "<P><B>Generated `date` by "			>> ${.CURDIR}/$@
	echo "<a href=Makefile>Makefile</a></B><P>"		>> ${.CURDIR}/$@
	echo "<MENU>"						>> ${.CURDIR}/$@
	@# Cant use ${FILES} in next line as need filenames one per line.
	(cd ${.CURDIR}; find . -type f \( \
		! -name index.html	-and \
		! -name index.lmth	-and \
		! -name index.html.tmp	\) \
		-print ) | grep -v .no_customise | sort > ${HOME}/tmp/$@.tmp
	for i in `cat ${HOME}/tmp/$@.tmp` ; do \
		echo "<li><a href=$$i>$$i</a><PRE>"		>> ${.CURDIR}/$@ ; \
		head -2 ${.CURDIR}/$$i | sed 's/</\&lt;/g' |	\
			sed 's/>/\&gt;/g' | sed 's/&/\&amp;/g'	>> ${.CURDIR}/$@ ; \
		echo "</PRE>"					>> ${.CURDIR}/$@ ; \
		done
	-rm ${HOME}/tmp/$@.tmp
	@# The head above should be changed to cat till blank line
	echo '</MENU><HR>'					>> ${.CURDIR}/$@
	echo '<a href="../txt/footer.html"><img src="/gifs/footer.gif"></a>' \
								>> ${.CURDIR}/$@
	echo '</BODY></HTML>'					>> ${.CURDIR}/$@
	chmod 644 ${.CURDIR}/$@

.include <berklix.mk>
