# Makefile for tPSM benchmark.
# Last updated: February 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 
	rm -rf workloads 
	mkdir workloads 



data: 
	@ echo "\n=============================="
	@ echo "Loading/creating data:"
	@ echo "=============================="
	@ echo ""
	ln -sf ../tXBench/data

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 ""
	@ # Create five copies of PSM queries; edit them  with sed.)"
	@ # Make the directory if necessary
	@ echo "Creating validtime (short) queries"
	@ if [ ! -d ./workloads/valid-short ];\
	then \
	   mkdir ./workloads/valid-short;\
	fi;
	@ # Copy the queries over
	@ cp -r ../PSM/workloads/*.sql ./workloads/valid-short
	@ # Use sed to change each query (i.e., add keywords)
	@ for f in `ls -d ./workloads/valid-short/*`; \
	do \
	 echo editing file $$f; \
	 sed 's/^SELECT/VALIDTIME \[2010-01-01, 2010-02-01\] SELECT/' $$f > tmp.txt; \
	 mv tmp.txt $$f; \
	done
	@ echo "Creating validtime (medium) queries"
	@ # Make the directory if necessary
	@ if [ ! -d ./workloads/valid-medium ];\
	then \
	   mkdir ./workloads/valid-medium;\
	fi;
	@ # Copy the queries over
	@ cp -r ../PSM/workloads/*.sql ./workloads/valid-medium
	@ # Use sed to change each query (i.e., add keywords)
	@ for f in `ls -d ./workloads/valid-medium/*`; \
	do \
	 echo editing file $$f; \
	 sed 's/^SELECT/VALIDTIME \[2010-01-01, 2010-07-01\] SELECT/' $$f > tmp.txt; \
	 mv tmp.txt $$f; \
	done
	@ echo "Creating validtime (long) queries"
	@ # Make the directory if necessary
	@ if [ ! -d ./workloads/valid-long ];\
	then \
	   mkdir ./workloads/valid-long;\
	fi;
	@ # Copy the queries over
	@ cp -r ../PSM/workloads/*.sql ./workloads/valid-long
	@ # Use sed to change each query (i.e., add keywords)
	@ for f in `ls -d ./workloads/valid-long/*`; \
	do \
	 echo editing file $$f; \
	 sed 's/^SELECT/VALIDTIME \[2010-01-01, 2010-12-31\] SELECT/' $$f > tmp.txt; \
	 mv tmp.txt $$f; \
	done
	@ echo "Creating nonsequenced queries"
	@ # Make the directory if necessary
	@ if [ ! -d ./workloads/nonsequenced ];\
	then \
	   mkdir ./workloads/nonsequenced;\
	fi;
	@ # Copy the queries over
	@ cp -r ../PSM/workloads/*.sql ./workloads/nonsequenced
	@ # Use sed to change each query (i.e., add keywords)
	@ for f in `ls -d ./workloads/nonsequenced/*`; \
	do \
	 echo editing file $$f; \
	 sed 's/^SELECT/NONSEQUENCED VALIDTIME SELECT/' $$f > tmp.txt; \
	 mv tmp.txt $$f; \
	done
	@ echo "Creating current queries"
	@ # Make the directory if necessary
	@ if [ ! -d ./workloads/current ];\
	then \
	   mkdir ./workloads/current;\
	fi;
	@ # Copy the queries over
	@ cp -r ../PSM/workloads/*.sql ./workloads/current
	@ # No need to add any keywords
    
    

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

vdata:
	@ echo "\n=============================="
	@ echo "Validating the data:"
	@ echo "=============================="
	@ echo ""
	@ echo "  (No validation required; component is copied from parent.)"

vworkload:
	@ echo "\n=============================="
	@ echo "Validating the workload against the schema:"
	@ echo "=============================="
	@ echo ""
	@ echo "  (The workload for this benchmark cannot be validated; see tPSM-*-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 tPSM-*-DB2)"

