Plan 9 from Bell Labs’s /usr/web/sources/contrib/fernan/nhc98/src/libraries/polyparse/configure

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


#!/bin/sh
#       configure -- prepare to compile/install the polyparse package
#       modified from the HaXml configure script: January 2007
#       author:   Malcolm.Wallace@cs.york.ac.uk, August 2002

SOFTWARE="polyparse"
VERSION="1.0"

if [ -f obj/prefix ]
then INSTALLDIR=`cat obj/prefix`
else INSTALLDIR=
fi

# We need a working `echo' command: at least Solaris2.6 may not have it.
CCC=${CC-gcc}
case `echo -n hello | wc -c | ( read n ; echo $n )` in
    5) ;;
    *) echo "The builtin 'echo' command doesn't do '-n' - emulating it."
       $CCC -o script/echo script/echo.c
       echo () { $PWD/script/echo "$@"; } ;;
esac

# We need a working `which' command: CYGWIN at least doesn't have it,
#  and some installed 'which's behave badly, e.g. Solaris, OSF/1.
which () {
  ( for path in `echo \"$PATH\" | sed -e 's/:/\" \"/g'`
    do
      thefile=`echo $path | tr -d "\""`/$1
      if [ -f "$thefile" -a -x "$thefile" ]
      then echo $thefile
           exit 0
      fi
    done; exit 1 )
}

DARWIN=false
CYGWIN=false
MINGW=false
SUNOS=false
case `uname -s` in
  CYGWIN*) CYGWIN=true;;
  MINGW*)  MINGW=true ;;
  Darwin*) DARWIN=true ;;
  SunOS*)  SUNOS=true ;;
esac

# Process command-line arguments
while [ "$1" != "" ]
do
  case $1 in
    --buildwith=*)  BUILDWITH=`echo "$1" | cut -c13-` ;;
    --buildopts=*)  BUILDOPTS=$BUILDOPTS" "`echo "$1" | cut -c13-` ;;
    --prefix=*)     INSTALLDIR=`echo "$1" | cut -c10-` ;;
    --help|-h)
  echo "`basename $0` options:     [default in brackets]"
  echo "  --buildwith=(ghc|hugs|nhc98) Build $SOFTWARE for the given compiler [detected]"
  echo "  --buildopts=flags    Give extra flags needed by your build compiler [none]"
  echo "  --prefix=dir         Installed files go under dir [compiler-specific]"
            exit 0 ;;
    --version|-v) echo "$SOFTWARE:     $VERSION"
                  exit 0 ;;
    *) echo "`basename $0`: unrecognised option $1"
       echo '    (use --help for option information)'
       exit 1 ;;
  esac
  shift
done

echo "Looking for Haskell compilers:"
# Assume that we start out with a blank config.
HMAKEKNOWN=
GHCKNOWN=
NHCKNOWN=
HUGSKNOWN=
HMAKENUM=0
GHCNUM=0
NHCNUM=0
HUGSNUM=0

echo -n "  Looking for hmake... "
if which hmake >/dev/null 2>&1
then
  HMAKEKNOWN=`which hmake`
  HMAKEVERSION=`${HMAKEKNOWN} --version | head -1 | cut -d' ' -f2`
  HMAKENUM=`echo $HMAKEVERSION | tr "v." "  " | ( read x y z; echo $x$y )`
fi
if [ "$HMAKEKNOWN" != "" ]
then echo "found ${HMAKEVERSION}"
else echo "(not found)"
fi

echo -n "  Looking for ghc...   "
if which ghc >/dev/null 2>&1
then
  GHCKNOWN=`which ghc`
  GHCVERSION=`${GHCKNOWN} --version 2>&1 | sed 's/^.*version[ ]*\([0-9.]*\).*/\1/'`
  GHCNUM=`echo $GHCVERSION | tr "v." "  " | ( read x y z; echo $x$y; )`
  if [ "$GHCNUM" -lt "100" ]
  then GHCNUM=${GHCNUM}0
  fi
fi
if [ "$GHCKNOWN" = "" ]
then echo "(not found)"
else echo "found ${GHCVERSION}"
     if [ "$GHCNUM" -lt "602" ]
     then  echo "    Warning: $SOFTWARE needs ghc-6.2 or later.  Ignoring ghc."
           GHCKNOWN=
     else  GHCLIBDIR=`${GHCKNOWN} -v 2>&1 | grep ' package config file: ' | head -1 | sed 's/.* package config file: //'`
           if $CYGWIN; then GHCLIBDIR=`cygpath -u $GHCLIBDIR`; fi
           if $MINGW; then GHCLIBDIR=`echo $GHCLIBDIR | tr '\\\\' '/'`; fi
           GHCLIBDIR=`dirname $GHCLIBDIR`
           GHCINCDIR=$GHCLIBDIR/imports
     fi
fi

# There may be another version of ghc to look for.
if [ -n "$BUILDWITH" ]
then
if [ "`basename $BUILDWITH | cut -c1-3`" = "ghc" ]
then
  VER=`basename $BUILDWITH | cut -c5-`
  if [ -n "$VER" -a "$VER" != "$GHCVERSION" ]
  then
    echo -n "  Looking for $BUILDWITH...   "
    if which $BUILDWITH >/dev/null 2>&1
    then
      GHC2KNOWN=`which $BUILDWITH`
      GHC2VERSION=`${GHC2KNOWN} --version 2>&1 | sed 's/^.*version[ ]*\([0-9.]*\).*/\1/'`
      GHC2NUM=`echo $GHC2VERSION | tr "." " " | ( read x y z; echo $x$y; )`
      if [ "$GHC2NUM" -lt "100" ]
      then GHC2NUM=${GHC2NUM}0
      fi
    fi
    if [ "$GHC2KNOWN" = "" ]
    then  echo "(not found)"
    else  echo "found ${GHC2VERSION}"
          if [ "$GHC2NUM" -lt "602" ]
          then echo "    Warning: $SOFTWARE needs ghc-6.2 or later.  Ignoring."
               GHC2KNOWN=
          else GHCKNOWN="$GHC2KNOWN"
               GHCVERSION="$GHC2VERSION"
               GHCNUM="$GHC2NUM"
               GHCLIBDIR=`${GHCKNOWN} -v 2>&1 | grep ' package config file: ' | head -1 | sed 's/.* package config file: //'`
               if $CYGWIN; then GHCLIBDIR=`cygpath -u $GHCLIBDIR`; fi
               if $MINGW; then GHCLIBDIR=`echo $GHCLIBDIR | tr '\\\\' '/'`; fi
               GHCLIBDIR=`dirname $GHCLIBDIR`
               GHCINCDIR=$GHCLIBDIR/imports
          fi
    fi
  fi
fi
fi

echo -n "  Looking for nhc98... "
if which nhc98 >/dev/null 2>&1
then
  NHCKNOWN=`which nhc98`
  NHCVERSION=`${NHCKNOWN} --version | head -1 | cut -d' ' -f2`
  NHCNUM=`echo $NHCVERSION | tr "v." "  " | ( read x y z; echo $x$y )`
fi
if [ "$NHCKNOWN" = "" ]
then  echo "(not found)"
else  echo "found ${NHCVERSION}"
     if [ "$HMAKENUM" -lt "306" ]
     then echo "    Warning: building with nhc98 needs hmake-3.06 or later."
          echo "    Available from:   http://www.haskell.org/hmake/"
     fi
     if [ "$NHCNUM" -lt "116" ]
     then  echo "    Warning: $SOFTWARE needs nhc98-1.16 or later.  Ignoring nhc98."
           NHCKNOWN=
     else  NHCLIBDIR=`grep '^NHC98LIBDIR' $NHCKNOWN | cut -c27- | cut -d'}' -f1 | head -1`
           NHCINCDIR=`grep '^NHC98INCDIR' $NHCKNOWN | cut -c27- | cut -d'}' -f1 | head -1`
     fi
fi

month() {
  read mon yr;
  case $mon in
    Jan*) echo 01;;
    Feb*) echo 02;;
    Mar*) echo 03;;
    Apr*) echo 04;;
    May)  echo 05;;
    Jun*) echo 06;;
    Jul*) echo 07;;
    Aug*) echo 08;;
    Sep*) echo 09;;
    Oct*) echo 10;;
    Nov*) echo 11;;
    Dec*) echo 12;;
    *)    echo 00;;
  esac;
}

echo -n "  Looking for hugs...  "
if which hugs >/dev/null 2>&1
then
  HUGSKNOWN=`which hugs`
  HUGSVERSION=`echo :q | $HUGSKNOWN 2>/dev/null | grep Version | cut -c18-32`
  HUGSNUM=`echo $HUGSVERSION | cut -d' ' -f2`
  HUGSNUM=$HUGSNUM`echo $HUGSVERSION | month`
fi
if [ "$HUGSKNOWN" = "" ]
then  echo "(not found)"
else  echo "found ${HUGSVERSION}"
  if [ "$HUGSNUM" -lt "200309" ]
  then  echo "    Warning: $SOFTWARE configuration only supports Hugs >= Sept 2003."
        HUGSKNOWN=
  fi
fi

if [ ! -z "$BUILDWITH" ]
then
  echo "  You want to build for only...  $BUILDWITH"
  if [ "`echo $BUILDWITH | cut -c1-3`" = "ghc" ]
  then
    if [ -z "$GHCKNOWN" ]
    then echo '   *** Did not find ghc - cannot continue.'
         exit 1
    else NHCKNOWN=
         HUGSKNOWN=
    fi
  else if [ "$BUILDWITH" = "nhc98" ]
  then
    if [ -z "$NHCKNOWN" ]
    then echo '   *** Did not find nhc98 - cannot continue.'
         exit 1
    else GHCKNOWN=
         HUGSKNOWN=
    fi
  else if [ "`echo $BUILDWITH | cut -c1-4`" = "hugs" ]
  then
    if [ -z "$HUGSKNOWN" ]
    then echo '   *** Did not find hugs - cannot continue.'
         exit 1
    else GHCKNOWN=
         NHCKNOWN=
    fi
  else echo '   *** I do not recognise this compiler:' $BUILDWITH
       exit 1
  fi;fi;fi;
fi

echo "  Files ultimately install in:"	# details generated below
echo "    (re-run ./configure --prefix=... if this wasn't your intention)"

if [ "$INSTALLDIR" != "" ]
then
  GHCLIBDIR=$INSTALLDIR/$SOFTWARE-$VERSION/ghc-$GHCVERSION/lib
  GHCINCDIR=$INSTALLDIR/$SOFTWARE-$VERSION/ghc-$GHCVERSION/imports
fi

# Prepare to build.
if [ ! -d obj ]
then mkdir obj
fi
if [ -f obj/compilers ]
then rm obj/compilers
fi
if [ "$HUGSKNOWN" != "" ]
then
  echo hugs >>obj/compilers
  if [ ! -d obj/hugs ]
  then mkdir obj/hugs
  fi
  cp -Rp src/Makefile obj/hugs
fi
if [ "$GHCKNOWN" != "" ]
then
  echo ghc >>obj/compilers
  if [ ! -d obj/ghc ]
  then mkdir obj/ghc
  fi
  echo $GHCLIBDIR >obj/ghc/ghclibdir
  echo $GHCINCDIR >obj/ghc/ghcincdir
  echo "      $GHCLIBDIR"	# report location to tty
  echo "      $GHCINCDIR"	# report location to tty
  if $CYGWIN || $MINGW
    then cygpath -w ${GHCLIBDIR} >obj/ghc/ghclibdirraw
         cygpath -w ${GHCINCDIR}/ >obj/ghc/ghcincdirraw
    else echo ${GHCLIBDIR} >obj/ghc/ghclibdirraw
         echo ${GHCINCDIR}/ >obj/ghc/ghcincdirraw
  fi
  if ghc-pkg-$GHCVERSION -l >/dev/null
    then echo ghc-pkg-$GHCVERSION >obj/ghc/ghcpkgcmd
    else echo ghc-pkg >obj/ghc/ghcpkgcmd
  fi
  echo ${BUILDWITH-ghc} >obj/ghccmd
  cp -Rp src/Text src/Makefile src/pkg.conf obj/ghc
  if [ "$GHCNUM" -ge "504" ]
  then echo "-package base" >obj/ghc/ghcpkgs
  else echo "" >obj/ghc/ghcpkgs
  fi
fi
if [ "$NHCKNOWN" != "" ]
then
  echo nhc98 >>obj/compilers
  if [ ! -d obj/nhc98 ]
  then mkdir obj/nhc98
  fi
  echo $NHCLIBDIR >obj/nhc98/nhc98libdir
  echo $NHCINCDIR >obj/nhc98/nhc98incdir
  echo "      $NHCLIBDIR"	# report location to tty
  echo "      $NHCINCDIR"	# report location to tty
  cp -Rp src/Text src/Makefile obj/nhc98
  if [ "$NHCNUM" -ge "116" ]
  then echo "-package base" >obj/nhc98/nhc98pkgs
  else echo "" >obj/nhc98/nhc98pkgs
  fi
fi

echo $INSTALLDIR >obj/prefix
if $CYGWIN || $MINGW ; then echo .exe >obj/exe; else touch obj/exe; fi
if $CYGWIN || $MINGW ; then echo main.exe >obj/out; else echo a.out >obj/out; fi
if $DARWIN ; then echo "-all_load -x"; else echo --whole-archive; fi >obj/ldopt
if $SUNOS ; then echo "-z allextract" >obj/ldopt; fi


echo "Ready to build.  Type 'make' then (as root) 'make install'."
exit 0

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to webmaster@9p.io.