default: php
help:
	@echo "USAGE: make php"

SRC     =       src
DEF	=	def
RAW	=	raw
SCRIPTS =       scripts
DESTBIN	=       @BINDIR@
DESTWWW =       @HTDOCS@/ippMonitor

GENERATE = $(SCRIPTS)/generate

PROGRAMS = \
$(DESTBIN)/skyplot.dvo

RAWSRC = \
$(DESTWWW)/Login.php \
$(DESTWWW)/SelectProject.php \
$(DESTWWW)/ipp.css \
$(DESTWWW)/ipp.php \
$(DESTWWW)/ipp.menu.dat \
$(DESTWWW)/ipp.cal.dat \
$(DESTWWW)/ipp.cal.php \
$(DESTWWW)/ipp.detrend.dat \
$(DESTWWW)/ipp.detrend.php \
$(DESTWWW)/ipp.dist.dat \
$(DESTWWW)/ipp.dist.php \
$(DESTWWW)/ipp.imfiles.dat \
$(DESTWWW)/ipp.imfiles.php \
$(DESTWWW)/ipp.load.dat \
$(DESTWWW)/ipp.load.php \
$(DESTWWW)/ipp.science.dat \
$(DESTWWW)/ipp.science.php \
$(DESTWWW)/ipp.stack.dat \
$(DESTWWW)/ipp.stack.php \
$(DESTWWW)/phptest.php \
$(DESTWWW)/site.php \
$(DESTWWW)/showimage.php \
$(DESTWWW)/nightSummary.php \
$(DESTWWW)/simplePlot.php \
$(DESTWWW)/simplePlotcam.php \
$(DESTWWW)/simplePlotraw.php \
$(DESTWWW)/skyplot.php \
$(DESTWWW)/getimage.php

