#!/bin/sh

#
# build-struct - script used in conjuction with Makefile of 'ztp-zbierka'
#                Creates directory structure for typeseting Postscript
#                and PDF document "ztp-zbierka.ps|ztp-zbierka.pdf"
#
# Usage: ./build-struct <directory>
#
# Developed by Lubomir Host 'rajo' <rajo AT platon.sk>
# Copyright (c) 2003 Platon SDG
# Licensed under terms of GNU General Public License.
# All rights reserved.
#
# Changelog:
# 30/01/2003 - created
#

# $Platon$

usage()
{
	echo "Usage:"
	echo
	echo "$0 '<PostScript|PDF>'"
	echo
}

test_environ()
{
	for i in $*; do
		if [ -z "${!i}" ]; then
			echo "Empty \$$i, did you specify it in Makefile and export it?"
		fi
	done

}

make_symlinks()
{
	for i in $DEPEND; do
		ln -s -f "../$i" "$i" \
			|| cp "../$i" "$i"
	done
	for i in IMAGES_DIR GRAPHS_DIR DATA_DIR; do
		ln -s -f -n "../${!i}" "./${!i}" \
			|| cp "../${!i}" "./${!i}"
	done
}

if [ "$#" -lt "1" ]; then
	usage;
fi

test_environ \
	DEPEND \
	OUTPUT \
	ps__OUTPUT \
	pdf_OUTPUT \
	ps__INPUT \
	pdf_INPUT \
	IMAGES_DIR \
	GRAPHS_DIR \
	DATA_DIR


echo "Building $1"
if [ "X$1" = "XPostScript" ]; then

	test -d PostScript || mkdir -p PostScript
	ln -s -f "PostScript/$ps__OUTPUT" "$ps__OUTPUT"
	cd PostScript \
		&& make_symlinks \
			&& ln -s -f "../$ps__INPUT" "$ps__INPUT"

elif [ "X$1" = "XPDF" ]; then

	test -d PDF || mkdir -p PDF
	ln -s -f "PDF/$pdf_OUTPUT" "$pdf_OUTPUT"
	cd PDF \
		&& make_symlinks \
			&& ln -s -f "../$pdf_INPUT" "$pdf_INPUT"

else
	echo "I don't know, what do you want with parameter '$1'..."
	exit 1
fi

