#!/bin/sh
#*=====================================================================*/
#*    serrano/prgm/project/bigloo/bigloo/autoconf/bootmethod           */
#*    -------------------------------------------------------------    */
#*    Author      :  Manuel Serrano                                    */
#*    Creation    :  Wed Aug  9 13:27:23 1995                          */
#*    Last change :  Sat May  1 12:24:03 2021 (serrano)                */
#*    -------------------------------------------------------------    */
#*    Select the build method for bootstrapping Bigloo. Echo one of:   */
#*      - bootstrap: this is an already bootstrapped version;          */
#*      - c: this is a pre-bootstrapped C version;                     */
#*      - cross: this is a source version that need cross compilation; */
#*      - source: as cross but Bigloo needs to be installed first.     */
#     The script exit with 0 on success, 1 on failure.                 */
#*=====================================================================*/

#*---------------------------------------------------------------------*/
#*    Global parameters                                                */
#*---------------------------------------------------------------------*/
bigloo=$BUILDBIGLOO
# the two following variables must always be overriden by arguments
release=4.4c
buildrelease=4.4b

if [ "$bigloo " = " " ]; then
  bigloo=bigloo
fi

#*---------------------------------------------------------------------*/
#*    arguments parsing                                                */
#*---------------------------------------------------------------------*/
while : ; do
  case $1 in
    "")
      break;;

    --release=*|-release=*)
      release="`echo $1 | sed 's/^[-a-z]*=//'`";;

    --buildrelease=*|-buildrelease=*)
      buildrelease="`echo $1 | sed 's/^[-a-z]*=//'`";;

    --bigloo=*|-bigloo=*)
      bigloo="`echo $1 | sed 's/^[-a-z]*=//'`";;

    -*)
      echo "Unknown option \"$1\", ignored" >&2;;
  esac
  shift
done

if [ -f comptime/Cc/cc.o ]; then
  echo "bootstrap"
  exit 0
elif [ -f comptime/Cc/cc.c ]; then
  echo "c"
  exit 0
else
  bglrelease=`$bigloo -q -eval "(exit (print (bigloo-config 'release-number)))" 2> /dev/null`

  if [ $bglrelease = $release -o $bglrelease = $buildrelease ]; then
    echo "cross:$bigloo"
    exit 0
  else
    echo "source"
    exit 0
  fi
fi

