#! /bin/sh

# Write a makefile to make KonStat2 and TestKon2.
# NOTE: This file was not created by Autoconf; I wrote it.
# Revised July 5, 2004
# ===============================================

# First, see if Konton2 files are present.

echo -e "\nLooking for the Konton2 source code files."
if [ -f KonStat2.c ] && [ -f TestKon2.c ] && [ -f Konton2.c ] && \
[ -f Konton2.h ] && [ -f KonTyps2.h ]; then
echo -e "The Konton2 source code files were found; OK so far.\n"
else
echo -e "The Konton2 source code files were not found; cannot continue.\a\n"
exit
fi
# ===============================================

# Next, see if Snow 2.0 files are present.

echo -e "Looking for the Snow 2.0 source code files."
if [ -f snow2.c ] && [ -f snow2.h ] && [ -f snow2tab.h ]; then
GOT_SNOW=1
echo -e "The Snow 2.0 source code files were found and will be used.\n"
else
GOT_SNOW=0
echo -e "The Snow 2.0 source code files were not found and won't be used.\n"
fi
# ===============================================

# Now, write the makefile.

echo -e "Writing the Makefile."
echo -e '# This makefile makes KonStat2 and TestKon2 without creating' > Makefile
echo -e '# .o files. This file was written by a configure script.' >> Makefile
echo -e "" >> Makefile
echo -e "both : KonStat2 TestKon2" >> Makefile
echo -e ".PHONY : both" >> Makefile
echo -e "" >> Makefile
if [ ${GOT_SNOW} == 1 ]; then
echo -e "KonStat2 : KonStat2.c Konton2.c Konton2.h KonTyps2.h snow2.c \\" >> Makefile
echo -e "snow2.h snow2tab.h Makefile" >> Makefile
echo -e "\tcc KonStat2.c Konton2.c snow2.c -Wall -lc -DTEST_SNOW2=1 -O -o KonStat2" >> Makefile
else
echo -e "KonStat2 : KonStat2.c Konton2.c Konton2.h KonTyps2.h Makefile" >> Makefile
echo -e "\tcc KonStat2.c Konton2.c -Wall -lc -DTEST_SNOW2=0 -O -o KonStat2" >> Makefile
fi
echo -e "\tchmod 700 KonStat2" >> Makefile
echo -e "" >> Makefile
echo -e "TestKon2 : TestKon2.c Konton2.c Konton2.h KonTyps2.h Makefile" >> Makefile
echo -e "\tcc TestKon2.c Konton2.c -Wall -lc -O -o TestKon2" >> Makefile
echo -e "\tchmod 700 TestKon2" >> Makefile
echo -e "" >> Makefile
echo -e ".PHONY : clean" >> Makefile
echo -e "clean :" >> Makefile
echo -e "\t-rm KonStat2 TestKon2" >> Makefile
chmod 600 Makefile
echo -e "Finished.\n"
# ===============================================
echo -e "\"make\" or \"make both\" makes both KonStat2 and TestKon2\n"
echo -e "\"make KonStat2\" makes KonStat2\n"
echo -e "\"make TestKon2\" makes TestKon2\n"
echo -e "\"make clean\" removes KonStat2 and TestKon2\n"
