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

SUBDIR += bsd

all:	automatic.html \
	fixes_files.lmth \
	fixes_files.html \
	fixes_diffs.lmth \
	fixes_diffs.html \
	index.html \
	obj \
	# ../src.tgz
	@${STA} #{
# ../src.tgz is about 24 Meg
# It is linked from this index.html
	@${FIN} #}

clean:
	@echo "Default clean if you remove this line, zaps index.html"# JJLATER
	@# maybe also zaps automatic.html fixes_diffs.html fixes_files.html
	@echo Suggestion zap these:
	-find . -name .depend | xargs rm

HEAD=head -6
# The head above should be changed to some better utility that cat's
# till a blank line

# LOTS!=cd ${.CURDIR} ; find . -type f
# # ../src.tgz: ${LOTS}
# ../src.tgz:
#	@echo "Ensuring a minimal size, first running:"
#	@echo " make clean && make cleandir && make clean"
#	make clean && make cleandir && make clean
#	tar -z -c --exclude $@ -f ../src.tgz \
#	src Inc standards/common.rof standards/umlauts.rof Makefile.inc
#	@# Makefile.inc to supply BINDIR to src/bsd/jhs/bin/public/brackets/
#	@# One day I might make a FreeBSD port as suggested by Chris H
#	@# http://lists.freebsd.org/pipermail/freebsd-hackers/\
#	@# 2015-March/047211.html
#	@# meantime I have created $@ as distfile/
#	@# for my entire ~/public_html/src/
#	@echo "This has been tested by installing into a fresh virgin jail,"
#	@echo "fetching and building ports I need for some tools."
#	@# My test is still from an Outer Berklix prison, building a
#	@# FreeBSD jail, then converting it to a Berklix jail.
#	@# I have not tried a more rigorous test, from a FreeBSD prison to
#	@# a FreeBSD jail to a Berklix jail.
#	@# ----------
#	@# Manually called occasionaly.
#	@# (It may be older than some components, as just built
#	@# intermittently as a convenience in case someone want to
#	@# fetch all sources in a single fetch).

berklix_install:
	@${STA} #{
	@echo "About to install your src.tgz into a new jail"
	@echo "Assuming you have already done this:"
	@echo " mkdir /somewhere/jail ; ln -s /somewhere/jail /jail"
	@echo " setenv DESTDIR /jail"
	@echo " cd /usr/src/etc && make distrib-dirs"
	@echo " cd /usr/src	&& make install"
	@echo " cd /jail/usr/ports"
	@echo " mdir ../distfiles; ln -s ../distfiles"
	@echo " mdir ../packages; ln -s ../packages"
	@echo " tar zxf /pri/FreeBSD/releases/\`uname -r`\/tars/ports.tgz"
	@echo " install -c -m 644 /usr/src/etc/master.passwd /jail/etc"
	@echo " install -c -m 644 /usr/src/etc/group /jail/etc"
	@#	passwd & group needed for root to avoid
	@#	mtree: line 6: unknown user root
	@#	mtree: line 6: unknown group wheel
	@#	when building /usr/ports/www/tidy
	@#	for public_html/src/bsd/jhs/bin/public/date
	@echo -n " install -c /site/domain/js.berklix.net/etc/make.conf.fetch"
	@echo " /jail/etc/make.conf"
	@#	make.conf needed to supply old local distfiles to match
	@#	existing uname -r ; that may no longer be on internet.
	@#	You will need your own local version of /etc/make.conf,
	@#	copying components from your files included by your
	@#	outer prison /etc/make.conf
	@# -----------------
	@echo	"cd /usr/src/etc ;install -c services /jail/etc
	@#	Needed to avoid fetch of local ports distfiles failing with:
	@#	ftp: Can't lookup `ftp.js.berklix.net:ftp': \
	@#		 servname not supported for ai_socktype
	@# -----------------
	mount -t devfs dev /jail/dev
	@#	avoid failure from /usr/ports/lang/perl5.14
	@#	/dev/null appears to be a file rather than a device
	@#	Leave the word, jump in a jail, & start adding Berklix
	@echo " chroot /jail"
	@#echo "	setenv HOME /home/me_in_jail"
	@echo " HOME=/home/me_in_jail;export HOME"
	@echo " mkdir -p $HOME/public_html"
	@echo " cd $HOME/public_html ; tar zxf src.tgz"
	@echo " cd $HOME/public_html/src && make berklix_install"
	@#	public_html/src is assumed for now by UMLAUTS_INC & COMMON_INC
	@#	by berklix2.mk for bsd/jhs/bin/public/satellite/data/
	@echo "The next 2 files are Not standard to generic FreeBSD"
	@echo "but will have been installed by the above,"
	@echo "if you are already running an external prison with src/"
	@echo "with Berklix hacks"
	@echo "If not, next ls will break, & you will need to:"
	@echo " cd bsd/fixes/FreeBSD/src/jhs/share/mk"
	@echo " install -c -m 755 berklix.mk berklix2.mk /usr/share/mk/"
	ls -l /usr/share/mk/berklix.mk /usr/share/mk/berklix2.mk
	pwd_mkdb -i -p -d /etc /etc/master.passwd
	make all install
	echo "The berklix tools are now installed."
	echo -n "I suggest you now apply the berklix patches"
	echo " to freebsd src & ports, by doing this:"
	echo "mkdir -p $HOME/bin/.sh ; cd $HOME/bin/.sh"
	echo "fetch http://berklix.com/~jhs/bin/.csh/customise"
	echo "./customise ; cd /usr/src && make install"
	@${FIN} #}

