#
# This script drives construction of Visual Studio (version 7.1) projects 
# files, using an xquery script (genproject.template),an input XML
# document, and a file containing a list of project names.
#

# project name list
PROJECTS=xqilla.projects

# xquery script template
TEMPLATE=genproject.template

# temporary script, post-sed-replacement
TEMP_SCRIPT=genproject.script

# xml document input template
CONFIG_INPUT=xqilla.template.xml

# temporary xml document, post-sed-replacement
CONFIG_OUTPUT=xqilla.xml

# substitute some variables in the XML document template
sed -f lib_paths.sed < $CONFIG_INPUT > $CONFIG_OUTPUT

# for each project/destination, substitute 2 variables in the XQuery script, then run it

for v in VC7.1 VC8
do
    PROJECT_OUTPUT_DIR=../Win32Projects/$v

    if [ $v = "VC7.1" ]; then
	VERSION="7.10"
    else
	VERSION="8.00"
    fi

    for i in `cat $PROJECTS`
    do
	sed -e "s!@PROJECT_NAME@!$i!g" -e "s!@PROJECT_INPUT@!$CONFIG_OUTPUT!g" -e"s!@VISUAL_STUDIO_VERSION@!$VERSION!g" < $TEMPLATE > $TEMP_SCRIPT
	TMP=$PROJECT_OUTPUT_DIR/$i.tmp.vcproj
	TARG=$PROJECT_OUTPUT_DIR/$i.vcproj
	xqilla -o $TMP $TEMP_SCRIPT
	rm -f $TEMP_SCRIPT
	cmp $TMP $TARG > /dev/null 2>&1 ||
	(echo "Building $TARG" && rm -f $TARG &&
	    cp $TMP $TARG && chmod 664 $TARG)
	rm -f $TMP
    done
done
