default: help
help:
	@echo "USAGE: make (target)"
	@echo "  targets: "
	@echo "  dvodist : the internal dvo distribution website (info pages only)"
	@echo "  dvodist-all : install pages for dvo data"
	@echo "  ippdata : the public ipp data distribution website"
	@echo ""
	@echo "  clean-dvodist : remove generated php files"
	@echo "  clean-ippdata : remove generated php files"

GENERATE = src/generate --htdocs @HTDOCS@ --rootdir @ROOTDIR@ --rootwww @ROOTWWW@

# we have 2 sites (or more?) controlled by this build directory
# make dvodist : internal web site
# make ippdata : external web site

# these are common code not available via the web server
SRC-UTIL = www-util
TGT-UTIL = @HTDOCS@/www-util

# these are the available web files
SRC-DVODIST = dvodist
SRC-IPPDATA = ippdata
TGT-DVODIST = @HTDOCS@/www-root
TGT-IPPDATA = @HTDOCS@/ippdata

# generated common code used by all installations
UTIL = \
$(TGT-UTIL)/ipp.page.php \
$(TGT-UTIL)/ipp.php \
$(TGT-UTIL)/markdown.php \
$(TGT-UTIL)/phptest.php

# pages which are generated (and thus depend on the config)
DVODIST-MKD = \
$(TGT-UTIL)/dvodist.page.php \
$(TGT-DVODIST)/index.php \
$(TGT-DVODIST)/test.php \
$(TGT-DVODIST)/docs.php \
$(TGT-DVODIST)/help.php \
$(TGT-DVODIST)/catdir.syn.test/index.php \
$(TGT-DVODIST)/catdir.syn.test/n3000/index.php \
$(TGT-DVODIST)/catdir.syn.test/n3730/index.php

# pages which are copied directly
DVODIST-RAW = \
$(TGT-DVODIST)/blank.html \
$(TGT-DVODIST)/PScolorlogo2.jpg \
$(TGT-DVODIST)/ipp.css \
$(TGT-UTIL)/dvodist.menu.dat 

DVODIST = $(DVODIST-MKD) $(DVODIST-RAW) 

IPPDATA-MKD = \
$(TGT-UTIL)/ippdata.page.php \
$(TGT-IPPDATA)/index.php \
$(TGT-IPPDATA)/docs/index.php \
$(TGT-IPPDATA)/docs/photladder.php \
$(TGT-IPPDATA)/photladder.20130107.subset/index.php \
$(TGT-IPPDATA)/photladder.20130107.subset/relphot-fits/index.php \
$(TGT-IPPDATA)/photladder.20130107.subset/relphot-csv/index.php \
$(TGT-IPPDATA)/photladder.20130107.subset/ubercal-fits/index.php \
$(TGT-IPPDATA)/photladder.20130107.subset/ubercal-csv/index.php \
$(TGT-IPPDATA)/ps1.filters/index.php \
$(TGT-IPPDATA)/catdir.syn.test/index.php \
$(TGT-IPPDATA)/catdir.syn.test/n3000/index.php \
$(TGT-IPPDATA)/catdir.syn.test/n3730/index.php \
$(TGT-IPPDATA)/help.php

IPPDATA-RAW = \
$(TGT-UTIL)/ippdata.menu.dat \
$(TGT-IPPDATA)/blank.html \
$(TGT-IPPDATA)/ipp.css \
$(TGT-IPPDATA)/PScolorlogo2.jpg \
$(TGT-IPPDATA)/ps1.filters/apj425122t3_mrt.txt \
$(TGT-IPPDATA)/docs/photladder-1206.20130301.pdf \
$(TGT-IPPDATA)/docs/2mass.compare/dH.allsky.20120528.v3.png \
$(TGT-IPPDATA)/docs/2mass.compare/dHK.allsky.20120528.v3.png \
$(TGT-IPPDATA)/docs/2mass.compare/dJ.allsky.20120528.v3.png \
$(TGT-IPPDATA)/docs/2mass.compare/dJH.allsky.20120528.v3.png \
$(TGT-IPPDATA)/docs/2mass.compare/dK.allsky.20120528.v3.png \
$(TGT-IPPDATA)/docs/2mass.compare/sigma.g.ubercal.20120528.v0.png \
$(TGT-IPPDATA)/docs/2mass.compare/sigma.i.ubercal.20120528.v0.png \
$(TGT-IPPDATA)/ipp.css

IPPDATA = $(IPPDATA-RAW) $(IPPDATA-MKD)

include $(SRC-DVODIST)/3pi.20120509/Makefile
include $(SRC-DVODIST)/3pi.20120525/Makefile
include $(SRC-DVODIST)/3pi.20120606/Makefile
include $(SRC-DVODIST)/3pi.20130227/Makefile
include $(SRC-DVODIST)/3pi.20140621/Makefile
include $(SRC-DVODIST)/LAP.3pi.PV1/Makefile
include $(SRC-DVODIST)/3pi.20120525.tables/Makefile
include $(SRC-DVODIST)/3pi.20130227.tables/Makefile
include $(SRC-DVODIST)/ubercal.data/Makefile

