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