SHELL = /bin/sh
DESTDIR = $(FTP_DIR)/bulk
TEMPDIR = $(DESTDIR)/tmp-bulkmake

XZIP = test.zip
XINCLUDE = index.html news.html glossary.html test.test

ZIP = bulk.zip
EXCLUDE = pali/fonts.html\
	patipatti.html\
	pariyatti.html\
	whoami.html\
	lib/thai.html\
	lib/thai/other/fistful.html lib/thai/other/attitude.html\
	lib/thai/sao.html lib/thai/simplyso.html lib/thai/yourown.html\
	lib/thai/iridescence.html\
	lib/misc.html\
	lib/modern.html\
	lib/leaves.html\
	lib/wheels.html\
	lib/bps/news/essay?.html\
	cdrom/cdlist.html\
	canon/tipitaka.html\
	canon/digha/dn?.html\
	canon/majjhima/mn?.html\
	canon/majjhima/mn??.html canon/majjhima/mn\?0a.html canon/majjhima/mn\?0b.html\
	canon/samyutta/sn?-*.html\
	canon/samyutta/sn??-?.html\
	canon/samyutta/sn??-??.html\
	canon/samyutta/sn22-59b.html canon/samyutta/sn35-28b.html\
	canon/samyutta/sn36-11b.html canon/samyutta/sn36-4b.html\
	canon/samyutta/sn36-6b.html canon/samyutta/sn36-7b.html\
	canon/samyutta/sn36-8b.html canon/samyutta/sn5-10b.html\
	canon/samyutta/sn5-1b.html canon/samyutta/sn5-2b.html\
	canon/samyutta/sn5-3b.html canon/samyutta/sn5-4b.html\
	canon/samyutta/sn5-5b.html canon/samyutta/sn5-6b.html\
	canon/samyutta/sn5-7b.html canon/samyutta/sn5-8b.html\
	canon/samyutta/sn5-9b.html canon/samyutta/sn56-11b.html\
	canon/samyutta/sn02-069.html   canon/samyutta/sn02-070.html\
	canon/samyutta/sn12-23a.html\
	canon/anguttara/an?-*.html\
	canon/anguttara/an??-?.html\
	canon/anguttara/an??-??.html\
	canon/anguttara/an*b.html\
	canon/khuddaka/khp/khp5a.html\
	canon/khuddaka/therigatha/thig?.html\
	canon/khuddaka/therigatha/thig?.html\
	canon/khuddaka/therigatha/thig03-3a.html\
	canon/khuddaka/theragatha/thag?.html\
	canon/khuddaka/udana/ud?-?.html\
	canon/khuddaka/udana/ud*b.html\
	canon/khuddaka/suttanipata/snp?-?.html\
	canon/khuddaka/suttanipata/snp1-1b.html\
	canon/khuddaka/suttanipata/snp2-10b.html\
	canon/khuddaka/suttanipata/snp2-3b.html\
	canon/khuddaka/suttanipata/snp2-4b.html\
	canon/khuddaka/suttanipata/snp2-9b.html\
	canon/khuddaka/suttanipata/snp3-12b.html\
	canon/khuddaka/suttanipata/snp3-2b.html\
	canon/khuddaka/suttanipata/snp3-8b.html\
	canon/khuddaka/suttanipata/snp4-11b.html\
	canon/khuddaka/suttanipata/snp4-15b.html\
	canon/khuddaka/suttanipata/snp4-4b.html\
	canon/khuddaka/suttanipata/snp4-5b.html\
	canon/khuddaka/suttanipata/snp4-6b.html\
	canon/khuddaka/suttanipata/snp5-15b.html\
	canon/khuddaka/suttanipata/snp5-16b.html\
	canon/khuddaka/suttanipata/snp5-1b.html\
	canon/khuddaka/suttanipata/snp5-3b.html\
	canon/khuddaka/suttanipata/snp5-4b.html\
	canon/khuddaka/dhp/?.html\
	canon/khuddaka/dhp1/?.html

INCLUDE = *.html\
	tech/*\
	cdrom/*html\
	pali/*.html\
	ptf/*.html\
	icon/*\
	lib/*.html\
	lib/study/*.html\
	lib/study/aids/*.html\
	lib/misc/*.html\
	lib/misc/chanting/*.html\
	lib/modern/*.html\
	lib/modern/ariyesako/*.html\
	lib/modern/ariyesako/*.gif\
	lib/modern/khema/*.html\
	lib/modern/thanissaro/*.html\
	lib/modern/thanissaro/bmc1/*.html\
	lib/modern/thanissaro/bmc2/*.html\
	lib/modern/thanissaro/wings/*.html\
	lib/modern/thanissaro/likefire/*.html\
	lib/bps/*.html\
	lib/bps/leaves/*.html\
	lib/bps/misc/*.html\
	lib/bps/news/*.html\
	lib/bps/wheels/*.html\
	lib/bps/wheels/wheel206/*.html\
	lib/thai/*.html\
	lib/thai/boowa/*.html\
	lib/thai/chah/*.html\
	lib/thai/fuang/*.html\
	lib/thai/kee/*.html\
	lib/thai/lee/*.html\
	lib/thai/mun/*.html\
	lib/thai/thate/*.html\
	lib/thai/other/*.html\
	lib/thai/suwat/*.html\
	canon/*.html \
	canon/abhidhamma/*.html\
	canon/vinaya/*.html\
	canon/digha/*.html\
	canon/majjhima/*.html\
	canon/samyutta/*.html\
	canon/anguttara/*.html\
	canon/khuddaka/*.html\
	canon/khuddaka/dhp/*.html\
	canon/khuddaka/dhp1/*.html\
	canon/khuddaka/iti/*.html\
	canon/khuddaka/khp/*.html\
	canon/khuddaka/suttanipata/*.html\
	canon/khuddaka/theragatha/*.html\
	canon/khuddaka/therigatha/*.html\
	canon/khuddaka/udana/*.html

# These are the files that must be edited for offline use
BULKFIX = index.html\
	help.html\
	faq.html\
	news.html\
	index-author.html\
	index-names.html\
	index-number.html\
	index-similes.html\
	index-subject.html\
	index-sutta.html\
	index-title.html\
	glossary.html\
	search.html\
	canon/index.html


$(ZIP): $(INCLUDE)
	@ echo "Updating $(ZIP)"
	zip -u -b /tmp $(DESTDIR)/$(ZIP) $(INCLUDE) -x $(EXCLUDE)
	chmod a+r $(DESTDIR)/$(ZIP)
	echo done.

# Some files in bulk.zip (like those with links to the search engine)
# need to be edited.
# The following takes care of this by extracting the relevant files, 
# sed'ing them, and then replacing them.
#
# jtb 010719: The following zip command may insert new zero-size
# files (directories) into the bulk file. These files are unnecessary
# and cosmetically annoying. But it's easiest just to let them be, and 
# sed them out of file listings. See my comment in bulklist.
bulkfix: $(BULKFIX)
	@ cd $(DESTDIR) ;\
	mkdir $(TEMPDIR)
	@ cd $(TEMPDIR); \
	unzip $(DESTDIR)/$(ZIP) $(BULKFIX); \
	find . -type f -exec bulkfix {} \; ;\
	zip -u -r -b /tmp $(DESTDIR)/$(ZIP) *
	@ /bin/rm -fR $(TEMPDIR)
	@ echo bulkfix done.

all:
	make -f BULKMAKE $(ZIP)


kill:
	rm $(DESTDIR)/$(ZIP)

