dnl    This file is part of the KDE libraries/packages
dnl    Copyright (C) 2001 Stephan Kulow (coolo@kde.org)
dnl                       modified by Walter Tasin (tasin@kdevelop.org)
dnl                       for c++ console applications

dnl    This file is free software; you can redistribute it and/or
dnl    modify it under the terms of the GNU Library General Public
dnl    License as published by the Free Software Foundation; either
dnl    version 2 of the License, or (at your option) any later version.

dnl    This library is distributed in the hope that it will be useful,
dnl    but WITHOUT ANY WARRANTY; without even the implied warranty of
dnl    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
dnl    Library General Public License for more details.

dnl    You should have received a copy of the GNU Library General Public License
dnl    along with this library; see the file COPYING.LIB.  If not, write to
dnl    the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
dnl    Boston, MA 02111-1307, USA.

# Original Author was Kalle@kde.org
# I lifted it in some mater. (Stephan Kulow)
# I used much code from Janos Farkas


AC_INIT(acinclude.m4) dnl a source file from your sub dir

dnl This is so we can use kde-common
dnl needed -- mean
AC_CONFIG_AUX_DIR(admin)

dnl This ksh/zsh feature conflicts with `cd blah ; pwd`
unset CDPATH

dnl Checking host/target/build systems, for make, install etc.
AC_CANONICAL_HOST

dnl Perform program name transformation
AC_ARG_PROGRAM
dnl Automake doc recommends to do this only here. (Janos)
AM_INIT_AUTOMAKE(avidemux,2.0.38rc1)

dnl almost the same like KDE_SET_PEFIX but the path is /usr/local
dnl
unset CDPATH
dnl make /usr/local the default for the installation
AC_PREFIX_DEFAULT(/usr/local)

dnl Ranlib
AC_PROG_RANLIB
AC_PROG_CXX
AC_PROG_LIBTOOL
dnl without this order in this file, automake will be confused!
dnl
AM_CONFIG_HEADER(config.h)


dnl create only shared libtool-libraries
AC_ENABLE_SHARED(no)

dnl set the following to yes, if you want to create static
dnl libtool-libraries, too.
AC_ENABLE_STATIC(no)

dnl create a working libtool-script
dnl KDE_PROG_LIBTOOL


dnl KDE_CHECK_EXTRA_LIBS
all_libraries="$all_libraries $USER_LDFLAGS"
all_includes="$all_includes $USER_INCLUDES"
AC_SUBST(all_includes)
AC_SUBST(all_libraries)
dnl avoid po mess
AC_SUBST(AUTODIRS)


dnl ___ added to ease install in uncommon place __

CPPFLAGS="  $USER_INCLUDES  $CPPFLAGS"
dnl __________gettext_________________
AM_GNU_GETTEXT( [external])
GETTEXT_PACKAGE=avidemux
AC_DEFINE_UNQUOTED([GETTEXT_PACKAGE], "$GETTEXT_PACKAGE",
                   [gettext package name])

LOCALEDIR=${datadir}/locale
AC_SUBST(LOCALEDIR)
AC_DEFINE_UNQUOTED([LOCALEDIR], "$LOCALEDIR",
                   [gettext locale dir])

dnl __________GTK2 Stuff____________

 AC_PATH_PROG(PKG_CONFIG, pkg-config, no)
 if test "$PKG_CONFIG" = "no" ; then
 	echo "************ pkg-config IS MANDATORY ***************"
 	AC_MSG_ERROR([*** pkg-config not found ! ***])
 fi

dnl    AC_PATH_PROG(PKG_CONFIG,pkg-config, AC_MSG_ERROR([*** pkg-config not found ! ***]))
   GTK_VERSION=`$PKG_CONFIG  gtk+-2.0 --modversion`

 if test "x$GTK_VERSION" = "x" ; then
 	echo "************ Cannot identify gtk2 version ***************"
 	AC_MSG_ERROR([*** pkg-config installed incorrectly or gtk2-dev absent ! ***])
 fi


   GTK_LIBS=`$PKG_CONFIG  gtk+-2.0 --libs`
   GLIB_LIBS=`$PKG_CONFIG  glib-2.0 --libs`
   GTHREAD_LIBS=`$PKG_CONFIG  gthread-2.0  --libs`

   GTK_LIBS="$GTK_LIBS $GLIB_LIBS $GTHREAD_LIBS"
   GTK_CFLAGS=`$PKG_CONFIG  gtk+-2.0 --cflags` 

   AC_SUBST(GTK_CFLAGS)
   AC_SUBST(GTK_LIBS)
   AC_SUBST(GTK_VERSION)

   
   AC_SUBST(AS)
   AC_SUBST(ASFLAGS)

dnl ______________________
dnl AC_DEFINE(USE_DIV5,0,[Divx 5])
dnl AC_DEFINE(USE_AC3,0,[A52dec])
AC_DEFINE(USE_FFMPEG,1,[FFMPEG])
dnl AC_DEFINE_UNQUOTED(ADM_LOCALEDIR, "$ADM_LOCALEDIR", [where did it go])