# This does not always work:
#	LISTFIXES!= cd ${.CURDIR} ; find bsd/fixes -type f -print
#	fixes_diffs.lmth:	${LISTFIXES} Makefile
#	fixes_files.lmth:	${LISTFIXES} Makefile
# as it sometimes complains about not knowing how to build
# bsd/fixes/FreeBSD/ports/jhs/x11-wm/fvwm/debug/index.html

fixes_head_lmth.tmp:	Makefile
	@${STA} #{
	echo \
	 '<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">' > ${.CURDIR}/`basename $@`
	echo "<head>"							>> ${.CURDIR}/`basename $@`
	echo "<meta name="generator" content="HTML Tidy, see www.w3.org">" >> ${.CURDIR}/`basename $@`
	echo "<title>Julian H. Stacey's Indexes of Patches in ~/src/bsd/fixes/</title>" >> ${.CURDIR}/`basename $@`
	echo "</head>"							>> ${.CURDIR}/`basename $@`
	echo "<body>"							>> ${.CURDIR}/`basename $@`
	echo -n "<!-- DO NOT EDIT - "					>> ${.CURDIR}/`basename $@`
	echo "Generated by ~/public_html/src/Makefile -->"		>> ${.CURDIR}/`basename $@`
	echo " "							>> ${.CURDIR}/`basename $@`
	echo "<h1><a href=../>Julian H. Stacey</a>'s"			>> ${.CURDIR}/`basename $@`
	echo -n "<br>Index of "						>> ${.CURDIR}/`basename $@`
	echo '~jhs/src/<a href="bsd/fixes/">bsd/fixes/</a></h1>'	>> ${.CURDIR}/`basename $@`
	echo "<p><b>Generated `date` by "				>> ${.CURDIR}/`basename $@`
	echo "<a href=Makefile>Makefile</a></b></p>"			>> ${.CURDIR}/`basename $@`
	@${FIN} #}

fixes_diffs_lst.tmp:
	@${STA} #{
	@echo "Creating $@ List of diffs only"
	(cd ${.CURDIR} ; find bsd/fixes -type f -name \*.diff | sort )	> ${.CURDIR}/`basename $@`
	@${FIN} #}

fixes_files_lst.tmp:
	@${STA} #{
	@echo -n "Creating $@ List of most files, including diff,"
	@echo " excluding executables *.tgz etc"
	echo "Removing executables"
	echo "Hashed out: (cd ${.CURDIR} && make clean)"
	@# If OBJDIR exists, then clean only happesn is OBJDIR so
	@# executable binaires may still lurk in ${.CURDIR}
	@echo "If next find errors as it has found nothing, that is Good!"
	@echo "Else If next find list files, You need to delete them:"
	-find . -type f \
		| xargs file \
		| grep -i executable \
		| grep -v "ASCII text executable" \
		| grep -v "POSIX shell script, ISO-8859 text executable"
	(cd ${.CURDIR} ; find bsd/fixes -type f \( \
		\! -name \*.EXE -a \
		\! -name \*.exe -a \
		\! -name \*.gz -a \
		\! -name \*.jpg -a \
		\! -name \*.lmth -a \
		\! -name \*.no_customise -a \
		\! -name \*.o -a \
		\! -name \*.pdf -a \
		\! -name \*.pgp -a \
		\! -name \*.png -a \
		\! -name \*.tgz -a \
		\! -name \*.xmhcache \
		\! -name \*/mail/\* -a \
		\) -print ) | sort | grep -v /mail/> ${.CURDIR}/`basename $@`
	@# bsd/jhs/bin/public/phone/fritz/mail/2 has high bit in mail
	@${FIN} #}

