#!/bin/bash
#
# Simple shell script for building SPLAT! and associated utilities.
# Written by John A. Magliacane, KD2BD May 2002.  Updated September 2009.
#

build_usgs2sdf()
{
	echo -n "Compiling usgs2sdf... "
	cc -Wall -O2 -fomit-frame-pointer usgs2sdf.c -o usgs2sdf

	if [ -x usgs2sdf ]; then
		echo "Done!"
	else
		echo "Compilation failed!"
	fi
}

build_srtm2sdf()
{
	echo -n "Compiling srtm2sdf... "
	cc -Wall -O2 -fomit-frame-pointer srtm2sdf.c -lbz2 -o srtm2sdf
	rm -f srtm2sdf-hd
	ln -s srtm2sdf srtm2sdf-hd

	if [ -x srtm2sdf ]; then
		echo "Done!"
	else
		echo "Compilation failed!"
	fi

}


if [ "$#" = "0" ]; then
	echo "Usage: build  { srtm2sdf, usgs2sdf, all }"
else
	if [ "$1" = "usgs2sdf" ]; then
		build_usgs2sdf
	fi

	if [ "$1" = "srtm2sdf" ]; then
		build_srtm2sdf
	fi

	if [ "$1" = "clean" ]; then
		rm -f usgs2sdf srtm2sdf srtm2sdf-hd
	fi

	if [ "$1" = "all" ]; then
		build_usgs2sdf
		build_srtm2sdf
	fi

	if [ "$1" != "citydecoder" ] && [ "$1" != "srtm2sdf" ] && [ "$1" != "usgs2sdf" ] && [ "$1" != "fontdata" ] && [ "$1" != "bearing" ] && [ "$1" != "clean" ] && [ "$1" != "all" ]; then
		echo "Usage: build { srtm2sdf, usgs2sdf, all }"
	fi
fi