DEFSRC = \
$(DESTWWW)/keptDetrendFrames.php \
$(DESTWWW)/masterDetrendFrames.php \
$(DESTWWW)/masterDetrendImfiles.php \
$(DESTWWW)/detInputExp.php \
$(DESTWWW)/detMasterFrame.php \
$(DESTWWW)/detMasterImfile.php \
$(DESTWWW)/detNormalizedExp.php \
$(DESTWWW)/detNormalizedImfile.php \
$(DESTWWW)/detNormalizedStatImfile.php \
$(DESTWWW)/detRegisteredImfile.php \
$(DESTWWW)/detProcessedImfile.php \
$(DESTWWW)/detProcessedExp.php \
$(DESTWWW)/detProcessedExp_noimage.php \
$(DESTWWW)/detResidExp.php \
$(DESTWWW)/detResidExp_noimage.php \
$(DESTWWW)/detResidImfile.php \
$(DESTWWW)/detStackedImfile.php \
$(DESTWWW)/detNormalizedExp_failure.php \
$(DESTWWW)/detNormalizedImfile_failure.php \
$(DESTWWW)/detNormalizedStatImfile_failure.php \
$(DESTWWW)/detProcessedImfile_failure.php \
$(DESTWWW)/detProcessedExp_failure.php \
$(DESTWWW)/detResidExp_failure.php \
$(DESTWWW)/detResidImfile_failure.php \
$(DESTWWW)/detStackedImfile_failure.php \
$(DESTWWW)/detRun.php \
$(DESTWWW)/detRunActive.php \
$(DESTWWW)/detRunSummary.php \
$(DESTWWW)/newExp.php \
$(DESTWWW)/newImfile.php \
$(DESTWWW)/guidePendingExp.php \
$(DESTWWW)/chipSummary.php \
$(DESTWWW)/chipStageExp.php \
$(DESTWWW)/chipPendingExp.php \
$(DESTWWW)/chipPendingImfile.php \
$(DESTWWW)/chipProcessedExp.php \
$(DESTWWW)/chipIQstats.php \
$(DESTWWW)/chipProcessedImfile.php \
$(DESTWWW)/chipProcessedImfile_failure.php \
$(DESTWWW)/camSummary.php \
$(DESTWWW)/camStageExp.php \
$(DESTWWW)/camPendingExp.php \
$(DESTWWW)/camProcessedExp.php \
$(DESTWWW)/camProcessedExp_Images.php \
$(DESTWWW)/camProcessedExp_failure.php \
$(DESTWWW)/camIQstats.php \
$(DESTWWW)/camProcessedImfile.php \
$(DESTWWW)/fakeSummary.php \
$(DESTWWW)/fakeStageExp.php \
$(DESTWWW)/fakePendingExp.php \
$(DESTWWW)/fakeProcessedExp.php \
$(DESTWWW)/fakePendingImfile.php \
$(DESTWWW)/fakeProcessedImfile.php \
$(DESTWWW)/fakeProcessedImfile_failure.php \
$(DESTWWW)/pzPendingExp.php \
$(DESTWWW)/pzPendingImfile.php \
$(DESTWWW)/pzDoneExp.php \
$(DESTWWW)/pzDoneImfile.php \
$(DESTWWW)/pzDoneExp_failed.php \
$(DESTWWW)/pzDoneImfile_failed.php \
$(DESTWWW)/rawUnknownExp.php \
$(DESTWWW)/rawDetrendExp.php \
$(DESTWWW)/rawDetrendExp_detrend.php \
$(DESTWWW)/rawImfile.php \
$(DESTWWW)/rawImfile_failed.php \
$(DESTWWW)/rawExp_failed.php \
$(DESTWWW)/rawScienceExp.php \
$(DESTWWW)/rawExp.php \
$(DESTWWW)/summitExp.php \
$(DESTWWW)/summitImfile.php \
$(DESTWWW)/warpSummary.php \
$(DESTWWW)/warpStageExp.php \
$(DESTWWW)/warpStageSkyfiles.php \
$(DESTWWW)/warpStageSkyfileInputs.php \
$(DESTWWW)/warpProcessedSkyfiles.php \
$(DESTWWW)/warpFailedSkyfiles.php \
$(DESTWWW)/diffSummary.php \
$(DESTWWW)/diffRun.php \
$(DESTWWW)/diffInputSkyfile.php \
$(DESTWWW)/diffProcessedSkyfile.php \
$(DESTWWW)/diffProcessedSkyfile_Images.php \
$(DESTWWW)/diffFailedSkyfile.php \
$(DESTWWW)/stackRun.php \
$(DESTWWW)/stackSummary.php \
$(DESTWWW)/stackInputSkyfile.php \
$(DESTWWW)/stackProcessedSkyfile.php \
$(DESTWWW)/stackProcessedSkyfile_Images.php \
$(DESTWWW)/stackFailedSkyfile.php \
$(DESTWWW)/magicRun.php \
$(DESTWWW)/magicSummary.php \
$(DESTWWW)/magicTrees.php \
$(DESTWWW)/magicProcessedNodes.php \
$(DESTWWW)/magicProcessedMasks.php \
$(DESTWWW)/magicProcessedMasks_Images.php \
$(DESTWWW)/magicFailedTrees.php \
$(DESTWWW)/magicFailedNodes.php \
$(DESTWWW)/magicFailedMasks.php \
$(DESTWWW)/distSummary.php \
$(DESTWWW)/distTarget.php \
$(DESTWWW)/distRun.php \
$(DESTWWW)/publishSummary.php \
$(DESTWWW)/publishClient.php \
$(DESTWWW)/publishRun.php \
$(DESTWWW)/publishDone.php \
$(DESTWWW)/distComponent.php \
$(DESTWWW)/destreakSummary.php \
$(DESTWWW)/destreakRun.php \
$(DESTWWW)/destreakFile.php \
$(DESTWWW)/calDB.php \
$(DESTWWW)/calRun.php \
$(DESTWWW)/flatcorrRun.php \
$(DESTWWW)/flatcorrChip.php \
$(DESTWWW)/flatcorrCamera.php

