dnl    This file is part of the KDE libraries/packages
dnl    Copyright (C) 2001 Stephan Kulow (coolo@kde.org)
 
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., 51 Franklin Street, Fifth Floor,
dnl    Boston, MA 02110-1301, USA.

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

dnl Process this file with autoconf to produce a configure script.

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

dnl This is so we can use kde-common
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_SYSTEM 
dnl Perform program name transformation
AC_ARG_PROGRAM

dnl Automake doc recommends to do this only here. (Janos)
AM_INIT_AUTOMAKE(k9copy, 1.2.4) dnl searches for some needed programs

KDE_SET_PREFIX

dnl generate the config header
AM_CONFIG_HEADER(config.h) dnl at the distribution this done

dnl Checks for programs.
AC_CHECK_COMPILERS
AC_ENABLE_SHARED(yes)
AC_ENABLE_STATIC(no)
KDE_PROG_LIBTOOL

dnl for NLS support. Call them in this order!
dnl WITH_NLS is for the po files
AM_KDE_WITH_NLS

KDE_USE_QT(3.0.0)
AC_PATH_KDE
#MIN_CONFIG(3.0.0)

dnl PACKAGE set before
AC_C_BIGENDIAN
AC_CHECK_KDEMAXPATHLEN

case "$target" in
    i?86-* | k?-*)
        AC_DEFINE([ARCH_X86],,[x86 architecture])
        AC_DEFINE([ARCH_386],,[386 architecture])
        ARCH_X86=yes
        ARCH_386=yes
        ARCH_X86_64=no
        ;;
    x86_64-*)
        AC_DEFINE([ARCH_X86_64],,[x86_64 architecture])
        ARCH_X86=no
        ARCH_386=no
        ARCH_X86_64=yes
        ;;
    *)
        ARCH_X86=no
        ARCH_386=no
        ARCH_X86_64=no
        ;;
esac

AC_MSG_CHECKING(for X86 architecture)
AC_MSG_RESULT($ARCH_X86)
AM_CONDITIONAL(ARCH_X86, [test "$ARCH_X86" = "yes"])

AC_MSG_CHECKING(for 386 architecture)
AC_MSG_RESULT($ARCH_386)
AM_CONDITIONAL(ARCH_386, [test "$ARCH_386" = "yes"])

AC_MSG_CHECKING(for X86_64 architecture)
AC_MSG_RESULT($ARCH_X86_64)
AM_CONDITIONAL(ARCH_X86_64, [test "$ARCH_X86_64" = "yes"])

have_gl=no
AC_CHECK_HEADER([GL/gl.h], \
[AC_DEFINE(HAVE_OPENGL, 1, [openGL support]) have_gl=yes], \
[AC_DEFINE(NO_OPENGL, 1, [No openGL support])])

AC_LANG_SAVE
AC_LANG_CPLUSPLUS
cxx_flags_safe="$CXXFLAGS"
CXXFLAGS="$CXXFLAGS -D__STDC_CONSTANT_MACROS -I$qt_includes"
AC_CHECK_HEADER([ffmpeg/avcodec.h], \
[AC_DEFINE(OLD_FFMPEG,1, [old ffmpeg])], \
  [AC_CHECK_HEADER([libavcodec/avcodec.h], \
   [AC_DEFINE(NEW_FFMPEG,1, [new ffmpeg])], \
   [AC_MSG_ERROR([libavcodec may be missing]) ])])
CXXFLAGS="$cxx_flags_safe"
AC_LANG_RESTORE

AC_LANG_SAVE
AC_LANG_CPLUSPLUS
cxx_flags_safe="$CXXFLAGS"
cflags_safe="$CFLAGS"
CXXFLAGS="$CXXFLAGS -D__STDC_CONSTANT_MACROS -I$qt_includes"
CFLAGS="$CFLAGS -D__STDC_CONSTANT_MACROS"
AC_MSG_CHECKING([if libavformat/avformat.h provides av_free_packet])
AC_TRY_LINK([#include <libavformat/avformat.h>
],[AVPacket *packet; av_free_packet(packet);],
AC_MSG_RESULT(yes),
[AC_MSG_RESULT(no)
AC_DEFINE(NEEDS_AV_FREE_PACKET,1,[no])])
CXXFLAGS="$cxx_flags_safe"
CFLAGS="$cflags_safe"
AC_LANG_RESTORE

  have_hal=no
  AC_MSG_CHECKING(for the HAL)

  AC_ARG_ENABLE([k3bdevices], 
                AC_HELP_STRING([--enable-k3bdevices], 
                [do not activate hal/dbus support (use k3bdevice instead)]),
                [enable_hal=no], 
                [enable_hal=yes])


  if test x"$enable_hal" = xyes; then
	hal_inc=NOTFOUND
	hal_lib=NOTFOUND
	hal=NOTFOUND
	
	search_incs="$kde_includes /usr/include /usr/include/hal /usr/local/include /usr/local/include/hal"
	AC_FIND_FILE(libhal.h libhal-storage.h, $search_incs, hal_incdir)
	
	if [test -r $hal_incdir/libhal.h] ; then
	HAL_INCS="-I$hal_incdir"
	hal_inc=FOUND
	fi
	
	if test -r $hal_incdir/libhal-storage.h ; then
	hal_storage_version=4
	grep LibHalVolume $hal_incdir/libhal-storage.h \
	> /dev/null 2>&1 && hal_storage_version=5
	if test $hal_storage_version = 4 ; then
	AC_DEFINE(HAL_0_4, , [HAL API version 0.4])
	fi
	fi
	
	search_libs="$kde_libraries /usr/lib64 /usr/lib /usr/local/lib /lib /lib64"
	AC_FIND_FILE(libhal.so, $search_libs, hal_libdir)
	
	if [test -r $hal_libdir/libhal.so] ; then
	HAL_LIBS="-L$hal_libdir -lhal"
	hal_lib=FOUND
	fi
	
	if [test -r $hal_libdir/libhal-storage.so] ; then
	HAL_LIBS_STORAGE="-L$hal_libdir -lhal-storage"
	hal_lib_storage=FOUND
	fi
	
	if [test $hal_inc = FOUND] && [test $hal_lib = FOUND] ; then
	AC_MSG_RESULT(headers $hal_incdir  libraries $hal_libdir)
		hal=FOUND
	else
	AC_MSG_RESULT(searched but not found)
	AC_MSG_ERROR(libhal may be missing) 
	fi
	
	AC_SUBST(HAL_INCS)
	AC_SUBST(HAL_LIBS)
	
	
	########### Check for DBus
	
	AC_MSG_CHECKING(for DBus)
	
	dbus_inc=NOTFOUND
	dbus_lib=NOTFOUND
	dbus=NOTFOUND
	
	search_incs="$kde_includes /usr/include /usr/include/dbus-1.0 /usr/local/include /usr/local/include/dbus-1.0"
	AC_FIND_FILE(dbus/dbus.h, $search_incs, dbus_incdir)
	
	search_incs_arch_deps="$kde_includes /usr/lib64/dbus-1.0/include /usr/lib/dbus-1.0/include /usr/local/lib/dbus-1.0/include"
	AC_FIND_FILE(dbus/dbus-arch-deps.h, $search_incs_arch_deps, dbus_incdir_arch_deps)
	
	if [test -r $dbus_incdir/dbus/dbus.h] && [test -r $dbus_incdir_arch_deps/dbus/dbus-arch-deps.h] ; then
	DBUS_INCS="-I$dbus_incdir -I$dbus_incdir_arch_deps"
	dbus_inc=FOUND
	fi
	
	search_libs="$kde_libraries /usr/lib64 /usr/lib /usr/local/lib /lib /lib64"
	AC_FIND_FILE(libdbus-1.so, $search_libs, dbus_libdir)
	
	if test -r $dbus_libdir/libdbus-1.so ; then
	DBUS_LIBS="-L$dbus_libdir -ldbus-1"
	dbus_lib=FOUND
	fi
	
	if [test $dbus_inc = FOUND] && [test $dbus_lib = FOUND] ; then
	AC_MSG_RESULT(headers $dbus_incdir $dbus_incdir_arch_deps  libraries $dbus_libdir)
	dbus=FOUND
	else
	AC_MSG_RESULT(searched but not found)
	AC_MSG_ERROR(dbus may be missing) 
	fi
	
	AC_SUBST(DBUS_INCS)
	AC_SUBST(DBUS_LIBS)
	
	
	########### Check if media HAL backend should be compiled
	
	HAL_DBUS_LIBS=""
	if [test "x$hal" = "xFOUND"] && [test "x$dbus" = "xFOUND"] &&  [ test $hal_storage_version = 5 ] ; then
	AC_DEFINE(HAVE_HAL, , [compile in HAL support])
	have_hal=yes
	HAL_DBUS_LIBS="$HAL_LIBS $HAL_LIBS_STORAGE $DBUS_LIBS"
	fi
	
	AC_SUBST(HAL_DBUS_LIBS)
else
	search_incs="$kde_includes /usr/include /usr/local/include"
	AC_FIND_FILE(k3bdevice.h, $search_incs, k3b_incdir)
	
	if [test -r $k3b_incdir/k3bdevice.h] ; then
		k3b_inc=FOUND
	fi
		
	search_libs="$kde_libraries /usr/lib64 /usr/lib /usr/local/lib /lib /lib64"
	AC_FIND_FILE(libk3bdevice.so, $search_libs, k3b_libdir)
	
	if [test -r $k3b_libdir/libk3bdevice.so] ; then
		K3B_LIBS="-lk3bdevice"
		k3b_lib=FOUND
	fi
		
	if [test $k3b_inc = FOUND] && [test $k3b_lib = FOUND] ; then
		AC_MSG_RESULT(headers $k3b_incdir  libraries $k3b_libdir)
		k3b=FOUND
	else
		AC_MSG_RESULT(libk3bdevice searched but not found)
		AC_MSG_ERROR(libk3bdevice may be missing) 
	fi
	
	AC_SUBST(K3B_LIBS)
	
fi

KDE_CREATE_SUBDIRSLIST
AC_CONFIG_FILES([ Makefile ])
AC_CONFIG_FILES([ doc/Makefile ])
AC_CONFIG_FILES([ doc/k9copy/Makefile ])
AC_CONFIG_FILES([ dvdread/Makefile ])
AC_CONFIG_FILES([ k9author/Makefile ])
AC_CONFIG_FILES([ k9decmpeg/Makefile ])
AC_CONFIG_FILES([ k9devices/Makefile ])
AC_CONFIG_FILES([ k9Mplayer/Makefile ])
AC_CONFIG_FILES([ k9vamps/Makefile ])
AC_CONFIG_FILES([ libdvdnav/Makefile ])
AC_CONFIG_FILES([ libk9copy/Makefile ])
AC_CONFIG_FILES([ po/Makefile ])
AC_CONFIG_FILES([ src/Makefile ])
AC_CONFIG_FILES([ src/icons/Makefile ])
AC_OUTPUT
if test "$all_tests" = "bad"; then
  if test ! "$cache_file" = "/dev/null"; then
    echo ""    
    echo "Please remove the file $cache_file after changing your setup"
    echo "so that configure will find the changes next time."
    echo ""
  fi
else
  echo ""
  echo "Good - your configure finished. Start make now"
  echo ""
fi
