#!/bin/sh
#
# tmpcomp       -- A temporary script to bootstrap the system
#
# Copyright © 2002-2021 Erick Gallesio - I3S-CNRS/ESSI <eg@unice.fr>
#
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
# USA.
#
#           Author: Erick Gallesio [eg@unice.fr]
#    Creation date:  1-Jan-2002 18:57 (eg)
# Last file update: 17-Jun-2021 09:31 (eg)
#

# This script is only used to compile the different components of the
# system which need compilation. It will not be installed since the
# user version is the stklos-compile script.

out="a.out"
in=""
Copt=""

for arg in $*
do
    case $1 in
        -o)
            out=$2
            shift 2
            ;;
        -C)
            Copt=--C-code
            shift
            ;;
        -*)
            echo "Unknown option $1"
            exit 1
            ;;
        *)
            break
            ;;
    esac
done

case $# in
    1) in=$1
       ;;
    *) echo "Usage: $0 [-C] [-o bytecode-file] src"
       exit 1
       ;;
esac

# Sep is now also ":"  on CYGWIN
sep=":"

if test -f ../src/boot.img ;then
    prefix=".."
else
    if test -f ../../src/boot.img ;then
        prefix="../.."
    else
        prefix="../../.."
    fi
fi

STKLOS_LOAD_PATH="${prefix}/lib${sep}${prefix}/gtklos"
STKLOS_BUILDING=1
export STKLOS_LOAD_PATH STKLOS_BUILDING

${prefix}/src/stklos -c -q -b ${prefix}/src/boot.img \
     -f ${prefix}/utils/stklos-compile.stk -- \
     --no-time $Copt --output=$out $in

if test X$Copt = X -a -e $out
then
    chmod a+x $out
fi
