#!/bin/sh
# Simple script to create host.cfg
#

if [ -z "$1" ]; then
    echo "Usage: $0 <configfile>"
    echo "Writes the system specific things to <configfile>"
    exit 1
fi

type=`uname`

# Reasonable defaults
CC="cc"
COMMON_CFLAGS="-g"
RANLIB="ranlib"
X11LIBDIR=""
X11INCDIR=""
MKDEPEND="makedepend -f\$@ -- \$(CFLAGS) -- \$^"

# Flags to link AROS binaries (ie. binaries which are to be started
# inside AROS). What we need is something like a shared lib: All
# references resolved but no startup-code added.
ILDFLAGS="-nostartfiles -nostdlib"

# If you need a special kind of assembler (eg. as), set $AS. If $AS is not
# set, $CC is used.
# Special flags for $AS are taken from $COMMON_AFLAGS, if it exists or
# from $COMMON_CFLAGS otherwise.
# If X11 is installed in a directory of it's own, you can specify that
# directory in $X11BASEDIR. $X11LIBDIR will then point to $X11BASEDIR/lib
# and $X11LDFLAGS will contain -L$X11LIBDIR. The same applies to $X11INCDIR.
# If only one part is in a nonstandard place (eg. the libs), you
# can set one of the $X11LIBDIR/X11INCDIRs, too.

case "$type" in
"Linux" )
	CC="gcc"
	COMMON_CFLAGS="-Wall -g -O0"
	ILDFLAGS="-nostartfiles -nostdlib -Xlinker -i"
	ARCH="linux"
	KERNEL="i386-emul"
	X11LIBDIR="/usr/X11R6/lib"
	MKDEPEND="makedepend -D__GNUC__ -Di386 -f\$@ -- \$(CFLAGS) -- \$^"
	;;
"HP-UX" )
	COMMON_CFLAGS="-Aa -g"
	RANLIB="true"
	ARCH="hppa"
	KERNEL="hppa-emul"
	;;
"OSF1" )
	ARCH="decunix"
	KERNEL="axp-emul"
	;;
"FreeBSD" )
	ARCH="freebsd"
	KERNEL="i386-emul"
	COMMON_CFLAGS="-Wall -g -O2"
	ILDFLAGS="-nostartfiles -nostdlib"
	X11BASEDIR="/usr/X11R6"
	AS="gcc"
	COMMON_AFLAGS="-x assembler-with-cpp"
	;;
"AmigaOS" )
	CC="gcc"
	COMMON_CFLAGS="-Wall -g -O0"
	ILDFLAGS="-nostartfiles -nostdlib"
	ARCH="amiga"
	KERNEL="m68k-native"
	MKDEPEND="gcc -M -o \$@ \$(CFLAGS) \$^"
	;;
esac

echo "# This file is automatically generated if it doesn't exist" > $1
echo "# DO NOT EDIT" >> $1
echo "# Edit \$(TOP)/configure instead and delete this file" >> $1
echo >> $1
echo "SYS_CC = $CC" >> $1
echo "COMMON_CFLAGS = $COMMON_CFLAGS" >> $1
echo "ILDFLAGS = \$(CFLAGS) $ILDFLAGS" >> $1
echo "RANLIB = $RANLIB" >> $1
echo "ARCH = $ARCH" >> $1
echo "KERNEL = $KERNEL" >> $1

if [ -z "$AS" ]; then
    echo "SYS_AS = $CC" >> $1
else
    echo "SYS_AS = $AS" >> $1
fi
if [ -z "$COMMON_AFLAGS" ]; then
    echo "COMMON_AFLAGS = $COMMON_CFLAGS" >> $1
else
    echo "COMMON_AFLAGS = $COMMON_AFLAGS" >> $1
fi

if [ -n "$X11BASEDIR" ]; then
    X11LIBDIR=$X11BASEDIR/lib
    X11INCDIR=$X11BASEDIR/include
fi

if [ -n "$X11LIBDIR" ]; then
    echo "X11LIBDIR = $X11LIBDIR" >> $1
    echo "X11LDFLAGS = -L$X11LIBDIR" >> $1
else
    echo "X11LIBDIR = /usr/lib" >> $1
    echo "X11LDFLAGS =" >> $1
fi
if [ -n "$X11INCDIR" ]; then
    echo "X11INCDIR = $X11INCDIR" >> $1
    echo "X11CCFLAGS = -I$X11INCDIR" >> $1
else
    echo "X11INCDIR = /usr/include" >> $1
    echo "X11CCFLAGS =" >> $1
fi

echo "MKDEPEND = $MKDEPEND" >> $1

cd config ; make TOP=.. CURDIR=./config config
