# Makefile for DC-SD benchmark.
# Last updated: January 22, 2013 (Stephen W. Thomas)
#
# See the main tBench README.txt file for usage instructions.
#
# This benchmark forms the foundation for tBench. As such, the data, schema, and
# workloads are not derived from any other benchmarks; they are taken as-is from
# the XBench DS/SD benchmark. Thus, this makefile does not do as much as the
# Makefiles of other benchmarks in tBench.


# 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 ""
	@ echo "  (No cleaning to do; this is the foundation benchmark)"

data: 
	@ echo "\n=============================="
	@ echo "Loading/creating data:"
	@ echo "=============================="
	@ echo ""
	@ echo "  (No data to load or create; this is the foundation benchmark)"

schema: 
	@ echo "\n=============================="
	@ echo "Loading/creating schema:"
	@ echo "=============================="
	@ echo ""
	@ echo "  (No schema to load or create; this is the foundation benchmark)"

workload: 
	@ echo "\n=============================="
	@ echo "Loading/creating workload:"
	@ echo "=============================="
	@ echo ""
	@ echo "  (No workload to load or create; this is the foundation benchmark)"


vschema:
	@ echo "\n=============================="
	@ echo "Validating the schema:"
	@ echo "=============================="
	@ echo ""
	xmllint --noout schemas/DCSD.xsd

vdata:
	@ echo "\n=============================="
	@ echo "Validating the data against the schema:"
	@ echo "=============================="
	@ echo ""
	@ if [ -f ./data/catalog-small.xml.bz2 ];\
    then \
	 echo Validating ./data/catalog-small.xml.bz2; \
	 bunzip2 ./data/catalog-small.xml.bz2; \
	 xmllint --noout --schema schemas/DCSD.xsd data/catalog-small.xml ;\
	 bzip2 data/catalog-small.xml; \
	 echo ""; \
    fi;
	@ if [ -f ./data/catalog-medium.xml.bz2 ];\
    then \
	 echo Validating ./data/catalog-medium.xml.bz2; \
	 bunzip2 ./data/catalog-medium.xml.bz2; \
	 xmllint --noout --schema schemas/DCSD.xsd data/catalog-medium.xml ;\
	 bzip2 data/catalog-medium.xml; \
	 echo ""; \
    fi;
	@ if [ -f ./data/catalog-large.xml.bz2 ];\
    then \
	 echo Validating ./data/catalog-large.xml.bz2; \
	 bunzip2 ./data/catalog-large.xml.bz2; \
	 xmllint --noout --schema schemas/DCSD.xsd data/catalog-large.xml ;\
	 bzip2 data/catalog-large.xml; \
	 echo ""; \
    fi;

vworkload:
	@ echo "\n=============================="
	@ echo "Validating the workload against the schema:"
	@ echo "=============================="
	@ echo ""
	@ echo "  (TODO: How to check goodness (syntax) of XQuery workload?)"

execute: 
	@ echo "\n=============================="
	@ echo "Executing the workload against the data:"
	@ echo "=============================="
	@ echo ""
	@ if [ -f ./data/catalog-small.xml.bz2 ];\
    then \
	 echo Running workload on ./data/catalog-small.xml.bz2; \
	 bunzip2 ./data/catalog-small.xml.bz2; \
	 for f in `ls workloads/*.xq`; \
	 do \
	  echo $$f ; \
	  java -cp $(NUXLIB) RunNux data/catalog-small.xml $$f 10 10 ; \
	 done; \
	 bzip2 ./data/catalog-small.xml; \
    fi;
	@ # An alternate way to run the queries above; however, the RunNux tool
	@ # Is preferred since it bulk loads and runs the queries multiple times and
	@ # displays the averages.
	@ #/usr/bin/time -f %e $(NUX) --out /dev/null --query $$f ./data/$(DATANAME) ; 
	@ # Call the RunNux tool to run Nux XQuery evaluation (average of 10 times)