dnl yes we are a free country :)
dnl we force mjpeg as it is now bundled
AC_DEFINE(USE_MJPEG,1,[MJPEG])
dnl AC_DEFINE(USE_MMX,0,[MMX])
dnl AC_DEFINE(USE_MP3,0,[libmad])
dnl AC_DEFINE(USE_MPEG,0,[libmpeg3])
dnl AC_DEFINE(OSS_SUPPORT,0,[OSS])
dnl AC_DEFINE(USE_XVID,0,[XVID_AS_DIVX])
dnl AC_DEFINE(USE_SDL,0,[XVID_AS_DIVX])
dnl AC_DEFINE(USE_XX_XVID,0,[XVID_AS_XVID])
dnl AC_DEFINE(USE_DIVX,0,[DIVX is present])
dnl ___________________________________

dnl ____________________________________
have_mad=yes
have_divxdecore=yes
have_divxencore=yes
have_oss=no
have_alsa=yes
have_xv=yes
have_lame=yes
have_xvid=yes
have_mjpeg=yes
have_lmpeg3=yes
have_lmpeg2=yes
have_divx=yes
have_little_endian=yes
have_vorbis=yes
have_ac3=yes
have_xx_xvid=yes
have_xx_xvid_cvs=yes
have_xvid4=yes
have_ff=yes
have_arts=yes
have_freetype=yes
have_xml2=yes
have_bsd=no
have_nasm=no
have_altivec=no
have_malloc=no
have_darwin=no
have_amd64=no
have_sdl=no;
have_faad=yes
have_faac=yes
have_ppc=no
have_x264=yes

dnl _________________ malloc.h ___________________

AC_CHECK_HEADERS(malloc.h,have_malloc_h=yes)
AC_CHECK_HEADERS(malloc/malloc.h,have_malloc_h=yes)
if test "x$have_malloc_h" = "xyes"; then
	CPPFLAGS="$CPPFLAGS -I/usr/include/malloc"
	AC_DEFINE(HAVE_MALLOC_H,1,[have malloc.h])
	
fi

dnl ______________ libxml2 _____________
AC_PATH_PROG(XML_CONFIG, xml2-config, no)
 if test "XML_CONFIG" = "no" ; then
	   	XML_LIBS=""
    		XML_CFLAGS=""
      		have_xml2=no
	else

 		XML_CFLAGS=`$XML_CONFIG  --cflags`
 		XML_LIBS=`$XML_CONFIG  --libs`
    old_flags=$CPPFLAGS
    CPPFLAGS="$CPPFLAGS $XML_CFLAGS"
    AC_CHECK_HEADERS(libxml/parser.h,,have_xml2=no)
    if test "x$have_xml2" = "xno"; then
    	AC_MSG_WARN(no parser.h valid header found for xml2)
    fi
 fi
if test "x$have_xml2" = "xyes"; then
AC_DEFINE(USE_LIBXML2,1,[LibXML2 is available])
fi


dnl __________________divx______________
dnl __________________x264 ______________
AC_MSG_CHECKING(for x264 codec )
AC_CHECK_HEADER(x264.h,,have_x264=no)
if test "x$have_x264" = "xyes"; then
   AC_CHECK_LIB(x264,x264_encoder_open,,have_x264=no,-lm)
fi
if test "x$have_x264" = "xyes"; then
	AC_DEFINE(USE_X264,1,[use x264 encoder])
fi


dnl __________________xvid 0.9 ______________
AC_MSG_CHECKING(for xvid codec 0.9)
AC_CHECK_HEADER(xvid.h,,have_xx_xvid=no)

dnl -- check API version 2.1 and not 2.0--

cat >> conftest.$ac_ext <<EOF
#include "xvid.h"
int main()
{
	#if  API_VERSION != ((2<<16)+1)
	#error Xvid Api Not 2.1
	#endif
return 1;
}
EOF

 ac_compile='${CXX} -c $CXXFLAGS $all_includes $CPPFLAGS conftest.$ac_ext > /dev/null'
 if AC_TRY_EVAL(ac_compile); then
   have_xx_xvid=yes
   AC_CHECK_LIB(xvidcore,xvid_encore,,have_xx_xvid=no,-lm)
 else
   have_xx_xvid=no
fi
dnl config.h 
 if test "x$have_xx_xvid" = "xyes"; then
 	AC_DEFINE(USE_XX_XVID,1,[use xvid api])
 fi

dnl __________________xvid 1.0 ______________
AC_MSG_CHECKING(for xvid codec 1.0)
AC_CHECK_HEADER(xvid.h,,have_xvid4=no)

dnl -- check API version 4.0
AC_TRY_COMPILE([
  	#include "xvid.h"
	#if ( XVID_API == ((4<<16)+0)) || ( XVID_API == ((4<<16)+1))
	#error Xvid Api is 4.0 :)
	#endif

],
int z=0
,[
  have_xvid4=no
])

AC_CHECK_LIB(xvidcore,xvid_encore,,have_xvid4=no,-lm)
 
if test "x$have_xvid4" = "xyes"; then
 	
	AC_CHECK_LIB(xvidcore,xvid_encore,,have_xvid4=no,-lm)
	if test "x$have_xvid4" = "xyes"; then
		AC_DEFINE(USE_XVID_4,1,[use xvid api 1.0 beta])
	fi
 fi

dnl __________________FFMPEG______________

dnl __________________/FFMPEG______________
dnl __________________OS dep stuff_____________

