#!/bin/sh
# Set up SWI-Prolog for a specific machine/operating system

ln="ln -s"

if [ $# != 1 ]
then
    echo "Usage: SETUP architecture"
    echo ""
    echo "Where architecture is one of:"
    ls src/md-*.h | sed -e '/src\/md-gener.h/d' \
                        -e 's/src\/md-\(.*\)\.h/	\1/'
    exit 1
fi

arch=$1

if [ -f $arch ]
then
    echo "Directory $arch already exists; setup aborted"
    exit 1
fi

if [ ! -f src/md-$arch.h ]
then
    echo "Machine description file md-$arch.h does not exists."
    echo "I will copy the generic md file into md-$arch.h"
    (cd src; cp md-gener.h md-$arch.h)
fi

mkdir $arch
cd $arch
$ln ../src/pl-*.[ch] .
$ln ../src/pl-*.i[ch] .
$ln ../src/sun-types.h .
$ln ../src/pl-export .
$ln ../src/ATOMS ../src/defatom.awk ../src/dump .
$ln ../src/extract.sed ../src/make.sed ../src/simpl.sed ../src/strip.sed .
if [ "$ln" = ln ]
then
mkdir gnu
(cd gnu; $ln ../../src/gnu/*.[ch] .)
else
$ln ../src/gnu .
fi

case $arch in
atari)
        $ln  ../src/pl.prj .
	$ln  ../src/tc.cfg .
	;;
esac

if [ -f ../src/Makefile.$arch ]
then
    $ln  ../src/Makefile.$arch Makefile
else
    $ln  ../src/Makefile Makefile
fi

$ln  ../src/md-$arch.h md.h

cat << _EOM_
Setup for $arch completed in directory $arch

For further installation:

	# Edit config.h.  Notably ensure M_SYSTEMHOME points to this
	directory.
	
	# Install the GNU readline library.  If you don't want to use
	this library, set O_READLINE in $arch/md.h to 0.

	# In you have version 1.2 of the readline library, make sure
	there is a '#define O_RL12 1' in $arch/md.h.  If you use
	version 1.1 this switch should be 0.

	Make sure to edit CFLAGS and LDFLAGS in $arch/md.h so that the
	compiler can find the readline header files and the library
	itself.

	# Type:

	% cd $arch
	% make

	# Test by running ./pl

	# If ok, install using

	% make install

	# If you want static linking to C-code, for example for installing
	XPCE, run

	% make runtime
_EOM_
