
MAGIC_DIR = ~/magic_tarballs

# necessary support for libQt (only used by magic)
QTDIR = qt-everywhere-opensource-src-4.6.1
QTSRC = $(MAGIC_DIR)/qt-everywhere-opensource-src-4.6.1.tar.gz
QTDEP := $(shell test -f $(QTSRC) && echo $(QTSRC))

PSCFG = ../psconfig/psconfig.csh
PSPREFIX := $(shell csh $(PSCFG) $(PSVERSION) --prefix)

default: all

all: ssa-core-cpp magic verify

install: magic.install verify.install

clean:
	if [ -d magic ]; then (cd magic && make -f Makefile.magic clean); fi
	if [ -d ssa-core-cpp ]; then (cd ssa-core-cpp && make clean); fi

update:
# get the source code (replace this with SVN interactions)
	tar xvzf $(MAGIC_DIR)/magic.tgz
	tar xvzf $(MAGIC_DIR)/ssa-core-cpp.tgz
	cp Makefile.magic magic/Makefile.magic
	cp magic/VerifyStreaks/main.cpp verify/VerifyStreaks.cpp

# tar xvzf $(QTSRC)

qt-everywhere: $(QTDIR)/lib/libQtCore.so

QTOPT = -fast \
	-opensource \
	-nomake tools \
	-nomake examples \
	-nomake demos \
	-nomake docs \
	-nomake translations \
	-no-xmlpatterns \
	-no-multimedia \
	-no-audio-backend \
	-no-phonon \
	-no-phonon-backend \
	-no-svg \
	-no-webkit \
	-no-javascript-jit \
	-no-script \
	-no-scripttools 

# the target (QTDEP) is blank unless QTSRC exists
$(QTDIR)/lib/libQtCore.so: $(QTDEP)
	echo $(PSCFG)
	echo $(PSPREFIX)
	if [ -d $(QTDIR) ]; then (cd $(QTDIR) && echo "yes" | ./configure $(QTOPT) -prefix $(PSPREFIX)); fi
	if [ -d $(QTDIR) ]; then (cd $(QTDIR) && make); fi
	if [ -d $(QTDIR) ]; then (cd $(QTDIR) && make install); fi

ssa-core-cpp: ssa-core-cpp/build/libSSA.a

ssa-core-cpp/build/libSSA.a:
	if [ -d ssa-core-cpp ]; then (cd ssa-core-cpp && ./configure && make); fi

magic: magic/DetectStreaks

magic/DetectStreaks:
	if [ -d magic ]; then (cd magic && make -f Makefile.magic); fi

magic.install:	ssa-core-cpp
	if [ -d magic ]; then (cd magic && make -f Makefile.magic install); fi

update.verify:
	cp magic/VerifyStreaks/main.cpp verify/VerifyStreaks.cpp

verify: verify/VerifyStreaks

verify/VerifyStreaks:
	if [ -d magic ]; then (cd verify && make); fi

verify.install:
	if [ -d magic ]; then (cd verify && make install); fi

# REMOVE = remove/src
# 
# remove: FORCE
# 	@cd $(REMOVE) && make -f Makefile.simple all
# 
# remove.install: remove
# 	@cd $(REMOVE) && make -f Makefile.simple install

FORCE:
