#!/bin/sh # # (c) Sean Seefried 2005 # # A library of useful functions for configure scripts # #-------------------------------------------------------------------- # Function "findprogram": find a program in the path #-------------------------------------------------------------------- findprogram () { if test -f $1; then return 0; fi saveIFS="$IFS" IFS=':' for dir in $PATH; do if test -z "$dir"; then dir=.; fi if test -f $dir/$1; then IFS="$saveIFS" return 0 fi done IFS="$saveIFS" return 1 } #-------------------------------------------------------------------- # Parse command-line arguments #-------------------------------------------------------------------- process_args () { arg="" while : ; do # put optional argument in the $arg variable case "$1" in -*=*) arg=`echo "$1" | sed 's/[-_a-zA-Z0-9]*=//'` arg=`eval echo $arg`;; # expand ~ *) arg="";; esac # match on the arguments case "$1" in "") break;; -?|--help) echo "usage:" echo " ./configure [options]" echo "" echo "options: [defaults in brackets]" echo " --help show this information" echo " --with-hc= the haskell compiler [$hc]" echo " --with-hc-pkg= package compiler [$hcpkg]" echo "install options:" echo " --prefix= install directory [$prefix]" exit 1;; -with-hc=*|--with-hc=*) hc="$arg";; -with-hc-pkg=*|--with-hc-pkg=*) hc_pkg="$arg";; esac # process next argument shift done return 0; } echoc() { echo configure: "$@" } #---------------------------------------------------------------------- # Get the version of the haskell compiler #---------------------------------------------------------------------- get_version() { echo "`$hc --version | sed -e 's|[^0-9.]*\([0-9.][0-9.]*\)|\1|'`" } #---------------------------------------------------------------------- # Get the version of the haskell compiler as an integer #---------------------------------------------------------------------- get_version_int() { version=`get_version` MAJ="`echo $version | sed 's|\([0-9][0-9]*\)\.\([0-9][0-9]*\)\.*\([0-9][0-9]*\)*|\1|'`" MIN="`echo $version | sed 's|\([0-9][0-9]*\)\.\([0-9][0-9]*\)\.*\([0-9][0-9]*\)*|\2|'`" PATCH="`echo $version | sed 's|\([0-9][0-9]*\)\.\([0-9][0-9]*\)\.*\([0-9][0-9]*\)*|\3|'`" if test "$PATCH" = "" ; then PATCH=0 fi echo `expr $MAJ \* 10000 + $MIN \* 100 + $PATCH` } # # Defaults # prefix=/usr/local hc="ghc" hcpkg="ghc-pkg"