# Makefile to run the various scripts needed once CVS updates have been performed.

dataset_path = dataset/loser
surveydir_path = surveys
cavern_flags = -qq -s
tar_flags = -cz --exclude "*/CVS" --ignore-case -f
svxtrace_cmd = ./svxtrace.py

###########

everything: autogen_pages folklist 3dfiles tarfiles surveytable qmlists prospecting_guide

###########

autogen_pages: indxal.htm

indxal.htm: noinfo/CAVETAB2.CSV noinfo/all.pos noinfo/make-indxal4.pl noinfo/areapage_skeletons/*.html noinfo/lengths.dat
	python noinfo/make-areaindices.py
	cd noinfo; perl ./make-indxal4.pl -q CAVETAB2.CSV

noinfo/all.pos: noinfo/all.3d
	3dtopos noinfo/all.3d noinfo/all.pos

###########

folklist: folk/index.htm

folk/index.htm: noinfo/folk.csv noinfo/make-folklist.py
	python noinfo/make-folklist.py < noinfo/folk.csv > folk/index.htm

###########

surveytable:
	cd $(surveydir_path); perl tablize-csv.pl Surveys.csv; perl tablizebyname-csv.pl Surveys.csv --quiet



# Output depends on entire contents of the survey tree;
# there appears to be no sensible way to run this at need.

###########

qmlists: smkridge/204/qm.html smkridge/204/atoz.html smkridge/234/qm.html

smkridge/204/qm.html: smkridge/204/qm.csv smkridge/204/tablize-qms.pl
	cd smkridge/204; perl tablize-qms.pl qm.csv

smkridge/234/qm.html: smkridge/234/qm.csv smkridge/234/tablize-qms.pl
	cd smkridge/234; perl tablize-qms.pl qm.csv
smkridge/204/atoz.html: smkridge/204/glossary.csv smkridge/204/make-glossary.pl
	cd smkridge/204; perl make-glossary.pl glossary.csv

###########

3dfiles: noinfo/all.3d smkridge/204/204.3d smkridge/234/234.3d plateau/76/76.3d noinfo/alltracks.3d

noinfo/all.3d: $(shell $(svxtrace_cmd) $(dataset_path)/all)
	cavern $(cavern_flags) $(dataset_path)/all -o noinfo/all.3d

smkridge/204/204.3d: $(shell $(svxtrace_cmd) $(dataset_path)/caves/204/204)
	cavern $(cavern_flags) $(dataset_path)/caves/204/204 -o smkridge/204/204.3d

smkridge/234/234.3d: $(shell $(svxtrace_cmd) $(dataset_path)/caves/234/234)
	cavern $(cavern_flags) $(dataset_path)/caves/234/234 -o smkridge/234/234.3d

plateau/76/76.3d: $(shell $(svxtrace_cmd) $(dataset_path)/caves/76/76)
	cavern $(cavern_flags) $(dataset_path)/caves/76/76 -o plateau/76/76.3d

noinfo/alltracks.3d: $(shell $(svxtrace_cmd) $(dataset_path)/fixedpts/gps/tracks/alltracks)
	cavern $(cavern_flags) $(dataset_path)/fixedpts/gps/tracks/alltracks.svx -o noinfo/alltracks.3d

###########

prospecting_guide: 3dfiles
	cd noinfo/prospecting_guide_scripts && python make-prospectingguide-new.py
	cd noinfo/prospecting_guide_scripts && python make-prospectingguide-new.py --white

###########

tarfiles: noinfo/all.tgz smkridge/204/surveydata.tgz smkridge/234/surveydata.tgz plateau/76/surveydata.tgz

noinfo/all.tgz: noinfo/all.3d
	tar $(tar_flags) noinfo/all.tgz -C $(dataset_path)/.. loser

smkridge/204/surveydata.tgz: smkridge/204/204.3d
	tar $(tar_flags) smkridge/204/surveydata.tgz -C $(dataset_path)/caves/ 204

smkridge/234/surveydata.tgz: smkridge/234/234.3d
	tar $(tar_flags) smkridge/234/surveydata.tgz -C $(dataset_path)/caves/ 234

plateau/76/surveydata.tgz: plateau/76/76.3d
	tar $(tar_flags) plateau/76/surveydata.tgz -C $(dataset_path)/caves/ 76

# (tarfiles depend on 3d files to avoid running the
# expensive $(shell ...) commands more than necessary.)

###########

clean:
	cut -d "," -f 6 noinfo/CAVETAB2.CSV | xargs rm -f
	rm -f indxal.htm folk/index.htm noinfo/all.pos
	rm -f noinfo/all.3d smkridge/204/204.3d smkridge/234/234.3d plateau/76/76.3d
	rm -f smkridge/204/surveydata.tgz smkridge/234/surveydata.tgz plateau/76/surveydata.tgz noinfo/all.tgz
	rm -f $(surveydir_path)/surveytable.html
	rm -f report.html
	find . -name ".cvsignore" | xargs rm

###########

report: everything
	rm -f report.html
	bigbro -ohtml report.html -local -fragments -failures -rec .* -ignore ".*/jnl/.*" -ignore ".*/icons/.*" -ignore ".*rdmap.*" -ignore ".*/cp/.*" -ignore ".*/surveys/.*" index.htm