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

dnl Disabling cache file - now commented and not used
dnl define([AC_CACHE_LOAD], )dnl
dnl define([AC_CACHE_SAVE], )dnl

dnl Default C source file
AC_INIT(../../gammu/gammu.c)

dnl Default prefix for package
AC_PREFIX_DEFAULT("/usr/local")

dnl Version
VERSION=`cat VERSION`
AC_DEFINE_UNQUOTED(VERSION, "$VERSION")
AC_SUBST(VERSION)

dnl Compiler flags
dnl -Wno-format-y2k is against "%c" format warning. The only problem is that
dnl this doesn't remove warning with gcc 2.95, but for 3.0 and 3.2 it works as
dnl expected.
if test x$CFLAGS = x ; then
    CFLAGS="-O2 -Wall -Wno-format-y2k"
else
    CFLAGS="$CFLAGS -Wno-format-y2k"
fi

dnl Checks for programs.
AC_PATH_PROG(RM, rm, no)
AC_PATH_PROG(MV, mv, no)
AC_PATH_PROG(INSTALL, install, no)
AC_PATH_PROG(FIND, find, no)
AC_PATH_PROG(RPMBUILD, rpmbuild)
AC_PATH_PROG(RPMBUILD, rpm, no)
AC_PATH_PROG(DOXYGEN, doxygen)


dnl Checks for library functions.
AC_PROG_GCC_TRADITIONAL
AC_FUNC_MEMCMP
AC_TYPE_SIGNAL
AC_FUNC_VPRINTF
AC_CHECK_FUNCS(scandir alphasort iswspace towlower)
dnl Now this is checking is not used
dnl AC_CHECK_FUNCS(mktime select socket strdup strerror strstr)
dnl AC_SUBST(HAVE_SCANDIR)
dnl AC_SUBST(HAVE_ALPHASORT)