dnl __________________Lrintf_____________

have_lrintf=no
AC_MSG_CHECKING(for lrintf in math.h)
AC_TRY_COMPILE([
  #include <math.h>
],[
  int arg = 0;
	arg=lrintf(0.5);
],[
  have_lrintf=yes
])
if test x$have_lrintf = xyes ; then
  AC_DEFINE(HAVE_LRINTF,1,[roundup function])
fi
AC_MSG_RESULT($have_lrintf)
dnl __________________fast int_____________

have_fastint=no
AC_MSG_CHECKING(for fastint)
AC_TRY_COMPILE([
  #include <stdio.h>
  #include <stdint.h>
],[
  int arg = 0;
  int_fast16_t fst=0;
],[
  have_fastint=yes
])
if test x$have_fastint = xno ; then
  AC_DEFINE(EMULATE_FAST_INT,1,[roundup function])
fi
AC_MSG_RESULT($have_lrintf)

dnl ____________________iconv need const ?___________________
have_consticonv=yes
AC_MSG_CHECKING(iconv needs const)
AC_TRY_COMPILE([
  #include <stdio.h>
  #include <stdlib.h>
  #include <iconv.h>
],[
char *in,*out;
size_t sin,sout,sz;
iconv_t _conv;		
	sin=1;
	sout=4;
 	sz=iconv(_conv,&in,&sin,&out,&sout);  


],[
  have_consticonv=no
])
if test x$have_consticonv = xyes ; then
  AC_DEFINE(ICONV_NEED_CONST,1,[Stricter prototyping])
fi
AC_MSG_RESULT($have_consticonv)


dnl __________________/OS dep stuff______________


dnl __________________oss______________
AC_MSG_CHECKING(for OSS audio support)
AC_TRY_COMPILE([
  #ifdef __NetBSD__
  #include <sys/ioccom.h>
  #include <soundcard.h>
  #else
  #include <sys/soundcard.h>
  #endif
],[
  int arg = SNDCTL_DSP_SETFRAGMENT;
],[
  have_oss=yes
])
if test x$have_oss = xyes ; then
  AC_DEFINE(OSS_SUPPORT,1,[OSS detected])
fi
AC_MSG_RESULT($have_oss)
dnl __________________/oss______________
dnl __________________ALSA______________
AC_MSG_CHECKING(for ALSA audio support)
AC_CHECK_HEADERS(alsa/asoundlib.h,,have_alsa=no)
dnl check version 0.9.x
if test "x$have_alsa" = "xyes"; then
have_alsa=no
AC_TRY_COMPILE([
#include <alsa/asoundlib.h>
],
[
#if SND_LIB_MAJOR!=0 || SND_LIB_MINOR!=9
#error Not alsa 0.9!
#endif
int arg = 0;
],[
have_alsa=yes
have_alsa_1=no
])
dnl __ if it fails, try alsa 1.0 ___
if test "x$have_alsa" = "xno"; then
AC_TRY_COMPILE([
#include <alsa/asoundlib.h>
],
[
#if SND_LIB_MAJOR!=1 || SND_LIB_MINOR!=0
#error Not alsa 1.0!
#endif
int arg = 0;
],[
have_alsa=yes
have_alsa_1=yes
])
fi
AC_CHECK_LIB(asound,snd_pcm_hw_params_set_channels,,have_alsa=no,-lm)
fi
if test "x$have_alsa" = "xyes"; then				
	AC_DEFINE(ALSA_SUPPORT,1,"[Use alsa as possible audio device]")
fi
if test "x$have_alsa_1" = "xyes"; then				
	AC_DEFINE(ALSA_1_0_SUPPORT,1,"[Alsa is 1.0]")
fi

dnl __________________/ALSA______________



dnl __________________Arts Daemon______________
AC_MSG_CHECKING(for Arts audio support)
AC_PATH_PROG(ART_CONFIG, artsc-config, no)
 if test "$ART_CONFIG" = "no" ; then
	   	ARTS_LIBS=""
    	ARTS_CFLAGS=""
      have_arts=no
	else

 		ARTS_CFLAGS=`$ART_CONFIG  --cflags`
 		ARTS_LIBS=`$ART_CONFIG  --libs`
    old_flags=$CPPFLAGS
    CPPFLAGS="$CPPFLAGS $ARTS_CFLAGS"
    AC_CHECK_HEADERS(artsc.h,,have_arts=no)
    if test "x$have_arts" = "xno"; then
    AC_MSG_WARN(no artsc.h valid header found)
    fi
    if test "x$have_arts" = "xyes"; then
				AC_MSG_WARN(artsc.h is there assuming the library is there also)    
	  		AC_DEFINE(USE_ARTS,1,"[Arts]") 	      	     
	  fi
	  CPPFLAGS=$old_flags
 fi
if test "x$have_arts" = "xno"; then
	   	ARTS_LIBS=""
    	ARTS_CFLAGS=""    
fi     

dnl __________________mad______________
AC_CHECK_HEADERS(mad.h,,have_mad=no)
if test "x$have_mad" = "xyes"; then
		AC_CHECK_LIB(mad,mad_decoder_run,,have_mad=no, -lm)
fi

AC_ARG_ENABLE(mad,[  --enable-mad           Force mad],have_mad=yes)
dnl AC_ARG_ENABLE(mad,[  --disable-mad          Force no mad],have_mad=0)

if test "x$have_mad" = "xyes"; then
	AC_DEFINE(USE_MP3,1,[libmad])
fi
 AC_MSG_CHECKING(mad library) 
 AC_MSG_RESULT($have_mad)
dnl __________________/mad______________
dnl ____________ faad ?________________
 AC_CHECK_HEADERS(faad.h,,have_faad=no)
 dnl AC_ARG_ENABLE(faad,[  --enable-faad           Force faad],have_faad=1)
 AC_ARG_ENABLE(faad,[  --disable-faad           Force no faad],have_faad=no)
   
    if test "x$have_faad" = "xyes"; then
		AC_CHECK_LIB( faad,faacDecInit,,have_faad=no, -lm )
		if test "x$have_faad" = "xyes"; then
	  		AC_DEFINE(USE_FAAD,1,"[Use faad audio decoder]")
		fi  
    fi     
 AC_MSG_CHECKING(faad2 library) 
 AC_MSG_RESULT($have_faad)
  
dnl _______________/faad_______________
dnl ____________ faac ?________________
 AC_CHECK_HEADERS(faac.h,,have_faac=no)
 
 AC_ARG_ENABLE(faac,[  --disable-faac           Force no faac],have_faac=no)
   
    if test "x$have_faac" = "xyes"; then
		AC_CHECK_LIB( faac,faacEncClose,,have_faac=no, -lm )
		if test "x$have_faac" = "xyes"; then
	  		AC_DEFINE(USE_FAAC,1,"[Use faac audio enccoder]")
		fi  
    fi     
 AC_MSG_CHECKING(faac library) 
 AC_MSG_RESULT($have_faac)
  
dnl _______________/faac_______________
dnl _________________ /freetype 2 _________________
dnl __________________ac3______________
AC_CHECK_HEADERS(a52dec/a52.h,,have_ac3=no)
if test "x$have_ac3" = "xyes"; then
		AC_CHECK_LIB(a52,a52_init,,have_ac3=no,-lm)
fi
if test "x$have_ac3" = "xyes"; then
AC_DEFINE(USE_AC3,1,[liba52dec])

fi
dnl __________________/ac3______________
dnl __________________VORBIS______________
AC_CHECK_LIB(vorbis,vorbis_info_init,,have_vorbis=no, -lm)
if test "x$have_vorbis" = "xyes"; then
	AC_CHECK_LIB(vorbisenc,vorbis_encode_init,,have_vorbis=no, -lm)
	if test "x$have_vorbis" = "xyes"; then
		AC_DEFINE(USE_VORBIS,1,[Vorbis audio codec])
	fi
fi
dnl __________________/VORBIS______________

dnl __________________LAME______________
AC_CHECK_HEADERS(lame/lame.h,,have_lame=no)
if test "x$have_lame" = "xyes"; then
AC_CHECK_LIB(mp3lame,lame_init,,have_lame=no, -lm)
fi
dnl __________________/mad______________
dnl __________________MJPEG______________
dnl AC_CHECK_HEADERS(mjpegtools/jpegutils.h,,have_mjpeg=no)
dnl if test "x$have_mjpeg" = "xyes"; then
dnl AC_CHECK_LIB( mjpegutils,mpeg_framerate_code_definition,,have_mjpeg=no, -lm )
dnl fi
dnl if test "x$have_mjpeg" = "xyes"; then
dnl AC_CHECK_LIB( lavjpeg,decode_jpeg_raw,,have_mjpeg=no, -lm -lmjpegutils)
dnl fi
dnl if test "x$have_mjpeg" = "xyes"; then
dnl AC_DEFINE(USE_MJPEG,1,[Mjpeg lib])
dnl fi
dnl __________________/MJEG______________




dnl __________________XV______________


AC_CHECK_HEADERS(sys/shm.h,,have_xv=no)

if test "x$have_xv" = "xyes"; then
 AC_CHECK_HEADERS(X11/extensions/XShm.h,,have_xv=no,
[
#include<stdio.h>
#include<X11/Intrinsic.h>
])
fi
if test "x$have_xv" = "xyes"; then
 AC_CHECK_HEADERS(X11/extensions/Xvlib.h,,have_xv=no,
[
#include<stdio.h>
#include<X11/Intrinsic.h>
])
fi


if test "x$have_xv" = "xyes"; then
AC_CHECK_LIB(Xv,XvShmPutImage,,have_xv=no,-L/usr/X11R6/lib -lXext -lX11 -lm)
fi
if test "x$have_xv" = "xyes"; then
	AC_DEFINE(USE_XV,1,[Try to use Xv extension])
fi
dnl __________________SDL______________

AC_MSG_CHECKING(libSDL support)
AC_PATH_PROG(SDL_CONFIG, sdl-config, "no")
 if test "$SDL_CONFIG" = "no" ; then
	   	SDL_LIBS=""
    		SDL_CFLAGS=""
      		have_sdl=no
	else

 		SDL_CFLAGS=`$SDL_CONFIG  --cflags`
 		SDL_LIBS=`$SDL_CONFIG  --libs`    		
    		CPPFLAGS="$CPPFLAGS $SDL_CFLAGS"
    		have_sdl=yes
 fi
