#!/bin/sh
# ------------------------------------------------------------------
#  CONFIG -- configuration script for A6 for Unix
#   This is free software, please see the file
#   "COPYING" for copyright and licence details
# ------------------------------------------------------------------

echo "A6 configure script for Unix v0.0.1, by Simon Collis"
echo ""
echo "(C) The A6 Development Team 1997"
echo ""
echo "This is free software, please see the file"
echo "'COPYING' for copyright and licence details"
echo ""
echo "Attempting to configure A6..."
echo ""

# ------------------------------------------------------------------
# MAKEFILE
# ------------------------------------------------------------------
echo "Building makefile..."

echo >makefile "# ------------------------------------------------------------------"
echo >>makefile "#  Makefile for A6"
echo >>makefile "#   This is free software, please see the file"
echo >>makefile "#   'COPYING' for copyright and licence details"
echo >>makefile "# ------------------------------------------------------------------"
echo >>makefile ""

echo >>makefile "# This file has been automatically generated;"
echo >>makefile "# please make any necessary changes to config"
echo >>makefile ""

# Standard definitions
echo >>makefile "# Standard definitions"
echo >>makefile "PROG=a6"
echo >>makefile "DEFD=NODEBUG"
echo >>makefile ""

# Objects and etc
echo >>makefile "# Objects"
echo >>makefile "OBJS1=\$(PROG).o asmfile.o assemble.o error.o"
echo >>makefile "OBJS2=global.o label.o outf.o psexpr.o"
echo >>makefile "OBJS3=psop.o pspop.o pstext.o treefind.o ustring.o"
echo >>makefile ""
echo >>makefile "OBJS=\$(OBJS1) \$(OBJS2) \$(OBJS3)"
echo >>makefile ""

# Shell (not needed for DOS or Amiga)
echo >>makefile "SHELL=/bin/sh"
echo >>makefile ""

# ------------------------------------------------------------------
# Compilers
# ------------------------------------------------------------------
echo "Checking for compiler..."

rm -f conf.* >/dev/null

# *** GNU C
if ! [ -e conf.cc ]; then
 echo "Checking for GNU C..."
 if `gcc -v`; then
  echo "Found GNU C..."
  echo >conf.cc ""
  echo >conf.gcc ""
  echo >>makefile "# Configuration for GNU C"
  echo >>makefile "CC=gcc"
  echo >>makefile "LN=gcc"
  echo >>makefile "CFLAGS=\$(OPT) -x c -ansi -pedantic-errors -fno-writable-strings -Wall -Wstrict-prototypes"
  echo >>makefile "AUX_CFLAGS=-DLINUX"
  echo >>makefile "LFLAGS=-L./"
  echo >>makefile "FROM="
  echo >>makefile "TO=-o"
  echo >>makefile "EXTRA_LIBS="
 fi
fi

if ! [ -e conf.cc ]; then
 echo "No supported C compilers found...  A6 configuration stopped."
 rm -f makefile conf.h >/dev/null
 exit -1
else
 echo >>makefile ""
 rm -f conf.cc >/dev/null
fi

# ------------------------------------------------------------------
# Targets
# ------------------------------------------------------------------

# Standard targets
echo >>makefile "# Targets"
echo >>makefile "all: \$(PROG) compare"
echo >>makefile ""
echo >>makefile "test:"
echo >>makefile "	cd test"
echo >>makefile "	../a6 -fp -o test.prg test.asm"
echo >>makefile "	../compare test.prg good.prg"
echo >>makefile ""
echo >>makefile "clean:"
echo >>makefile "	rm -f a6 compare *.o"
echo >>makefile ""
echo >>makefile "distclean:"
echo >>makefile "	rm -f a6 compare *.o test/test.prg makefile conf.*"
echo >>makefile ""
echo >>makefile "install:"
echo >>makefile "	cp -f \$(PROG) /usr/bin"
echo >>makefile ""
echo >>makefile "\$(PROG): \$(OBJS)"
echo >>makefile "	\$(LN) \$(LFLAGS) \$(AUX_LFLAGS) \$(TO) \$(PROG) \$(FROM) \$(OBJS) \$(EXTRA_LIBS) \$(AUX_LIBS)"
echo >>makefile ""
echo >>makefile "compare: compare.o"
echo >>makefile "	\$(LN) \$(LFLAGS) \$(AUX_LFLAGS) \$(TO) compare \$(FROM) compare.o \$(EXTRA_LIBS) \$(AUX_LIBS)"
echo >>makefile ""
echo >>makefile "%.o %.c:"
echo >>makefile "	\$(CC) -c -D\$(DEFD) \$(CFLAGS) \$(AUX_CFLAGS) \$*.c"

# ------------------------------------------------------------------
# CONF.H
# ------------------------------------------------------------------

echo "Building conf.h..."

echo >conf.h "/* ------------------------------------------------------------------"
echo >>conf.h "    CONF.H -- configuration details for the A6 cross-assembler"
echo >>conf.h "     This is free software, please see the file"
echo >>conf.h "     'COPYING' for copyright and licence details"
echo >>conf.h "   ------------------------------------------------------------------ */"
echo >>conf.h ""

echo >>conf.h "/* This file has been automatically generated; *"
echo >>conf.h " * please make any necessary changes to config */"
echo >>conf.h ""

echo >>conf.h "#ifndef _CONF_H"
echo >>conf.h "#define _CONF_H"
echo >>conf.h ""

echo >>conf.h "#define PATH_SEPARATOR ':'"
echo >>conf.h "#define PATH_SLASH '/'"
echo >>conf.h ""

echo >>conf.h "#endif"

echo ""
echo "The configuration of A6 succeeded, to make A6 type"

if [ -e conf.gcc ]; then
 echo "    make all"
 echo "    make test"
 echo "    make install"
 rm -f conf.gcc >/dev/null
fi
