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