# Makefile for PSM benchmark.
# Last updated: January 24, 2013 (Stephen W. Thomas)
#
# See the main tBench README.txt file for usage instructions.

# First, load the default settings and paths from the parent Makefile.inc. 
include ../../Makefile.inc

# Targets
all: clean create validate execute
create: data schema workload
validate: vschema vdata vworkload


# Make these targets always run (not dependent on any timestamps)
.PHONY: clean data schema workload vdata vschema vworkload execute

clean: 
	@ echo "\n=============================="
	@ echo "Cleaning the benchmark:"
	@ echo "=============================="
	@ echo ""
	rm -rf data 
	mkdir data 
	rm -rf logs 
	mkdir logs 



data: 
	@ echo "\n=============================="
	@ echo "Loading/creating data:"
	@ echo "=============================="
	@ echo ""
	@ # Use tGen to shred the XML document from DC-SD benchmark
	@ # We do so three times: one for each size of catalog (if they exist)
	@ if [ -f ../DC-SD/data/catalog-small.xml.bz2 ];\
	then \
	   echo "";\
	   echo "Unzipping small catalog file.";\
	   bunzip2 ../DC-SD/data/catalog-small.xml.bz2; \
	   echo "Shredding catalog file.";\
	   java -Xmx1g -cp $(TGENLIB) tGenerator settings/tGen_settings.txt \
	   OUTPUT_DIR data/small INPUT_FILE ../DC-SD/data/catalog-small.xml > logs/small.log 2>&1; \
	   echo "Rezipping small catalog file.";\
	   bzip2 ../DC-SD/data/catalog-small.xml; \
	fi;
	@ if [ -f ../DC-SD/data/catalog-medium.xml.bz2 ];\
	then \
	   echo "";\
	   echo "Unzipping medium catalog file.";\
	   bunzip2 ../DC-SD/data/catalog-medium.xml.bz2; \
	   echo "Shredding catalog file.";\
	   java -Xmx1g -cp $(TGENLIB) tGenerator settings/tGen_settings.txt \
	   OUTPUT_DIR data/medium INPUT_FILE ../DC-SD/data/catalog-medium.xml > logs/medium.log  2>&1; \
	   echo "Rezipping medium catalog file.";\
	   bzip2 ../DC-SD/data/catalog-medium.xml; \
	fi;
	@ if [ -f ../DC-SD/data/catalog-large.xml.bz2 ];\
	then \
	   echo "";\
	   echo "Unzipping large catalog file.";\
	   bunzip2 ../DC-SD/data/catalog-large.xml.bz2; \
	   echo "Shredding catalog file.";\
	   java -Xmx1g -cp $(TGENLIB) tGenerator settings/tGen_settings.txt \
	   OUTPUT_DIR data/large INPUT_FILE ../DC-SD/data/catalog-large.xml > logs/large.log  2>&1; \
	   echo "Rezipping large catalog file.";\
	   bzip2 ../DC-SD/data/catalog-medium.xml; \
	fi;

schema: 
	@ echo "\n=============================="
	@ echo "Loading/creating schema:"
	@ echo "=============================="
	@ echo ""
	@ echo "  (Schema currently needs to be created manually.)"

workload: 
	@ echo "\n=============================="
	@ echo "Loading/creating workload:"
	@ echo "=============================="
	@ echo ""
	@ echo "  (Workload currently needs to be created manually. When TXL transformations are complete, add them here.)"

vschema:
	@ echo "\n=============================="
	@ echo "Validating the schema:"
	@ echo "=============================="
	@ echo ""
	@ echo "  (The schema for this benchmark cannot be validated; see PSM-DB2)"

vdata:
	@ echo "\n=============================="
	@ echo "Validating the shredding process:"
	@ echo "=============================="
	@ echo ""
	@ for f in `ls -d data/*`; \
	do \
	 echo Validating the data in $$f; \
	 $(TGENTOOLS)/checkKeys.pl $$f ;\
	 $(TGENTOOLS)/checkRefs.pl $$f ;\
	 echo ""; \
	done
	@ echo ""
	@ echo "\n=============================="
	@ echo "Validating the data against the schema:"
	@ echo "=============================="
	@ echo ""
	@ echo "  (The data for this benchmark cannot be validated; see PSM-DB2)"

vworkload:
	@ echo "\n=============================="
	@ echo "Validating the workload against the schema:"
	@ echo "=============================="
	@ echo ""
	@ echo "  (The workload for this benchmark cannot be validated; see PSM-DB2)"

execute: 
	@ echo "\n=============================="
	@ echo "Executing the workload against the data:"
	@ echo "=============================="
	@ echo ""
	@ echo "  (The workload for this benchmark is not meant to be executed; see PSM-DB2)"

