First version, development moved to 5110-connected machine
[gnokii.git] / configure.in
1 dnl
2 dnl  Makefile for the GNOKII tool suite.
3 dnl 
4 dnl  Copyright (C) 1999 Hugh Blemings & Pavel Janík ml.
5 dnl                2000 Karel Zak, Pawe³ Kot
6 dnl
7 dnl  $Id$
8 dnl
9
10 AC_INIT(gnokii/gnokii.c)
11
12 AC_CONFIG_AUX_DIR(config)
13
14 AC_CANONICAL_SYSTEM
15 AC_PREFIX_DEFAULT("/usr/local")
16
17 dnl ======================== Default setting
18 test -n "$CFLAGS"   || export CFLAGS="-O2 -Wall"
19 ALL_LINGUAS="cs de et fi nl sk pl it"
20
21 dnl ======================== Checks for programs.
22 AC_PROG_CC
23 AC_LANG_C
24 AC_PROG_CPP
25 AC_PROG_LEX
26 if test -z "$AR";then
27         AC_PATH_PROG(AR, ar, no)
28 fi
29 AC_PATH_PROG(RM, rm, no)
30 AC_PATH_PROG(FIND, find, no)
31 AC_CHECK_PROGS(MAKE, gmake make)
32 AC_PROG_INSTALL
33
34 dnl Let us have $prefix variable aviable here
35 test x"$prefix" = xNONE && prefix="$ac_default_prefix"
36
37 AC_ARG_WITH(cfg_model,
38         [  --with-cfg-model=5110   specifies the mobile phone model],,
39         [ with_cfg_model="5110" ])
40 AC_DEFINE_UNQUOTED(CONFIG_CFG_MODEL, "$with_cfg_model")
41 AC_ARG_WITH(cfg_port,
42         [  --with-cfg-port=/dev/ttyS0 specifies the mobile phone port],,
43         [ with_cfg_port="/dev/ttyS0" ])
44 AC_DEFINE_UNQUOTED(CONFIG_CFG_PORT, "$with_cfg_port")
45 AC_ARG_WITH(cfg_initlength,
46         [  --with-cfg-initlength=default specifies the mobile phone initlength],,
47         [ with_cfg_initlength="default" ])
48 AC_DEFINE_UNQUOTED(CONFIG_CFG_INITLENGTH, "$with_cfg_initlength")
49
50 AC_ARG_ENABLE(debug, 
51         [  --enable-debug          compile with debug code],
52         [ #CFLAGS="-g -Wall"
53           AC_DEFINE(DEBUG)
54           debug="yes" ],
55         [ debug="no"  ]
56 )
57
58 AC_ARG_ENABLE(xdebug,
59         [  --enable-xdebug         compile with xdebug code],
60         [ AC_DEFINE(XDEBUG)
61           xdebug="yes" ],
62         [ xdebug="no"  ]
63 )
64
65 AC_ARG_ENABLE(rlpdebug, 
66         [  --enable-rlpdebug       compile with RLP debug code],
67         [ AC_DEFINE(RLP_DEBUG)
68           rlpdebug="yes" ],
69         [ rlpdebug="no"  ]
70 )
71
72 dnl ======================== NLS support
73
74 LIBS=""
75 NLS_LIBS=""
76 NLS_CFLAGS=""
77
78 AC_ARG_WITH(libintl,
79         [  --with-libintl=DIR      specifies the base NLS],
80         [ if test "x$withval" = "xyes"; then
81                 AC_MSG_WARN(Usage is --with-libintl=DIR)
82           else
83                 NLS_LIBS="-L$withval/lib"
84                 NLS_CFLAGS="-I$withval/include"
85           fi
86         ]
87 )
88
89 AC_ARG_ENABLE(nls,
90         [  --enable-nls            force use of NLS],
91         [ USE_NLS=$enableval ],
92         [ USE_NLS=no ]
93 )
94
95 if test "$USE_NLS" = "yes"; then
96         AC_PROG_MAKE_SET
97         AC_CHECK_HEADERS(locale.h)
98         AC_CHECK_FUNCS(setlocale)
99         AC_SUBST(HAVE_LOCALE_H)  
100
101         CPPFLAGS="$CPPFLAGS $NLS_CFLAGS"
102         AC_TRY_CPP([#include <libintl.h>],
103                    [ AC_DEFINE(HAVE_LIBINTL_H)
104                      AC_MSG_RESULT([checking for libintl.h... yes]) ],
105                    [ AC_MSG_WARN(not found header file: libintl.h !!!)
106                      USE_NLS=no ]
107         )
108 fi
109
110 if test "$USE_NLS" = "yes"; then
111         AC_CHECK_FUNC(gettext,
112                       AC_DEFINE(HAVE_LIBINTL),
113                       AC_CHECK_LIB(intl, gettext,
114                                    [ NLS_LIBS="$NLS_LIBS -lintl"
115                                      AC_DEFINE(HAVE_LIBINTL) ],
116                                    [ AC_MSG_WARN(not found library: intl !!!)
117                                      USE_NLS=no ],
118                                    $NLS_LIBS
119                       )
120         )
121 fi
122
123 if test "$USE_NLS" = "yes"; then
124
125         AC_SUBST(HAVE_LIBINTL_H)
126         AC_SUBST(HAVE_LIBINTL)
127
128         dnl Handle localedir
129         LOCALEDIR='${prefix}/share/locale'
130         AC_ARG_WITH(locale-dir,
131                     [  --with-locale-dir=DIR   Location of the locale file(s)
132                         [PREFIX/share/locale]],
133                     [ if test x$withval = xyes; then
134                         AC_MSG_WARN(Usage is: --with-locale-dir=basedir)
135                       else
136                         if test x$withval = xno; then
137                                 AC_MSG_WARN(Usage is: --with-locale-dir=basedir)
138                         else
139                                 LOCALEDIR=$withval
140                         fi
141                       fi
142                     ]
143         )
144         AC_SUBST(LOCALEDIR)
145
146         AC_PATH_PROG(MSGFMT, msgfmt, $MSGFMT)
147         if test -n "$MSGFMT"; then
148                 AC_CHECK_FUNCS(dcgettext)
149                 AC_PATH_PROG(GMSGFMT, gmsgfmt, $MSGFMT)
150                 AC_PATH_PROG(XGETTEXT, xgettext, $XGETTEXT)
151                 AC_PATH_PROG(MSGMERGE, msgmerge, $MSGMERGE)
152
153                 dnl Test whether we really found GNU xgettext.
154                 if test -n "$XGETTEXT"; then
155                         if $XGETTEXT --omit-header /dev/null 2> /dev/null; then
156                                 : ;
157                         else
158                                 AC_MSG_RESULT([found xgettext program is not GNU xgettext; ignore it])
159                                 XGETTEXT=""
160                         fi
161                 fi
162
163                 dnl We add another test for comparing GNU xgettext with openwin xgettext
164                 if test -n "$XGETTEXT"; then
165                         if $XGETTEXT --help > /dev/null 2> /dev/null; then
166                                 : ;
167                         else
168                                 AC_MSG_RESULT([found xgettext program is not GNU xgettext; ignore it])
169                                 XGETTEXT=""
170                         fi
171                 fi
172
173                 dnl Test whether we really found GNU msgfmt.
174                 if test -n "$MSGFMT"; then
175                         if $MSGFMT < /dev/null 2> /dev/null; then
176                                 AC_MSG_RESULT([found msgfmt program is not GNU msgfmt; NLS will not be installed])
177                                 MSGFMT=""
178                         fi
179                 fi
180
181                 AC_TRY_LINK(,
182                             [ extern int _nl_msg_cat_cntr;
183                               return _nl_msg_cat_cntr],
184                             [ CATOBJEXT=.gmo
185                               DATADIRNAME=share],  
186                             [ CATOBJEXT=.mo
187                               DATADIRNAME=lib]
188                 )
189                 INSTOBJEXT=.mo
190         fi
191
192         if test -n "$ALL_LINGUAS"; then
193                 for lang in $ALL_LINGUAS; do
194                         CATALOGS="$CATALOGS $lang$CATOBJEXT"
195                 done
196         fi
197         AC_SUBST(CATALOGS)
198         AC_SUBST(CATOBJEXT)
199         AC_SUBST(INSTOBJEXT)
200         AC_SUBST(DATADIRNAME)
201 fi
202
203 dnl don't use NLS, when there is no gettext installed
204 if test x"$MSGFMT" = x; then
205         USE_NLS=no
206 fi
207
208 if test x"$USE_NLS" = xyes; then
209         AC_DEFINE(USE_NLS)
210 fi
211
212 dnl ======================== Checks for libraries.
213
214 AC_ARG_WITH(libpthread, 
215    [  --with-libpthread=DIR   specifies the base libpthread],
216    [ if test x$withval = xyes
217      then 
218       AC_MSG_WARN(Usage is: --with-libpthread=DIR)
219      else
220       PTHREAD_LIBS="-L$withval/lib/"
221       PTHREAD_CFLAGS="-I$withval/include/"
222      fi
223    ]
224 )
225
226 dnl Check for libpthread
227 PTHREAD_LIBS_SAVE="$PTHREAD_LIBS"
228 PTHREAD_LIBS=error
229 AC_CHECK_LIB(pthread, pthread_attr_init, [
230                       PTHREAD_CFLAGS="$PTHREAD_CFLAGS -D_REENTRANT"
231                       PTHREAD_LIBS="$PTHREAD_LIBS_SAVE -lpthread" ])
232
233 dnl FIXME: test this on *BSD and report results immediatelly to the ml please
234 dnl If it is not found, try to check for c_r (on FreeBSD)
235 if test "x$PTHREAD_LIBS" = xerror; then
236   AC_CHECK_LIB(c_r, pthread_attr_init, [
237                     PTHREAD_CFLAGS="$PTHREAD_CFLAGS -D_THREAD_SAFE"
238                     PTHREAD_LIBS="-pthread" ])
239 fi
240
241 dnl FIXME: do we really test here if libc contains this function?
242 if test "x$PTHREAD_LIBS" = xerror -a "x$cross_compiling" = xno; then
243    AC_CHECK_FUNC(pthread_attr_init, PTHREAD_LIBS="",
244       AC_MSG_ERROR(not found library: pthread !!!))
245 fi
246
247 dnl The following is taken from inn sources
248 AC_MSG_CHECKING(for tm_gmtoff in struct tm)
249 AC_TRY_LINK([#include <time.h>],
250         [struct tm t; t.tm_gmtoff = 0],
251         [AC_MSG_RESULT(yes)
252          AC_DEFINE(HAVE_TM_GMTON)],
253         [AC_MSG_RESULT(no)])
254
255 dnl The following is taken from inn sources
256 AC_MSG_CHECKING(for timersub)
257 AC_TRY_LINK([#include <sys/time.h>],
258         [timersub(NULL, NULL, NULL)],
259         [AC_DEFINE(HAVE_TIMEOPS)
260          AC_DEFINE(HAVE_TIMEOPS)
261          AC_MSG_RESULT(yes)],
262         [AC_MSG_RESULT(no)])
263
264 have_termios="no"
265 dnl Checking for setspeed in termios.h
266 AC_MSG_CHECKING(for cfsetspeed in termios.h)
267 AC_TRY_LINK([#include <termios.h>],
268         [struct termios t; cfsetspeed(&t, B9600);],
269         [AC_DEFINE(HAVE_CFSETSPEED)
270          have_termios="yes"
271          AC_MSG_RESULT(yes)],
272         AC_MSG_RESULT(no))
273
274 if test $have_termios = "no"; then
275    AC_MSG_CHECKING(for cfsetispeed and cfsetospeed in termios.h)
276    AC_TRY_LINK([#include <termios.h>],
277                [struct termios t; cfsetispeed(&t, B9600);  cfsetospeed(&t, B9600);],
278                [AC_DEFINE(HAVE_CFSETISPEED)
279                 AC_DEFINE(HAVE_CFSETOSPEED)
280                 have_termios="yes"
281                 AC_MSG_RESULT(yes)],
282                [AC_MSG_RESULT(no)])
283
284    if test $have_termios = "no"; then
285       AC_MSG_CHECKING(for c_ispeed and c_ospeed in struct termios)
286       AC_TRY_LINK([#include <termios.h>],
287                   [struct termios t; t.c_iflag = B9600; t.c_oflag = B9600;],
288                   [AC_DEFINE(HAVE_TERMIOS_CSPEED)
289                    AC_MSG_RESULT(yes)],
290                   [AC_MSG_RESULT(no)])
291    fi
292 fi
293
294 dnl ======================== Checks for getopt_long support 
295
296 AC_CHECK_HEADER(getopt.h, ,
297       [CFLAGS="$CFLAGS -I../getopt"])
298
299 AC_ARG_WITH(gnugetopt,
300    [  --with-getopt=DIR       specifies the getopt library location directory],
301    [ if test x$withval=yes; then
302         AC_MSG_WARN(Usage is: --with-getopt=DIR) 
303      else
304         GETOPT_LIBS="-L$withval"
305      fi
306    ]
307 )
308
309 OWN_GETOPT=""
310 AC_CHECK_FUNC(getopt_long, , [
311         LIBS="$LIBS $GETOPT_LIBS"
312            AC_CHECK_LIB(gnugetopt, getopt_long, LIBS="$LIBS -lgnugetopt",
313             OWN_GETOPT="1")])
314
315 dnl ======================== Checks for X base support 
316
317 if test "$no_x" = yes -o "$with_x" = "no"; then
318    x_support="no"
319    XPM_CFLAGS=""
320    XPM_LIBS=""
321    GTK_CFLAGS=""
322    GTK_LIBS=""
323 else
324    AC_PATH_X
325    CPPFLAGS="$CPPFLAGS -I$x_includes"
326    AC_CHECK_HEADERS(X11/xpm.h,
327                     [ XPMINC="yes" ],
328                     [ XPMINC="no" ])
329
330    if test "x$XPMINC" = "xno"; then
331       x_support="no"
332       XPM_CFLAGS=""
333       XPM_LIBS=""
334       GTK_CFLAGS=""
335       GTK_LIBS=""
336       AC_MSG_WARN(Cannot find include X11/xpm.h)
337       AC_MSG_WARN(Disabling xgnokii.)
338    elif test "x$x_libraries" = "xNONE"; then
339       x_support="no"
340       XPM_CFLAGS=""
341       XPM_LIBS=""
342       GTK_CFLAGS=""
343       GTK_LIBS=""
344       AC_MSG_WARN(Cannot find library libX11.)
345       AC_MSG_WARN(Disabling xgnokii.)
346    else
347       AC_CHECK_LIB(Xpm, XpmWriteFileFromXpmImage,
348             [ XPM_CFLAGS="-I$x_includes" XPM_LIBS="-L$x_libraries -lXpm -lX11"
349               AC_DEFINE(XPM) ],
350             AC_MSG_WARN(Cannot found library libXpm - disabling XPM support.),
351             [ -L$x_libraries -lX11 ]
352       )
353
354       AC_PATH_PROGS(GTK_CONFIG, gtk-config gtk12-config, no)
355       if test "$GTK_CONFIG" = no; then
356          x_support="no"
357          GTK_CFLAGS=""
358          GTK_LIBS=""
359          AC_MSG_WARN(Cannot find gtk-config.)
360          AC_MSG_WARN(Disabling xgnokii.)
361       else
362          GTK_CFLAGS=`$GTK_CONFIG --cflags`
363          GTK_LIBS=`$GTK_CONFIG --libs`
364          x_support="yes"   
365
366          XGNOKIIDIR='${prefix}/share'
367          XGNOKIIPATH=${prefix}/share
368          AC_ARG_WITH(xgnokiidir,
369             [  --with-xgnokiidir=DIR   specifies the base for xgnokii],
370             [ if test x$withval = xyes; then 
371                  AC_MSG_WARN(Usage is: --with-xgnokiilib=DIR)
372               else
373                  XGNOKIIDIR="$withval"
374                  XGNOKIIPATH="$withval"
375               fi
376             ]
377          )
378       fi
379    fi
380 fi
381
382 dnl ======================== Check for libsocket
383 AC_CHECK_LIB(socket, socket)
384
385 dnl ======================== Additional switches
386
387 AC_ARG_ENABLE(security, 
388    [  --enable-security       enable all security features ],
389    [ AC_DEFINE(SECURITY)
390      security="yes" ],
391    [ security="no"  ]
392 )
393
394 AC_ARG_ENABLE(win32, 
395    [  --enable-win32          if you want win32 suport ],
396    [ AC_DEFINE(WIN32)
397      win32="-DWIN32" ],
398    [ win32=""]
399 )
400
401 AC_CHECK_FUNC(grantpt,
402    [ AC_TRY_RUN([
403 #define  _XOPEN_SOURCE 500
404
405 #include <features.h>
406 #include <stdlib.h>
407 #include <sys/types.h>
408 #include <sys/stat.h>
409 #include <fcntl.h>
410 #include <unistd.h>
411
412 int main()
413 {
414         char *name = NULL;
415         int master, err;
416
417         master = open("/dev/ptmx", O_RDWR | O_NOCTTY | O_NONBLOCK);
418         if (master >= 0) {
419                 err = grantpt(master);
420                 err = err || unlockpt(master);
421                 if (!err) {
422                         name = ptsname(master);
423                 } else {
424                         exit(-1);
425                 }
426         } else {
427                 exit(-1);
428         }
429         close(master);
430         exit(0);
431 }
432                 ],
433                 AC_DEFINE(USE_UNIX98PTYS),
434                 AC_MSG_WARN("No unix98ptys"),
435                 AC_MSG_WARN("Ensure to disable unix98ptys when crosscompiling"))
436    ]
437 )
438
439 dnl ======================== Checks for header files.
440 AC_HEADER_STDC
441 AC_HEADER_SYS_WAIT
442 AC_CHECK_HEADERS(fcntl.h sys/ioctl.h sys/time.h unistd.h)
443
444 dnl ======================== Checks for typedefs, structures, and compiler characteristics.
445 AC_C_CONST
446 AC_C_INLINE
447 AC_TYPE_PID_T
448 AC_TYPE_SIZE_T
449 AC_HEADER_TIME
450 AC_STRUCT_TM
451
452 dnl ======================== Checks for library functions.
453 AC_PROG_GCC_TRADITIONAL
454 AC_FUNC_MEMCMP
455 AC_TYPE_SIGNAL
456 AC_FUNC_STRFTIME
457 AC_CHECK_FUNCS(mktime select strdup strstr strtol strtok strsep snprintf)
458
459 CFLAGS="$CFLAGS $NLS_CFLAGS"
460 LIBS="$LIBS $NLS_LIBS"
461
462 PACKAGE=gnokii
463 XPACKAGE=xgnokii
464 AC_DEFINE_UNQUOTED(VERSION, "`cat VERSION`")
465 AC_DEFINE_UNQUOTED(XVERSION, "`cat xgnokii/VERSION`")
466 HAVE_XGNOKII=$x_support
467
468 case "$INSTALL" in
469   'config/install-sh -c') INSTALL=`pwd`/$INSTALL
470    ;;
471 esac
472
473 SHELL=${CONFIG_SHELL-/bin/sh}
474
475 AC_SUBST(SHELL)
476 case "$build_os" in
477   solaris*) SHELL=/bin/ksh
478    ;;
479 esac
480
481 AC_CONFIG_HEADER(include/config.h)
482
483 AC_SUBST(PACKAGE)
484 AC_SUBST(VERSION)
485 AC_SUBST(AR)
486 AC_SUBST(XVERSION)
487 AC_SUBST(XPACKAGE)
488 AC_SUBST(XGNOKIIDIR)
489 AC_SUBST(XGNOKIIPATH)
490 AC_SUBST(exec_prefix)
491 AC_SUBST(USE_NLS)
492 AC_SUBST(GTK_CFLAGS)
493 AC_SUBST(GTK_LIBS)
494 AC_SUBST(PTHREAD_CFLAGS)
495 AC_SUBST(PTHREAD_LIBS)
496 AC_SUBST(XPM_CFLAGS)
497 AC_SUBST(XPM_LIBS)
498 AC_SUBST(OWN_GETOPT)
499 AC_SUBST(USE_UNIX98PTYS)
500 AC_SUBST(HAVE_XGNOKII)
501
502 AC_OUTPUT(
503    Makefile.global
504    po/Makefile.in
505    packaging/RedHat/gnokii.spec
506    packaging/Slackware/SlackBuild,
507    [sed -e "/POTFILES =/r po/POTFILES" po/Makefile.in > po/Makefile]
508    )
509
510
511 dnl ======================== Final report
512
513 echo "
514
515   G N O K I I
516
517   A Linux/Unix toolset and driver for Nokia mobile phones.
518
519   Copyright (C) 1999-2000  The Gnokii Development Team.
520
521   This program is free software; you can redistribute it and/or modify
522   it under the terms of the GNU General Public License as published by
523   the Free Software Foundation; either version 2 of the License, or
524   (at your option) any later version.
525  
526   See file COPYING for more details.
527
528     Host system:        $host_os
529     Gnokii version:     $VERSION
530     Xgnokii version:    $XVERSION
531     X (GTK) support:    $x_support
532     Debug:              $debug
533     XDebug:             $xdebug
534     RLPDebug:           $rlpdebug
535     NLS:                $USE_NLS
536     Security:           $security
537     Win32:              $win32 
538     Prefix:             $prefix
539
540   Type '${MAKE}' for compilation or '${MAKE} makelib' when want to compile
541   all binaries with one shared library
542   
543   After it '${MAKE} install', '${MAKE} install-suid', '${MAKE} install-strip'
544   or '${MAKE} install-ss' to install gnokii.
545 "