PICTURES = \
$(DESTWWW)/PScolorlogo2.jpg \
$(DESTWWW)/broken.png \
$(DESTWWW)/down.png \
$(DESTWWW)/down_sel.png \
$(DESTWWW)/left.png \
$(DESTWWW)/left_sel.png \
$(DESTWWW)/missing.png \
$(DESTWWW)/right.png \
$(DESTWWW)/right_sel.png \
$(DESTWWW)/up.png \
$(DESTWWW)/up_sel.png \
$(DESTWWW)/missing.png

DESTLINK = $(DESTWWW)/index.php

php: $(RAWSRC) $(DEFSRC) $(PICTURES) $(DESTLINK) $(PROGRAMS)

# dependancy rules for binary code #########################
# .PRECIOUS: %.$(ARCH).o
# .PRECIOUS: $(BIN)/%.$(ARCH)

$(DESTLINK): $(DESTWWW)/Login.php
	rm -f $@
	ln -s $(DESTWWW)/Login.php $@

$(SRC)/%.php: $(DEF)/%.d $(DEF)/autocode.php $(GENERATE)
	@if [ ! -d $(SRC) ]; then mkdir -p $(SRC); fi
	$(GENERATE) $< $(DEF)/autocode.php $@

# generated php code is built into SRC first
$(DESTWWW)/%.php: $(SRC)/%.php
	@if [ ! -d $(DESTWWW) ]; then mkdir -p $(DESTWWW) || exit; fi
	rm -f $(DESTWWW)/$*.php || exit
	cp $(SRC)/$*.php $(DESTWWW)/$*.php || exit

# non-generated php code is copied directly
$(DESTWWW)/%.php: $(RAW)/%.php
	@if [ ! -d $(DESTWWW) ]; then mkdir -p $(DESTWWW) || exit; fi
	rm -f $(DESTWWW)/$*.php || exit
	cp $(RAW)/$*.php $(DESTWWW)/$*.php || exit

# all other files are copied directly
$(DESTWWW)/%.css: $(RAW)/%.css
	@if [ ! -d $(DESTWWW) ]; then mkdir -p $(DESTWWW) || exit; fi
	rm -f $(DESTWWW)/$*.css || exit
	cp $(RAW)/$*.css $(DESTWWW)/$*.css || exit

$(DESTWWW)/%.dat: $(RAW)/%.dat
	@if [ ! -d $(DESTWWW) ]; then mkdir -p $(DESTWWW) || exit; fi
	rm -f $(DESTWWW)/$*.dat || exit
	cp $(RAW)/$*.dat $(DESTWWW)/$*.dat || exit

$(DESTWWW)/%.jpg: $(RAW)/%.jpg
	@if [ ! -d $(DESTWWW) ]; then mkdir -p $(DESTWWW) || exit; fi
	rm -f $(DESTWWW)/$*.jpg || exit
	cp $(RAW)/$*.jpg $(DESTWWW)/$*.jpg || exit

$(DESTWWW)/%.jpeg: $(RAW)/%.jpeg
	@if [ ! -d $(DESTWWW) ]; then mkdir -p $(DESTWWW) || exit; fi
	rm -f $(DESTWWW)/$*.jpeg || exit
	cp $(RAW)/$*.jpeg $(DESTWWW)/$*.jpeg || exit

$(DESTWWW)/%.png: $(RAW)/%.png
	@if [ ! -d $(DESTWWW) ]; then mkdir -p $(DESTWWW) || exit; fi
	rm -f $(DESTWWW)/$*.png || exit
	cp $(RAW)/$*.png $(DESTWWW)/$*.png || exit

$(DESTBIN)/%: $(SCRIPTS)/%
	@if [ ! -d $(DESTBIN) ]; then mkdir -p $(DESTBIN) || exit; fi
	cp $(SCRIPTS)/$* $(DESTBIN)/$* || exit
	chmod +x $(DESTBIN)/$* || exit

# utilities #################################################

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

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