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)/dbadmin

RAWSRC = \
$(DESTWWW)/Login.php \
$(DESTWWW)/SelectProject.php \
$(DESTWWW)/ipp.css \
$(DESTWWW)/ipp.cal.dat \
$(DESTWWW)/ipp.cal.php \
$(DESTWWW)/ipp.detrend.dat \
$(DESTWWW)/ipp.detrend.php \
$(DESTWWW)/ipp.diff.dat \
$(DESTWWW)/ipp.diff.php \
$(DESTWWW)/ipp.imfiles.dat \
$(DESTWWW)/ipp.imfiles.php \
$(DESTWWW)/ipp.load.dat \
$(DESTWWW)/ipp.load.php \
$(DESTWWW)/ipp.menu.dat \
$(DESTWWW)/ipp.php \
$(DESTWWW)/ipp.science.dat \
$(DESTWWW)/ipp.science.php \
$(DESTWWW)/ipp.stack.dat \
$(DESTWWW)/ipp.stack.php \
$(DESTWWW)/ipp.warp.dat \
$(DESTWWW)/ipp.warp.php \
$(DESTWWW)/phptest.php \
$(DESTWWW)/site.php \
$(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)/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)/detProcessedImfile.php \
$(DESTWWW)/detProcessedExp.php \
$(DESTWWW)/detResidExp.php \
$(DESTWWW)/detResidImfile.php \
$(DESTWWW)/detRun.php \
$(DESTWWW)/detRunSummary.php \
$(DESTWWW)/detStackedImfile.php \
$(DESTWWW)/newExp.php \
$(DESTWWW)/newImfile.php \
$(DESTWWW)/guidePendingExp.php \
$(DESTWWW)/chipStageExp.php \
$(DESTWWW)/chipPendingExp.php \
$(DESTWWW)/chipPendingImfile.php \
$(DESTWWW)/chipProcessedExp.php \
$(DESTWWW)/chipProcessedImfile.php \
$(DESTWWW)/chipProcessedImfile_failure.php \
$(DESTWWW)/camStageExp.php \
$(DESTWWW)/camPendingExp.php \
$(DESTWWW)/camProcessedExp.php \
$(DESTWWW)/camProcessedExp_NoImages.php \
$(DESTWWW)/camProcessedExp_failure.php \
$(DESTWWW)/camProcessedImfile.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)/warpRun.php \
$(DESTWWW)/warpInputExp.php \
$(DESTWWW)/warpSkycellMap.php \
$(DESTWWW)/warpSkyfile.php \
$(DESTWWW)/diffRun.php \
$(DESTWWW)/diffInputSkyfile.php \
$(DESTWWW)/diffSkyfile.php \
$(DESTWWW)/stackRun.php \
$(DESTWWW)/stackInputSkyfile.php \
$(DESTWWW)/stackSumSkyfile.php \
$(DESTWWW)/calDB.php \
$(DESTWWW)/calRun.php \
$(DESTWWW)/flatcorrRun.php \
$(DESTWWW)/flatcorrExp.php


PICTURES = \
$(DESTWWW)/PScolorlogo2.jpg \
$(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
