#!/bin/sh

INIT_DIR=`pwd`

if [ $# -le 1 ]; then 
	echo Usage: compile_c_library platform location
	exit 1
fi

ISE_PLATFORM=$1; export ISE_PLATFORM

. $INIT_DIR/set_aliases


remtrace Compile the C libraries C code for $ISE_PLATFORM in $2
remtrace libpng
cd $2/C_library/libpng
if echo "$ISE_PLATFORM" | grep "linux" >/dev/null 2>&1; then
	cp scripts/makefile.linux .
	make -f makefile.linux
elif echo "$ISE_PLATFORM" | grep "solaris" >/dev/null 2>&1; then
	cp scripts/makefile.solaris .
	make -f makefile.solaris
elif echo "$ISE_PLATFORM" | grep "irix" >/dev/null 2>&1; then
	cp scripts/makefile.sgi .
	make -f makefile.sgi
elif [ "$ISE_PLATFORM" = "hpux-11" ]; then
	cp scripts/makefile.hpux .
	make -f makefile.hpux
elif [ "$ISE_PLATFORM" = "alpha" ]; then
	cp scripts/makefile.dec .
	make -f makefile.dec
elif echo "$ISE_PLATFORM" | grep "openbsd" >/dev/null 2>&1; then
	cp scripts/makefile.gcc .
	make -f makefile.gcc
elif echo "$ISE_PLATFORM" | grep "freebsd" >/dev/null 2>&1; then
	cp scripts/makefile.gcc .
	make -f makefile.gcc
elif echo "$ISE_PLATFORM" | grep "macosx" >/dev/null 2>&1; then
	cp scripts/makefile.gcc .
	make -f makefile.gcc
else
	rep=$ISE_PLATFORM
	if [ ! -f "scripts/makefile.$rep" ]; then
		echo Here are the available makefiles:
		ls scripts
		echo "What is the extension of the makefile that should be used?"
		while [ ! -f "scripts/makefile.$rep" ]; do
			echo "scripts/makefile.$rep doesn't exist... Try another one"
			read rep
		done
	fi
	cp scripts/makefile.$rep .
	make -f makefile.$rep
fi

remtrace zlib
cd $2/C_library/zlib
sh ./configure
make
cd $2