fixes_files.lmth:	fixes_head_lmth.tmp fixes_files_lst.tmp
	@${STA} #{
	rm -f				${.CURDIR}/fixes_tail_lst.tmp
	ln -s fixes_files_lst.tmp	${.CURDIR}/fixes_tail_lst.tmp
	@#				make fixes_tail_lmth.tmp
	cd ${.CURDIR} && make fixes_tail_lmth.tmp
	ls -l ${.CURDIR}/fixes_head_lmth.tmp
	ls -l ${.CURDIR}/fixes_tail_lmth.tmp
	cat ${.CURDIR}/fixes_head_lmth.tmp ${.CURDIR}/fixes_tail_lmth.tmp \
							> ${.CURDIR}/`basename $@`
	@# Not necessary to rm the common ${.CURDIR}/fixes_head_lmth.tmp
	@# Remove the switchable symbolic link ${.CURDIR}/fixes_tail_lmth.tmp
	rm ${.CURDIR}/fixes_tail_lmth.tmp
	@# Not necessary to rm fixes_files_lst.tmp
	@${FIN} #}

fixes_diffs.lmth:	fixes_head_lmth.tmp fixes_diffs_lst.tmp
	@${STA} #{
	rm -f ${.CURDIR}/fixes_tail_lst.tmp
	ln -s fixes_diffs_lst.tmp ${.CURDIR}/fixes_tail_lst.tmp
	cd ${.CURDIR} && make fixes_tail_lmth.tmp
	cat ${.CURDIR}/fixes_head_lmth.tmp ${.CURDIR}/fixes_tail_lmth.tmp \
							> ${.CURDIR}/`basename $@`
	@# Not necessary to rm the common ${.CURDIR}/fixes_head_lmth.tmp
	@# Remove the switchable symbolic link ${.CURDIR}/fixes_tail_lmth.tmp
	rm ${.CURDIR}/fixes_tail_lmth.tmp
	@# Not necessary to rm fixes_diffs_lst.tmp
	@${FIN} #}

# fixes_files.lmth from fixes_files.lmth via standard berklix.mk macros
# fixes_diffs.html from fixes_diffs.lmth via standard berklix.mk macros

# Some files are called *_lmth.tmp & *_lst.tmp rather than .lmth & .lst,
# to avoid any chance of suffix rules interfering

fixes_tail_lmth.tmp:	fixes_tail_lst.tmp Makefile
#	Dependency fixes_tail_lst.tmp is just a sanity check,
#	it is pre-created by fixes_files.lmth & fixes_diffs.lmth
	@${STA} #{
	echo "<h2>Generic, not just for jhs@</h2>"		> ${.CURDIR}/`basename $@`
	echo "<ul>"						>> ${.CURDIR}/`basename $@`
	grep -v /jhs/ ${.CURDIR}/fixes_tail_lst.tmp		> ${.CURDIR}/fixes_tail2_lst.tmp
	@echo "Checking size: `wc ${.CURDIR}/fixes_tail2_lst.tmp`"
	for i in `cat ${.CURDIR}/fixes_tail2_lst.tmp` ; do \
		echo -n "Starting fixes_tail_lmth.tmp : $i" ; \
		echo " `ls -l ${.CURDIR}/fixes_tail_lst.tmp` generic $$i" ; \
		echo " "					>> ${.CURDIR}/`basename $@` ; \
		echo "<li><a href=\"$$i\">$$i</a>"		>> ${.CURDIR}/`basename $@` ; \
		echo "	<div style=\"margin-left: 2em\"><pre>"	>> ${.CURDIR}/`basename $@` ; \
		${HEAD} ${.CURDIR}/$$i | sed 's/</\&lt;/g' |		\
		 sed 's/>/\&gt;/g' | sed 's/&/\&amp;/g'		>> ${.CURDIR}/`basename $@` ; \
		echo "	</pre></div></li>"			>> ${.CURDIR}/`basename $@` ; \
		echo -n "Finishing fixes_tail_lmth.tmp : $i" ; \
		echo " `ls -l ${.CURDIR}/fixes_tail_lst.tmp` generic $$i" ; \
		done
	echo "</ul><hr><h2>For jhs@ systems, "			>> ${.CURDIR}/`basename $@`
	echo "probably not for generic application</H2><UL>"	>> ${.CURDIR}/`basename $@`