dnl Checks for header files.
AC_HEADER_STDC
AC_CHECK_HEADERS(dirent.h)
AC_CHECK_HEADER(linux/irda.h,
	[AC_DEFINE(HAVE_IRDA)
	irda="yes"],
	[irda="no"],
	[#include <sys/socket.h>
#include <linux/types.h>
#include <sys/ioctl.h>])
dnl This checking is not used now
dnl AC_CHECK_HEADERS(mysql/mysql.h)
dnl AC_CHECK_HEADERS(fcntl.h sys/file.h sys/ioctl.h sys/time.h unistd.h)
dnl AC_SUBST(HAVE_DIRENT_H)


dnl Checks for typedefs, structures, and compiler characteristics.
AC_C_CONST
AC_TYPE_PID_T
AC_TYPE_SIZE_T
AC_HEADER_TIME
AC_STRUCT_TM

dnl Checks for libraries.
CHECK_PTHREAD(
	[AC_DEFINE(HAVE_PTHREAD)
        pthread="yes"],
	[echo "WARNING: pthread can not be used, searching disabled!"
        pthread="no"])
LDLIBS="$LDLIBS $PTHREAD_LIBS $PTHREAD_CFLAGS"
CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
AC_CACHE_CHECK([for the Bluez Bluetooth stack], ac_cv_have_sockaddr_rc,
     [AC_TRY_COMPILE([#include <sys/socket.h>
          #include <bluetooth/bluetooth.h>
          #include <bluetooth/rfcomm.h>],
          [struct sockaddr_rc rc;],
           ac_cv_have_sockaddr_rc=yes,
               ac_cv_have_sockaddr_rc=no)])

dnl doc directory
DOC_DIR="$datadir/doc/gammu"
AC_ARG_WITH(docdir,
	[  --with-docdir=DIR       Specifies the documentation directory],
	[ if test x$withval = xyes; then
		AC_MSG_WARN(Usage is: --with-docdir=DIR)
	  else
		DOC_DIR="$withval"
	  fi
	]
)
AC_SUBST(DOC_DIR)

dnl locales directory
LOCALE_DIR="$datadir/gammu"
AC_ARG_WITH(localedir,
	[  --with-localedir=DIR       Specifies the localisation directory],
	[ if test x$withval = xyes; then
		AC_MSG_WARN(Usage is: --with-localedir=DIR)
	  else
		LOCALE_DIR="$withval"
	  fi
	]
)
AC_SUBST(LOCALE_DIR)

dnl Path for making RPM
RPM_DIR="/usr/src/RPM"
AC_ARG_WITH(rpmdir,
	[  --with-rpmdir=DIR       Specifies the directory for making RPM],
	[ if test x$withval = xyes; then
		AC_MSG_WARN(Usage is: --with-rpmdir=DIR)
	  else
		RPM_DIR="$withval"
	  fi
	],[
		if test -r /usr/lib/rpm/macros  ; then
			get_rpm_var() {
			VALUE=$(grep -s "^%$1[[[:space:]]]" ~/.rpmmacros /usr/lib/rpm/macros | head -n 1 | awk '{print $2}')
			if test -z "$VALUE"  ; then
				exit 1
			fi

			while echo "$VALUE" | grep -q '%' ; do
			VAR=$(echo "$VALUE" | sed 's/^[[^%]]*%{\([[^}]]*\)}.*$/\1/')
			REPL=$(get_rpm_var "$VAR")
			VALUE=$(echo "$VALUE" | sed "s@%{$VAR}@$REPL@")
		done
		echo $VALUE
		}

		VALUE=$(get_rpm_var _topdir)
		if test ! -z "$VALUE"  ; then
			RPM_DIR="$VALUE"
		fi
		fi
	]
)
AC_SUBST(RPM_DIR)

dnl temp directory
TEMP_DIR="/tmp"
AC_ARG_WITH(tmpdir,
	[  --with-tmpdir=DIR       Specifies the temporary directory],
	[ if test x$withval = xyes; then
		AC_MSG_WARN(Usage is: --with-tmpdir=DIR)
	  else
		TEMP_DIR="$withval"
	  fi
	]
)
AC_SUBST(TEMP_DIR)

dnl Path for bluetooth library
gsm_bt_dir=""
AC_ARG_WITH(bluedir,
	[  --with-bluedir=DIR      Specifies the base libbluetooth],
	[ if test x$withval = xyes; then
		AC_MSG_WARN(Usage is: --with-bluedir=DIR)
	  else
		LDLIBS="$LDLIBS -L$withval/lib/ -lbluetooth"
		CFLAGS="$CFLAGS -I$withval/include/"
		gsm_bt_dir="$withval"
	  fi
	]
)

dnl Enabling or not protocols
AC_ARG_ENABLE(mbus,
	[  --disable-mbus          Disable Nokia MBUS2 protocol],
	[gsm_enable_mbus2="no"],
	[AC_DEFINE(GSM_ENABLE_MBUS2) gsm_enable_mbus2="yes"])
AC_ARG_ENABLE(fbus,
	[  --disable-fbus          Disable Nokia FBUS2 protocol],
	[gsm_enable_fbus2="no"],
	[AC_DEFINE(GSM_ENABLE_FBUS2) gsm_enable_fbus2="yes"])
AC_ARG_ENABLE(fbusdlr3,
	[  --disable-fbusdlr3      Disable Nokia FBUS2 protocol
	                  with DLR3(P) cable (Nokia 6210/63xx/71xx)],
	[gsm_enable_fbus2dlr3="no"],
	[AC_DEFINE(GSM_ENABLE_FBUS2DLR3) gsm_enable_fbus2dlr3="yes"])
AC_ARG_ENABLE(fbusdku5,
	[  --disable-fbusdku5      Disable Nokia FBUS2 protocol
	                  with DKU5 cable (Nokia with Pop-Port)],
	[gsm_enable_fbus2dku5="no"],
	[AC_DEFINE(GSM_ENABLE_FBUS2DKU5) gsm_enable_fbus2dku5="yes"])
AC_ARG_ENABLE(fbusblue,
	[  --disable-fbusblue      Disable Nokia FBUS2 protocol
	                  over Bluetooth legacy device (Nokia 6210)],
	[gsm_enable_fbus2blue="no"],
	[AC_DEFINE(GSM_ENABLE_FBUS2BLUE) gsm_enable_fbus2blue="yes"])
AC_ARG_ENABLE(fbusirda,
	[  --disable-fbusirda      Disable FBUS2 over direct infrared device
	                  (Nokia 5210/61xx/82xx)],
	[gsm_enable_fbus2irda="no"],
	[AC_DEFINE(GSM_ENABLE_FBUS2IRDA) gsm_enable_fbus2irda="yes"])
AC_ARG_ENABLE(phonetblue,
	[  --disable-phonetblue    Disable Nokia PHONET FBUS over Bluetooth
                          legacy device (all new Nokias)],
	[gsm_enable_phonetblue="no"],
	[AC_DEFINE(GSM_ENABLE_PHONETBLUE) gsm_enable_phonetblue="yes"])
AC_ARG_ENABLE(mrouterblue,
	[  --disable-mrouterblue   Disable Symbian with m-router (TCPIP based)
                          over Bluetooth legacy device],
	[gsm_enable_mrouterblue="no"],
	[AC_DEFINE(GSM_ENABLE_MROUTERBLUE) gsm_enable_mrouterblue="yes"])
AC_ARG_ENABLE(at,
	[  --disable-at            Disable AT protocol],
	[gsm_enable_at="no"],
	[AC_DEFINE(GSM_ENABLE_AT) gsm_enable_at="yes"])
AC_ARG_ENABLE(irdaphonet,
	[  --disable-irdaphonet    Disable NOKIA PHONET FBUS over irda sockets
	                  (all new Nokia)],
	[gsm_enable_irdaphonet="no"],
	[if test $irda = yes ; then
		AC_DEFINE(GSM_ENABLE_IRDAPHONET)
		gsm_enable_irdaphonet="yes"
	 else
		gsm_enable_irdaphonet="no"
	 fi])
AC_ARG_ENABLE(irdaat,
	[  --disable-irdaat        Disable AT commands over irda sockets],
	[gsm_enable_irdaat="no"],
	[if test $irda = yes ; then
		AC_DEFINE(GSM_ENABLE_IRDAAT)
		gsm_enable_irdaat="yes"
	 else
		gsm_enable_irdaat="no"
	 fi])
AC_ARG_ENABLE(irdaobex,
	[  --disable-irdaobex      Disable OBEX over irda sockets],
	[gsm_enable_irdaobex="no"],
	[if test $irda = yes ; then
		AC_DEFINE(GSM_ENABLE_IRDAOBEX)
		gsm_enable_irdaobex="yes"
	 else
		gsm_enable_irdaobex="no"
	 fi])
AC_ARG_ENABLE(bluefbus,
	[  --disable-bluefbus      Disable Nokia FBUS2 over Bluetooth stack
                          (Nokia 6210)],
	[gsm_enable_bluefbus2="no"],
	[if test $ac_cv_have_sockaddr_rc = yes; then
		AC_DEFINE(GSM_ENABLE_BLUEFBUS2)
		gsm_enable_bluefbus2="yes"
		if ( echo $LDLIBS | grep -v -q -e -lbluetooth ) ; then
			LDLIBS="$LDLIBS -lbluetooth"
		fi
	  else
		gsm_enable_bluefbus2="no"
	  fi])
AC_ARG_ENABLE(bluephonet,
	[  --disable-bluephonet    Disable Nokia PHONET FBUS over Bluetooth
                          stack (all new Nokias)],
	[gsm_enable_bluephonet="no"],
	[if test $ac_cv_have_sockaddr_rc = yes; then
		AC_DEFINE(GSM_ENABLE_BLUEPHONET)
		gsm_enable_bluephonet="yes"
		if ( echo $LDLIBS | grep -v -q -e -lbluetooth ) ; then
			LDLIBS="$LDLIBS -lbluetooth"
		fi
	  else
		gsm_enable_bluephonet="no"
	  fi])
AC_ARG_ENABLE(blueat,
	[  --disable-blueat        Disable AT commands over Bluetooth stack],
	[gsm_enable_blueat="no"],
	[if test $ac_cv_have_sockaddr_rc = yes; then
		AC_DEFINE(GSM_ENABLE_BLUEAT)
		gsm_enable_blueat="yes"
		if ( echo $LDLIBS | grep -v -q -e -lbluetooth ) ; then
			LDLIBS="$LDLIBS -lbluetooth"
		fi
	  else
		gsm_enable_blueat="no"
	  fi])	
AC_ARG_ENABLE(blueobex,
	[  --disable-blueobex      Disable OBEX over Bluetooth stack],
	[gsm_enable_blueobex="no"],
	[if test $ac_cv_have_sockaddr_rc = yes; then
		AC_DEFINE(GSM_ENABLE_BLUEOBEX)
		gsm_enable_blueobex="yes"
		if ( echo $LDLIBS | grep -v -q -e -lbluetooth ) ; then
			LDLIBS="$LDLIBS -lbluetooth"
		fi
	  else
		gsm_enable_blueobex="no"
	  fi])	

dnl Some general options
AC_ARG_ENABLE(debug,
	[  --enable-debug          Compile with debug code],
	[AC_DEFINE(DEBUG) debug="yes"],
	[debug="no"])
AC_ARG_ENABLE(cb,
	[  --enable-cb             Enable Cell Broadcast messages support],
	[AC_DEFINE(GSM_ENABLE_CELLBROADCAST) gsm_enable_cellbroadcast="yes"],
	[gsm_enable_cellbroadcast="no"])
AC_ARG_ENABLE(7110incoming,
	[  --enable-7110incoming   Enable Nokia 62xx/71xx/9xxx incoming call/SMS info],
	[AC_DEFINE(GSM_ENABLE_N71_92INCOMINGINFO) gsm_enable_71_92incominginfo="yes"],
	[gsm_enable_71_92incominginfo="no"])
AC_ARG_ENABLE(6210calendar,
	[  --enable-6210calendar   Force using 6210 frames for calendar for DCT4 phones],
	[AC_DEFINE(GSM_FORCE_DCT4_CALENDAR_6210) gsm_force_dct4_calendar_6210="yes"],
	[gsm_force_dct4_calendar_6210="no"])
AC_ARG_ENABLE(backup,
	[  --disable-backup        Disable backup/restore functions],
	[gsm_enable_backup="no"],
	[AC_DEFINE(GSM_ENABLE_BACKUP) gsm_enable_backup="yes"])

dnl Phone modules
AC_ARG_ENABLE(alcatel,
	[  --disable-alcatel       Disable Alcatel phone support],
	[gsm_enable_alcatel="no"],
	[AC_DEFINE(GSM_ENABLE_ALCABUS)
	 AC_DEFINE(GSM_ENABLE_ALCATEL) gsm_enable_alcatel="yes"])
AC_ARG_ENABLE(6110,
	[  --disable-6110          Disable Nokia 61xx and compatible support],
	[gsm_enable_nokia6110="no"],
	[AC_DEFINE(GSM_ENABLE_NOKIA6110) gsm_enable_nokia6110="yes"])
AC_ARG_ENABLE(6510,
	[  --disable-6510          Disable Nokia 6510 and compatible support],
	[gsm_enable_nokia6510="no"],
	[AC_DEFINE(GSM_ENABLE_NOKIA6510) gsm_enable_nokia6510="yes"])
AC_ARG_ENABLE(7110,
	[  --disable-7110          Disable Nokia 7110 and compatible support],
	[gsm_enable_nokia7110="no"],
	[AC_DEFINE(GSM_ENABLE_NOKIA7110) gsm_enable_nokia7110="yes"])
AC_ARG_ENABLE(9210,
	[  --disable-9210          Disable Nokia 9210 and compatible support],
	[gsm_enable_nokia9210="no"],
	[AC_DEFINE(GSM_ENABLE_NOKIA9210) gsm_enable_nokia9210="yes"])
AC_ARG_ENABLE(atgen,
	[  --disable-atgen         Disable generic AT phones support],
	[gsm_enable_atgen="no"],
	[AC_DEFINE(GSM_ENABLE_ATGEN) gsm_enable_atgen="yes"])
AC_ARG_ENABLE(obexgen,
	[  --disable-obexgen       Disable generic OBEX phones support],
	[gsm_enable_obexgen="no"],
	[AC_DEFINE(GSM_ENABLE_OBEXGEN) gsm_enable_obexgen="yes"])
AC_ARG_ENABLE(mroutergen,
	[  --disable-mroutergen    Disable Symbian m-router phones support],
	[gsm_enable_mroutergen="no"],
	[AC_DEFINE(GSM_ENABLE_MROUTERGEN) gsm_enable_mroutergen="yes"])
AC_ARG_ENABLE(3650,
	[  --disable-3650          Disable Nokia 3650 and compatible support],
	[gsm_enable_nokia3650="no"],
	[AC_DEFINE(GSM_ENABLE_NOKIA3650) gsm_enable_nokia3650="yes"])

AC_SUBST(LDLIBS)

dnl Writing output files
AC_CONFIG_HEADER(config.h)
AC_OUTPUT(Makefile.cfg
	  ../pkgconfig/gammu.pc
	  ../doxygen/Doxyfile
	  ../rpm/gammu.spec
	  ../../gammu/msvc6.mak/gammu.rc
	  ../../gammu/msvc7.mak/gammu.rc
          ../../gammu/bcc6.mak/gammu.bpr
	  ../../win32/dll/msvc6.mak/gammu.rc
	  ../../win32/dll/msvc7.mak/gammu.rc)

dnl Writing info
echo "
  G A M M U (GNU All Mobiles Management Utilities)
  (c) 2002 - 2003 by Marcin Wiacek (www.mwiacek.com)
  Version $VERSION

  Directories
  -----------
  Prefix                                        - $prefix
  Executable prefix                             - $exec_prefix
  
  Man pages                                     - $mandir/man1
  Shared .so library                            - $libdir
  Docs and examples                             - $DOC_DIR
  Localisation files                            - $LOCALE_DIR
  Include files                                 - $includedir/gammu
  Binaries                                      - $bindir
  RPM making directory                          - $RPM_DIR
  Temporary directory                           - $TEMP_DIR
  Bluetooth library path                        - $gsm_bt_dir
  
  General options
  ---------------
  Debug                                         - $debug
  CB messages                                   - $gsm_enable_cellbroadcast
  Backup functions                              - $gsm_enable_backup
  Searching phones (requires pthread)           - $pthread

  Phone protocols
  ---------------
  AT                                            - $gsm_enable_at
  Alcatel                                       - $gsm_enable_alcatel
  Nokia MBUS2                                   - $gsm_enable_mbus2
  Nokia FBUS2                                   - $gsm_enable_fbus2
  Nokia FBUS2 for DLR3 cable                    - $gsm_enable_fbus2dlr3 "
dnl Add info about DKU5
echo "  Nokia FBUS2 for Bluetooth legacy device       - $gsm_enable_fbus2blue
  Nokia FBUS2 for direct infrared device        - $gsm_enable_fbus2irda
  Nokia PHONET FBUS for Bluetooth legacy device - $gsm_enable_phonetblue "
dnl SYMBIAN with m-router for Bluetooth legacy    - $gsm_enable_mrouterblue
echo "
  Phone protocols with infrared stack
  -----------------------------------
  AT commands                                   - $gsm_enable_irdaat
  Nokia PHONET FBUS                             - $gsm_enable_irdaphonet
  OBEX                                          - $gsm_enable_irdaobex

  Phone protocols with Bluez Bluetooth stack
  ------------------------------------------
  AT commands                                   - $gsm_enable_blueat
  Nokia FBUS2                                   - $gsm_enable_bluefbus2
  Nokia PHONET FBUS                             - $gsm_enable_bluephonet
  OBEX                                          - $gsm_enable_blueobex

  Phone modules
  -------------
  Alcatel BE5 (OT 500, 501, 701, other)         - $gsm_enable_alcatel
  AT (Siemens, Alcatel, Nokia, WaveCom, other)  - $gsm_enable_atgen
  Nokia 3210/33xx/3410/51xx/5210/5510/61xx/82xx - $gsm_enable_nokia6110
  Nokia 35xx/5100/6100/63xx/65xx/6610/72x0/83xx - $gsm_enable_nokia6510
           Use always 6210 frames for calendar  - $gsm_force_dct4_calendar_6210
  Nokia 62xx/71xx                               - $gsm_enable_nokia7110
           Incoming call/SMS info               - $gsm_enable_71_92incominginfo
  Nokia 92xx                                    - $gsm_enable_nokia9210
           Incoming call/SMS info               - $gsm_enable_71_92incominginfo
  Nokia 3650                                    - $gsm_enable_nokia3650
  OBEX (Nokia, SonyEricsson, other)             - $gsm_enable_obexgen "
dnl  Symbian with m-router (3650, other)           - $gsm_enable_mroutergen
echo "
  Please use now:
  
  * "make"            to make static version of Gammu
  * "make install"    to install Gammu in your system (root)
  * "make installlib" to install Gammu with library in your system (root)
  * "make makerpm"    to make RPM package
  * "make makedeb"    to make Debian package
"
