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