if test "x$have_sdl" = "xyes" ;  then
	AC_DEFINE(USE_SDL,1,[Use SDL ])
fi
dnl __________________/SDL______________





dnl ____________ free type 2________________
 AC_MSG_CHECKING(Freetype2 support)
 AC_PATH_PROG(FREETYPE_CONFIG, freetype-config, no)
 if test "$FREETYPE_CONFIG" = "no" ; then
    have_freetype=no
    FREETYPE_LIBS=""
    FREETYPE_CFLAGS=""
 else   
 		FREETYPE_CFLAGS=`$FREETYPE_CONFIG  --cflags`
 		FREETYPE_LIBS=`$FREETYPE_CONFIG  --libs`
   	old_flags=$CPPFLAGS
    CPPFLAGS="$CPPFLAGS $FREETYPE_CFLAGS -I/usr/X11R6/include"
    AC_CHECK_HEADERS(ft2build.h,,have_freetype=no)
    if test "x$have_freetype" = "xno"; then
    AC_MSG_WARN(no ft2build.h valid header found)
    fi
    if test "x$have_freetype" = "xyes"; then
				AC_MSG_WARN(ft2build.h is there assuming the library is there also)
	  		AC_DEFINE(USE_FREETYPE,1,"[Use FreeType2 font rendering]")
	  fi
	  CPPFLAGS=$old_flags
 fi
   
if test "x$have_freetype" = "xno"; then
	   	FREETYPE_LIBS=""
    	FREETYPE_CFLAGS=""
fi


dnl _________________ /freetype 2 _________________

AC_MSG_CHECKING(/usr/local/ is full of divx)
AC_MSG_RESULT("yes")

dnl __________________________________________

use_debug=0

dnl debug

AC_ARG_WITH(debug, [  debug flag],
  [
	   use_debug=1

  ]
)

CXXFLAGS="   -I.. -IADM_library -I../ADM_library  -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64"
CFLAGS=" $CFLAGS"

dnl ___________________profiling _______________________

use_profile=0

dnl debug

AC_ARG_WITH(profile, [  profile flag],
  [
	   use_profile=1

  ]
)
if test "x$use_profile" = "x1"; then
CXXFLAGS="$CXXFLAGS -pg "
CFLAGS="$CFLAGS -pg "
LDFLAGS="$LDFLAGS -pg "
fi
dnl ____________________ Cygwin / mingwin ? ___________
use_cygwin=no
AC_MSG_CHECKING(win32 host)


AC_TRY_COMPILE([
	#if !defined(__CYGWIN__) &&!defined(__MINGW32__)
		#error
	#endif

],
int z=0
,[
  use_cygwin=yes
])

AC_MSG_RESULT($use_cygwin)




