dnl $Id: configure.in,v 1.75 2001/12/22 13:26:36 aleidinger Exp $
dnl
dnl
dnl don't forget to set ASM_FOR_ARCH to a space delimited list of
dnl processor architectures, for which assembler routines exist
dnl
dnl
dnl Exported and configured variables:
dnl CC
dnl CFLAGS
dnl LDFLAGS
dnl LDADD
dnl NASM

dnl extra vars for frontend:
dnl FRONTEND_LDFLAGS
dnl FRONTEND_CFLAGS
dnl FRONTEND_LDADD

AC_PREREQ(2.13)
AC_INIT(libmp3lame/lame.c)

dnl check system
AC_CANONICAL_SYSTEM
AC_VALIDATE_CACHED_SYSTEM_TUPLE

dnl automake
AM_INIT_AUTOMAKE(lame,3.91)
AM_CONFIG_HEADER(config.h)
AM_MAINTAINER_MODE
AM_MAKE_INCLUDE

dnl libtool
# AC_DISABLE_SHARED
AC_PROG_LIBTOOL
CFLAGS="${ac_save_CFLAGS}"

# increase this when the shared lib becomes totally incompatible
LIB_MAJOR_VERSION=0

# increase this when changes are made, but they are upward compatible
# to previous versions
LIB_MINOR_VERSION=0

dnl check environment
AC_AIX
AC_ISC_POSIX
AC_MINIX
AC_CYGWIN
AC_EXEEXT

dnl # work around for a bug, don't know where it is exactly
if test "${ac_cv_cygwin}" = "yes"; then
	if test "${CC}" != "gcc"; then
		AC_MSG_ERROR([Please use]
			[   CC=gcc ./configure]
			[Abort this configure run and add "CC=gcc" or you will]
			[see errors and no lame.exe will be build.])
	fi
fi

dnl check programs
AM_PROG_CC_STDC

dnl more automake stuff
AM_C_PROTOTYPES

AC_CHECK_HEADER(dmalloc.h)
if test "$ac_cv_header_dmalloc_h" = "yes"; then
	AM_WITH_DMALLOC
fi

dnl Checks for header files.
AC_HEADER_STDC
AC_CHECK_HEADERS( \
		 errno.h \
		 fcntl.h \
		 limits.h \
		 string.h \
		 sys/soundcard.h \
		 sys/time.h \
		 unistd.h \
		 linux/soundcard.h)

dnl Checks for typedefs, structures, and compiler characteristics.
AC_C_CONST
AC_C_INLINE
if test ${cross_compiling} = "no"; then
	AC_C_BIGENDIAN
fi

if test "${GCC}" = "yes"; then
	AC_MSG_CHECKING(version of GCC)
	GCC_version=`${CC} --version`
	AC_MSG_RESULT(${GCC_version})
fi

AC_CHECK_SIZEOF(short, 2)
AC_CHECK_SIZEOF(unsigned short, 2)
AC_CHECK_SIZEOF(int, 4)
AC_CHECK_SIZEOF(unsigned int, 4)
AC_CHECK_SIZEOF(long, 4)
AC_CHECK_SIZEOF(unsigned long, 4)
AC_CHECK_SIZEOF(long long, 8)
AC_CHECK_SIZEOF(unsigned long long, 8)
AC_CHECK_SIZEOF(float, 4)
AC_CHECK_SIZEOF(double, 8)

if test ${cross_compiling} = "no"; then
	AC_C_LONG_DOUBLE
fi
if test "${ac_cv_c_have_long_double}" = "yes" ; then
	AC_CHECK_SIZEOF(long double, 12)
fi

AC_CHECK_TYPE(uint8_t, unsigned char)
AC_CHECK_TYPE(int8_t, char)
AC_CHECK_TYPE(uint16_t, unsigned short)
AC_CHECK_TYPE(int16_t, short)
if test "${ac_cv_sizeof_int}" = "4" ; then
	AC_CHECK_TYPE(uint32_t, unsigned int)
	AC_CHECK_TYPE(int32_t, int)
elif test "${ac_cv_sizeof_long}" = "4" ; then
	AC_CHECK_TYPE(uint32_t, unsigned long)
	AC_CHECK_TYPE(int32_t, long)
else
	# can't determine default value in case the type isn't present
	AC_MSG_ERROR(CHECK_TYPE_int32_t - please report to lame-dev@lists.sourceforge.net)
