#!/bin/sh
#
# This is the configuration script for lcrash.
# 

# Version information for lcrash
GUI_VERSION=0
LCRASH_VERSION_NUMBER=00100200
LCRASH_VERSION_STRING="0.10.2"
LCRASH_FLAVOR="xlcrash"
LCRASH_DATE="\$Date: 2004/12/21 23:26:17 $"

config_header=include/lc_config.h

# Loop over all args

while :
do

# Get the first arg, and shuffle
	case $# in
		0)
		break
		;;
		esac

# Get the first arg, and shuffle
	option=$1
	shift

# Make all options have two hyphens
	orig_option=$option # Save original for error messages
	case $option in
		--*) ;;
		-*) option=-$option ;;
		esac

# Split out the argument for options that take them
	case $option in
	--*=*)
		optarg=`echo $option | sed -e 's/^[^=]*=//'`
		arguments="$arguments $option"
		;;
	esac

# Now, process the options. Note that there are a number of unused
# options (e.g., --prefix) that have to be here to so that configure
# runs properly via rpm -ba.
	case $option in

        --arch*)
                ARCH=$optarg                                  
                ;;

        --bfd-version*)
                BFD_VERSION_NUMBER=$optarg
		;;

        --help | --he*)
                fatal=yes
                ;;

	--cleanup)
		clean=1
		;;

	--*)
        	echo "configure: Unrecognized option: \"$orig_option\"; use --help for usage." >&2
		exit 1
		;;
	esac
done

if [ $clean ] ;
then
	if [ -f $config_header ] ;
	then
		echo "configure: removing $config_header"
		rm -f $config_header
	fi
	exit 0
fi

# print usage of configure script
if [ $fatal ] ;
then
	echo
	echo usage: configure [OPTIONS]
	echo
	echo Options:
	echo ' --cleanup          Clean up the build area (e.g., removing lc_config.h)'
	echo ' --help             Print this message'
	exit 0
fi

# Let's start clean...
rm -f $config_header
rm -f lcrash/include/dis-asm.h

#
# generate lcrash config header file
#
echo "/* This file is automaticly generated by the lkcdutils configure script." > $config_header
echo " * Do not edit by hand!" >> $config_header
echo " */" >> $config_header
echo "#define _BFD_VERSION_NUMBER_(a,b,c) (((a) << 24) + ((b) << 12) + (c))" >> $config_header
echo "#define BFD_VERSION_NUMBER $BFD_VERSION_NUMBER" >> $config_header
echo "#define GUI_VERSION $GUI_VERSION" >> $config_header
echo "#define LCRASH_VERSION_NUMBER $LCRASH_VERSION_NUMBER" >> $config_header
echo "#define LCRASH_VERSION_STRING \"$LCRASH_VERSION_STRING\""\
 >> $config_header
echo "#define LCRASH_FLAVOR \"$LCRASH_FLAVOR\"" >> $config_header
echo "#define LCRASH_DATE \"$LCRASH_DATE\"" >> $config_header

# check for /usr/include/dis-asm.h
# might have to use lcrash/include/dis-asm.h instead
if [ ! -f /usr/include/dis-asm.h ]
then
    echo "configure: /usr/include/dis-asm.h does not exist"
    echo "configure:     using lcrash/include/dis-asm.h instead"
    cp lcrash/include/lc_dis-asm.h lcrash/include/dis-asm.h
else
    echo "configure: /usr/include/dis-asm.h exists"
fi