.if exists (/site)
	grep /jhs/ ${.CURDIR}/fixes_tail_lst.tmp	\
					> ${.CURDIR}/fixes_tail2_lst.tmp
.else	# There are no /jhs/ components in a chroot cdrom, so prepend '-'
	-grep /jhs/ ${.CURDIR}/fixes_tail_lst.tmp\
					> ${.CURDIR}/fixes_tail2_lst.tmp
.endif
	@echo "Checking size: `wc ${.CURDIR}/fixes_tail2_lst.tmp`"
	for i in `cat ${.CURDIR}/fixes_tail2_lst.tmp` ; do \
		echo -n "Starting fixes_tail_lmth.tmp : $i" ; \
		echo " `ls -l ${.CURDIR}/fixes_tail_lst.tmp` jhs $$i" ; \
		echo " "					>> ${.CURDIR}/`basename $@` ; \
		echo "<li><a href=\"$$i\">$$i</a>"		>> ${.CURDIR}/`basename $@` ; \
		echo "	<div style=\"margin-left: 2em\"><pre>"	>> ${.CURDIR}/`basename $@` ; \
		${HEAD} ${.CURDIR}/$$i | sed 's/</\&lt;/g'\
		| sed 's/>/\&gt;/g' | sed 's/&/\&amp;/g'	>> ${.CURDIR}/`basename $@` ; \
		echo "	</pre></div></li>"			>> ${.CURDIR}/`basename $@` ; \
		echo -n "Finishing fixes_tail_lmth.tmp : $i" ; \
		echo " `ls -l ${.CURDIR}/fixes_tail_lst.tmp` jhs $$i" ; \
		done
	@rm ${.CURDIR}/fixes_tail_lst.tmp ${.CURDIR}/fixes_tail2_lst.tmp
	echo '</ul>'						>> ${.CURDIR}/`basename $@`
	@# echo -n '<hr><a href="../txt/footer.html">'		>> ${.CURDIR}/`basename $@`
	@# echo '<img alt="footer" src="/gifs/footer.gif"></a>' >> ${.CURDIR}/`basename $@`
	echo '</body>'						>> ${.CURDIR}/`basename $@`
	echo '</html>'						>> ${.CURDIR}/`basename $@`
	chmod 644 ${.CURDIR}/`basename $@`
	@${FIN} #}

CLN =
CLN += fixes_diffs.lmth
CLN += fixes_diffs_lst.tmp
CLN += fixes_files.lmth
CLN += fixes_files_lst.tmp
CLN += ${.CURDIR}/fixes_head_lmth.tmp
CLN += ${.CURDIR}/fixes_tail_lmth.tmp
CLN += ${.CURDIR}/fixes_tail_lst.tmp
CLN += ${.CURDIR}/fixes_tail2_lst.tmp

cleanx:
	@${STA} #{
	rm -f ${CLN}
	cd ${.CURDIR} && rm -f ${CLN}
	@echo "Suggestion: make cleanmore"
	@# this label was in hopes to avoid a berklix.mk clean
	@# that might zap:
	@# index.html automatic.html fixes_files.html fixes_diffs.html
	@# but when this label was 'clean' the berklix.mk clean got called
	@# insteda, so Ive made it cleanx
	@${FIN} #}

cleanmore:	clean
	@${STA} #{
	rm -f \
	automatic.html \
	fixes_diffs.html \
	fixes_files.html \
	index.html
	@${FIN} #}

.include <berklix.mk>