fi
if test "${ac_cv_sizeof_long}" = "8" ; then
	AC_CHECK_TYPE(uint64_t, unsigned long)
	AC_CHECK_TYPE(int64_t, long)
elif test "${ac_cv_sizeof_long_long}" = "8" ; then
	AC_CHECK_TYPE(uint64_t, unsigned long long)
	AC_CHECK_TYPE(int64_t, long long)
else
	# can't determine default value in case the type isn't present
	AC_MSG_ERROR(CHECK_TYPE_int64_t - please report to lame-dev@lists.sourceforge.net)
fi

alex_IEEE854_FLOAT80
if test "${alex_cv_ieee854_float80}" = "yes" ; then
	if test "${ac_cv_c_long_double}" = "yes" ; then
		AC_CHECK_TYPE(ieee854_float80_t, long double)
		AC_DEFINE(HAVE_IEEE854_FLOAT80, 1, [system has 80 bit floats])
	fi
fi
AC_CHECK_TYPE(ieee754_float64_t, double)
AC_CHECK_TYPE(ieee754_float32_t, float)

AC_DEFINE(LAME_LIBRARY_BUILD, 1, [requested by Frank, seems to be temporary needed for a smooth transition])


if test ${cross_compiling} = "yes"; then
	AC_MSG_WARN([]
  [**************************************************************************]
  [*                                                                        *]
  [* You are cross compiling:                                               *]
  [*   - I did not have a change to determine                               *]
  [*     + the size of:                                                     *]
  [*       - short                                                          *]
  [*       - unsigned short                                                 *]
  [*       - int                                                            *]
  [*       - unsigned int                                                   *]
  [*       - long                                                           *]
  [*       - unsigned long                                                  *]
  [*       - float                                                          *]
  [*       - double                                                         *]
  [*       - long double                                                    *]
  [*     + the endianess of the target system                               *]
  [*   - You have to provide appropriate defines for them in config.h, e.g. *]
  [*     + define SIZEOF_SHORT to 2 if the size of a short is 2             *]
  [*     + define WORDS_BIGENDIAN if your system is a big endian system     *]
  [*                                                                        *]
  [**************************************************************************])
fi

AC_TYPE_SIZE_T
AC_HEADER_TIME

dnl Checks for library functions.
AC_FUNC_ALLOCA
AC_CHECK_FUNCS(gettimeofday socket strtol)


dnl Initialize configuration variables for the Makefile
CFLAGS=${CFLAGS}
CONFIG_DEFS=${CONFIG_DEFS}
NASM=
INCLUDES="-I\$(top_srcdir)/include -I\$(srcdir)"
FRONTEND_LDFLAGS=
FRONTEND_CFLAGS=
LIB_SOURCES=
MAKEDEP="-M"
RM_F="rm -f"

AC_ARG_ENABLE(nasm,
  [  --enable-nasm              Allow the use of nasm if available],
  ASM_FOR_ARCH="i386", ASM_FOR_ARCH="")

dnl Checks for libraries.

AC_CHECK_HEADERS(termcap.h)
AC_CHECK_HEADERS(ncurses/termcap.h)
AC_CHECK_LIB(termcap, initscr, HAVE_TERMCAP="termcap")
AC_CHECK_LIB(curses, initscr, HAVE_TERMCAP="curses")
AC_CHECK_LIB(ncurses, initscr, HAVE_TERMCAP="ncurses")
 
dnl math lib
AC_CHECK_LIB(m, cos, USE_LIBM="-lm")
dnl free fast math library
AC_CHECK_LIB(ffm, cos, USE_LIBM="-lffm -lm")
dnl Compaq fast math library.
AC_CHECK_LIB(cpml, cos, USE_LIBM="-lcpml")
CONFIG_MATH_LIB="${USE_LIBM}"

AC_CHECK_LIB(sndfile, sf_open_read, HAVE_SNDFILE="yes")


dnl configure use of features

AM_PATH_GTK(1.2.0, HAVE_GTK="yes", HAVE_GTK="no")
if test "${HAVE_GTK}" = "yes"; then
	AC_DEFINE(HAVE_GTK, 1, have working GTK)
fi


dnl ElectricFence malloc debugging
AC_MSG_CHECKING(use of ElectricFence malloc debugging)
AC_ARG_ENABLE(efence,
  [  --enable-efence            Use ElectricFence for malloc debugging],
  CONFIG_EFENCE="${enableval}", CONFIG_EFENCE="no")

case "${CONFIG_EFENCE}" in
yes)
	AC_CHECK_LIB(efence, EF_Print, HAVE_EFENCE="-lefence")
	if test "x${HAVE_EFENCE}" != "x-lefence"; then
		AC_MSG_RESULT(yes, but libefence not found)
	else
		LDADD="${LDADD} ${HAVE_EFENCE}"
		AC_DEFINE(HAVE_EFENCE, 1, we link against libefence)
		AC_MSG_RESULT("${CONFIG_EFENCE}")
	fi
	;;
no)
	AC_MSG_RESULT("${CONFIG_EFENCE}")
	;;
*)
	AC_MSG_ERROR(bad value »${CONFIG_EFENCE}« for efence option)
	;;
esac


dnl libsndfile
AC_MSG_CHECKING(use of file io)
WARNING=
AC_ARG_WITH(fileio, 
  [  --with-fileio=lame         Use lame's internal file io routines [default]]
  [             =sndfile      Use Erik de Castro Lopo's libsndfile]
  [                           (no stdin possible currently)],
  CONFIG_FILEIO="${withval}", CONFIG_FILEIO="lame")
AC_ARG_WITH(sndfile-prefix,
  [  --with-sndfile-prefix=DIR  Alternate location for libsndfile],
  CONFIG_SNDFILE_PREFIX="${withval}", CONFIG_SNDFILE_PREFIX="")
if test "${CONFIG_FILEIO}" = "sndfile" ; then
  if test "x${CONFIG_SNDFILE_PREFIX}" != "x" ; then 
    # look for sndfile lib. This overrides any standard location
    LA_SEARCH_LIB(SNDFILE_LIB_LOC, SNDFILE_INC_LOC, \
      libsndfile.a, sndfile.h, $CONFIG_SNDFILE_PREFIX) 
    if test "x${SNDFILE_LIB_LOC}" != "x" ; then
      HAVE_SNDFILE="yes"
      FRONTEND_LDFLAGS="-L${SNDFILE_LIB_LOC} ${FRONTEND_LDFLAGS}"
      INCLUDES="-I${SNDFILE_INC_LOC} ${INCLUDES}"
    else
      WARNING="sndfile lib not found in specified prefix."
    fi
  fi
  if test "${HAVE_SNDFILE}" = "yes" ; then
    FRONTEND_LDADD="-lsndfile ${FRONTEND_LDADD}"
    AC_DEFINE(LIBSNDFILE, 1, build with libsndfile support)
  else
    # default
    CONFIG_FILEIO="lame"
    WARNING="${WARNING} Could not find any sndfile lib on system."
  fi
else
  CONFIG_FILEIO="lame"
fi 
AC_MSG_RESULT(${CONFIG_FILEIO})
if test "x${WARNING}" != "x" ; then
  AC_MSG_WARN($WARNING)
fi


dnl check if we should remove hooks for analyzer code in library
dnl default library must include these hooks
AC_MSG_CHECKING(use of analyzer hooks)
AC_ARG_ENABLE(analyzer-hooks,
  [  --disable-analyzer-hooks   Exclude analyzer hooks],
  CONFIG_ANALYZER="${enableval}", CONFIG_ANALYZER="yes")

case "${CONFIG_ANALYZER}" in
yes)
	;;
no)
	AC_DEFINE(NOANALYSIS, 1, build without hooks for analyzer)
	;;
*)
	AC_MSG_ERROR(bad value »${CONFIG_ANALYZER}« for analyzer-hooks option)
	;;
esac
AC_MSG_RESULT($CONFIG_ANALYZER)


dnl mpg123 decoder
AC_MSG_CHECKING(use of mpg123 decoder)
AC_ARG_ENABLE(decoder, 
  [  --disable-decoder          Exclude mpg123 decoder],
  CONFIG_DECODER="${enableval}", CONFIG_DECODER="yes")
AC_ARG_ENABLE(decode-layer1, 
  [  --disable-decoder-layer1   Exclude layer1 decoding],
  CONFIG_DECODER_L1="${enableval}", CONFIG_DECODER_L1="yes")
AC_ARG_ENABLE(decode-layer1, 
  [  --disable-decoder-layer2   Exclude layer2 decoding],
  CONFIG_DECODER_L2="${enableval}", CONFIG_DECODER_L2="yes")

AM_CONDITIONAL(LIB_WITH_DECODER, test "x${CONFIG_DECODER}" = "xyes")

if test "${CONFIG_DECODER}" != "no" ; then
	CONFIG_DECODER="yes (Layer"
	AC_DEFINE(HAVE_MPGLIB, 1, build with mpglib support)
  
	if test "${CONFIG_DECODER_L1}" != "no"; then
		CONFIG_DECODER="${CONFIG_DECODER} 1,"
		AC_DEFINE(USE_LAYER_1, 1, build with layer 1 decoding)
	fi
	if test "${CONFIG_DECODER_L2}" != "no"; then
		CONFIG_DECODER="${CONFIG_DECODER} 2,"
		AC_DEFINE(USE_LAYER_2, 1, build with layer 2 decoding)
	fi
	CONFIG_DECODER="${CONFIG_DECODER} 3)"
fi
AC_MSG_RESULT($CONFIG_DECODER)


dnl vorbis
WARNING=
AC_ARG_WITH(vorbis, 
  [  --with-vorbis              Use vorbis library to decode ogg files]
  [                           [default: no]],
  CONFIG_VORBIS="${withval}", CONFIG_VORBIS="no")
AC_ARG_WITH(vorbis-prefix,
  [  --with-vorbis-prefix=DIR   Alternate location for vorbis],
  CONFIG_VORBIS_PREFIX="${withval}", CONFIG_VORBIS_PREFIX="")
if test "${CONFIG_VORBIS}" != "no" ; then
  if test "x${CONFIG_VORBIS_PREFIX}" != "x" ; then
    # look for vorbis lib. This overrides any standard location
    LA_SEARCH_LIB(VORBIS_LIB_LOC, VORBIS_INC_LOC, \
      libvorbis.a, vorbis/codec.h, ${CONFIG_VORBIS_PREFIX})
    if test "x${VORBIS_LIB_LOC}" != "x" ; then
      HAVE_VORBIS="yes"
      FRONTEND_LDFLAGS="-L${VORBIS_LIB_LOC} ${FRONTEND_LDFLAGS}"
      INCLUDES="-I${VORBIS_INC_LOC} ${INCLUDES}"
    else
      WARNING="vorbis lib not found in specified prefix."
    fi
  fi

  AC_CHECK_LIB(vorbis, ogg_sync_init, HAVE_VORBIS="yes")

  if test "${HAVE_VORBIS}" = "yes" ; then
    FRONTEND_LDFLAGS="-lvorbis -logg ${FRONTEND_LDFLAGS}"
    AC_DEFINE(HAVE_VORBIS, 1, build with vorbis support)
  else
    CONFIG_VORBIS="no"
  fi
fi
AC_MSG_CHECKING(use of vorbis)
AC_MSG_RESULT(${CONFIG_VORBIS})
if test "x${WARNING}" != "x" ; then
  AC_MSG_WARN($WARNING)
fi



AC_MSG_CHECKING(if the lame frontend should be build)
AC_ARG_ENABLE(frontend,
  [  --disable-frontend         Do not build the lame executable [default: build it]],
    WITH_FRONTEND="${enableval}", WITH_FRONTEND=yes)
if test "x${WITH_FRONTEND}" = "xyes"; then
	WITH_FRONTEND=lame
	AC_MSG_RESULT(yes)
else
	WITH_FRONTEND=
	AC_MSG_RESULT(no)
fi



AC_MSG_CHECKING(if mp3x is requested)
AC_ARG_ENABLE(mp3x,
  [  --enable-mp3x              Build GTK frame analyzer [default: no]],
    WITH_MP3X="${enableval}", WITH_MP3X=no)
if test "x${WITH_MP3X}" = "xyes"; then
	WITH_MP3X=mp3x
	AC_MSG_RESULT(yes)
else
	WITH_MP3X=
	AC_MSG_RESULT(no)
fi

if test "${HAVE_GTK}" = "no"; then
	if test "x${WITH_MP3X}" = "xmp3x"; then
		AC_MSG_WARN(can't build mp3x, no GTK installed)
		WITH_MP3X=
	fi
	if test "x${CONFIG_ANALYZER}" != "xyes"; then
		AC_MSG_WARN(can't build mp3x because of disabled analyzer hooks)
		WITH_MP3X=
	fi
fi

AC_MSG_CHECKING(if mp3rtp is requested)
AC_ARG_ENABLE(mp3rtp,
  [  --enable-mp3rtp            Build mp3rtp [default: no]],
    WITH_MP3RTP="${enableval}", WITH_MP3RTP=no)
if test "x${WITH_MP3RTP}" = "xyes"; then
	WITH_MP3RTP=mp3rtp
	AC_MSG_RESULT(yes)
else
	WITH_MP3RTP=
	AC_MSG_RESULT(no)
fi


#
# this is from vorbis
#
dnl check GLIBC
case $target in 
*86-*-linux*)
	# glibc < 2.1.3 has a serious FP bug in the math inline header
	# that will cripple Vorbis.  Look to see if the magic FP stack
	# clobber is missing in the mathinline header, thus indicating
	# the buggy version

	AC_EGREP_CPP(log10.*fldlg2.*fxch,[
		#define __LIBC_INTERNAL_MATH_INLINES 1
	     	#define __OPTIMIZE__
		#include <math.h>
		],bad=maybe,bad=no)

	AC_MSG_CHECKING(glibc mathinline bug)
	if test ${bad} = "maybe" ;then
	      AC_EGREP_CPP(log10.*fldlg2.*fxch.*st\([[0123456789]]*\),
				[
				#define __LIBC_INTERNAL_MATH_INLINES 1
			     	#define __OPTIMIZE__
				#include <math.h>
				],bad=no,bad=yes)
	fi
	AC_MSG_RESULT(${bad})
	if test ${bad} = "yes" ;then
 AC_MSG_WARN([                                                        ])
 AC_MSG_WARN([********************************************************])
 AC_MSG_WARN([* The glibc headers on this machine have a serious bug *])
 AC_MSG_WARN([* in /usr/include/bits/mathinline.h  This bug affects  *])
 AC_MSG_WARN([* all floating point code, not only LAME, but all code *])
 AC_MSG_WARN([* built on this machine. Upgrading to glibc 2.1.3 is   *])
 AC_MSG_WARN([* strongly urged to correct the problem.               *])
 AC_MSG_WARN([*Note: that upgrading glibc will not fix any previously*])
 AC_MSG_WARN([* built programs; this is a compile-time bug.          *])
 AC_MSG_WARN([* To work around the problem for this build of LAME,   *])
 AC_MSG_WARN([* autoconf is disabling all math inlining.  This will  *])
 AC_MSG_WARN([* hurt LAME performace but is necessary for LAME to    *])
 AC_MSG_WARN([* work correctly.  Once glibc is upgraded, rerun       *])
 AC_MSG_WARN([* configure and make to build with inlining.           *])
 AC_MSG_WARN([********************************************************])
 AC_MSG_WARN([                                                        ])

	AC_DEFINE(__NO_MATH_INLINES, 1, work around a glibc bug)
	fi;;
esac


dnl configure use of VBR bitrate histogram
dnl todo: always use yes as default, use simulation instead ?
AC_MSG_CHECKING(use of VBR bitrate histogram)
if test "x${HAVE_TERMCAP}" != "x"; then
  BRH_DEFAULT="yes"
else
  BRH_DEFAULT="no"
fi
AC_ARG_ENABLE(brhist, 
  [  --enable-brhist            Include the VBR bitrate histogram feature]
  [                           [default: yes if any termcap available]],
  CONFIG_BRHIST="${enableval}", CONFIG_BRHIST="${BRH_DEFAULT}")
if test "${CONFIG_BRHIST}" != "no" ; then
	AC_DEFINE(BRHIST, 1, enable VBR bitrate histogram)

	if test "${BRH_DEFAULT}" = "yes" ; then
		FRONTEND_LDADD="-l${HAVE_TERMCAP} ${FRONTEND_LDADD}"
		CONFIG_BRHIST="yes, with ${HAVE_TERMCAP}"
		AC_DEFINE(HAVE_TERMCAP, 1, have termcap)
	else
		CONFIG_BRHIST="yes, simulated termcap"
	fi
fi
AC_MSG_RESULT(${CONFIG_BRHIST})
AM_CONDITIONAL(WITH_BRHIST, test "${CONFIG_BRHIST}" != "no")



dnl ### processor specific options ###
case $target_cpu in
*86)
	CPUTYPE="i386"

	# this may make a faster binary
	AC_DEFINE(TAKEHIRO_IEEE754_HACK, 1, IEEE754 compatible machine)
	;;
*)
	CPUTYPE="no"
	;;
esac



AC_MSG_CHECKING(for FLOAT8 as float)
AC_ARG_ENABLE(all-float,
  [  --enable-all-float         Whether to make all floting point variables as float, not double]
  [                           [default: no]],   
    CONFIG_ALLFLOAT="${enableval}", CONFIG_ALLFLOAT="no")
case "${CONFIG_ALLFLOAT}" in
no)
	;;
yes)
	AC_DEFINE(FLOAT8, float, float instead of double)
	;;
*)
	AC_MSG_ERROR(bad value »${CONFIG_ALLFLOAT}« for all-float option)
	;;
esac
AC_MSG_RESULT(${CONFIG_ALLFLOAT})



AC_PATH_PROG(NASM, nasm, no)
case "${NASM}" in
no)
	;;
*)
	AC_MSG_CHECKING(for assembler routines for this processor type)
	for recurse_over in ${ASM_FOR_ARCH}
	do
		if test "${CPUTYPE}" = "${recurse_over}"; then
			include_asm_routines="yes"
		fi
	done
	if test "x${include_asm_routines}" = "xyes"; then
		AC_DEFINE(HAVE_NASM, 1, have nasm)
		AC_DEFINE(MMX_choose_table, 1, use MMX version of choose_table)
	else
		include_asm_routines="no"
		NASM="no"
	fi
	AC_MSG_RESULT(${include_asm_routines})
	;;
esac
AM_CONDITIONAL(HAVE_NASM, test "${NASM}" != "no")

if test "x$CYGWIN" = "xyes"; then
	NASM_FORMAT="-f win32 -DWIN32"
else
	NASM_FORMAT="-f elf"
fi

AC_MSG_CHECKING(for additional optimizations)
AC_ARG_ENABLE(expopt,
  [  --enable-expopt=full,norm  Whether to enable experimental optimizations]
  [                           [default: no]],   
    CONFIG_EXPOPT="${enableval}", CONFIG_EXPOPT="no")

if test "x$GCC" = "xyes"; then
	# gcc defaults. OS specific options go in versious sections below
        # from the gcc man pages:  "there is no reason to use -pedantic"
	CFLAGS="-Wall -pipe ${CFLAGS}"


	OPTIMIZATION="-O3 -fomit-frame-pointer -ffast-math -funroll-loops"
	case "${GCC_version}" in
	2.96*)
           # for buggy version of gcc shipped with RH7.1, back of on some
           # optimizations
           OPTIMIZATION="-O -fomit-frame-pointer -ffast-math -funroll-loops "
           ;;
        esac



	OPTIMIZATION_NORM="-fschedule-insns2"

	OPTIMIZATION_FULL="-fmove-all-movables -freduce-all-givs \
			-fsched-interblock -fbranch-count-reg -fforce-addr"

	case "${CONFIG_EXPOPT}" in
	no)
		;;
	norm|yes)
		OPTIMIZATION="${OPTIMIZATION} ${OPTIMIZATION_NORM}"
		;;
	full)
		OPTIMIZATION="${OPTIMIZATION} ${OPTIMIZATION_NORM} \
			${OPTIMIZATION_FULL}"

		# some hardware dependend options
		case "${GCC_version}" in
		2.9*|3.*)
			# "new" GCC, use some "new" CPU specific optimizations
			case ${target_cpu} in
			*486)
				OPTIMIZATION="${OPTIMIZATION} -m486 \
					-mfancy-math-387"
				;;
			*586)
				OPTIMIZATION="${OPTIMIZATION} -mcpu=pentium \
					-march=pentium -mfancy-math-387"
				;;
			*686)
				OPTIMIZATION="${OPTIMIZATION} -mcpu=pentiumpro \
					-march=pentiumpro -mfancy-math-387"
				;;
			*86)
				OPTIMIZATION="${OPTIMIZATION} -mfancy-math-387"
				;;
			alpha*)
				OPTIMIZATION="${OPTIMIZATION} -mfp-regs"
				AC_DEFINE(FLOAT, double, double is faster than float on Alpha)
				# add "-mcpu=21164a -Wa,-m21164a" to optimize
				# for 21164a (ev56) CPU
				;;
			*)
				OPTIMIZATION="${OPTIMIZATION} -fdelayed-branch"
				;;
			esac
		;;
	*)
		AC_MSG_ERROR(bad value »${CONFIG_EXPOPT}« for expopt option)
		;;
	esac
esac

	AC_MSG_RESULT(${CONFIG_EXPOPT})
else
	AC_MSG_RESULT(no)
fi





AC_MSG_CHECKING(for debug options)
AC_ARG_ENABLE(debug,
  [  --enable-debug=alot,norm   Enable debugging (disables optimizations)]
  [                           [default: no]],
    CONFIG_DEBUG="${enableval}", CONFIG_DEBUG="no")

if test "x$GCC" = "xyes"; then
	DEBUG_NORM_OPT="-O -g -Wall"
	DEBUG_ANOYING="-Wbad-function-cast -Wcast-align \
		-Wcast-qual -Wchar-subscripts -Wconversion \
		-Wmissing-prototypes -Wnested-externs -Wpointer-arith \
		-Wredundant-decls -Wshadow -Wstrict-prototypes \
		-Wwrite-strings -Winline \
		-Wformat -Wswitch -Waggregate-return -Wmissing-noreturn \
		-Wimplicit-int -fno-builtin"

	case "${CONFIG_DEBUG}" in
	no)
		AC_DEFINE(NDEBUG, 1, no debug build)
		;;
	norm|yes)
		AC_DEFINE(ABORTFP, 1, debug define)
		OPTIMIZATION="${DEBUG_NORM_OPT}"
		;;
	anoying)
		AC_DEFINE(ABORTFP, 1, debug define)
		OPTIMIZATION="${DEBUG_NORM_OPT} ${DEBUG_ANOYING}"
		;;
	alot)
		AC_DEFINE(ABORTFP, 1, debug define)
		AC_DEFINE(DEBUG, 1, alot of debug output)
		OPTIMIZATION="${DEBUG_NORM_OPT}"
		;;
	*)
		AC_MSG_ERROR(bad value »${CONFIG_DEBUG}« for debug option)
	esac

	AC_MSG_RESULT(${CONFIG_DEBUG})
else
	AC_MSG_RESULT(no)
fi



dnl ###  system specific options  ###

##########################################################################
# LINUX on Digital/Compaq Alpha CPUs
##########################################################################
case $target in
alpha*-*-linux*)

################################################################
#### Check if 'ccc' is in our path
################################################################
if test "`which ccc 2>/dev/null | grep -c ccc`" != "0" ; then
	# Compaq's C Compiler
	CC=ccc

################################################################
#### set 'OPTIMIZATION = -arch host -tune host' 
####              to generate/tune instructions for this machine
####     'OPTIMIZATION += -migrate -fast -inline speed -unroll 0' 
####              tweak to run as fast as possible :)
####     'OPTIMIZATION += -w0' 
####              set warning and linking flags
################################################################
	OPTIMIZATION="-arch host -tune host"
	OPTIMIZATION="-migrate -fast -inline speed -unroll 0 $OPTIMIZATION"
	OPTIMIZATION="-w0 $OPTIMIZATION"


################################################################
#### to debug, uncomment
################################################################
	# For Debugging
	#OPTIMIZATION="-g3 $OPTIMIZATION"

################################################################
#### define __DECALPHA__ (i was getting re-declaration warnings
####   in machine.h
################################################################
	# Define DEC Alpha
	AC_DEFINE(__DECALPHA__, 1, we're on DEC Alpha)
fi  #  gcc or ccc?
;; # alpha


##########################################################################
# SunOS
##########################################################################
sparc-*-sunos4*)
	if test CC = "cc"; then
		OPTIMIZATION="-O -xCC"
		MAKEDEP="-xM"
		# for gcc, use instead:
		#   CC="gcc"
		#   OPTIMIZATION="-O"
		#   MAKEDEP="-M"
AC_MSG_WARN([Please contact lame@lists.sourceforge.net with the output of the configure run and the file config.cache. Thank you for your cooperation.])
	fi
;; #SunOS

##########################################################################
# SGI
##########################################################################
*-sgi-irix*)
	if test CC = "cc"; then
		OPTIMIZATION="-O3 -woff all"
	fi
;; # SGI

##########################################################################
# Compaq Alpha running Dec Unix (OSF)
##########################################################################
alpha*-dec-osf*)
	if test CC = "cc"; then
		OPTIMIZATION="-fast -O3 -std -g3 -non_shared"
	fi
;; #OSF

##########################################################################
# BeOS
##########################################################################
*-*-beos*) # todo:is this the right string ?
	if test CC = "\$(BE_C_COMPILER)"; then
		case $target in
		bepc*-*-*)
		 # todo: is this right architecture ? was: if ($(ARCH),BePC)
	   		OPTIMIZATION="-O9 -fomit-frame-pointer -march=pentium \
				-mcpu=pentium -ffast-math -funroll-loops \
				-fprofile-arcs -fbranch-probabilities"
		;;
   		*) OPTIMIZATION="-opt all"
		   MAKEDEP="-make"
AC_MSG_WARN([Please contact lame@lists.sourceforge.net with the output of the configure run and the file config.cache. Thank you for your cooperation.])
		;;
		esac
	fi
;; #BeOS
esac

# todo: include the following tests in the case-list
UNAME=`uname`
ARCH=`uname -m`

###########################################################################
# MOSXS (Rhapsody PPC)
###########################################################################
if test "$UNAME" = "Rhapsody"; then
#   CC="cc"   # should be handled already by autoconf
   MAKEDEP="-make"
fi

##########################################################################
# OS/2
##########################################################################
# Properly installed EMX runtime & development package is a prerequisite.
# tools I used: make 3.76.1, uname 1.12, sed 2.05, PD-ksh 5.2.13
#
##########################################################################
if test "$UNAME" = "OS/2"; then
   SHELL=sh
   #CC=gcc # should already be handled by configure

   # file extension should already be handled by automake (I don't know,
   # please  give feedback!
   #FILE_EXTENSION=".exe"

# Uncomment & inspect the GTK lines to use MP3x GTK frame analyzer.
# Properly installed XFree86/devlibs & GTK+ is a prerequisite.
# The following works for me using Xfree86/OS2 3.3.5 and GTK+ 1.2.3:
#   AC_DEFINE(HAVE_GTK, 1, have GTK)
#   AC_DEFINE(__ST_MT_ERRNO__, 1)
#   INCLUDES="-IC:/XFree86/include/gtk12 -IC:/XFree86/include/glib12 \
#             -IC:/XFree86/include $INCLUDES"
#   FRONTEND_LDFLAGS="-LC:/XFree86/lib -lgtk12 -lgdk12 -lgmodule -lglib12 \
#             -lXext -lX11 -lshm -lbsd -lsocket -lm $FRONTEND_LDFLAGS"
#   FRONTEND_CFLAGS="-Zmtd -Zsysv-signals -Zbin-files $FRONTEND_CFLAGS"
fi

###########################################################################
# AmigaOS
###########################################################################
# Type 'Make ARCH=PPC' for PowerUP and 'Make ARCH=WOS' for WarpOS
#
###########################################################################
if test "$UNAME" = "AmigaOS" ; then
	CC="gcc -noixemul"
	OPTIMIZATION="$OPTIMIZATION -m68020-60 -m68881"
	MAKEDEP="-MM"
	if test "$ARCH" = "WOS"; then
		CC="ppc-amigaos-gcc -warpup"
		OPTIMIZATION="$OPTIMIZATION -mmultiple -mcpu=603e"
		AR="ppc-amigaos-ar"
		RANLIB="ppc-amigaos-ranlib"
	fi
	if test "$ARCH",PPC; then
		CC="ppc-amigaos-gcc"
		OPTIMIZATION="$OPTIMIZATION -mmultiple -mcpu=603e"
		AR="ppc-amigaos-ar"
		RANLIB="ppc-amigaos-ranlib"
	fi
fi


CFLAGS="${OPTIMIZATION} ${CFLAGS}"
LDADD="${CONFIG_MATH_LIB} ${LDADD}"



AC_SUBST(INCLUDES)

AC_SUBST(FRONTEND_LDFLAGS)
AC_SUBST(FRONTEND_CFLAGS)
AC_SUBST(FRONTEND_LDADD)
AC_SUBST(LDADD)

AC_SUBST(LIB_MAJOR_VERSION)
AC_SUBST(LIB_MINOR_VERSION)

AC_SUBST(NASM)
AC_SUBST(NASM_FORMAT)

AC_SUBST(MAKEDEP)
AC_SUBST(RM_F)

AC_SUBST(LIBTOOL_DEPS)

AC_SUBST(WITH_FRONTEND)
AC_SUBST(WITH_MP3X)
AC_SUBST(WITH_MP3RTP)

AC_SUBST(CPUTYPE)

AC_SUBST(CONFIG_DEFS)

AC_OUTPUT(Makefile libmp3lame/Makefile libmp3lame/i386/Makefile frontend/Makefile mpglib/Makefile doc/Makefile doc/html/Makefile doc/man/Makefile include/Makefile Dll/Makefile misc/Makefile debian/Makefile dshow/Makefile lame.spec)
