Sun Mar 11 15:22:42 CET 2007 Jochen Eisinger <coffee@silcnet.org>
[silc.git] / apps / irssi / configure.in
1 AC_INIT(src)
2
3 # we don't want VERSION in our config.h
4 if test -n "`grep '^#undef VERSION' config.h.in`"; then
5   grep -v '^#undef VERSION' config.h.in > config.h.in.temp
6   mv -f config.h.in.temp config.h.in
7 fi
8
9 AM_CONFIG_HEADER(config.h)
10 AM_INIT_AUTOMAKE(SILC-Client, 0.8.11+)
11
12 AM_MAINTAINER_MODE
13
14 AC_ISC_POSIX
15 AC_PROG_CC
16 AC_PROG_CPP
17 AC_STDC_HEADERS
18 AM_PROG_LIBTOOL
19
20 AC_PATH_PROG(sedpath, sed)
21 AC_PATH_PROG(perlpath, perl)
22
23 dnl * --disable-static isn't a good idea, complain if it's used
24 if test "x$enable_static" = "xno"; then
25         AC_ERROR([Don't give --disable-static option to configure])
26 fi
27
28 AC_CHECK_HEADERS(string.h stdlib.h unistd.h dirent.h sys/ioctl.h sys/resource.h)
29
30 # check posix headers..
31 AC_CHECK_HEADERS(sys/time.h sys/utsname.h)
32
33 AC_ARG_WITH(socks,
34 [  --with-socks            Build with socks support],
35         if test x$withval = xyes; then
36                 want_socks=yes
37         else
38                 if test "x$withval" = xno; then
39                         want_socks=no
40                 else
41                         want_socks=yes
42                 fi
43         fi,
44         want_socks=no)
45
46 AC_ARG_WITH(textui,
47 [  --with-textui           Build text frontend],
48         if test x$withval = xyes; then
49                 want_textui=yes
50         else
51                 if test "x$withval" = xno; then
52                         want_textui=no
53                 else
54                         want_textui=yes
55                 fi
56         fi,
57         want_textui=yes)
58
59 AC_ARG_WITH(bot,
60 [  --with-bot              Build irssi-bot],
61         if test x$withval = xyes; then
62                 want_irssibot=yes
63         else
64                 if test "x$withval" = xno; then
65                         want_irssibot=no
66                 else
67                         want_irssibot=yes
68                 fi
69         fi,
70         want_irssibot=no)
71
72 AC_ARG_WITH(proxy,
73 [  --with-proxy            Build irssi-proxy],
74         if test x$withval = xyes; then
75                 want_irssiproxy=yes
76         else
77                 if test "x$withval" = xno; then
78                         want_irssiproxy=no
79                 else
80                         want_irssiproxy=yes
81                 fi
82         fi,
83         want_irssiproxy=no)
84
85 AC_ARG_WITH(terminfo,
86 [  --with-terminfo         Use terminfo directly instead of curses],
87         if test x$withval = xyes; then
88                 want_terminfo=yes
89         else
90                 if test "x$withval" = xno; then
91                         want_terminfo=no
92                 else
93                         want_terminfo=yes
94                 fi
95         fi,
96         want_terminfo=yes)
97
98 AC_ARG_WITH(cuix,
99 [  --with-cuix             Use curses ui extended],
100     if test x$withval = xyes; then
101             want_terminfo=no
102             want_cuix=yes
103     fi, want_cuix=no)
104
105 AC_ARG_WITH(modules,
106 [  --with-modules          Specify what modules to build in binary],
107         if test x$withval != xyes -a x$withval != xno; then
108                 build_modules="$withval"
109         fi)
110
111 if test "x$prefix" != "xNONE"; then
112         prefix=`eval echo $prefix`
113         PERL_MM_PARAMS="INSTALLDIRS=perl PREFIX=$prefix"
114         perl_library_dir="PERL_USE_LIB"
115         perl_set_use_lib=yes
116
117         perl_prefix_note=yes
118 fi
119
120 AC_ARG_WITH(glib1,
121 [  --with-glib1            Use GLIB 1.2 instead of 2.0 if both exist],
122         if test x$withval = xyes; then
123                 want_glib1=yes
124         else
125                 if test "x$withval" = xno; then
126                         want_glib1=no
127                 else
128                         want_glib1=yes
129                 fi
130         fi,
131         want_glib1=no)
132
133 AC_ARG_WITH(perl-staticlib,
134 [  --with-perl-staticlib   Specify that we want to link perl libraries
135                         statically in irssi, default is no],
136         if test x$withval = xyes; then
137                 want_staticperllib=yes
138         else
139                 if test "x$withval" = xno; then
140                         want_staticperllib=no
141                 else
142                         want_staticperllib=yes
143                 fi
144         fi,
145         want_staticperllib=no)
146
147
148 AC_ARG_WITH(perl-lib,
149 [  --with-perl-lib=[site|vendor|DIR]  Specify where to install the
150                         Perl libraries for irssi, default is site],
151         if test "x$withval" = xyes; then
152                 want_perl=yes
153         elif test "x$withval" = xno; then
154                 want_perl=no
155         elif test "x$withval" = xsite; then
156                 want_perl=yes
157                 perl_prefix_note=no
158                 PERL_MM_PARAMS=""
159         elif test "x$withval" = xvendor; then
160                 want_perl=yes
161                 perl_prefix_note=no
162                 if test -z "`$perlpath -v|grep '5\.0'`"; then
163                         PERL_MM_PARAMS="INSTALLDIRS=vendor"
164                 else
165                         PERL_MM_PARAMS="INSTALLDIRS=perl PREFIX=`perl -e 'use Config; print $Config{prefix}'`"
166                 fi
167                 perl_library_dir="(vendor default - `$perlpath -e 'use Config; print $Config{archlib}'`)"
168         else
169                 want_perl=yes
170                 perl_prefix_note=no
171                 PERL_MM_PARAMS="INSTALLDIRS=perl LIB=$withval"
172                 perl_library_dir="PERL_USE_LIB"
173                 perl_set_use_lib=yes
174         fi,
175         want_perl=yes)
176
177 AC_ARG_WITH(perl,
178 [  --with-perl[=yes|no|module]  Build with Perl support - also specifies
179                         if it should be built into main irssi binary
180                         (static, default) or as module],
181         if test x$withval = xyes; then
182                 want_perl=static
183         elif test x$withval = xstatic; then
184                 want_perl=static
185         elif test x$withval = xmodule; then
186                 want_perl=module
187         else
188                 want_perl=no
189         fi,
190         want_perl=static)
191
192 AC_ARG_WITH(file-offset-size,
193 [  --with-file-offset-size=BITS  Set size of file offsets. Usually 32 or 64.
194                           (default: 64 if available)],
195         preferred_off_t_bits=$withval,
196         preferred_off_t_bits=64)
197
198 AC_ARG_ENABLE(ipv6,
199 [  --enable-ipv6           Enable IPv6 support],
200         if test x$enableval = xyes; then
201                 want_ipv6=yes
202         else
203                 if test "x$enableval" = xno; then
204                         want_ipv6=no
205                 else
206                         want_ipv6=yes
207                 fi
208         fi,
209         want_ipv6=no)
210
211 dnl **
212 dnl ** just some generic stuff...
213 dnl **
214
215 dnl * OS specific options
216 case "$host_os" in
217   hpux*)
218     CFLAGS="$CFLAGS -D_XOPEN_SOURCE_EXTENDED"
219     ;;
220   *)
221     ;;
222 esac
223
224
225 AC_CHECK_FUNCS(mkfifo fcntl nl_langinfo)
226
227 AC_CHECK_FUNC(socket, [], [
228         AC_CHECK_LIB(socket, socket, [
229                 LIBS="$LIBS -lsocket"
230         ])
231 ])
232
233 AC_CHECK_FUNC(inet_addr, [], [
234         AC_CHECK_LIB(nsl, inet_addr, [
235                 LIBS="$LIBS -lnsl"
236         ])
237 ])
238
239 dnl * gcc specific options
240 if test "x$ac_cv_prog_gcc" = "xyes"; then
241   CFLAGS="$CFLAGS -Wall"
242 fi
243
244 dnl * socklen_t - AC_CHECK_TYPE() would be _really_ useful if it only would
245 dnl * accept header files where to find the typedef..
246 AC_MSG_CHECKING([for socklen_t])
247 AC_CACHE_VAL(irssi_cv_type_socklen_t,
248 [AC_TRY_COMPILE([
249 #include <sys/types.h>
250 #include <sys/socket.h>],
251 [socklen_t t;],
252 irssi_cv_type_socklen_t=yes,
253 irssi_cv_type_socklen_t=no,
254 )])
255 if test $irssi_cv_type_socklen_t = no; then
256 AC_DEFINE(socklen_t, int, Define to 'int' if <sys/socket.h> doesn't define.)
257 fi
258 AC_MSG_RESULT($irssi_cv_type_socklen_t)
259
260 dnl * off_t checks, try to make it 64bit
261 AC_DEFINE_UNQUOTED(_FILE_OFFSET_BITS, $preferred_off_t_bits)
262
263 AC_CHECK_SIZEOF(int)
264 AC_CHECK_SIZEOF(long)
265 AC_CHECK_SIZEOF(long long)
266 AC_CHECK_SIZEOF(off_t)
267
268 if test $ac_cv_sizeof_off_t = 8; then
269   offt_64bit=yes
270 else
271   offt_64bit=no
272 fi
273
274 if test x$ac_cv_sizeof_off_t = x$ac_cv_sizeof_long; then
275   # try to use unsigned long always first
276   AC_DEFINE_UNQUOTED(PRIuUOFF_T, "lu")
277   AC_DEFINE(UOFF_T_LONG, [], [UOFF_T_LONG])
278 elif test x$ac_cv_sizeof_off_t = x$ac_cv_sizeof_int; then
279   # next try int
280   AC_DEFINE_UNQUOTED(PRIuUOFF_T, "u")
281   AC_DEFINE(UOFF_T_INT, [], [UOFF_T_INT])
282 elif test x$ac_cv_sizeof_off_t = x$ac_cv_sizeof_long_long; then
283   # and finally long long
284   AC_DEFINE_UNQUOTED(PRIuUOFF_T, "llu")
285   AC_DEFINE(UOFF_T_LONG_LONG, [], [UOFF_T_LONG_LONG])
286 else
287   AC_ERROR([Couldn't find integer type for off_t])
288 fi
289
290 dnl **
291 dnl ** check for socks
292 dnl **
293
294 if test "x$want_socks" = "xyes"; then
295         AC_CHECK_LIB(socks, connect, [
296                 LIBS="$LIBS -lsocks"
297                 AC_CHECK_HEADER(socks.h, [
298                         AC_DEFINE(HAVE_SOCKS_H)
299                         CFLAGS="$CFLAGS -DSOCKS"
300                         AC_MSG_RESULT(["socks5 library found, building with it"])
301                 ], [
302                         AC_MSG_RESULT(["socks4 library found, building with it"])
303                         CFLAGS="$CFLAGS -Dconnect=Rconnect -Dgetsockname=Rgetsockname -Dgetpeername=Rgetpeername -Dbind=Rbind -Daccept=Raccept -Dlisten=Rlisten -Dselect=Rselect"
304                 ])
305         ])
306 fi
307
308 if test "x$want_cuix" = "xyes"; then
309     AC_DEFINE([HAVE_CUIX], [1] ,[Enable cuix support])
310 fi
311
312 dnl **
313 dnl ** fe-text checks
314 dnl **
315
316 AC_DEFUN(AC_CHECK_GLIBDIR,[
317   AC_MSG_CHECKING([whether GLib is unpacked to irssi dir])
318
319   GLIB_DIR=`for d in *; do test -f $d/glib.h && echo $d; done`
320   if test -n "$GLIB_DIR"; then
321     dnl * glib in irssi directory, use it
322     AC_MSG_RESULT([yes, using it])
323
324     dnl * we have to do this at this point so we know what libs gmodule needs
325     if test ! -f $GLIB_DIR/.libs/libglib.a; then
326       echo
327       echo "configuring GLib ..."
328       echo
329       cd $GLIB_DIR
330       if test ! -f glib-config; then
331         ./configure
332       fi
333       ${MAKE-make}
334       cd ..
335       echo
336     fi
337
338     GLIB_LDEXTRA=`$GLIB_DIR/glib-config --libs gmodule|$sedpath -e 's/-lglib//' -e 's/-lgmodule//' -e 's,-L/usr/local/lib ,,'|$sedpath 's/ \+/ /g'`
339     full_glib_dir="`pwd`/$GLIB_DIR"
340     GLIB_CFLAGS="-I$full_glib_dir -I$full_glib_dir/gmodule"
341     if test -f $full_glib_dir/.libs/libglib.a; then
342       GLIB_LIBS="$full_glib_dir/.libs/libglib.a $GLIB_LDEXTRA"
343       if test -f $full_glib_dir/gmodule/.libs/libgmodule.a; then
344         GLIB_LIBS="$GLIB_LIBS $full_glib_dir/gmodule/.libs/libgmodule.a"
345         AC_DEFINE(HAVE_GMODULE)
346         have_gmodule=yes
347       fi
348     else
349       GLIB_LIBS="$full_glib_dir/libglib.a $GLIB_LDEXTRA"
350       if test -f $full_glib_dir/gmodule/libgmodule.a; then
351         GLIB_LIBS="$GLIB_LIBS $full_glib_dir/gmodule/libgmodule.a"
352         AC_DEFINE(HAVE_GMODULE)
353         have_gmodule=yes
354       fi
355     fi
356     AC_SUBST(GLIB_CFLAGS)
357     AC_SUBST(GLIB_LIBS)
358   else
359     AC_MSG_RESULT([no])
360   fi
361 ])
362
363 AC_CHECK_GLIBDIR
364
365 if test -z "$GLIB_DIR"; then
366   if test "x$want_glib1" = "xyes"; then
367     dnl * check only for glib1
368     checks="1 2"
369   else
370     dnl * check glib2 then glib1
371     checks="3 4 1 2"
372   fi
373
374   for try in $checks; do
375     glib_config_args=
376     if test $try = 1 -o $try = 3; then
377       glib_modules=gmodule
378     else
379       echo "*** trying without -lgmodule"
380       glib_modules=
381     fi
382     if test $try = 1 -o $try = 2; then
383       AM_PATH_GLIB(1.2.0,,, $glib_modules)
384     else
385       AM_PATH_GLIB_2_0(2.0.0,,, $glib_modules)
386     fi
387     if test "$GLIB_LIBS"; then
388       if test $glib_modules = gmodule; then
389         AC_DEFINE(HAVE_GMODULE)
390         have_gmodule=yes
391       fi
392       break
393     fi
394   done
395
396   if test -z "$GLIB_LIBS"; then
397     echo
398     echo "*** If you don't have GLIB, you can get it from ftp://ftp.gtk.org"
399     echo "*** If you can't install GLIB anywhere or if you don't want to,"
400     echo "*** you can just unpack it to Irssi's source directory and"
401     echo "*** Irssi will automatically compile and use it."
402     echo
403
404     glib_url=ftp://ftp.gtk.org/pub/gtk/v2.8/
405     glib_file=glib-2.8.3.tar.gz
406
407     dlcmd=
408     if test -n "`wget --version 2>/dev/null|grep -i wget`"; then
409       dlcmd="wget -c $glib_url$glib_file"
410     elif test -n "`ncftpget --version 2>/dev/null|grep -i ncftp`"; then
411       dlcmd="ncftpget -z $glib_url$glib_file"
412     elif test -n "`lynx --version 2>/dev/null|grep -i lynx`"; then
413       dlcmd="lynx --source $glib_url$glib_file > $glib_file"
414     elif test -n "`curl --version 2>/dev/null|grep -i curl`"; then
415       dlcmd="curl -C - $glib_url$glib_file"
416     fi
417     if test -n "$dlcmd"; then
418       echo "*** I can download GLib for you now. If you don't want to, press CTRL-C now."
419       echo
420       echo "*** Press ENTER to continue"
421       read answer
422       eval $dlcmd
423       if `gunzip $glib_file`; then
424         glib_file=`echo $glib_file|$sedpath s/\.gz$//`
425         if `tar xf $glib_file`; then
426           rm -f $glib_file
427           AC_CHECK_GLIBDIR
428         fi
429       fi
430     fi
431
432     if test -z "$GLIB_LIBS"; then
433       AC_ERROR([GLIB is required to build irssi.])
434     fi
435   fi
436 fi
437
438 LIBS="$LIBS $GLIB_LIBS"
439
440 dnl **
441 dnl ** Recode
442 dnl **
443 AC_MSG_CHECKING([if we can use recode, requires GLIB2])
444 if test "$glib_config_major_version" = "2"; then
445   AC_DEFINE([HAVE_GLIB2], [], ["HAVE_GLIB2"])
446   AC_MSG_RESULT([yes])
447 else
448   AC_MSG_RESULT([no, using glib1])
449 fi
450
451 dnl **
452 dnl ** check if we can link dynamic libraries to modules
453 dnl ** also checks if libraries are built to .libs dir
454 dnl **
455
456 AC_MSG_CHECKING([if we can link dynamic libraries with modules])
457 DYNLIB_MODULES=no
458
459 dnl ** compile object file
460 cat > conftest.c <<EOF
461 #include <math.h>
462 int modfunc(){return (int)floor(1.2);}
463 EOF
464
465 ./libtool --mode=compile $CC $CFLAGS -c conftest.c 2> /dev/null > /dev/null
466 if test ! -s conftest.lo; then
467   AC_ERROR([error compiling test module])
468 fi
469
470 dnl ** link to library
471 ./libtool --mode=link $CC $CFLAGS $LDFLAGS -rpath /usr/lib conftest.lo -lm -o libconftest.la > /dev/null
472 if test ! -s .libs/libconftest.a; then
473   AC_ERROR([error, can't even find .a library])
474 fi
475
476 dnl ** check if dynamic linking worked
477 libfile=`grep '^library_names' libconftest.la|$sedpath "s/library_names='\(.*\)'.*/\1/"|$sedpath 's/.* \([[^ ]]*\)$/\1/'`
478 if test ! -s .libs/$libfile; then
479   AC_MSG_RESULT([no, error linking test module])
480 else
481   cat > conftest.c <<EOF
482 #include <gmodule.h>
483 main() {
484 GModule *m; int (*modfunc)(void);
485 m = g_module_open(".libs/$libfile", 0);
486 if (!m) g_print("error loading: %s", g_module_error());
487 else if (!g_module_symbol(m, "modfunc", (gpointer *) &modfunc))
488   g_print("modfunc() symbol not found from module");
489 else if (modfunc() == 1) g_print("ok"); else g_print("wrong result?! 1 vs %d", modfunc());
490 return 0; }
491 EOF
492   $CC $CFLAGS $LDFLAGS conftest.c -o conftest $GLIB_CFLAGS $GLIB_LIBS 2> /dev/null > /dev/null
493   if test ! -s conftest; then
494     AC_MSG_RESULT([no, error compiling test program])
495   else
496     status="`./conftest`"
497     if test "x$status" = "xok"; then
498       DYNLIB_MODULES=yes
499       AC_MSG_RESULT([yes])
500     else
501       AC_MSG_RESULT([no, error running: $status])
502     fi
503   fi
504 fi
505 rm -rf conftest conftest.* libconftest.* .libs
506
507 dnl **
508 dnl ** curses checks
509 dnl **
510
511 if test "x$want_textui" = "xyes"; then
512         AC_CHECK_CURSES
513
514         TEXTUI_LIBS="$LIBS $CURSES_LIBS"
515         if test "x$has_curses" = "xtrue"; then
516                 AC_CHECK_FUNC(use_default_colors, AC_DEFINE(HAVE_NCURSES_USE_DEFAULT_COLORS))
517                 AC_CHECK_FUNC(idcok, AC_DEFINE(HAVE_CURSES_IDCOK))
518                 AC_CHECK_FUNC(resizeterm, AC_DEFINE(HAVE_CURSES_RESIZETERM))
519                 AC_CHECK_FUNC(wresize, AC_DEFINE(HAVE_CURSES_WRESIZE))
520                 AC_CHECK_FUNC(setupterm,, [
521                         want_termcap=yes
522                 ])
523         else
524                 AC_CHECK_LIB(tinfo, setupterm, [
525                   TEXTUI_LIBS="$LIBS -ltinfo"
526                   want_terminfo=yes
527                 ], AC_CHECK_LIB(termlib, tgetent, [
528                   TEXTUI_LIBS="$LIBS -ltermlib"
529                   want_termcap=yes
530                 ], AC_CHECK_LIB(termcap, tgetent, [
531                   TEXTUI_LIBS="$LIBS -ltermcap"
532                   want_termcap=yes
533                 ], [
534                   AC_ERROR(Terminfo/termcap not found - install ncurses-devel package)
535                   want_textui=no
536                 ])))
537         fi
538         AC_SUBST(TEXTUI_LIBS)
539         if test "x$want_termcap" = "xyes"; then
540                 AC_CHECK_FUNC(tparm,, need_tparm=yes)
541         else
542                 AC_DEFINE(HAVE_TERMINFO)
543         fi
544 fi
545
546 dnl **
547 dnl ** perl checks
548 dnl **
549
550 if test "$want_perl" != "no"; then
551         AC_MSG_CHECKING(for working Perl support)
552
553         if test -z "$perlpath"; then
554                 perl_check_error="perl binary not found"
555         else
556                 PERL_CFLAGS=`$perlpath -MExtUtils::Embed -e ccopts 2>/dev/null`
557         fi
558
559         if test "x$ac_cv_prog_gcc" = "xyes" -a -z "`echo $host_os|grep 'bsd\|linux'`"; then
560                 dnl * several systems have Perl compiled with native compiler
561                 dnl * but irssi is being compiled with GCC. Here we try to
562                 dnl * fix those command line options a bit so GCC won't
563                 dnl * complain about them. Normally there's only few options
564                 dnl * that we want to keep:
565                 dnl * -Ddefine -Uundef -I/path -fopt -mopt
566                 PERL_CFLAGS=`echo $PERL_CFLAGS | $perlpath -pe 's/^(.* )?-[^DUIfm][^ ]+/\1/g; s/^(.* )?\+[^ ]+/\1/g'`
567
568                 PERL_EXTRA_OPTS="CCCDLFLAGS=\"-fPIC\""
569                 AC_SUBST(PERL_EXTRA_OPTS)
570         fi
571
572         if test -z "$PERL_CFLAGS"; then
573                 if test -n "$perl_check_error"; then
574                         perl_check_error="Error getting perl CFLAGS"
575                 fi
576                 AC_MSG_RESULT([not found, building without Perl])
577                 want_perl=no
578         else
579                 PERL_LDFLAGS=`$perlpath -MExtUtils::Embed -e ldopts 2>/dev/null`
580
581                 dnl * Perl 5.004 and older use perl_xxx variables while
582                 dnl * later use PL_perl_xxx variables ..
583                 have_pl_perl=`$perlpath -e 'print $] < 5.005 ? "no" : "yes";'`
584                 if test "x$have_pl_perl" = "xyes"; then
585                         AC_DEFINE(HAVE_PL_PERL)
586                 fi
587
588                 if test "x$DYNLIB_MODULES" = "xno" -a "$want_perl" != "static"; then
589                         dnl * wanted perl as module, won't get it.
590                         want_perl=static
591                         perl_mod_error="Dynamic library dependencies don't work with modules"
592                 fi
593
594                 if test "$want_perl" != "static"; then
595                         dnl * dynaloader.a -> libperl_dynaloader.la
596                         DYNALOADER_A=`echo $PERL_LDFLAGS | $perlpath -pe 's/^(.* )*([[^ ]]*DynaLoader\.a).*/\2/'`
597                 fi
598
599                 dnl * don't check libperl.a if dynaloader.a wasn't found..
600                 if test -n "$DYNALOADER_A"; then
601                         dnl * find either libperl.a or libperl.so
602                         LIBPERL_A=`echo "$PERL_LDFLAGS -L/usr/lib"|$perlpath -e 'foreach (split(/ /, <STDIN>)) { if (/^-L(.*)/) { my $dir=$1; if (\`ls $dir/libperl.so* 2>/dev/null\`) { print "-lperl"; last; }; if (-e "$dir/libperl.a") { print "$dir/libperl.a"; last } } };'`
603                         if test -z "$LIBPERL_A"; then
604                                 perl_mod_error="Didn't find location of -lperl"
605                                 DYNALOADER_A=
606                         elif test "$LIBPERL_A" = "-lperl"; then
607                                 LIBPERL_A=
608                         fi
609                 fi
610
611                 dnl * remove all database stuffs
612                 dnl * nsl is already in ldflags
613                 dnl * libc is of course linked without needing -lc
614                 dnl * -rdynamic must not be in LIBADD line
615                 for word in -ldb -ldbm -lndbm -lgdbm -lc -rdynamic; do
616                   PERL_LDFLAGS=`echo $PERL_LDFLAGS | $sedpath -e "s/$word //" -e "s/$word$//"`
617                 done
618
619                 case "$host_os" in
620                   linux*)
621                     PERL_LDFLAGS=`echo $PERL_LDFLAGS | $sedpath -e 's/-lposix //' -e 's/-lposix$//'`
622                     ;;
623                   hpux*)
624                     if test "x$ac_cv_prog_gcc" = "xyes"; then
625                       PERL_CFLAGS=`echo $PERL_CFLAGS | $sedpath -e 's/-Ae //' -e 's/-Ae$//'`
626                       PERL_LDFLAGS=`echo $PERL_LDFLAGS | $sedpath -e 's/-Ae //' -e 's/-Ae$//'`
627                     fi
628                     ;;
629                   *)
630                     ;;
631                 esac
632
633                 dnl * check that perl's ldflags actually work
634                 echo "main(){perl_alloc(); return 0;}" > conftest.c
635                 $CC $CFLAGS conftest.c -o conftest $LDFLAGS $PERL_LDFLAGS 2> perl.error.tmp > /dev/null
636                 if test ! -s conftest; then
637                         perl_check_error="Error linking with perl libraries: $PERL_LDFLAGS: `cat perl.error.tmp`"
638                         AC_MSG_RESULT([error linking with perl libraries, building without Perl])
639                         want_perl=no
640                 fi
641
642                 rm -f perl.error.tmp
643         fi
644
645         if test "x$want_perl" != "xno"; then
646                 if test "x$want_perl" = "xstatic"; then
647                         AC_MSG_RESULT(ok)
648                 elif test -z "$DYNALOADER_A"; then
649                         AC_MSG_RESULT([error parsing ldopts, building Perl into irssi binary instead of as module])
650                         want_perl=static
651                 else
652                         AC_MSG_RESULT(ok)
653                         PERL_LDFLAGS=`echo $PERL_LDFLAGS | $perlpath -pe 's/^(.* )*[[^ ]]*DynaLoader\.a/\1libperl_dynaloader.la/'`
654                         if test -n "$LIBPERL_A"; then
655                                 PERL_LDFLAGS=`echo $PERL_LDFLAGS | $sedpath -e 's/-lperl /libperl_orig.la /' -e 's/-lperl$/libperl_orig.la$/'`
656                         fi
657                         AC_SUBST(LIBPERL_A)
658                         AC_SUBST(DYNALOADER_A)
659                 fi
660
661                 if test "x$want_perl" = "xstatic"; then
662                         dnl * building with static perl support
663                         dnl * all PERL_LDFLAGS linking is done in fe-text
664                         PERL_LINK_FLAGS="$PERL_LDFLAGS"
665                         PERL_LINK_LIBS="../perl/libperl_core_static.la"
666                         PERL_FE_LINK_LIBS="../perl/libfe_perl_static.la"
667                         PERL_LDFLAGS=
668                         AC_DEFINE(HAVE_STATIC_PERL)
669
670                         dnl * build only static library of perl module
671                         perl_module_lib=
672                         perl_module_fe_lib=
673                         perl_static_lib=libperl_core_static.la
674                         perl_static_fe_lib=libfe_perl_static.la
675                         PERL_LIBTOOL='$(SHELL) $(top_builddir)/libtool'
676                 else
677                         dnl * build dynamic library of perl module
678                         perl_module_lib=libperl_core.la
679                         perl_module_fe_lib=libfe_perl.la
680                         perl_static_lib=
681                         perl_static_fe_lib=
682                         PERL_LIBTOOL='$(SHELL) $(top_builddir)/libtool'
683                 fi
684
685                 if test "x$want_staticperllib" = "xyes"; then
686                         PERL_MM_PARAMS="$PERL_MM_PARAMS LINKTYPE=static"
687                         PERL_LINK_LIBS="$PERL_LINK_LIBS ../perl/common/blib/arch/auto/Irssi/Irssi.a ../perl/irc/blib/arch/auto/Irssi/Irc/Irc.a ../perl/ui/blib/arch/auto/Irssi/UI/UI.a ../perl/textui/blib/arch/auto/Irssi/TextUI/TextUI.a"
688                         PERL_STATIC_LIBS=1
689                 else
690                         PERL_STATIC_LIBS=0
691                 fi
692
693                 # figure out the correct @INC path - we'll need to do this
694                 # through MakeMaker since it's difficult to get it right
695                 # otherwise.
696                 if test "x$perl_set_use_lib" = "xyes"; then
697                         perl -e 'use ExtUtils::MakeMaker; WriteMakefile("NAME" => "test", "MAKEFILE" => "Makefile.test");' $PERL_MM_PARAMS >/dev/null
698                         PERL_USE_LIB=`perl -e 'open(F, "Makefile.test"); while (<F>) { chomp; if (/^(\w+) = (.*$)/) { $keys{$1} = $2; } }; $key = $keys{INSTALLARCHLIB}; while ($key =~ /\\$\((\w+)\)/) { $value = $keys{$1}; $key =~ s/\\$\($1\)/$value/; }; print $key;'`
699                         rm -f Makefile.test
700                 fi
701
702                 AC_SUBST(perl_module_lib)
703                 AC_SUBST(perl_static_lib)
704                 AC_SUBST(perl_module_fe_lib)
705                 AC_SUBST(perl_static_fe_lib)
706                 AC_SUBST(PERL_LIBTOOL)
707
708                 AC_SUBST(PERL_LINK_FLAGS)
709                 AC_SUBST(PERL_LINK_LIBS)
710                 AC_SUBST(PERL_FE_LINK_LIBS)
711
712                 AC_SUBST(PERL_LDFLAGS)
713                 AC_SUBST(PERL_CFLAGS)
714
715                 AC_SUBST(PERL_USE_LIB)
716                 AC_SUBST(PERL_MM_PARAMS)
717                 AC_SUBST(PERL_STATIC_LIBS)
718         fi
719 fi
720
721 dnl ** check what we want to build
722 AM_CONDITIONAL(BUILD_TEXTUI, test "$want_textui" = "yes")
723 AM_CONDITIONAL(BUILD_IRSSIBOT, test "$want_irssibot" = "yes")
724 AM_CONDITIONAL(BUILD_IRSSIPROXY, test "$want_irssiproxy" = "yes")
725 AM_CONDITIONAL(BUILD_PLUGINS, test "$want_plugins" = "yes")
726 AM_CONDITIONAL(HAVE_PERL, test "$want_perl" != "no")
727 AM_CONDITIONAL(HAVE_STATIC_PERL, test "$want_perl" = "static")
728 AM_CONDITIONAL(NEED_TPARM, test "$need_tparm" = "yes")
729 AM_CONDITIONAL(USE_CURSES, test "$want_terminfo" != "yes" -a "$want_termcap" != "yes")
730 AM_CONDITIONAL(BUILD_SERVERTEST, false)
731 AM_CONDITIONAL(USE_CUIX, test "$want_cuix" = "yes")
732
733 # move LIBS to PROG_LIBS so they're not tried to be used when linking eg. perl libraries
734 PROG_LIBS=$LIBS
735 LIBS=
736 AC_SUBST(PROG_LIBS)
737
738 dnl **
739 dnl ** Keep all the libraries here so each frontend doesn't need to
740 dnl ** keep track of them all
741 dnl **
742 dnl ** (these could be made configurable)
743
744 CHAT_MODULES="silc"
745 silc_MODULES=""
746 if test -n "$build_modules"; then
747         silc_MODULES="$silc_MODULES $build_modules"
748 fi
749
750 dnl ****************************************
751
752 AC_SUBST(CHAT_MODULES)
753 AC_SUBST(silc_MODULES)
754
755 CORE_LIBS="../core/libcore.a ../lib-config/libirssi_config.a ../lib-popt/libpopt.a"
756 FE_COMMON_LIBS=""
757
758 CHAT_LIBS=""
759 for c in $CHAT_MODULES; do
760         module_inits=""
761         module_deinits=""
762         fe_module_inits=""
763         fe_module_deinits=""
764         CHAT_LIBS="$CHAT_LIBS ../$c/lib$c.a ../$c/core/lib${c}_core.a"
765         if test -f $srcdir/src/fe-common/$c/module.h; then
766                 FE_COMMON_LIBS="$FE_COMMON_LIBS../fe-common/$c/libfe_common_$c.a "
767         fi
768         for s in `eval echo \\$${c}_MODULES`; do
769                 CHAT_LIBS="$CHAT_LIBS ../$c/$s/lib${c}_$s.a"
770                 module_inits="$module_inits ${c}_${s}_init();"
771                 module_deinits="${c}_${s}_deinit(); $module_deinits"
772                 if test -f $srcdir/src/fe-common/$c/$s/module.h; then
773                         FE_COMMON_LIBS="$FE_COMMON_LIBS../fe-common/$c/$s/libfe_${c}_$s.a "
774                         fe_module_inits="$fe_module_inits fe_${c}_${s}_init();"
775                         fe_module_deinits="fe_${c}_${s}_deinit(); $fe_module_deinits"
776                 fi
777         done
778
779         file="$srcdir/src/$c/$c.c"
780         echo "/* this file is automatically generated by configure - don't change */" > $file
781         echo "void ${c}_core_init(void); void ${c}_core_deinit(void);" >> $file
782         if test -n "$module_inits"; then
783                 echo "$module_inits" | $sedpath -e 's/()/(void)/g' -e 's/ /void /g' >> $file
784                 echo "$module_deinits" | $sedpath -e 's/ *$//' -e 's/()/(void)/g' -e 's/ /void /g' -e 's/^/void /' >> $file
785         fi
786         echo "void ${c}_init(void) { ${c}_core_init(); $module_inits }" >> $file
787         echo "void ${c}_deinit(void) { $module_deinits ${c}_core_deinit(); }" >> $file
788
789         if test -f $srcdir/src/fe-common/$c/module.h; then
790                 file="$srcdir/src/fe-common/$c/${c}-modules.c"
791                 echo "/* this file is automatically generated by configure - don't change */" > $file
792                 if test -n "$fe_module_inits"; then
793                         echo "$fe_module_inits" | $sedpath -e 's/()/(void)/g' -e 's/ /void /g' >> $file
794                         echo "$fe_module_deinits" | $sedpath -e 's/ *$//' -e 's/()/(void)/g' -e 's/ /void /g' -e 's/^/void /' >> $file
795                 fi
796                 echo "void fe_${c}_modules_init(void) { $fe_module_inits }" >> $file
797                 echo "void fe_${c}_modules_deinit(void) { $fe_module_deinits }" >> $file
798         fi
799 done
800
801 FE_COMMON_LIBS="$FE_COMMON_LIBS../fe-common/core/libfe_common_core.a"
802
803 dnl ** common libraries needed by frontends
804 COMMON_NOUI_LIBS="$CHAT_LIBS $CORE_LIBS"
805 COMMON_LIBS="$FE_COMMON_LIBS $COMMON_NOUI_LIBS"
806 AC_SUBST(COMMON_NOUI_LIBS)
807 AC_SUBST(COMMON_LIBS)
808
809 dnl **
810 dnl ** IPv6 support
811 dnl **
812
813 if test "x$want_ipv6" = "xyes"; then
814         AC_MSG_CHECKING([for IPv6])
815         AC_CACHE_VAL(irssi_cv_type_in6_addr,
816         [AC_TRY_COMPILE([
817         #include <sys/types.h>
818         #include <sys/socket.h>
819         #include <netinet/in.h>
820         #include <netdb.h>
821         #include <arpa/inet.h>],
822         [struct in6_addr i;],
823         irssi_cv_type_in6_addr=yes,
824         irssi_cv_type_in6_addr=no,
825         )])
826         if test $irssi_cv_type_in6_addr = yes; then
827                 AC_DEFINE(HAVE_IPV6)
828         fi
829         AC_MSG_RESULT($irssi_cv_type_in6_addr)
830 fi
831
832 dnl **
833 dnl ** IRSSI_VERSION_DATE and IRSSI_VERSION_TIME
834 dnl **
835 #VERSION_DATE=`head -1 $srcdir/ChangeLog|sed 's/^\(....\)-\(..\)-\(..\).*/\1\2\3/'`
836 #VERSION_TIME=`head -1 $srcdir/ChangeLog|sed -e 's/^[[^ ]]* \(..\):\(..\).*/\1\2/' -e 's/^0*//'`
837 #AC_SUBST(VERSION_DATE)
838 #AC_SUBST(VERSION_TIME)
839
840 #
841 # Glue into SILC build system
842 #
843 INCLUDE_DEFINES_INT="include \$(top_srcdir)/Makefile.defines_int"
844 AC_SUBST(INCLUDE_DEFINES_INT)
845
846 AC_OUTPUT(
847 Makefile
848 src/Makefile
849 src/core/Makefile
850 src/fe-common/Makefile
851 src/fe-common/core/Makefile
852 src/fe-common/silc/Makefile
853 src/fe-text/Makefile
854 src/lib-config/Makefile
855 src/lib-popt/Makefile
856 src/silc/Makefile
857 src/silc/core/Makefile
858 src/perl/Makefile
859 src/perl/common/Makefile.PL
860 src/perl/ui/Makefile.PL
861 src/perl/textui/Makefile.PL
862 src/perl/silc/Makefile.PL
863 scripts/Makefile
864 scripts/examples/Makefile
865 docs/Makefile
866 docs/help/Makefile
867 docs/help/in/Makefile
868 irssi-version.h
869 stamp.h
870 irssi.spec
871 irssi-config)
872
873 dnl ** for building from objdir
874 old_dir=`pwd` && cd $srcdir && whole_dir=`pwd` && cd $old_dir
875 if test "x$old_dir" != "x$whole_dir"; then
876         $LN_S $srcdir/irssi-version.h irssi-version.h
877
878         if test "x$want_perl" != "xno"; then
879                 subdirfiles=""
880                 for i in $whole_dir/src/perl/common $whole_dir/src/perl/irc $whole_dir/src/perl/ui $whole_dir/src/perl/textui; do
881                         subdirfiles=`echo $subdirfiles $i/typemap $i/module.h $i/*.pm $i/*.xs`
882                 done
883                 for file in $whole_dir/src/perl/*.[[ch]] $whole_dir/src/perl/libperl_orig.la $whole_dir/src/perl/libperl_dynaloader.la $subdirfiles; do
884                         link=`echo $file|$sedpath "s?$whole_dir/??"`
885                         rm -f $link
886                         $LN_S $file $link
887                 done
888         fi
889 fi
890
891 echo
892
893 if test "x$want_textui" = "xno"; then
894         text=no
895 elif test "x$want_termcap" = "xyes"; then
896         text="yes, using termcap"
897 elif test "x$want_terminfo" = "xyes"; then
898         text="yes, using terminfo"
899 else
900         text="yes, using curses"
901 fi
902 echo "Building text frontend ..... : $text"
903 echo "Building irssi bot ......... : $want_irssibot"
904 echo "Building irssi proxy ....... : $want_irssiproxy"
905 echo "Building with IPv6 support . : $want_ipv6"
906 if test "x$have_gmodule" = "xyes"; then
907         echo "Building with module support : yes"
908 else
909         echo "Building with module support : NO!! /LOAD will not work!"
910         echo " - You're missing gmodule (comes with glib) for some reason,"
911         echo "   or it doesn't work in your system."
912 fi
913
914 if test "x$want_perl" = "xstatic"; then
915         echo "Building with Perl support . : static (in irssi binary)"
916 elif test "x$want_perl" = "xmodule"; then
917         echo "Building with Perl support . : module"
918 else
919         if test -z "$perl_check_error"; then
920                 echo "Building with Perl support . : no"
921         else
922                 echo "Building with Perl support . : NO!"
923                 echo " - $perl_check_error"
924         fi
925 fi
926
927 if test "x$want_perl" != "xno" -a "x$perl_mod_error" != "x"; then
928         echo " - NOTE: Perl support will be compiled statically to irssi, not as"
929         echo "   a module as requested. Reason:"
930         echo "   $perl_mod_error"
931
932         if test -f /etc/debian_version; then
933                 echo " - Try: apt-get install libperl-dev"
934         fi
935 fi
936
937 if test "x$want_perl" != "xno"; then
938         if test "$perl_library_dir" = "PERL_USE_LIB"; then
939                 perl_library_dir=$PERL_USE_LIB
940         fi
941         if test -z "$perl_library_dir"; then
942                 perl_library_dir="(site default - `$perlpath -e 'use Config; print $Config{sitearch}'`)"
943         fi
944         echo "Perl library directory ..... : $perl_library_dir"
945         if test "x$perl_prefix_note" = "xyes"; then
946                 echo "  - NOTE: This was automatically set to the same directory you gave with"
947                 echo "  --prefix. If you want the perl libraries to install to their 'correct'"
948                 echo "  path, you'll need to give --with-perl-lib=site option to configure."
949                 echo "  Anyway, installing perl to this directory should work just as well."
950         fi
951 fi
952
953 echo "Install prefix ............. : $prefix"
954
955 echo
956 echo "If there was any problems, read the INSTALL file."