#! /bin/sh
# lightningize - Prepare a package to use lightning.
# Generated automatically from lightningize.in by configure.
# Copyright (C) 1996-2000 Free Software Foundation, Inc.
# Originally by Gordon Matzigkeit <gord@gnu.ai.mit.edu>, 1996
#
# 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.
#
# As a special exception to the GNU General Public License, if you
# distribute this file as part of a program that contains a
# configuration script generated by Autoconf, you may include it under
# the same distribution terms that you use for the rest of that program.

# The name of this program.
progname=`echo "$0" | sed 's%^.*/%%'`

# Constants.
PROGRAM=lightningize
PACKAGE=@PACKAGE@
VERSION=@VERSION@

# Directory names.
prefix=@prefix@
datadir=@datadir@
includedir=@includedir@
pkgdatadir=${datadir}/lightning
pkgincludedir=${includedir}/lightning
aclocaldir=${datadir}/aclocal

BACKENDS="@BACKENDS@"
file_base_names="asm core funcs fp"
macro_name=LIGHTNING_CONFIGURE_IF_NOT_FOUND
lightning_m4="$aclocaldir/lightning.m4"

# Global variables.
automake=
copy=
force=
configure_ac=
status=0
dry_run=no
help="Try \`$progname --help' for more information."
rm="rm -f"
ln_s="@LN_S@"
cp="cp -f"
mkdir="mkdir"

for arg
do
  case "$arg" in
  --help)
    cat <<EOF
Usage: $progname [OPTION]...

Prepare a package to use lightning.

     --automake       work silently, and assume that Automake is in use
 -c, --copy           copy files rather than symlinking them
     --debug          enable verbose shell tracing
 -n, --dry-run        print commands rather than running them
 -f, --force          replace existing files
     --help           display this message and exit
     --version        print version information and exit

You must \`cd' to the top directory of your package before you run
\`$progname'.
EOF
    exit 0
    ;;

  --version)
    echo "$PROGRAM (GNU $PACKAGE) $VERSION"
    exit 0
    ;;

  --automake)
    automake=yes
    ;;

  -c | --copy)
    ln_s=
    ;;

  --debug)
    echo "$progname: enabling shell trace mode"
    set -x
    ;;

  -n | --dry-run)
    if test "$dry_run" != yes; then
      dry_run=yes
      rm="echo $rm"
      test -n "$ln_s" && ln_s="echo $ln_s"
      cp="echo $cp"
      mkdir="echo $mkdir"
    fi
    ;;

  -f | --force)
    force=yes
    ;;

  -*)
    echo "$progname: unrecognized option \`$arg'" 1>&2
    echo "$help" 1>&2
    exit 1
    ;;

  *)
    echo "$progname: too many arguments" 1>&2
    echo "$help" 1>&2
    exit 1
    ;;
  esac
done

if test -f configure.ac; then
  configure_ac=configure.ac
elif test -f configure.in; then
  configure_ac=configure.in
else
  echo "$progname: \`configure.ac' does not exist" 1>&2
  echo "$help" 1>&2
  exit 1
fi


if test -z "$automake"; then
  if egrep "^$macro_name" $configure_ac >/dev/null 2>&1; then :
  else
    echo "Remember to add \`$macro_name' to \`$configure_ac'."
  fi

  if grep 'generated automatically by aclocal' aclocal.m4 >/dev/null 2>&1; then
    updatemsg="update your \`aclocal.m4' by running aclocal"
  else
    updatemsg="add the contents of \`$lightning_m4' to \`aclocal.m4'"
  fi

  if egrep '^AC_DEFUN\(\['$macro_name aclocal.m4 >/dev/null 2>&1; then
    # Check the version number on lightning.m4 and the one used in aclocal.m4.
    instserial=`grep '^# serial ' $lightning_m4 | grep $macro_name | sed -e 's/^# serial \([0-9][0-9]*\).*$/\1/; q'`

    if test -z "$instserial"; then
      echo "$progname: warning: no serial number on \`$lightning_m4'" 1>&2
    else
      # If the local macro has no serial number, we assume it's ancient.
      localserial=`grep '^# serial ' aclocal.m4 | grep $macro_name | sed -e 's/^# serial \([0-9][0-9]*\).*$/\1/; q'`

      test -z "$localserial" && localserial=0

      if test "$localserial" -lt "$instserial"; then
	echo "You should $updatemsg."
      elif test "$localserial" -gt "$instserial"; then
	echo "$progname: \`$lightning_m4' is serial $instserial, less than $localserial in \`aclocal.m4'" 1>&2
	if test -z "$force"; then
	  echo "Use \`--force' to replace newer lightning files with this version." 1>&2
	  exit 1
	fi
	echo "To remain compatible, you should $updatemsg."
      fi
    fi
  else
    echo "You should $updatemsg."
  fi
fi

# Create the list of directories and files to be updated
# Syntax is DESTINATION-DIRECTORY:ABSOLUTE-SRC-PATH

dirs="lightning"
files="lightning:$includedir/lightning.h lightning:$pkgdatadir/Makefile.am"
for i in $file_base_names; do
  files="$files lightning:$pkgincludedir/$i-common.h"
done
for j in $BACKENDS; do
  dirs="$dirs lightning/$j"
  for i in $file_base_names; do
    files="$files lightning/$j:$pkgincludedir/$j/$i.h"
  done
done

for dir in $dirs; do
  if $mkdir $dir; then :
  else
    echo "$progname: cannot create \`$dir'" 1>&2
    status=1
  fi
done

for file in $files; do
  base=`echo $file | sed 's%^.*/%%' `
  src=`echo $file | sed 's/^.*://' `
  dest=`echo $file | sed 's/:.*//' `/$base
  if test -f "$dest" && test -z "$force"; then
    test -z "$automake" && echo "$progname: \`$dest' exists: use \`--force' to overwrite" 1>&2
    continue
  fi

  $rm $dest
  if test -n "$ln_s" && $ln_s $src $dest; then :
  elif $cp $src $dest; then :
  else
    echo "$progname: cannot copy \`$src' to \`$dest'" 1>&2
    status=1
  fi
done

exit $status

# Local Variables:
# mode:shell-script
# sh-indentation:2
# End:
