# GNUmakefile
#
#      Makefile for demo directory of Veil
#
#      Copyright (c) 2005, 2006 Marc Munro
#      Author:  Marc Munro
#      License: BSD
#
# $Id: GNUmakefile,v 1.3 2006/10/04 15:50:09 bloodnok Exp $
#
# Do not attempt to use this makefile directly: its targets are available
# and should be built from the main GNUmakefile in the parent directory.

# ----------
# 
.PHONY: demo_all demo_clean demo dropdemo

DEMO_DIR = demo
DEMO_GARBAGE = $(garbage:%=$(DEMO_DIR)/%)

DEMO_DB = veildemo
DEMO_OWNER = vdemo_owner
DEMO_VEIL = vdemo_veil
DEMO_USER = vdemo_user

demo_all: 
demo_install:

demo:	src_all
	createdb $(DEMO_DB)
	. tools/psql_funcs.sh; \
	cd demo; \
	rm -f demo_build.log; \
	vdemo_owner=$(DEMO_OWNER); \
	vdemo_veil=$(DEMO_VEIL); \
	vdemo_user=$(DEMO_USER); export vdemo_owner vdemo_user vdemo_veil; \
	psql -d $(DEMO_DB) -f create.sql -v VOWNER=$(DEMO_OWNER) \
	   -v VEIL=$(DEMO_VEIL) -v VUSER=$(DEMO_USER) 2>&1 | \
	   psql_clean demo_build.log

# Drop the veil demo database
dropdemo:
	-dropdb $(DEMO_DB)
	-dropuser $(DEMO_OWNER)
	-dropuser $(DEMO_VEIL)
	-dropuser $(DEMO_USER)

# This generates the xml definition of the demo database directly from the
# database.  Or would, if it worked properly.
#demo.xml: $(shell ls demo/*sql)
#	-$(DB2XML) | awk '/<schema/, /<\/schema>/' > $@

# Autograph from cf consulting.  Generates an input file for dot from an 
# xml schema definition
AUTOGRAPH_XSL = $(HOME)/bin/autograph.xsl
AUTOGRAPH = $(XSLTPROC) --xinclude $(AUTOGRAPH_XSL)

veil_demo.png: demo.xml veil_demo.xml
	$(AUTOGRAPH) veil_demo.xml > demo.dot
	$(DOT) $@ demo.dot

# Clean this directory and ensure regression test db is removed.
demo_clean:
	@echo Cleaning demo...
	rm -f $(DEMO_GARBAGE) $(DEMO_DIR)/demo_build.log

demo_distclean: demo_clean