DVODIST_DIRS = \
$(DIST-3pi-20120509) \
$(DIST-3pi-20120525) \
$(DIST-3pi-20120606) \
$(DIST-3pi-20130227) \
$(DIST-LAP-3pi-PV1) \
$(DIST-3pi-20120525-tables) \
$(DIST-3pi-20130227-tables) \
$(DIST-ubercal-data)

dvodist-all: $(UTIL) $(DVODIST) $(DVODIST_DIRS)
dvodist: $(UTIL) $(DVODIST)

ippdata: $(UTIL) $(IPPDATA)

# mkd files are used to generate php files
$(TGT-UTIL)/%.php: $(SRC-UTIL)/%.mkd
	@if [ ! -d $(TGT-UTIL) ]; then mkdir -p $(TGT-UTIL) || exit; fi
	rm -f $(TGT-UTIL)/$*.php || exit
	$(GENERATE) $(SRC-UTIL)/$*.mkd $(TGT-UTIL)/$*.php || exit

# non-generated common utilities (not dest for htdocs)
$(TGT-UTIL)/%: $(SRC-UTIL)/%
	@if [ ! -d $(TGT-UTIL) ]; then mkdir -p $(TGT-UTIL) || exit; fi
	cp $(SRC-UTIL)/$* $(TGT-UTIL)/$* || exit
	chmod +x $(TGT-UTIL)/$* || exit

#### dvodist

# common non-generated code from a common location
$(TGT-DVODIST)/%: $(SRC-UTIL)/%
	@if [ ! -d $(TGT-DVODIST) ]; then mkdir -p $(TGT-DVODIST) || exit; fi
	cp $(SRC-UTIL)/$* $(TGT-DVODIST)/$* || exit
	chmod +x $(TGT-DVODIST)/$* || exit

# mkd files are used to generate php files
$(TGT-DVODIST)/%.php: $(SRC-DVODIST)/%.mkd
	@if [ ! -d $(@D) ]; then mkdir -p $(@D) || exit; fi
	rm -f $(TGT-DVODIST)/$*.php || exit
	$(GENERATE) $(SRC-DVODIST)/$*.mkd $(TGT-DVODIST)/$*.php || exit

# non-generated php code is copied directly
$(TGT-DVODIST)/%: $(SRC-DVODIST)/%
	@if [ ! -d $(@D) ]; then mkdir -p $(@D) || exit; fi
	cp $(SRC-DVODIST)/$* $(TGT-DVODIST)/$* || exit
	chmod +x $(TGT-DVODIST)/$* || exit

#### ippdata

# common non-generated code from a common location
$(TGT-IPPDATA)/%: $(SRC-UTIL)/%
	@if [ ! -d $(TGT-IPPDATA) ]; then mkdir -p $(TGT-IPPDATA) || exit; fi
	cp $(SRC-UTIL)/$* $(TGT-IPPDATA)/$* || exit
	chmod +x $(TGT-IPPDATA)/$* || exit

# mkd files are used to generate php files
$(TGT-IPPDATA)/%.php: $(SRC-IPPDATA)/%.mkd
	@if [ ! -d $(@D) ]; then mkdir -p $(@D) || exit; fi
	rm -f $(TGT-IPPDATA)/$*.php || exit
	$(GENERATE) $(SRC-IPPDATA)/$*.mkd $(TGT-IPPDATA)/$*.php || exit

# non-generated php code is copied directly
$(TGT-IPPDATA)/%: $(SRC-IPPDATA)/%
	@if [ ! -d $(@D) ]; then mkdir -p $(@D) || exit; fi
	cp $(SRC-IPPDATA)/$* $(TGT-IPPDATA)/$* || exit
	chmod +x $(TGT-IPPDATA)/$* || exit

# utilities #################################################
clean-dvodist:	
	rm -f $(DVODIST-MKD) $(UTIL-MKD) $(DVODIST_DIRS)

clean-ippdata:	
	rm -f $(IPPDATA-MKD) $(UTIL-MKD)

clean:	
	rm -f `find . -name "*.o"`
	rm -f `find . -name "*~"`
	rm -f `find . -name "#*"`

.PRECIOUS: $(SRC)/%.mkd
.PRECIOUS: $(SRC)/%.php
.PRECIOUS: $(SRC)/%.css
.PRECIOUS: $(SRC)/%.dat
.PRECIOUS: $(SRC)/%.png
.PRECIOUS: $(SRC)/%.jpg
.PRECIOUS: $(SRC)/%.pdf
.PRECIOUS: $(SRC)/%.jpeg


# these are the scripts used to generate the index listings
# probably do not need to install these (not used by the web ui)
PROG = \
$(SRC-PROG)/mkdist.20120509.sh \
$(SRC-PROG)/mkdist.20120525.sh \
$(SRC-PROG)/mkdist.20120606.sh \
$(SRC-PROG)/mkdist.testcat.sh \
$(SRC-PROG)/mkindex.sh
