1dnl
2dnl Makefile for the GNOKII tool suite.
3dnl
4dnl  Copyright (C) 1999 Hugh Blemings & Pavel Janik ml.
5dnl                2000 Karel Zak, Pawel Kot
6dnl                2002 BORBELY Zoltan
7dnl
8
9dnl
10dnl IMPORTANT NOTE
11dnl The first PKG_CHECK_MODULES call must not be conditional
12dnl
13
14AC_INIT([gnokii],
15	[0.6.31],
16	[gnokii-users@nongnu.org],
17	[gnokii],
18	[http://www.gnokii.org/])
19
20# Before making a release, the GNOKII_LT_VERSION string should be modified.
21# The string is of the form C:R:A.
22# - If interfaces have been changed or added, but binary compatibility has
23#   been preserved, change to C+1:0:A+1
24# - If binary compatibility has been broken (eg removed or changed interfaces)
25#   change to C-A+1:0:0
26# - If the interface is the same as the previous version, change to C:R+1:A
27GNOKII_LT_VERSION_CURRENT=7
28GNOKII_LT_VERSION_REVISION=0
29GNOKII_LT_VERSION_AGE=0
30AC_SUBST(GNOKII_LT_VERSION_CURRENT)
31AC_SUBST(GNOKII_LT_VERSION_REVISION)
32AC_SUBST(GNOKII_LT_VERSION_AGE)
33
34dnl xgnokii version
35XVERSION=1.0
36
37dnl smsd version
38SVERSION=1.5.2
39
40AC_CANONICAL_SYSTEM
41AC_GNU_SOURCE
42
43AC_CONFIG_SRCDIR([gnokii/gnokii.c])
44dnl gettext doesn't like the config.status being somewhere else :(
45dnl AC_CONFIG_AUX_DIR(config)
46AC_CONFIG_MACRO_DIR([m4])
47
48AM_INIT_AUTOMAKE([1.8 dist-bzip2])
49
50AC_PREFIX_DEFAULT("/usr/local")
51
52dnl ======================== Checks for programs.
53AC_PROG_CC
54AM_PROG_CC_C_O
55AC_PROG_CPP
56AC_PROG_LEX
57# If there's no flex/lex utility and there's no generated common/gnvcal.c file, we won't be able to compile
58if test "x$LEX" = "x:" && test ! -f common/gnvcal.c; then
59	echo "You need one of the following:"
60	echo " - installed lex/flex"
61	echo " - generated common/gnvcal.c file (included in release tarballs, not included in GIT)"
62	exit 1
63fi
64
65AC_PATH_PROG(RM, rm, no)
66AC_PATH_PROG(FIND, find, no)
67AC_CHECK_PROGS(MAKE, gmake make)
68AC_CHECK_PROGS(AR, ar)
69AC_PROG_INSTALL
70
71dnl ======================= Localisation and i18n
72
73IT_PROG_INTLTOOL([0.35.0])
74AM_LANGINFO_CODESET
75
76dnl Add the languages which your application supports to po/LINGUAS
77GETTEXT_PACKAGE=gnokii
78AC_DEFINE_UNQUOTED(GETTEXT_PACKAGE, ["$GETTEXT_PACKAGE"], [Define to the Gettext package name])
79AC_SUBST(GETTEXT_PACKAGE)
80AM_GLIB_GNU_GETTEXT
81AM_ICONV
82
83dnl -----------------------------
84dnl Checks for FreeBSD Build
85dnl -----------------------------
86AC_MSG_CHECKING(if building on FreeBSD)
87
88if test `uname -s` = "FreeBSD" ; then
89	AC_MSG_RESULT(yes)
90	CPPFLAGS="$CFLAGS -I/usr/local/include"
91	LDFLAGS="$LDFLAGS -L/usr/local/lib"
92else
93	AC_MSG_RESULT(no)
94fi
95
96dnl -----------------------------
97dnl Checks for NetBSD Build
98dnl -----------------------------
99AC_MSG_CHECKING(if building on NetBSD)
100
101if test `uname -s` = "NetBSD" ; then
102        AC_MSG_RESULT(yes)
103        CPPFLAGS="$CFLAGS -I/usr/pkg/include/"
104        LDFLAGS="$LDFLAGS -L/usr/pkg/lib/"
105else
106        AC_MSG_RESULT(no)
107fi
108
109dnl ======================== Libtool versioning
110AC_LIBTOOL_WIN32_DLL
111define([AC_PROVIDE_AC_LIBTOOL_WIN32_DLL])
112AC_PROG_LIBTOOL
113
114#
115# Make libtool use --silent when --silent is passed to make
116#
117changequote(,)dnl
118LIBTOOL="${LIBTOOL} \$(shell echo \"\$(MFLAGS)\" | awk '/^[^ ]*s/ { print \"--silent\" }')"
119changequote([,])dnl
120
121GNOKII_LT_VERSION=$GNOKII_LT_VERSION_CURRENT:$GNOKII_LT_VERSION_REVISION:$GNOKII_LT_VERSION_AGE
122AC_SUBST(GNOKII_LT_VERSION)
123
124# As used in common/gnokii.h
125LIBGNOKII_VERSION_MAJOR=`expr $GNOKII_LT_VERSION_CURRENT - $GNOKII_LT_VERSION_AGE`
126LIBGNOKII_VERSION_MINOR=$GNOKII_LT_VERSION_AGE
127LIBGNOKII_VERSION_RELEASE=$GNOKII_LT_VERSION_REVISION
128LIBGNOKII_VERSION_STRING="$LIBGNOKII_VERSION_MAJOR.$LIBGNOKII_VERSION_MINOR.$LIBGNOKII_VERSION_RELEASE"
129
130AC_SUBST(LIBGNOKII_VERSION_MAJOR)
131AC_SUBST(LIBGNOKII_VERSION_MINOR)
132AC_SUBST(LIBGNOKII_VERSION_RELEASE)
133AC_SUBST(LIBGNOKII_VERSION_STRING)
134AC_DEFINE_UNQUOTED(VERSION, "$VERSION", [The current version])
135
136dnl ======================== Default setting
137
138dnl Let us have $prefix variable available here
139test x"$prefix" = xNONE && prefix="$ac_default_prefix"
140
141debug="yes"
142xdebug="yes"
143rlpdebug="yes"
144
145AC_ARG_ENABLE(fulldebug,
146	[  --enable-fulldebug      compile with full debugging support],
147	[ if test x$enable_fulldebug = xyes; then
148		if test "x$GCC" = "xyes"; then
149			CFLAGS="$CFLAGS -ggdb3 -Wall"
150		fi
151	  fi ]
152)
153
154dnl AC_ARG_ENABLE(debug,
155dnl	[  --enable-debug          compile with debug code],
156dnl	[ if test x$enable_debug = xno; then debug="no"; fi ],
157dnl	[ debug="yes" ]
158dnl )
159debug="yes"
160
161AC_ARG_ENABLE(xdebug,
162	[  --enable-xdebug         compile with xdebug code],
163	[ if test x$enable_xdebug = xno; then xdebug="no"; fi ],
164	[ xdebug="yes" ]
165)
166
167AC_ARG_ENABLE(rlpdebug,
168	[  --enable-rlpdebug       compile with RLP debug code],
169	[ if test x$enable_rlpdebug = xno; then rlpdebug="no"; fi ],
170	[ rlpdebug="yes" ]
171)
172
173if test $debug = "yes"; then
174	AC_DEFINE(DEBUG, 1, [Whether debug is turned on])
175fi
176if test $xdebug = "yes"; then
177	AC_DEFINE(XDEBUG, 1, [Whether xdebug is turned on])
178fi
179if test $rlpdebug = "yes"; then
180	AC_DEFINE(RLP_DEBUG, 1, [Whether rlpdebug is turned on])
181fi
182
183dnl ======================== Set gcc CFLAGS if we use gcc
184if test "x$GCC" = "xyes"; then
185	CFLAGS="$CFLAGS -Wall"
186fi
187
188dnl ======================== Set some gcc CFLAGS to reduce build warnings
189if test "x$GCC" = "xyes"; then
190  OLD_CFLAGS="$CFLAGS"
191
192  CFLAGS="-Wno-pointer-sign"
193  AC_MSG_CHECKING(if gcc supports $CFLAGS compiler option)
194  AC_TRY_COMPILE( [], [ int main() { return 0; } ],
195		ac_cv_have_no_pointer_sign=yes,
196		ac_cv_have_no_pointer_sign=no)
197  AC_MSG_RESULT($ac_cv_have_no_pointer_sign)
198  CFLAGS="-fvisibility=hidden"
199  AC_MSG_CHECKING(if gcc supports $CFLAGS compiler option)
200  AC_TRY_COMPILE( [], [ int main() { return 0; } ],
201		ac_cv_have_hidden_visibility=yes,
202		ac_cv_have_hidden_visibility=no)
203  AC_MSG_RESULT($ac_cv_have_hidden_visibility)
204  CFLAGS="-fno-strict-aliasing"
205  AC_MSG_CHECKING(if gcc supports $CFLAGS compiler option)
206  AC_TRY_COMPILE( [], [ int main() { return 0; } ],
207		ac_cv_have_strict_aliasing=yes,
208		ac_cv_have_strict_aliasing=no)
209  AC_MSG_RESULT($ac_cv_have_strict_aliasing)
210
211  CFLAGS="$OLD_CFLAGS"
212  if test $ac_cv_have_no_pointer_sign = yes; then
213    CFLAGS="$CFLAGS -Wno-pointer-sign"
214  fi
215  if test $ac_cv_have_hidden_visibility = yes; then
216    CFLAGS="$CFLAGS -fvisibility=hidden"
217  fi
218  if test $ac_cv_have_strict_aliasing = yes; then
219    CFLAGS="$CFLAGS -fno-strict-aliasing"
220  fi
221fi
222
223dnl ======================== avoid deprecated warnings here
224# CFLAGS="$CFLAGS -DGNOKII_DEPRECATED=''"
225
226dnl ======================== Checks for libraries.
227
228AC_ARG_WITH(libpthread,
229   [  --with-libpthread=DIR   specifies the base libpthread],
230   [ if test x$withval = xyes
231     then
232      AC_MSG_WARN(Usage is: --with-libpthread=DIR)
233     else
234      PTHREAD_LIBS="-L$withval/lib/"
235      PTHREAD_CFLAGS="-I$withval/include/"
236     fi
237   ]
238)
239
240ACX_PTHREAD
241if test "x$PTHREAD_CFLAGS" = "x-pthread"; then
242	PTHREAD_LIBS="$PTHREAD_LIBS -pthread"
243fi
244
245dnl FIXME: do we really test here if libc contains this function?
246if test "x$PTHREAD_LIBS" = xerror; then
247   AC_CHECK_FUNC(pthread_attr_init, PTHREAD_LIBS="",
248      [AC_MSG_WARN(not found library: pthread!!!)
249       AC_MSG_WARN(disabling xgnokii and smsd)])
250fi
251
252AC_CACHE_CHECK(for tm_gmtoff in struct tm, ac_cv_have_tm_gmtoff,
253	[AC_TRY_COMPILE([#include <time.h>],
254		[struct tm t; t.tm_gmtoff = 0],
255		ac_cv_have_tm_gmtoff=yes,
256		ac_cv_have_tm_gmtoff=no)])
257if test $ac_cv_have_tm_gmtoff = yes; then
258	AC_DEFINE(HAVE_TM_GMTON, 1, [Whether tm_gmtoff is available])
259fi
260
261AC_CACHE_CHECK(for timer operations, ac_cv_have_timeops,
262	[AC_TRY_LINK([#include <sys/time.h>],
263		[struct timeval tv; timerisset(&tv); timerclear(&tv); timercmp(&tv, &tv, <); timeradd(&tv, &tv, &tv); timersub(&tv, &tv, &tv); ],
264		ac_cv_have_timeops=yes,
265		ac_cv_have_timeops=no)])
266if test $ac_cv_have_timeops = yes; then
267        AC_DEFINE(HAVE_TIMEOPS, 1, [Whether timer operations are available])
268fi
269
270have_termios="no"
271dnl Checking for setspeed in termios.h
272AC_CACHE_CHECK(for cfsetspeed in termios.h, ac_cv_have_cfsetspeed,
273	[AC_TRY_LINK([#include <termios.h>],
274		[struct termios t; cfsetspeed(&t, B9600);],
275		ac_cv_have_cfsetspeed=yes,
276		ac_cv_have_cfsetspeed=no)])
277if test $ac_cv_have_cfsetspeed = yes; then
278        AC_DEFINE(HAVE_CFSETSPEED, 1, [Whether cfsetspeed is available])
279        have_termios="yes"
280fi
281
282if test $have_termios = "no"; then
283	AC_CACHE_CHECK(for cfsetispeed and cfsetospeed in termios.h, ac_cv_have_cfsetiospeed,
284		[AC_TRY_LINK([#include <termios.h>],
285			[struct termios t; cfsetispeed(&t, B9600);  cfsetospeed(&t, B9600);],
286			ac_cv_have_cfsetiospeed=yes,
287			ac_cv_have_cfsetiospeed=no)])
288	if test $ac_cv_have_cfsetiospeed = yes; then
289		AC_DEFINE(HAVE_CFSETISPEED, 1, [Whether cfsetispeed is available])
290		AC_DEFINE(HAVE_CFSETOSPEED, 1, [Whether cfsetospeed is available])
291		have_termios="yes"
292	fi
293fi
294
295if test $have_termios = "no"; then
296	AC_CACHE_CHECK(for c_ispeed and c_ospeed in struct termios, ac_cv_have_c_iospeed,
297		[AC_TRY_COMPILE([#include <termios.h>],
298			[struct termios t; t.c_iflag = B9600; t.c_oflag = B9600;],
299			ac_cv_have_c_iospeed=yes,
300			ac_cv_have_c_iospeed=yes)])
301	if test ac_cv_have_c_iospeed = yes; then
302		AC_DEFINE(HAVE_TERMIOS_CSPEED, 1, [Whether c_ispeed and c_ospeed are available])
303	fi
304fi
305
306dnl ======================== readline support
307# Readline included by default unless explicitly asked not to
308test "${with_readline+set}" != "set" && with_readline=yes
309
310USE_READLINE="no"
311
312AC_MSG_CHECKING(whether to use readline)
313AC_ARG_WITH(readline,
314[  --with-readline[=DIR]     Look for readline include/libs in DIR
315  --without-readline      Don't include readline support],
316[  case "$with_readline" in
317  yes)
318    AC_MSG_RESULT(yes)
319
320    AC_CHECK_HEADERS(readline.h history.h readline/readline.h)
321    AC_CHECK_HEADERS(readline/history.h)
322
323    AC_CHECK_HEADERS(readline.h readline/readline.h,[
324      for termlib in ncurses curses termcap terminfo termlib; do
325	AC_CHECK_LIB(${termlib}, tgetent, [TERMLIBS="-l${termlib}"; break])
326      done
327      AC_CHECK_LIB(readline, readline,
328        [TERMLIBS="-lreadline $TERMLIBS"
329        AC_DEFINE([HAVE_READLINE], [1], [Use readline])
330	USE_READLINE="yes"
331        break], [TERMLIBS=], $TERMLIBS)])
332    ;;
333  no)
334    AC_MSG_RESULT(no)
335    ;;
336  *)
337    AC_MSG_RESULT(yes)
338
339    # Needed for AC_CHECK_HEADERS and AC_CHECK_LIB to look at
340    # alternate readline path
341    _ldflags=${LDFLAGS}
342    _cppflags=${CPPFLAGS}
343
344    # Add additional search path
345    LDFLAGS="-L$with_readline/lib $LDFLAGS"
346    CPPFLAGS="-I$with_readline/include $CPPFLAGS"
347
348    AC_CHECK_HEADERS(readline.h history.h readline/readline.h)
349    AC_CHECK_HEADERS(readline/history.h)
350
351    AC_CHECK_HEADERS(readline.h readline/readline.h,[
352      for termlib in ncurses curses termcap terminfo termlib; do
353	AC_CHECK_LIB(${termlib}, tgetent, [TERMLIBS="-l${termlib}"; break])
354      done
355      AC_CHECK_LIB(readline, readline,
356        [TERMLDFLAGS="-L$with_readline/lib"
357        TERMCPPFLAGS="-I$with_readline/include"
358        CPPFLAGS="-I$with_readline/include $CPPFLAGS"
359        TERMLIBS="-lreadline $TERMLIBS"
360        AC_DEFINE([HAVE_READLINE], [1], [Use readline])
361	USE_READLINE="yes"
362        break], [TERMLIBS= CPPFLAGS=$_cppflags], $TERMLIBS)])
363
364    LDFLAGS=$_ldflags
365    ;;
366  esac],
367  AC_MSG_RESULT(no)
368)
369AC_SUBST(TERMLIBS)
370AC_SUBST(TERMLDFLAGS)
371
372dnl ======================== Check for libical
373AC_ARG_WITH(libical,
374   [  --with-libical=DIR      specifies the base libical],
375   [ if test x$withval = xyes
376     then
377      AC_MSG_WARN(Usage is: --with-libical=DIR)
378     else
379      ICAL_LIBS="-L$withval/lib/"
380      ICAL_CFLAGS="-I$withval/include/"
381     fi
382   ]
383)
384
385USE_LIBICAL="no"
386AC_ARG_ENABLE(libical,
387       	      AC_HELP_STRING([--disable-libical],
388               	             [disable libical support (default is autodetected)]
389                            ),,
390       	      [enable_libical=yes])
391
392if test "$enable_libical" = "yes"; then
393	ICAL_LIBS="$ICAL_LIBS -lpthread -lical"
394	OLD_CFLAGS="$CFLAGS"
395	OLD_LIBS="$LIBS"
396	LIBS="$LIBS $ICAL_LIBS"
397	CFLAGS="$CFLAGS $ICAL_CFLAGS"
398	AC_MSG_CHECKING(whether libical is installed)
399	AC_TRY_LINK([
400	   #include <libical/ical.h>
401	   ],[
402	   int priority;
403	   icalcomponent *pIcal=NULL;
404	   struct icaltimetype atime = icaltime_from_string("20031231T223000");
405
406	   pIcal = icalcomponent_vanew(
407	      ICAL_VCALENDAR_COMPONENT,
408	      icalproperty_new_version("2.0"),
409	      icalproperty_new_prodid("//Gnokii.org//NONSGML v.0.5.8"),
410	      0
411	   );
412	   atime.is_daylight = 1;
413	   priority = icalproperty_get_priority(icalcomponent_get_first_property(pIcal, ICAL_PRIORITY_PROPERTY));
414	   ],
415	   [
416	      AC_MSG_RESULT(yes)
417	      USE_LIBICAL="yes"
418	      AC_DEFINE([HAVE_LIBICAL],[1],[Use libical])
419	      AC_SUBST(ICAL_LIBS)
420	      AC_SUBST(ICAL_CFLAGS)
421	   ],
422	   [
423	      AC_MSG_RESULT(no)
424	      ICAL_LIBS=""
425	   ]
426	)
427	LIBS="$OLD_LIBS"
428	CFLAGS="$OLD_CFLAGS"
429fi
430
431dnl ======================== Check for libusb
432USE_LIBUSB="no"
433AC_ARG_ENABLE(libusb,
434              AC_HELP_STRING([--disable-libusb],
435                             [disable libusb support (default is autodetected)]
436                            ),,
437              [enable_libusb=yes])
438if test "$enable_libusb" = "yes"; then
439	AC_MSG_CHECKING(whether libusb is installed)
440	AC_TRY_COMPILE([#include <usb.h>],
441		[struct usb_dev_handle *dev;],
442		[
443			AC_MSG_RESULT(yes)
444			AC_DEFINE([HAVE_LIBUSB],[1],[Use libusb])
445			USE_LIBUSB="yes"
446			USB_LIBS="-lusb"
447			AC_SUBST(USB_LIBS)
448		],
449		[
450			AC_MSG_RESULT(no)
451		]
452	)
453fi
454
455dnl ======================== Checks for Linux Phonet support
456USE_SOCKETPHONET="no"
457AC_ARG_ENABLE(phonet,
458              AC_HELP_STRING([--disable-phonet],
459                             [disable phonet support (default is autodetected)]
460                            ),,
461              [enable_phonet=yes])
462if test "$enable_phonet" = "yes"; then
463	AC_CHECK_HEADER(linux/phonet.h,
464		[AC_DEFINE(HAVE_SOCKETPHONET, 1, [Whether Phonet is available])
465		 USE_SOCKETPHONET="yes"],,
466		[#include <sys/socket.h>
467		 #include <linux/phonet.h>])
468fi
469
470dnl ======================== Checks for gethostbyname support
471AC_CHECK_FUNC(gethostbyname, ,
472	AC_CHECK_LIB(nsl, gethostbyname, TCP_LIBS="-lnsl"
473		     AC_SUBST(TCP_LIBS)))
474dnl Haiku requires -lnetwork for socket functions
475AC_CHECK_FUNC(gethostbyname, ,
476	AC_CHECK_LIB(network, gethostbyname, TCP_LIBS="-lnetwork"
477		     AC_SUBST(TCP_LIBS)))
478
479dnl ======================== Checks for Linux IrDA support
480USE_IRDA="no"
481AC_ARG_ENABLE(irda,
482              AC_HELP_STRING([--disable-irda],
483                             [disable irda support (default is autodetected)]
484                            ),,
485              [enable_irda=yes])
486if test "$enable_irda" = "yes"; then
487	AC_CHECK_HEADER(linux/irda.h,
488		[AC_DEFINE(HAVE_IRDA, 1, [Whether IrDA is available])
489		 USE_IRDA="yes"],,
490		[#include <sys/socket.h>
491		 #include <sys/ioctl.h>
492		 #include <linux/types.h>])
493fi
494
495dnl ======================== Defines location for gettext
496AC_ARG_WITH(gettext,
497	[  --with-gettext=DIR      specifies the base gettext],
498	[ if test x$withval = xyes; then
499		AC_MSG_WARN(Usage is: --with-gettext=DIR)
500	  else
501		CFLAGS="$CFLAGS -I$withval"
502	  fi
503	]
504)
505
506dnl ======================== Checks for Bluetooth support
507USE_BLUETOOTH="no"
508AC_ARG_WITH(bluetooth,
509	[  --with-bluetooth=DIR    specifies the base libbluetooth],
510	[ if test x$withval = xyes; then
511		AC_MSG_WARN(Usage is: --with-bluetooth=DIR)
512	  else
513		LIBS="$LIBS -L$withval/lib"
514		CFLAGS="$CFLAGS -I$withval/net -I$withval/"
515	  fi
516	]
517)
518AC_ARG_ENABLE(bluetooth,
519              AC_HELP_STRING([--disable-bluetooth],
520                             [disable Bluetooth support (default is autodetected)]
521                            ),,
522              [enable_bluetooth=yes])
523
524dnl ======================== Checks for Linux Bluetooth support
525if test `uname -s` = "Linux" ; then
526	if test "$enable_bluetooth" = "yes" -a "$USE_BLUETOOTH" = "no"; then
527		AC_MSG_NOTICE([checking for the Linux Bluetooth support])
528		AC_CACHE_CHECK(for the struct sockaddr_rc in <bluetooth/rfcomm.h>, ac_cv_have_sockaddr_rc,
529			[AC_TRY_COMPILE([#include <sys/socket.h>
530					#include <bluetooth/bluetooth.h>
531					#include <bluetooth/rfcomm.h>],
532				[struct sockaddr_rc rc;],
533				ac_cv_have_sockaddr_rc=yes,
534				ac_cv_have_sockaddr_rc=no)])
535		if test $ac_cv_have_sockaddr_rc = yes; then
536			AC_DEFINE(HAVE_BLUETOOTH, 1, [Whether Bluetooth is available])
537			AC_DEFINE(HAVE_BLUETOOTH_BLUEZ,[],[Compile on Linux])
538			USE_BLUETOOTH="yes"
539			BLUETOOTH_LIBS="-lbluetooth"
540			AC_SUBST(BLUETOOTH_LIBS)
541		fi
542	fi
543fi
544
545dnl ======================== Checks for MacOSX Bluetooth support
546if test `uname -s` = "Darwin" ; then
547	if test "$enable_bluetooth" = "yes" -a "$USE_BLUETOOTH" = "no"; then
548		AC_MSG_NOTICE([checking for the MacOS X Bluetooth support])
549		AC_CHECK_HEADERS(CoreFoundation/CoreFoundation.h)
550		AC_CHECK_HEADERS(IOBluetooth/Bluetooth.h)
551		AC_CHECK_HEADERS([IOBluetooth/IOBluetoothUserLib.h], [], [],
552			[[#ifdef HAVE_COREFOUNDATION_COREFOUNDATION_H
553			  #  include <CoreFoundation/CoreFoundation.h>
554			  #endif
555			  #ifdef HAVE_IOBLUETOOTH_BLUETOOTH_H
556			  #  include <IOBluetooth/Bluetooth.h>
557			  #endif
558			]])
559		AC_TRY_COMPILE([#include <CoreFoundation/CoreFoundation.h>
560				#include <IOBluetooth/Bluetooth.h>
561				#include <IOBluetooth/IOBluetoothUserLib.h>],
562
563				[CFStringRef strDevice;
564				strDevice = CFStringCreateWithCString(NULL, NULL, NULL);
565				IOBluetoothNSStringToDeviceAddress(NULL, NULL);],
566			ac_cv_have_iobluetooth=yes,
567			ac_cv_have_iobluetooth=no)
568
569		if test $ac_cv_have_iobluetooth = yes; then
570			AC_DEFINE(HAVE_BLUETOOTH, 1, [Whether Bluetooth is available])
571			AC_DEFINE(HAVE_BLUETOOTH_MACOSX,[],[Compile on Darwin / Mac OSX])
572			USE_BLUETOOTH="yes"
573			BLUETOOTH_LIBS="$PTHREAD_LIBS -Wl,-framework,CoreFoundation -Wl,-framework,IOBluetooth -Wl,-framework,Foundation"
574			AC_SUBST(BLUETOOTH_LIBS)
575		fi
576	fi
577fi
578
579dnl ======================== Checks for FreeBSD/netgraph Bluetooth support
580if test `uname -s` = "FreeBSD" ; then
581	if test "$enable_bluetooth" = "yes" -a "$USE_BLUETOOTH" = "no"; then
582		AC_MSG_NOTICE([checking for the FreeBSD/netgraph Bluetooth support])
583		AC_CACHE_CHECK(for the struct sockaddr_rfcomm from <bluetooth.h>, ac_cv_have_sockaddr_rfcomm,
584			[AC_TRY_COMPILE([#include <bluetooth.h>],
585				[struct sockaddr_rfcomm rc;],
586				ac_cv_have_sockaddr_rfcomm=yes,
587				ac_cv_have_sockaddr_rfcomm=no)])
588
589		if test $ac_cv_have_sockaddr_rfcomm = yes; then
590			AC_DEFINE(HAVE_BLUETOOTH, 1, [Whether Bluetooth is available])
591			AC_DEFINE(HAVE_BLUETOOTH_NETGRAPH, [], [Compile on FreeBSD])
592			USE_BLUETOOTH="yes"
593			AC_CHECK_LIB(bluetooth, bt_aton,
594				[BLUETOOTH_LIBS="-lbluetooth" ac_cv_have_bt_lib=yes],
595				ac_cv_have_bt_lib=no)
596			if test $ac_cv_have_bt_lib = yes; then
597				AC_CHECK_LIB(sdp, sdp_open,
598					[BLUETOOTH_LIBS="$BLUETOOTH_LIBS -lsdp"])
599				AC_SUBST(BLUETOOTH_LIBS)
600			fi
601		fi
602	fi
603fi
604
605dnl ======================== Checks for NetBSD/netbt Bluetooth support
606if test `uname -s` = "NetBSD" ; then
607	if test "$enable_bluetooth" = "yes" -a "$USE_BLUETOOTH" = "no"; then
608		AC_MSG_NOTICE([checking for the NetBSD/netbt Bluetooth support])
609		AC_CACHE_CHECK(for the struct sockaddr_bt from <bluetooth.h>, ac_cv_have_sockaddr_bt,
610			[AC_TRY_COMPILE([#include <bluetooth.h>],
611				[struct sockaddr_bt rc;],
612				ac_cv_have_sockaddr_bt=yes,
613				ac_cv_have_sockaddr_bt=no)])
614
615		if test $ac_cv_have_sockaddr_bt = yes; then
616			AC_DEFINE(HAVE_BLUETOOTH, 1, [Whether Bluetooth is available])
617			AC_DEFINE(HAVE_BLUETOOTH_NETBT, [], [Compile on NetBSD])
618			USE_BLUETOOTH="yes"
619			CFLAGS="$CFLAGS -DCOMPAT_BLUEZ"
620			AC_CHECK_LIB(bluetooth, bt_aton,
621				[BLUETOOTH_LIBS="-lbluetooth" ac_cv_have_bt_lib=yes],
622				ac_cv_have_bt_lib=no)
623			if test $ac_cv_have_bt_lib = yes; then
624				AC_CHECK_LIB(sdp, sdp_open,
625					[BLUETOOTH_LIBS="$BLUETOOTH_LIBS -lsdp"])
626				AC_SUBST(BLUETOOTH_LIBS)
627			fi
628		fi
629	fi
630fi
631
632dnl ======================== Checks for X base support
633
634PKG_CHECK_MODULES(GTK, gtk+-2.0 >= 2.0, found_gtk=yes, found_gtk=no)
635
636if test "$no_x" = yes -o "$with_x" = "no"; then
637   x_support="no"
638   XPM_CFLAGS=""
639   XPM_LIBS=""
640   GTK_CFLAGS=""
641   GTK_LIBS=""
642else
643   AC_PATH_X
644   if test "x$x_libraries" = "xNONE"; then
645      x_support="no"
646      XPM_CFLAGS=""
647      XPM_LIBS=""
648      GTK_CFLAGS=""
649      GTK_LIBS=""
650      AC_MSG_WARN(Cannot find library libX11.)
651      AC_MSG_WARN(Disabling xgnokii.)
652   else
653      if test "x$x_includes" != "x"; then
654         XINCL="-I$x_includes"
655      else
656         XINCL=""
657      fi
658      if test "x$x_libraries" != "x"; then
659         XLIBS="-L$x_libraries"
660      else
661         XLIBS=""
662      fi
663      CPPFLAGS="$CPPFLAGS $XINCL"
664      AC_CHECK_HEADERS(X11/xpm.h,
665          [ AC_CHECK_LIB(Xpm, XpmWriteFileFromXpmImage,
666                [ XPM_CFLAGS="$XINCL"
667                  XPM_LIBS="$XLIBS -lXpm -lX11"
668                  AC_DEFINE(XPM, 1, [Whether the Xpm library is available]) ],
669                AC_MSG_WARN(Cannot found library libXpm - disabling XPM support.),
670                [ $XLIBS -lX11 ]
671            )
672          ]
673      )
674      if test "x$PTHREAD_LIBS" = xerror; then
675         x_support="no"
676         GTK_CFLAGS=""
677         GTK_LIBS=""
678      else
679         if test "$found_gtk" = no; then
680            x_support="no"
681            GTK_CFLAGS=""
682            GTK_LIBS=""
683            AC_MSG_WARN(Cannot find GTK+ 2.0.)
684            AC_MSG_WARN(Disabling xgnokii.)
685         else
686            x_support="yes"
687         fi
688      fi
689   fi
690fi
691
692AM_CONDITIONAL(XGNOKII, test "x$_support" = "xyes")
693
694dnl ======================== Check for libsocket
695AC_CHECK_LIB(socket, socket)
696
697dnl ======================== Checks for glib support for libgnokii and smsd
698PKG_CHECK_MODULES(GLIB, glib-2.0)
699
700dnl ======================== Checks for gmodule support for smsd
701PKG_CHECK_MODULES(GMODULE, gmodule-2.0, found_gmodule=yes, found_gmodule=no)
702
703dnl ======================== Autodetect for possibilities to compile smsd
704AC_ARG_ENABLE(smsd,
705	AC_HELP_STRING([--disable-smsd],
706		[disable smsd support (default is autodetected)]),,
707	[enable_smsd=yes])
708
709if test "$enable_smsd" = yes; then
710	if test "$found_gmodule" = no; then
711		AC_MSG_WARN(Cannot find gmodule 2.0.)
712		AC_MSG_WARN(Disabling smsd.)
713		enable_smsd="no"
714	fi
715fi
716
717AM_CONDITIONAL(SMSD, test "x$enable_smsd" = "xyes")
718
719dnl ======================== Checks for databases support for smsd
720
721dnl === PostgreSQL
722AC_ARG_ENABLE(postgres,
723	AC_HELP_STRING([--disable-postgres],
724	[disable PostgreSQL support (default is autodetected)]),
725	[enable_postgres=$enableval],
726	[enable_postgres=yes])
727have_postgres=no
728AC_PATH_PROG(PGCONFIG, pg_config, no)
729if test x$enable_postgres != xno && test x$PGCONFIG != xno ; then
730	have_postgres=yes
731	pg_libdir=`$PGCONFIG --libdir`
732	POSTGRES_LIBS="-L$pg_libdir -lpq"
733	pg_includedir=`$PGCONFIG --includedir`
734	POSTGRES_CFLAGS="-I$pg_includedir"
735	AC_SUBST(POSTGRES_LIBS)
736	AC_SUBST(POSTGRES_CFLAGS)
737fi
738
739AM_CONDITIONAL(HAVE_POSTGRES, test "x$have_postgres" = "xyes")
740
741dnl === SQLite
742AC_ARG_ENABLE(sqlite,
743	AC_HELP_STRING([--disable-sqlite],
744	[disable SQLite support (default is autodetected)]),
745	[enable_sqlite=$enableval],
746	[enable_sqlite=yes])
747have_sqlite=no
748PKG_CHECK_MODULES(SQLITE3, sqlite3, have_sqlite=yes, have_sqlite=no)
749if test x$enable_sqlite != xno && test x$PKGCONF != xno ; then
750	SQLITE_LIBS=SQLITE3_LIBS
751	dnl SQLITE_CFLAGS=SQLITE3_CFLAGS
752	AC_SUBST(SQLITE_LIBS)
753	AC_SUBST(SQLITE_CFLAGS)
754fi
755AM_CONDITIONAL(HAVE_SQLITE, test "x$have_sqlite" = "xyes")
756
757dnl === MySQL
758AC_ARG_ENABLE(mysql,
759	AC_HELP_STRING([--disable-mysql],
760	[disable MySQL support (default is autodetected)]),
761	[enable_mysql=$enableval],
762	[enable_mysql=yes])
763have_mysql=no
764dnl Prefer mysql_config5 if it is installed
765AC_PATH_PROG(MYSQLCONFIG5, mysql_config5, no)
766if test x$MYSQLCONFIG5 = xno ; then
767	AC_PATH_PROG(MYSQLCONFIG, mysql_config, no)
768else
769	MYSQLCONFIG=$MYSQLCONFIG5
770fi
771if test x$enable_mysql != xno && test x$MYSQLCONFIG != xno ; then
772	have_mysql=yes
773	MYSQL_LIBS=`$MYSQLCONFIG --libs`
774	MYSQL_CFLAGS=`$MYSQLCONFIG --cflags`
775	AC_SUBST(MYSQL_LIBS)
776	AC_SUBST(MYSQL_CFLAGS)
777fi
778
779AM_CONDITIONAL(HAVE_MYSQL, test "x$have_mysql" = "xyes")
780
781dnl ======================== Additional switches
782
783AC_ARG_ENABLE(security,
784   [  --enable-security       enable all security features @<:@default=no@:>@],
785   [ if test x$enable_security = xyes; then
786	AC_DEFINE(SECURITY, 1, [Whether security features are enabled])
787     	security="yes"
788     else
789	security="no"
790     fi ],
791   [ security="no" ]
792)
793
794dnl ======================== Checks for libpcsclite
795USE_LIBPCSCLITE="no"
796AC_ARG_ENABLE(libpcsclite,
797              AC_HELP_STRING([--disable-libpcsclite],
798                             [disable libpcsclite support (default is autodetected)]
799                            ),,
800              [enable_libpcsclite=yes])
801if test "$enable_libpcsclite" = "yes"; then
802	PKG_CHECK_MODULES(LIBPCSCLITE, libpcsclite >= 1.3.1, USE_LIBPCSCLITE=yes, USE_LIBPCSCLITE=no)
803	if test "$USE_LIBPCSCLITE" = yes; then
804		AC_DEFINE([HAVE_PCSC], [1], [Define if you have libpcsclite])
805		OLD_CFLAGS="$CFLAGS"
806		CFLAGS="$LIBPCSCLITE_CFLAGS $OLD_CFLAGS"
807		AC_CHECK_TYPE([LPCSTR],
808		    [AC_DEFINE([HAVE_LPCSTR], 1,
809		       [Define to 1 if libpcsclite defines the type 'LPCSTR'.])],
810		    [], [#include <PCSC/wintypes.h>])
811		CFLAGS="$OLD_CFLAGS"
812	fi
813fi
814
815AC_ARG_ENABLE(win,
816   [  --enable-win            if you want Windows support ],
817   [ if test x$enable_win32 = xyes; then
818	AC_DEFINE(WIN32, 1, [Whether compiling on Windows])
819	WIN32=1
820	if test x$cross_compiling = xyes; then
821		AC_DEFINE(WIN32_CROSS, 1, [Define if you cross compile Windows.])
822		WIN32_CROSS=1
823		win32="cross"
824	else
825 		win32="yes"
826	fi
827	AC_CHECK_HEADER(af_irda.h, [AC_DEFINE(HAVE_IRDA, 1, [Whether IrDA is available]) USE_IRDA="yes"])
828     else
829	win32="no"
830     fi ],
831   [ win32="no"]
832)
833
834AM_CONDITIONAL(WIN32, test "x$WIN32" = "x1")
835
836AC_ARG_ENABLE(unix98test,
837   [  --enable-unix98test     if you want to disable UNIX98 test and assume to
838                          use it; default is enabled],
839   [ if test x$enable_unix98test = xno; then
840	unix98test="no"
841     else
842	unix98test="yes"
843     fi ],
844   [ unix98test="yes"]
845)
846
847if test x$unix98test = xyes; then
848
849AC_CHECK_FUNC(grantpt,
850   [ AC_TRY_RUN([
851#define  _XOPEN_SOURCE 500
852
853#include <stdlib.h>
854#include <sys/types.h>
855#include <sys/stat.h>
856#include <fcntl.h>
857#include <unistd.h>
858
859int main()
860{
861	char *name = NULL;
862        int master, err;
863
864        master = open("/dev/ptmx", O_RDWR | O_NOCTTY | O_NONBLOCK);
865        if (master >= 0) {
866                err = grantpt(master);
867                err = err || unlockpt(master);
868                if (!err) {
869                        name = ptsname(master);
870                } else {
871                        exit(-1);
872                }
873        } else {
874		exit(-1);
875	}
876	close(master);
877	exit(0);
878}
879                ],
880                have_unix98=yes,
881                AC_MSG_WARN("No unix98ptys"),
882		have_unix98=yes)
883   ]
884)
885
886fi
887
888if test x$have_unix98 = xyes; then
889	AC_DEFINE(USE_UNIX98PTYS, 1, [Whether Unix98 support is available])
890fi
891
892AC_TRY_COMPILE( [#define _XOPEN_SOURCE 500
893		 #include <sys/types.h>
894		 #include <sys/socket.h>],
895		[struct msghdr msg; msg.msg_control;],
896		AC_DEFINE(HAVE_MSGHDR_MSG_CONTROL, 1, [Whether struct msghdr has a msg_control member])
897)
898
899dnl ======================== Checks for header files.
900AC_HEADER_STDC
901AC_HEADER_STDBOOL
902AC_HEADER_SYS_WAIT
903AC_CHECK_HEADERS(fcntl.h sys/ioctl.h sys/time.h unistd.h sys/file.h)
904AC_CHECK_HEADERS(string.h strings.h ctype.h stdlib.h stdarg.h stdint.h)
905AC_CHECK_HEADERS(stddef.h sys/socket.h sys/modem.h termios.h sys/filio.h)
906AC_CHECK_HEADERS(inttypes.h wchar.h direct.h sys/param.h dirent.h sys/types.h)
907
908dnl ======================== Checks for typedefs, structures, and compiler characteristics.
909AC_C_CONST
910AC_C_INLINE
911AC_TYPE_PID_T
912AC_TYPE_SIZE_T
913AC_HEADER_TIME
914AC_STRUCT_TM
915AC_CHECK_TYPE([u_int8_t],
916    [AC_DEFINE([HAVE_U_INT8_T], 1,
917       [Define to 1 if the system has the type 'u_int8_t'.])])
918
919dnl we don't check for long double and long long int, only
920dnl ancient platforms don't have them
921AC_DEFINE(HAVE_LONG_LONG, 1, [Whether the platform has a long long int type])
922AC_DEFINE(HAVE_LONG_DOUBLE, 1, [Whether the platform has a long double type])
923
924AC_CACHE_CHECK(for __ptr_t, ac_cv_c___ptr_t,
925	[AC_TRY_COMPILE([#include <stdio.h>],
926		[__ptr_t foo = NULL;],
927		ac_cv_c___ptr_t=yes, ac_cv_c___ptr_t=no)])
928if test $ac_cv_c___ptr_t = yes; then
929	AC_DEFINE(HAVE_PTR_T, 1, [Whether __ptr_t is available])
930fi
931
932dnl ======================== Checks for library functions.
933AC_PROG_GCC_TRADITIONAL
934AC_FUNC_MEMCMP
935AC_TYPE_SIGNAL
936AC_FUNC_STRFTIME
937AC_CHECK_FUNCS(mktime timegm gettimeofday select poll wcrtomb)
938AC_CHECK_FUNCS(strchr strdup strndup strstr strtol strtok strsep)
939AC_CHECK_FUNCS(asprintf vasprintf snprintf vsnprintf getpass setenv)
940AC_CACHE_CHECK(for ISO C99 compliant snprintf,ac_cv_func_snprintf_c99,
941	[AC_TRY_RUN([
942#include <stdio.h>
943
944int main()
945{
946	char buf[] = {0, 0, 0, 0};
947
948	snprintf(buf, 3, "ABC");
949	exit ((buf[2] != 0) || (snprintf(NULL, 0, "%d", 100) != 3));
950}],ac_cv_func_snprintf_c99=yes,ac_cv_func_snprintf_c99=no,ac_cv_func_snprintf_c99=no)])
951if test $ac_cv_func_snprintf_c99 = yes; then
952	AC_DEFINE(HAVE_C99_SNPRINTF, 1, [Whether snprintf is available])
953fi
954AC_CACHE_CHECK(for ISO C99 compliant vsnprintf,ac_cv_func_vsnprintf_c99,
955	[AC_TRY_RUN([
956#include <stdio.h>
957#include <stdarg.h>
958
959int doit(char *buf, int len, const char *s, ...)
960{
961	va_list ap;
962	int r;
963
964	va_start(ap, s);
965	r = vsnprintf(buf, len, s, ap);
966	va_end(ap);
967
968	return r;
969}
970
971int main()
972{
973	char buf[] = {0, 0, 0, 0};
974
975	doit(buf, 3, "ABC");
976	exit ((buf[2] != 0) || (doit(NULL, 0, "%d", 100) != 3));
977}],ac_cv_func_vsnprintf_c99=yes,ac_cv_func_vsnprintf_c99=no,ac_cv_func_vsnprintf_c99=no)])
978if test $ac_cv_func_vsnprintf_c99 = yes; then
979	AC_DEFINE(HAVE_C99_VSNPRINTF, 1, [Whether vsnprintf is available])
980fi
981
982CFLAGS="$CFLAGS $NLS_CFLAGS"
983LIBS="$LIBS $NLS_LIBS"
984
985XPACKAGE=xgnokii
986AC_DEFINE_UNQUOTED(XVERSION, "$XVERSION", [The current xgnokii version])
987
988HAVE_XGNOKII=$x_support
989
990AC_DEFINE_UNQUOTED(SVERSION, "$SVERSION", [The current SMSD version])
991
992case "$INSTALL" in
993  'config/install-sh -c') INSTALL=`pwd`/$INSTALL
994   ;;
995esac
996
997SHELL=${CONFIG_SHELL-/bin/sh}
998
999AC_SUBST(SHELL)
1000case "$build_os" in
1001  solaris*) SHELL=/bin/ksh
1002   ;;
1003esac
1004
1005AC_EXPAND_DIR(mgnokiidev_bindir, "${sbindir}")
1006AC_DEFINE_UNQUOTED(SBINDIR, "$mgnokiidev_bindir", [Where mgnokiidev gets installed])
1007
1008AC_EXPAND_DIR(prefix_dir, "${prefix}")
1009AC_DEFINE_UNQUOTED(PREFIX, "$prefix_dir", [Root dir for gnokii, xgnokii and smsd])
1010
1011AC_CONFIG_HEADERS([include/config.h])
1012
1013AC_SUBST(PACKAGE)
1014AC_SUBST(VERSION)
1015AC_SUBST(XVERSION)
1016AC_SUBST(XPACKAGE)
1017
1018AC_SUBST(exec_prefix)
1019
1020AC_SUBST(GLDFLAGS)
1021
1022AC_SUBST(PTHREAD_CFLAGS)
1023AC_SUBST(PTHREAD_LIBS)
1024
1025AC_SUBST(OWN_GETOPT)
1026AC_SUBST(USE_UNIX98PTYS)
1027AC_SUBST(NEED_LOCALE_CHARSET)
1028
1029AC_SUBST(LIBS)
1030
1031AC_SUBST(GTK_CFLAGS)
1032AC_SUBST(GTK_LIBS)
1033AC_SUBST(XPM_CFLAGS)
1034AC_SUBST(XPM_LIBS)
1035AC_SUBST(HAVE_XGNOKII)
1036AC_SUBST(WIN32)
1037AC_SUBST(WIN32_CROSS)
1038
1039AC_SUBST(HAVE_LIBICAL)
1040AC_SUBST(HAVE_LIBUSB)
1041AC_SUBST(HAVE_SOCKETPHONET)
1042
1043AC_OUTPUT(
1044	  Makefile
1045	  getopt/Makefile
1046	  Docs/Makefile
1047	  Docs/man/Makefile
1048	  Docs/protocol/Makefile
1049	  Docs/sample/Makefile
1050	  Docs/sample/logo/Makefile
1051	  Docs/sample/vCalendar/Makefile
1052	  Docs/sample/ringtone/Makefile
1053	  Docs/sample/ppp/Makefile
1054	  include/Makefile
1055	  include/gnokii.h
1056	  include/data/Makefile
1057	  include/devices/Makefile
1058	  include/phones/Makefile
1059	  include/links/Makefile
1060	  include/gnokii/Makefile
1061	  common/gnokii.pc
1062	  common/Makefile
1063	  common/data/Makefile
1064	  common/devices/Makefile
1065	  common/links/Makefile
1066	  common/phones/Makefile
1067	  gnokii/Makefile
1068	  gnokiid/Makefile
1069	  smsd/Makefile
1070	  utils/Makefile
1071	  xgnokii/xgnokii.pc
1072	  xgnokii/Makefile
1073	  xgnokii/xpm/Makefile
1074	  po/Makefile.in
1075	  testsuite/Makefile
1076	  testsuite/data/Makefile
1077	  Windows/Makefile
1078  )
1079
1080dnl ======================== Final report
1081
1082echo "
1083
1084  G N O K I I
1085
1086  A toolset and driver for the mobile phones.
1087
1088  Copyright (C) 1999-2011  The Gnokii Development Team.
1089
1090  This program is free software; you can redistribute it and/or modify
1091  it under the terms of the GNU General Public License as published by
1092  the Free Software Foundation; either version 2 of the License, or
1093  (at your option) any later version.
1094
1095  See file COPYING for more details.
1096
1097    Host system:        $host_os
1098    Gnokii version:     $VERSION
1099    Xgnokii version:    $XVERSION
1100    SMSD version:       $SVERSION
1101    X (GTK+) support:   $x_support
1102    smsd support:       $enable_smsd
1103    Postgres support:   $have_postgres
1104    SQLite support:     $have_sqlite
1105    MySQL support:      $have_mysql
1106    Debug:              $debug
1107    XDebug:             $xdebug
1108    RLPDebug:           $rlpdebug
1109    NLS:                $USE_NLS
1110    IrDA:               $USE_IRDA
1111    ical read support:  $USE_LIBICAL
1112    Bluetooth:          $USE_BLUETOOTH
1113    libusb support:     $USE_LIBUSB
1114    phonet support:     $USE_SOCKETPHONET
1115    libpcsclite support:$USE_LIBPCSCLITE
1116    readline support:   $USE_READLINE
1117    Security:           $security
1118    Build Shared Lib:   $enable_shared
1119    Build Static Lib:   $enable_static
1120    Windows:            $win32
1121    Prefix:             $prefix
1122
1123  Type '${MAKE}' for compilation and then '${MAKE} install', to
1124  install gnokii.
1125"
1126
1127
1128