dnl ____________________ CPU____________________________
echo "Checking cpu/system type"
adm_cpu=`uname -m`;
dnl reset config.cpu, avoid weird bugs
echo "CPU type : $adm_cpu"
use_mmx=0
case $adm_cpu in
	i386|i486|i586|i686)
		use_mmx=1
		have_little_endian=yes;
		AC_DEFINE(CONFIG_X86,1,[FFMPEG])
		AC_DEFINE(ARCH_X86,1,[post proc])
		LMPG_OPT=-DARCH_X86
		have_x86=yes
		AC_ARG_ENABLE(mmx,[  --disable-mmx           don't use MMX acceleration],use_mmx=0)
		


		if test "x$use_mmx" = "x1"; then
		AC_DEFINE(USE_MMX,1,"Use MMX acceleration")
		AC_DEFINE(HAVE_ASM_MMX,1,"Use MMX acceleration")
		AC_DEFINE(HAVE_MMX,1,"Use MMX acceleration")
		AC_DEFINE(HAVE_X86CPU,1,"Use X86 CPU for mpeg2enc")
		AC_DEFINE(RUNTIME_CPUDETECT,1,"Let ffmpeg decide which is faster")
		dnl FIXME
		dnl

		echo "TARGET_MMX=yes" >> adm_lavcodec/config.cpu

		AC_PATH_PROG(NASM_CONFIG, nasm, no)
 		if test "$NASM_CONFIG" = "no" ; then
			AS=""
			CCAS=""
			echo "Nasm not found ($nasm/$NASM_CONFIG)"
			have_nasm="no"
			echo "nasm $have_nasm"
		else
			AS="$NASM_CONFIG"
			CCAS=$AS
			if test "x$use_cygwin" = "xno"; then
				ASFLAGS="-f elf"
			else
				ASFLAGS="-f win32 -DPREFIX"
			fi
			CCASFLAGS=$ASFLAGS			
			echo "TARGET_MMX_NASM=yes" >> adm_lavcodec/config.cpu
			AC_DEFINE(HAVE_ASM_NASM,1,"Use MMX acceleration")
			echo "nasm found : $NASM_CONFIG"
			have_nasm="yes"
		fi

		echo "MMX is ON"
		else
		touch adm_lavcodec/config.cpu
		fi;;
	x86_64)
		have_little_endian=yes;
		echo "TARGET_X86_64=yes" >> adm_lavcodec/config.cpu
		AC_DEFINE(HAVE_X86_64,1,"X86_64 amd64 assembly")
		AC_DEFINE(ARCH_X86_64,1,"X86_64 amd64 assembly")
		have_amd64=yes
		echo "ADM64";;
	sparc|sparc64)
		have_little_endian=no;
		LMPG_OPT="";
		touch adm_lavcodec/config.cpu				
		AC_DEFINE(ADM_BIG_ENDIAN,1,[Big endian cpu  sparc or powerpc])		
		AC_DEFINE(WORDS_BIGENDIAN,1,[Big endian cpu  sparc or powerpc]);;
		
	sun4u)
		LDFLAGS="$LDFLAGS -lposix4";
		have_little_endian=no;
		LMPG_OPT="";
		touch adm_lavcodec/config.cpu
		AC_DEFINE(ADM_SPARC,1,[Sparc workstations])
		AC_DEFINE(ADM_BIG_ENDIAN,1,[Big endian cpu  sparc or powerpc])		
		AC_DEFINE(WORDS_BIGENDIAN,1,[Big endian cpu  sparc or powerpc]);;
	ppc)
		have_little_endian=no;
		LMPG_OPT="";
		have_ppc=yes
		touch adm_lavcodec/config.cpu
		echo "TARGET_PPC=yes" > adm_lavcodec/config.cpu
		dnl we assume to be on linux-ish system here
		AC_DEFINE(restrict,__restrict__,[roundup function])
		AC_DEFINE(ADM_BIG_ENDIAN,1,[Big endian cpu  sparc or powerpc])
		AC_DEFINE(ARCH_POWERPC,1,[Enable powerpc optim])		
		AC_ARG_ENABLE(altivec,[  --enable-altivec           enable  altivec acceleration(ppc)],have_altivec=yes)
		AC_DEFINE(WORDS_BIGENDIAN,1,[Big endian cpu  sparc or powerpc]);;

	*)
		adm_cpu=`uname -p`;
		case $adm_cpu in
			powerpc)
			echo "Power Macintosh (darwin ??)"
			have_darwin=yes
			have_little_endian=no
  			AC_DEFINE(ADM_BSD_FAMILY,1,[BSD os specific ifdef])
			LMPG_OPT="";
			LDFLAGS="$LDFLAGS  \
				-framework CoreServices \
				-framework CoreAudio  \
				-framework AudioUnit"  
			touch adm_lavcodec/config.cpu
			echo "TARGET_DARWIN=yes" >> adm_lavcodec/config.cpu
			echo "TARGET_PPC=yes" >> adm_lavcodec/config.cpu
			AC_DEFINE(ADM_BIG_ENDIAN,1,[Big endian cpu  sparc or powerpc])
			AC_DEFINE(CONFIG_DARWIN,0,[Say to ffmpeg we are using darwin macOsX])
			AC_DEFINE(WORDS_BIGENDIAN,1,[Big endian cpu  sparc or powerpc])
			AC_ARG_ENABLE(altivec,[  --enable-altivec           enable  altivec acceleration(ppc)],have_altivec=yes)
			AC_DEFINE(ARCH_POWERPC,1,[Enable powerpc optim])
			have_ppc=yes;;
			*)
			have_little_endian=no;
			LMPG_OPT="";
			touch adm_lavcodec/config.cpu
			AC_DEFINE(ADM_BIG_ENDIAN,1,[Big endian cpu  sparc or powerpc])
			AC_DEFINE(WORDS_BIGENDIAN,1,[Big endian cpu  sparc or powerpc]);;
		esac
esac
ALTIVEC_SWITCH=''
AC_MSG_CHECKING(for Altivec )
AC_MSG_RESULT($have_altivec)
if test "x$have_altivec" = "xyes"; then
		echo "Altivec enabled";
		echo "TARGET_ALTIVEC=yes" >> adm_lavcodec/config.cpu
		AC_DEFINE(HAVE_ALTIVEC,1,[Enable altivec by default])
		if test "x$have_darwin" = "xno"; then
			AC_DEFINE(HAVE_ALTIVEC_H,1,[Enable altivec by default])
			ALTIVEC_SWITCH='-mabi=altivec -maltivec'
			
		else
			dnl we are using macOsX, deal with how they do stuff
			ALTIVEC_SWITCH='-mabi=altivec -maltivec -faltivec -force_cpusubtype_ALL'
		fi
		CFLAGS="$CFLAGS $ALTIVEC_SWITCH"
		CXXFLAGS="$CXXFLAGS $ALTIVEC_SWITCH"
		AC_DEFINE(ARCH_PPC,1,[Altivec for libmpeg2])
		dnl AC_DEFINE(USE_ALTIVEC,1,[Altivec for mpeg2enc]) 

fi
echo "cpu done"
dnl ____________________ /CPU____________________________

if test "x$use_cygwin" = "xyes"; then
	AC_DEFINE(MEMALIGN_HACK,1,"sse on cywin")
	AC_DEFINE(CYG_MANGLING,1,"Name mangling")
	AC_DEFINE(rindex,ADM_rindex,"rindex does not exist on cygwin")
	AC_DEFINE(index,ADM_index,"rindex does not exist on cygwin")
	AC_DEFINE(fseeko,fseeko_adm,"")
	AC_DEFINE(ftello,ftello_adm,"")
	#AC_DEFINE(link(x,y),-1,"")	
	CXXFLAGS=" $CXXFLAGS -mno-cygwin -mms-bitfields"
	CFLAGS=" $CFLAGS -mno-cygwin -mms-bitfields"
	echo "CFLAGS= -mno-cygwin -mms-bitfields -I/usr/include/mingw -I/rot/include " >> adm_lavcodec/config.cpu
fi
dnl ______________ vectors ? for altivec mainly and a bit of 386 (fft) _______
dnl (except for amd64 ? bug in ubuntu ?)
if test "x$have_amd64" = "xno"; then
use_builtin=no
AC_MSG_CHECKING(Built in vectors)


AC_TRY_COMPILE([
	
#if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 2)
#else
#error no vector builtins
#endif
],
int z=0
,[
  use_builtin=yes
])

AC_MSG_RESULT(use_builtin)
if test "x$use_builtin" = "xyes"; then
	AC_DEFINE(HAVE_BUILTIN_VECTOR,1,[Enable altivec by default])
fi 
fi
dnl ________________NASM__________________
AC_SUBST(AS)
AC_SUBST(AS_FLAGS)
AM_PROG_AS
dnl __________ conditional ___________________

AM_CONDITIONAL(HAVE_NASM, test "x$have_nasm" = "xyes")
AM_CONDITIONAL(BUILD_MMX, test "x$use_mmx" = "x1")

AM_CONDITIONAL(BUILD_MMX_COMPATIBLE, test "x$use_mmx" = "x1" || test "x$have_amd64" = "xyes")

AM_CONDITIONAL(BUILD_DARWIN, test "x$have_darwin" = "xyes")
AM_CONDITIONAL(BUILD_PPC, test "x$have_ppc" = "xyes")
AM_CONDITIONAL(BUILD_ALTIVEC, test "x$have_altivec" = "xyes")
AM_CONDITIONAL(BUILD_A64, test "x$have_amd64" = "xyes")
dnl ____________________BSD famiy patch____________________________
AC_TRY_COMPILE([
  	#include <stdlib.h>

	#if !defined (__FreeBSD__) && !defined(__NetBSD__) && !defined(__OpenBSD__) && !defined(__APPLE__)
		#error
	#endif

],
int z=0
,[
  	AC_DEFINE(ADM_BSD_FAMILY,1,[BSD os specific ifdef])
	have_bsd=yes;
	echo "BSD type OS"
])


dnl ____________________ /BSD____________________________

dnl _________debug and optims________________
dnl __ builtin means gcc3, for gcc 2 we stick to -O2 ___
if test "x$use_debug" = "x1"; then
	AC_DEFINE(ADM_DEBUG,1,[be verbose])
	CXXFLAGS="$CXXFLAGS -O1 -g3"
	CFLAGS="$CFLAGS -O1 -g3"
	
else
	if test "x$use_builtin" = "x1"; then
		CXXFLAGS="$CXXFLAGS -O3"
		CFLAGS="$CFLAGS -O3"
	else
		CXXFLAGS="$CXXFLAGS -O2"
		CFLAGS="$CFLAGS -O2"
	fi
fi
CFLAGS="$CFLAGS -falign-loops=16"
CXXFLAGS="$CXXFLAGS -falign-loops=16"
dnl ___________________lavcodec _________________________

AC_DEFINE(CONFIG_RISKY,1,[FFMPEG])
AC_DEFINE(CONFIG_ENCODERS,1,[FFMPEG])
AC_DEFINE(CONFIG_DECODERS,1,[FFMPEG])
AC_DEFINE(CONFIG_MPEGAUDIO_HP,1,[FFMPEG])

dnl _________mpeg2dec_______________
AC_DEFINE(ACCEL_DETECT,1,[MPEG2DEC])

dnl ______________________________________________________
  AC_SUBST(LMPG_OPT)
  AC_SUBST(ALTIVEC_SWITCH)

  AC_SUBST(XML_CFLAGS)
  AC_SUBST(XML_LIBS)
  
  AC_SUBST(SDL_LIBS)

   AC_SUBST(ARTS_CFLAGS)
   AC_SUBST(ARTS_LIBS)

  AC_SUBST(FREETYPE_CFLAGS)
  AC_SUBST(FREETYPE_LIBS)

dnl **   mean   ***
echo " GTK+ version        : $GTK_VERSION"
echo " Divx5.0.5 ?         : $have_divx"
echo " *** DISABLED ***"
echo " Xvid 0.9 Codec      : $have_xx_xvid"
echo " Xvid 1.0 Codec      : $have_xvid4"
echo " x264 encoder c      : $have_x264"
echo " Mad decoder         : $have_mad"
echo " OSS                 : $have_oss"
echo " ALSA                : $have_alsa"
echo " SDL                 : $have_sdl"
echo " Xvideo              : $have_xv"
echo " Lame                : $have_lame"
echo " Ogg Vorbis          : $have_vorbis"
echo " Faad2(decoder)      : $have_faad"
echo " Faac (encoder)      : $have_faac"
echo " A52/AC3             : $have_ac3"
echo " FFMPEG              : $have_ff"
echo " ARTS                : $have_arts"
echo " FreeType            : $have_freetype"
echo " XML2                : $have_xml2"
echo " locale              : $ADM_LOCALEDIR"
echo " Little endian cpu   : $have_little_endian"
if test "x$use_mmx" = "x1"; then
echo " MMX                 : yes"
else
echo " MMX                 : no"
fi
echo " AMD64               : $have_amd64"
echo " Altivec             : $have_altivec"
echo " PPC                 : $have_ppc"
echo " MacOsX(Darwin)      : $have_darwin"
echo " nasm                : $have_nasm ( $AS )"
echo " Cygwin              : $use_cygwin"
echo " Gcc supports vectors: $use_builtin"
 if test "x$have_xml2" = "xno"; then
 	echo "************ LIBXML2 IS MANDATORY ***************"
 	echo "************ get it from http://www.xmlsoft.org*********"
	AC_MSG_ERROR([*** No xml2 found***])
