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