fi
dnl _______________________________________________________
dnl autogen prefs..
dnl _______________________________________________________
cd avidemux/
if test ../admin/prefs_gen.pl -nt prefs.in; then
	touch prefs.in
fi
if test prefs.in -nt prefs.h -o prefs.in -nt prefs.cpp; then
	echo "Regeneration preferences definitions"
	perl ../admin/prefs_gen.pl
fi
cd ..

AC_CONFIG_FILES([ Makefile  ])
AC_CONFIG_FILES([ adm_lavcodec/Makefile ])
AC_CONFIG_FILES([ adm_lavcodec/i386/Makefile ])
AC_CONFIG_FILES([ adm_lavcodec/libpostproc/Makefile ])
AC_CONFIG_FILES([ adm_lavcodec/ppc/Makefile ])
AC_CONFIG_FILES([ avidemux/Makefile ])
AC_CONFIG_FILES([ avidemux/ADM_3gp/Makefile ])
AC_CONFIG_FILES([ avidemux/ADM_audio/Makefile ])
AC_CONFIG_FILES([ avidemux/ADM_audiocodec/Makefile ])
AC_CONFIG_FILES([ avidemux/ADM_audiodevice/Makefile ])
AC_CONFIG_FILES([ avidemux/ADM_audiofilter/Makefile ])
AC_CONFIG_FILES([ avidemux/ADM_codecs/Makefile ])
AC_CONFIG_FILES([ avidemux/ADM_colorspace/Makefile ])
AC_CONFIG_FILES([ avidemux/ADM_dialog/Makefile ])
AC_CONFIG_FILES([ avidemux/ADM_editor/Makefile ])
AC_CONFIG_FILES([ avidemux/ADM_encoder/Makefile ])
AC_CONFIG_FILES([ avidemux/ADM_filter/Makefile ])
AC_CONFIG_FILES([ avidemux/ADM_gui/Makefile ])
AC_CONFIG_FILES([ avidemux/ADM_gui2/Makefile ])
AC_CONFIG_FILES([ avidemux/ADM_h263/Makefile ])
AC_CONFIG_FILES([ avidemux/ADM_inpics/Makefile ])
AC_CONFIG_FILES([ avidemux/ADM_lavformat/Makefile ])
AC_CONFIG_FILES([ avidemux/ADM_library/Makefile ])
AC_CONFIG_FILES([ avidemux/ADM_lvemux/Makefile ])
AC_CONFIG_FILES([ avidemux/ADM_mpeg2dec/Makefile ])
AC_CONFIG_FILES([ avidemux/ADM_mpegindexer/Makefile ])
AC_CONFIG_FILES([ avidemux/ADM_mplex/Makefile ])
AC_CONFIG_FILES([ avidemux/ADM_nuv/Makefile ])
AC_CONFIG_FILES([ avidemux/ADM_ogm/Makefile ])
AC_CONFIG_FILES([ avidemux/ADM_openDML/Makefile ])
AC_CONFIG_FILES([ avidemux/ADM_requant/Makefile ])
AC_CONFIG_FILES([ avidemux/ADM_script/Makefile ])
AC_CONFIG_FILES([ avidemux/ADM_toolkit/Makefile ])
AC_CONFIG_FILES([ avidemux/ADM_video/Makefile ])
AC_CONFIG_FILES([ avidemux/ADM_vp32/Makefile ])
AC_CONFIG_FILES([ avidemux/ADM_vp32/include/Makefile ])
AC_CONFIG_FILES([ avidemux/ADM_xvidratectl/Makefile ])
AC_CONFIG_FILES([ avidemux/libMpeg2Dec/Makefile ])
AC_CONFIG_FILES([ avidemux/libtoolame/Makefile ])
AC_CONFIG_FILES([ avidemux/mpeg2enc/Makefile ])
AC_CONFIG_FILES([ avidemux/oplug_avi/Makefile ])
AC_CONFIG_FILES([ avidemux/oplug_mpeg/Makefile ])
AC_CONFIG_FILES([ avidemux/oplug_mpegFF/Makefile ])
AC_CONFIG_FILES([ avidemux/oplug_ogm/Makefile ])
AC_CONFIG_FILES([ avidemux/xpm/Makefile ])
AC_CONFIG_FILES([ m4/Makefile ])
AC_CONFIG_FILES([ po/Makefile ])
AC_OUTPUT
