1dnl ----------------------------------------------------------
24nl configure.in for ircii, 2.3.  copyright (c) matthew green, 1993,
3dnl except those bits attributed otherwise.
4dnl thanks to the screen 3.3 configure.in for giving me examples to
5dnl work from and steal ;)
6dnl
7
8AC_INIT([epic5],[2])
9AC_CONFIG_SRCDIR([source/irc.c])
10AC_CONFIG_HEADER([include/defs.h])
11AC_LANG(C)
12
13dnl ----------------------------------------------------------
14dnl
15dnl grok the version number - from source/irc.c
16dnl
17VERSION=`sed -n -e 's/";$//' -e '/const char irc_version.. = .EPIC.-/s///p' -e '/const char irc_version/q' < $srcdir/source/irc.c`
18AC_SUBST([VERSION])
19echo this is EPIC5 version $VERSION
20echo
21
22AC_PROG_CC
23AC_PROG_CPP
24
25dnl ----------------------------------------------------------
26AC_MSG_CHECKING([for an extra library directory])
27AC_ARG_WITH([localdir],
28[  --with-localdir=/usr/local        An extra directory to look for stuff.],[
29   if test "x$withval" = "x" ; then
30      if test -d /usr/local/lib ; then
31	withval="/usr/local"
32      elif test -d /usr/pkg/lib ; then
33	withval="/usr/pkg"
34      elif test -d /opt/lib ; then
35	withval="/opt"
36      fi
37   fi
38
39   if test "x$withval" != "x" && \
40      test -d "$withval"; then
41      with_extra_libdir="yes"
42   else
43      with_extra_libdir="no"
44   fi
45
46   if test "x$with_extra_libdir" = "xyes" ; then
47      LIBS="-L$withval/lib $LIBS"
48      CFLAGS="-I$withval/include/ $CFLAGS"
49      localdir=$withdir
50   fi
51],[
52   if test "x$withval" = "x" ; then
53      if test -d /usr/local/lib ; then
54	withval="/usr/local"
55      elif test -d /usr/pkg/lib ; then
56	withval="/usr/pkg"
57      elif test -d /opt/lib ; then
58	withval="/opt"
59      fi
60   fi
61
62   if test "x$withval" != "x" && \
63      test -d "$withval"; then
64      with_extra_libdir="yes"
65   else
66      with_extra_libdir="no"
67   fi
68
69   if test "x$with_extra_libdir" = "xyes" ; then
70      LIBS="-L$withval/lib $LIBS"
71      CFLAGS="-I$withval/include/ $CFLAGS"
72      localdir=$withdir
73   fi
74])
75AC_MSG_RESULT([$with_extra_libdir, $withval])
76
77dnl ----------------------------------------------------------
78dnl ----------------------------------------------------------
79dnl
80dnl System specific checks
81dnl
82dnl ----------------------------------------------------------
83dnl ----------------------------------------------------------
84
85AC_CHECK_LIB([cext], [setenv], [LIBS="$LIBS -lcext"],)
86
87dnl
88dnl Checking for Macintosh OS X (Written by Zach)
89dnl Please note -- MAC OS X perl support only works with macports!
90dnl
91AC_MSG_CHECKING([for Macintosh OS X])
92( $CC --version 2>&1 | grep 'apple-darwin' > /dev/null ) && \
93       apple_compiler="yes" \
94       perl_arch_flags="$(perl -MExtUtils::Embed -e 'ccopts;print "\n"; ldopts' | grep -o -- '-arch [-_0-9a-zA-Z]*' | sort -u)" \
95       CFLAGS="$CFLAGS $perl_arch_flags"
96AC_MSG_RESULT([ok])
97
98
99
100dnl ----------------------------------------------------------
101AC_MSG_CHECKING([if you want threaded stdout])
102AC_ARG_WITH(threaded-stdout,
103[  --with-threaded-stdout[=yes]      Threaded stdout so the client doesn't block when gnu screen malfunctions.],[
104	if test "x$withval" = "x" ; then
105		with_threaded_stdout="no"
106	elif test "x$withval" = "xy" ; then
107		with_threaded_stdout="yes"
108		if [ "x$sun_compiler" = "xyes" ] ; then
109			CFLAGS="CFLAGS -mt"
110		else
111			CFLAGS="$CFLAGS -pthread"
112		fi
113	elif test "x$withval" = "xY" ; then
114		with_threaded_stdout="yes"
115		if [ "x$sun_compiler" = "xyes" ] ; then
116			CFLAGS="CFLAGS -mt"
117		else
118			CFLAGS="$CFLAGS -pthread"
119		fi
120	elif test "x$withval" = "xyes" ; then
121		with_threaded_stdout="yes"
122		if [ "x$sun_compiler" = "xyes" ] ; then
123			CFLAGS="CFLAGS -mt"
124		else
125			CFLAGS="$CFLAGS -pthread"
126		fi
127	elif test "x$withval" = "xYES" ; then
128		with_threaded_stdout="yes"
129		if [ "x$sun_compiler" = "xyes" ] ; then
130			CFLAGS="CFLAGS -mt"
131		else
132			CFLAGS="$CFLAGS -pthread"
133		fi
134	else
135		with_threaded_stdout="no"
136	fi
137],[
138	with_threaded_stdout="no"
139])
140AC_MSG_RESULT($with_threaded_stdout)
141if test "x$with_threaded_stdout" = "xyes" ; then
142	AC_DEFINE([WITH_THREADED_STDOUT], 1, [Define this if you want to use threaded stdout])
143	threading=1
144fi
145
146
147dnl ----------------------------------------------------------
148dnl   Where does this belong?
149AC_MSG_CHECKING([which multiplexer function to use])
150AC_ARG_WITH(multiplex,
151[  --with-multiplex[=TYPE]           Multiplexer type (select,poll,freebsd-kqueue,pthread,solaris-ports)],[
152	if test "x$withval" = "x"; then
153		with_multiplex="select"
154	elif test "x$withval" = "xselect"; then
155		with_multiplex="select"
156	elif test "x$withval" = "xpoll"; then
157		with_multiplex="poll"
158	elif test "x$withval" = "xfreebsd-kqueue"; then
159		with_multiplex="kqueue"
160	elif test "x$withval" = "xsolaris-ports"; then
161		with_multiplex="port_create"
162	elif test "x$withval" = "xpthread"; then
163		with_multiplex="pthread_create"
164		if [ "x$sun_compiler" = "xyes" ] ; then
165			CFLAGS="CFLAGS -mt"
166		else
167			CFLAGS="$CFLAGS -pthread"
168		fi
169	else
170		with_multiplex="select"
171	fi
172],[
173	with_multiplex="select"
174])
175AC_MSG_RESULT($with_multiplex)
176AC_CHECK_FUNC($with_multiplex, [
177	if test "x$with_multiplex" = "xselect" ; then
178		AC_DEFINE([USE_SELECT], 1, [Define this if you want to use select as the multiplexer])
179		threading=0
180	elif test "x$with_multiplex" = "xpoll" ; then
181		AC_DEFINE([USE_POLL], 1, [Define this if you want to use poll as the multiplexer])
182		threading=0
183	elif test "x$with_multiplex" = "xkqueue" ; then
184		AC_DEFINE([USE_FREEBSD_KQUEUE], 1, [Define this if you want to use freebsd kqueue() as the multiplexer])
185		threading=0
186	elif test "x$with_multiplex" = "xport_create" ; then
187		AC_DEFINE([USE_SOLARIS_PORTS], 1, [Define this if you want to use Solaris ports as the multiplexer])
188		threading=0
189	elif test "x$with_multiplex" = "xpthread_create" ; then
190		AC_DEFINE([USE_PTHREAD], 1, [Define this if you want to use pthreads as the multiplexer])
191		threading=1
192	fi
193],[
194	AC_DEFINE([USE_SELECT], 1, [Define this if you want to use select as the multiplexer])
195	threading=0
196])
197
198
199dnl ----------------------------------------------------------
200dnl
201dnl Check for libraries before we check for functions!
202dnl
203
204if test -z "$libsocket"; then
205	AC_CHECK_LIB(socket, socket, LIBS="$LIBS -lsocket",)
206fi
207
208dnl Check to see if libarchive actually works
209dnl XXX I don't understand why this is even necessary.
210AC_ARG_WITH([libarchive], [  --without-libarchive              Disable libarchive support.],
211	[], [with_libarchive=maybe])
212if test "x$with_libarchive" != "xno" ; then
213	have_libarchive=""
214	orig_LIBS="$LIBS"
215	AC_CHECK_LIB(archive, archive_read_new, [LIBS="$LIBS -larchive"])
216	AC_MSG_CHECKING(whether libarchive works the way I expect)
217	AC_LINK_IFELSE([AC_LANG_PROGRAM([[
218			#include <archive.h>
219		]], [[
220			struct archive *x;
221			const char *s = "bogus.zip";
222			x = archive_read_new();
223			archive_read_support_format_all(x);
224			archive_read_open_file(x, s, 10240);
225		]])],
226		[have_libarchive="yes"])
227
228	if test "x$have_libarchive" = "x"; then
229		LIBS="$orig_LIBS"
230		AC_MSG_RESULT(no)
231		if test "x$with_libarchive" = "xyes" ; then
232			AC_MSG_ERROR([--with-libarchive was specified but libarchive could not be found.  Please install libarchive, or do not specify --with-libarchive.])
233                fi
234	else
235		AC_MSG_RESULT(yes)
236		AC_DEFINE([HAVE_LIBARCHIVE], 1, [Define this if you have a working libarchive])
237	fi
238fi
239
240dnl -----
241AC_ARG_WITH(ssl,
242[  --with-ssl[=PATH]                 Help me find your SSL installation (DIR is OpenSSL's install dir).],[
243	if test -z "$withval"; then
244		with_ssl="yes"
245	fi
246])
247
248AC_MSG_CHECKING(whether to include SSL support)
249if test "x$with_ssl" = "xno"; then
250	AC_MSG_RESULT(no)
251	AC_MSG_ERROR([You cannot explicitly turn off OpenSSL support any more.  This error is intentional.  Please remove --without-ssl and try again.])
252else
253	saved_LIBS="$LIBS"
254	saved_CFLAGS="$CFLAGS"
255
256	# First, let's see if the user overrode the openssl location
257	ssldir="$with_ssl"
258	if test "x$ssldir" != "x" -a "x$ssldir" != "xyes"; then
259	    if test -f "$ssldir/include/openssl/ssl.h" &&
260			test -f "$ssldir/lib/libssl.a"; then
261		LIBS="$saved_LIBS -L$ssldir/lib -lssl -lcrypto"
262	        CFLAGS="$saved_CFLAGS -I$ssldir/include"
263		AC_LINK_IFELSE([AC_LANG_PROGRAM([[
264				#include <openssl/ssl.h>
265			]], [[
266				SSL_library_init();
267			]])],
268			[have_ssl="yes"])
269	    fi
270
271	    if test "x$have_ssl" != "xyes"; then
272		AC_MSG_RESULT([no])
273		AC_MSG_ERROR([I could not find the OpenSSL installed at $with_ssl you asked me to use with --with-ssl=$with_ssl.  Please ensure that directory contains the files 'include/openssl/ssl.h' and 'lib/libssl.a'.  If you are unsure, remove --with-ssl and just let me auto-detect it.])
274	    fi
275	else
276		# Second, let's see if it just works by default
277		LIBS="$saved_LIBS -lssl -lcrypto"
278		CFLAGS="$saved_CFLAGS"
279		AC_LINK_IFELSE([AC_LANG_PROGRAM([[
280				#include <openssl/ssl.h>
281			]], [[
282				SSL_library_init();
283			]])],
284			[have_ssl="yes"])
285
286		# Otherwise, go hunting for it.
287		if test "x$have_ssl" = "x" ; then
288		    for ssldir in $localdir/ssl $localdir/openssl; do
289			if test "x$have_ssl" != "x"; then
290				break;
291			fi
292
293			if test "x$ssldir" = "x"; then
294				continue;
295			fi
296
297			if test -f "$ssldir/include/openssl/ssl.h" &&
298				test -f "$ssldir/lib/libssl.a"; then
299			    CFLAGS="$saved_CFLAGS -I$ssldir/include"
300			    LIBS="$saved_LIBS -L$ssldir/lib -lssl -lcrypto"
301			    AC_LINK_IFELSE([AC_LANG_PROGRAM([[
302					#include <openssl/ssl.h>
303				]], [[
304					SSL_library_init();
305				]])],
306				[have_ssl="yes"])
307			fi
308		    done
309		fi
310	fi
311
312	# If we found it somewhere, great!  Otherwise, revert.
313	if test ! -n "$have_ssl"; then
314		LIBS="$saved_LIBS"
315		CFLAGS="$saved_CFLAGS"
316		AC_MSG_RESULT([no])
317		if test "x$with_ssl" != "x"; then AC_MSG_ERROR([You requested SSL support, but OpenSSL was not found. Please supply a pathname to OpenSSL])
318		fi
319		AC_MSG_ERROR([I was unable to find OpenSSL.  If it is not installed, please install it.  If it is installed, please help me find it using --with-ssl=/usr/local or similar.])
320	else
321	    if test "x$threading" = "x1" ; then
322		AC_MSG_RESULT([yes])
323		AC_MSG_CHECKING([whether your SSL is threading compatable])
324		AC_RUN_IFELSE([AC_LANG_PROGRAM([[
325#define OPENSSL_THREAD_DEFINES
326#include <stdlib.h>
327#include <openssl/opensslconf.h>
328]],[[
329#if defined(THREADS)
330        return 0;
331#else
332        return 1;
333#endif
334]])],
335		AC_MSG_RESULT([yes])
336		AC_DEFINE([HAVE_SSL], 1, [Define this if you have a working ssl]),
337		AC_MSG_RESULT([no. Your system can not do SSL with pthreads]),:)
338	    else
339		AC_DEFINE([HAVE_SSL], 1, [Define this if you have a working ssl])
340		AC_MSG_RESULT([yes])
341	    fi
342	fi
343fi
344
345AC_CHECK_LIB(sun, getpwnam, LIBS="$LIBS -lsun",)
346AC_CHECK_LIB(dgc, inet_addr, LIBS="$LIBS -ldgc",)
347AC_CHECK_LIB(resolv, gethostbyname, LIBS="$LIBS -lresolv",)
348AC_CHECK_LIB(crypt, crypt, LIBS="$LIBS -lcrypt",)
349AC_CHECK_LIB(m, pow, LIBS="$LIBS -lm",)
350AC_CHECK_LIB(rt, clock_gettime, LIBS="$LIBS -lrt",)
351
352termcap=0;
353warn_again=0;
354AC_MSG_CHECKING(whether you want to use termcap instead of terminfo/ncurses)
355AC_ARG_WITH(termcap,
356[  --with-termcap                    Force use of termcap even if terminfo/ncurses is available ],
357[   AC_MSG_RESULT(yes)
358    AC_CHECK_LIB(termcap, tgetent, termcap=1;LIBS="-ltermcap $LIBS",
359      AC_CHECK_LIB(termlib, tgetent, termcap=1;LIBS="-ltermlib $LIBS",
360        AC_CHECK_LIB(curses,  tgetent, termcap=1;LIBS="-lcurses $LIBS",
361          AC_MSG_WARN(I cant find tgetent.  Youll have to help me.))))],
362[   AC_MSG_RESULT(no)
363    AC_CHECK_LIB(ncurses, setupterm, LIBS="-lncurses $LIBS",
364      AC_CHECK_LIB(tinfo,   setupterm, LIBS="-ltinfo $LIBS",
365	  AC_CHECK_LIB(curses, setupterm, LIBS="-lcurses $LIBS",
366	    AC_CHECK_LIB(curses, tgetent, termcap=1;LIBS="-lcurses $LIBS",
367              AC_CHECK_LIB(termlib, tgetent, termcap=1;LIBS="-ltermlib $LIBS",
368                AC_CHECK_LIB(termcap, tgetent, termcap=1;LIBS="-ltermcap $LIBS",
369	          AC_MSG_WARN(I cant find tgetent.  Youll have to help me.)
370		  warn_again=1))))))])
371
372dnl ----------------------------------------------------------
373dnl
374dnl Checking for headers, functions, and a type declarations
375dnl
376
377AC_CHECK_HEADERS(fcntl.h ieeefp.h inttypes.h math.h ndbm.h netdb.h regex.h stdargs.h stddef.h stdint.h sys/cdefs.h sys/fcntl.h sys/file.h sys/filio.h sys/select.h sys/sysctl.h sys/syslimits.h sys/time.h sys/un.h sys/param.h termios.h sys/termios.h xlocale.h,)
378if test $termcap -eq 0 ; then
379	AC_CHECK_HEADERS(term.h,)
380else
381	AC_CHECK_HEADERS(termcap.h,)
382fi
383
384AC_CHECK_FUNC(arc4random, AC_DEFINE([HAVE_ARC4RANDOM], 1, [Define this if you have arc4random()]),)
385AC_CHECK_FUNC(clock_gettime, AC_DEFINE([HAVE_CLOCK_GETTIME], 1, [Define if you have clock_gettime()]),)
386AC_CHECK_FUNC(fchdir, AC_DEFINE([HAVE_FCHDIR], 1, [Define if you have fchdir()]),)
387AC_CHECK_FUNC(fpathconf, AC_DEFINE([HAVE_FPATHCONF], 1, [Define if you have fpathconf()] ),)
388AC_CHECK_FUNC(getlogin, AC_DEFINE([HAVE_GETLOGIN], 1, [Define if you have getlogin()]),)
389AC_CHECK_FUNC(getaddrinfo, AC_DEFINE([HAVE_GETADDRINFO], 1, [Define if you have getaddrinfo()]),)
390AC_CHECK_FUNC(getnameinfo, AC_DEFINE([HAVE_GETNAMEINFO], 1, [Define if you have getnameinfo()]),)
391AC_CHECK_FUNC(getpass, AC_DEFINE([HAVE_GETPASS], 1, [Define if you have getpass()]),)
392AC_CHECK_FUNC(getpgid, AC_DEFINE([HAVE_GETPGID], 1, [Define if you have getpgid()]),)
393AC_CHECK_FUNC(getservbyport, AC_DEFINE([HAVE_GETSERVBYPORT], 1, [Define if you have getservbyport()]),)
394AC_CHECK_FUNC(gettimeofday, AC_DEFINE([HAVE_GETTIMEOFDAY], 1, [Define if you have gettimeofday()]),)
395AC_CHECK_FUNC(killpg, AC_DEFINE([HAVE_KILLPG], 1, [Define if you have killpg()]),)
396AC_CHECK_FUNC(memmove, AC_DEFINE([HAVE_MEMMOVE], 1, [Define if you have have_memmove()]),)
397AC_CHECK_FUNC(nanosleep, AC_DEFINE([HAVE_NANOSLEEP], 1, [Define if you have nanosleep()]),)
398AC_CHECK_FUNC(uname, AC_DEFINE([HAVE_UNAME], 1, [Define if you have uname()]),)
399AC_CHECK_FUNC(realpath, AC_DEFINE([HAVE_REALPATH], 1, [Define if you have realpath()]),)
400AC_CHECK_FUNC(setenv, AC_DEFINE([HAVE_SETENV], 1, [Define if you have setenv()]),)
401AC_CHECK_FUNC(setsid, AC_DEFINE([HAVE_SETSID], 1, [Define if you have setsid()]),)
402AC_CHECK_FUNC(tcsetpgrp, AC_DEFINE([HAVE_TCSETPGRP], 1, [Define if you have tcsetpgrp()]),)
403if test $termcap -eq 0 ; then
404	AC_CHECK_FUNC(setupterm, AC_DEFINE([HAVE_TERMINFO], 1, [Define if you have terminfo()]),)
405fi
406AC_CHECK_FUNC(snprintf, AC_DEFINE([HAVE_SNPRINTF], 1, [Define if you have snprintf()]),)
407AC_CHECK_FUNC(strerror, AC_DEFINE([HAVE_STRERROR], 1, [Define if you have strerror()]),)
408AC_CHECK_FUNC(strlcat, AC_DEFINE([HAVE_STRLCAT], 1, [Define if you have strlcat()]),)
409AC_CHECK_FUNC(strlcpy, AC_DEFINE([HAVE_STRLCPY], 1, [Define if you have strlcpy()]),)
410AC_CHECK_FUNC(strptime, AC_DEFINE([HAVE_STRPTIME], 1, [Define if you have strptime()]),)
411AC_CHECK_FUNC(strtoul, AC_DEFINE([HAVE_STRTOUL], 1, [Define if you have strtoul()]),)
412AC_CHECK_FUNC(sysconf, AC_DEFINE([HAVE_SYSCONF], 1, [Define if you have sysconf()]),)
413AC_CHECK_FUNC(sysctlbyname, AC_DEFINE([HAVE_SYSCTLBYNAME], 1, [Define if you have sysctlbyname()]),)
414AC_CHECK_FUNC(unsetenv, AC_DEFINE([HAVE_UNSETENV], 1, [Define if you have unsetenv()]),)
415AC_CHECK_FUNC(vsnprintf, AC_DEFINE([HAVE_VSNPRINTF], 1, [Define if you have vsnprintf()]),)
416AC_MSG_CHECKING(for isfinite)
417AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
418	#include <math.h>
419]],[[
420	int x = isfinite(0.0);
421	return 0;
422]])],
423   [ AC_MSG_RESULT(yes)
424     AC_DEFINE([HAVE_ISFINITE], 1, [Define if you have isfinite()]) ],
425   [ AC_MSG_RESULT(no) ])
426AC_CHECK_FUNC(finite, AC_DEFINE([HAVE_FINITE], 1, [Define if you have finite()]),)
427AC_CHECK_FUNC(tparm, AC_DEFINE([HAVE_TPARM], 1, [Define if you have tparm()]),)
428AC_CHECK_FUNC(newlocale, AC_DEFINE([HAVE_NEWLOCALE], 1, [Define if you have newlocale()]),)
429
430dnl -- Because someone is trying to use CentOS 5.11...
431AC_MSG_CHECKING(whether you are using a gnu libc that is so old it needs a hack to use newlocale)
432AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
433	#include <locale.h>
434	#include <xlocale.h>
435	#include <stdlib.h>
436]],[[
437	locale_t utf8_locale;
438	utf8_locale = newlocale(LC_ALL_MASK, "en_US.UTF-8", 0);
439	return 0;
440]])],
441   [ AC_MSG_RESULT(no, good) ],
442   [ AC_MSG_RESULT(yes, ugh.)
443     AC_MSG_CHECKING(whether we can fix that with _GNU_SOURCE)
444     AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
445	#define _GNU_SOURCE
446	#include <locale.h>
447	#include <xlocale.h>
448	#include <stdlib.h>
449     ]],[[
450	locale_t utf8_locale;
451	utf8_locale = newlocale(LC_ALL_MASK, "en_US.UTF-8", 0);
452	return 0;
453     ]])],
454     [ AC_MSG_RESULT(yes)
455       AC_DEFINE(NEWLOCALE_REQUIRES__GNU_SOURCE, 1, [Define this if newlocale() requires #define __GNU_SOURCE to work]) ],
456     [ AC_MSG_RESULT(no.  bummer for you)
457       AC_DEFINE(NEWLOCALE_DOESNT_WORK, 1, [Define this if newlocale() doesn't work the way I expect]) ], :), ], :)
458
459dnl -- Oh why does this have to be so painful? --
460AC_MSG_CHECKING(whether term.h works by itself)
461AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
462	#include <term.h>
463	#include <stdlib.h>
464]],[[
465       return 0;
466]])],
467	[ AC_MSG_RESULT(yes) ],
468	[ AC_MSG_RESULT(no)
469	  AC_MSG_CHECKING(whether term.h requires termio.h and curses.h)
470	  AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
471		#include <termio.h>
472		#include <curses.h>
473		#include <term.h>
474		#include <stdlib.h>
475	  ]],[[
476	       return 0;
477	  ]])],
478  	  [ AC_MSG_RESULT(yes)
479  	    AC_DEFINE([TERM_H_REQUIRES_CURSES_H], 1, [Define if <term.h> requires <curses.h> to be included first]) ],
480  	  [ AC_MSG_RESULT(no, ugh)
481  	    AC_DEFINE([DONT_USE_TERM_H], 1, [Define if <term.h> should be avoided]) ], :), ] :)
482
483AC_HEADER_TIME
484AC_HEADER_DIRENT
485AC_TYPE_MODE_T
486AC_TYPE_OFF_T
487AC_TYPE_PID_T
488AC_TYPE_SIZE_T
489AC_TYPE_SSIZE_T
490AC_TYPE_UID_T
491AC_FUNC_ALLOCA
492
493dnl ---------------------------------------------------------
494dnl
495dnl Check for a useful SO_SNDLOWAT.
496dnl Some systems (eg, linux) can be bothered to #define SO_SNDLOWAT
497dnl but can't be bothered to implement it, instead returning an error.
498dnl How completely bogus.  Don't #define it if you don't support it!
499dnl
500AC_MSG_CHECKING(for useful SO_SNDLOWAT)
501AC_RUN_IFELSE([AC_LANG_PROGRAM([[
502	#include <sys/types.h>
503	#include <sys/socket.h>
504	#include <stdlib.h>
505]],[[
506	#ifndef SO_SNDLOWAT
507		return 1;
508	#else
509		int d = socket(AF_INET, SOCK_STREAM, 0);
510		int size = 256;
511		if (setsockopt(d, SOL_SOCKET, SO_SNDLOWAT, &size, sizeof(size)) < 0)
512			return 1;
513		return 0;
514	#endif
515]])],
516  AC_MSG_RESULT(yes, your SO_SNDLOWAT is useful)
517  AC_DEFINE([HAVE_SO_SNDLOWAT], 1, [Define this if you have SO_SNDLOWAT]),
518  AC_MSG_RESULT(no, your SO_SNDLOWAT is broken and/or worthless), :)
519
520dnl ----------------------------------------------------------
521dnl
522dnl Check for a realpath() that works.
523dnl
524AC_MSG_CHECKING(for useful realpath)
525AC_RUN_IFELSE([AC_LANG_PROGRAM([[
526	#include <sys/param.h>
527	#include <stdlib.h>
528]],[[
529	char resolved_path[PATH_MAX];
530
531	if (realpath("/etc/filethatdoesnotexist", resolved_path) == 0)
532		return 1;
533	return 0;
534]])],
535  AC_MSG_RESULT(yes),
536  AC_MSG_RESULT(no, your realpath is broken and/or worthless)
537  AC_DEFINE([HAVE_BROKEN_REALPATH], 1, [Define this if your realpath() doesn't work for nonexistant files]), :)
538
539dnl ----------------------------------------------------------
540dnl
541dnl Check for sys_siglist declaration
542dnl
543
544AC_MSG_CHECKING(for sys_siglist declaration)
545AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
546	#include <sys/types.h>
547	#include <sys/signal.h>
548	#include <signal.h>
549	#include <unistd.h>
550	#include <stdlib.h>
551]],[[
552	char *s = sys_siglist[0];
553	return 0;
554]])],
555	[ AC_MSG_RESULT(yes)
556  	  AC_DEFINE([HAVE_SYS_SIGLIST], 1, [Define if you have sys_siglist]) ],
557  	[ AC_MSG_RESULT(no) ], :)
558
559dnl ------------------------------------------------------------------
560
561AC_TYPE_INT8_T
562AC_TYPE_UINT8_T
563AC_TYPE_INT16_T
564AC_TYPE_UINT16_T
565AC_TYPE_INT32_T
566AC_TYPE_UINT32_T
567AC_TYPE_INT64_T
568AC_TYPE_UINT64_T
569AC_TYPE_INTMAX_T
570AC_TYPE_UINTMAX_T
571AC_TYPE_INTPTR_T
572
573AC_CHECK_TYPE([socklen_t],
574	[AC_DEFINE([HAVE_SOCKLEN_T], 1, [Define if you have socklen_t])], ,
575	[[ #include <sys/socket.h> ]])
576
577AC_CHECK_TYPE([struct linger], ,
578	[AC_DEFINE([NO_STRUCT_LINGER], 1, [Define if you do not have struct linger])],
579	[[ #include <sys/socket.h> ]])
580
581dnl ----------------------------------------------------------
582dnl
583dnl It makes a big difference if your system's (struct sockaddr)
584dnl structures look like this:
585dnl
586dnl struct sockaddr {
587dnl     u_char     sa_len;
588dnl     u_char     sa_family;
589dnl     char       sa_data[14];
590dnl };
591dnl
592dnl 	or this
593dnl
594dnl struct sockaddr {
595dnl     u_short    sa_family;
596dnl     char       sa_data[14];
597dnl };
598dnl
599dnl so check for that here.
600dnl
601dnl -----------------------------------------------------------
602
603AC_MSG_CHECKING([to see if your struct sockaddr includes a length field])
604AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
605	#include <sys/types.h>
606	#include <sys/socket.h>
607	#include <stdlib.h>
608]],[[
609	struct sockaddr sa;
610	sa.sa_len = 0;
611	return 0;
612]])],
613  	[ AC_DEFINE([HAVE_SA_LEN], 1, [Define this if your struct sockaddr has a sa_len field])
614	  AC_MSG_RESULT([yes]) ],
615  	[ AC_MSG_RESULT([no]) ], :)
616
617dnl ----------------------------------------------------------
618dnl
619dnl checks for ipv6-related things
620dnl
621
622AC_MSG_CHECKING([whether to support ipv6])
623AC_ARG_WITH(ipv6,
624[  --without-ipv6                    Refuse to support IPv6],[
625	if test "x$withval" = "xno" ; then
626		AC_MSG_RESULT([no])
627		AC_DEFINE([DO_NOT_USE_IPV6], 1, [Define this if ipv6 was forbidden by user])
628	else
629		AC_MSG_RESULT([yes])
630	fi
631],[AC_MSG_RESULT([yes])])
632
633AC_CHECK_TYPE([struct sockaddr_storage],
634	[AC_DEFINE([HAVE_STRUCT_SOCKADDR_STORAGE], 1, [Define if you have struct sockaddr_storage])], ,
635	[[ #include <sys/socket.h> ]])
636AC_CHECK_TYPE([struct sockaddr_in6],
637	[AC_DEFINE([HAVE_STRUCT_SOCKADDR_IN6], 1, [Define if you have struct sockaddr_in6])], ,
638	[[ #include <netinet/in.h> ]])
639AC_CHECK_TYPE([struct addrinfo],
640	[AC_DEFINE([HAVE_STRUCT_ADDRINFO], 1, [Define if you have struct addrinfo])], ,
641	[[ #include <netdb.h> ]])
642
643dnl ----------------------------------------------------------
644dnl
645dnl Some implementations of getaddrinfo (*cough*KAME*cough*) don't
646dnl support the AF_UNIX protocol family.  For these partially incomplete
647dnl implementations, we must add our own support in a wrapper.
648dnl
649
650AC_MSG_CHECKING([to see if your getaddrinfo supports AF_UNIX])
651AC_RUN_IFELSE([AC_LANG_PROGRAM([[
652	#include <sys/types.h>
653	#include <sys/socket.h>
654	#include <netdb.h>
655	#include <sys/un.h>
656	#include <stdlib.h>
657	#include <string.h>
658]],[[
659	struct addrinfo hints;
660	struct addrinfo *results;
661	int	retval;
662
663	memset(&hints, 0, sizeof(hints));
664	hints.ai_flags = 0;
665	hints.ai_family = AF_UNIX;
666	hints.ai_socktype = SOCK_STREAM;
667	hints.ai_protocol = 0;
668
669	retval = getaddrinfo(0, "/tmp/.ircd/6667", &hints, &results);
670	if (retval != 0)
671		return 1;
672	else
673		return 0;
674]])],
675  AC_MSG_RESULT([yes]),
676  AC_DEFINE([GETADDRINFO_DOES_NOT_DO_AF_UNIX], 1, [Define this if your getaddrinfo() does not support AF_UNIX])
677  AC_MSG_RESULT([no. ugh]), :)
678
679dnl ----------------------------------------------------------
680dnl
681dnl Socks4 or Socks5 or neither?
682dnl
683
684AC_MSG_CHECKING(whether to support SOCKS)
685AC_ARG_WITH(socks,
686[  --with-socks[=PATH]               Compile with SOCKS (libsocks without socks.h) firewall traversal support.],
687[ case "$withval" in
688  no)
689	AC_MSG_RESULT(no)
690	;;
691  *)
692	if test "x$withval" != "xyes"; then
693		LIBS="$LIBS -L$withval"
694	fi
695
696	AC_MSG_RESULT(yes)
697	LIBS="$LIBS -lsocks"
698	AC_DEFINE([SOCKS], 1, [Define this if you wanted to use SOCKS])
699	AC_DEFINE([connect], [Rconnect], [Defined when using SOCKS])
700	AC_DEFINE([getsockname], [Rgetsockname], [Defined when using SOCKS])
701	AC_DEFINE([bind], [Rbind], [Defined when using SOCKS])
702	AC_DEFINE([accept], [Raccept], [Defined when using SOCKS])
703	AC_DEFINE([listen], [Rlisten], [Defined when using SOCKS])
704	AC_DEFINE([select], [Rselect], [Defined when using SOCKS])
705	;;
706  esac ],
707  AC_MSG_RESULT(no)
708)
709
710AC_MSG_CHECKING(whether to support SOCKS5)
711AC_ARG_WITH(socks5,
712[  --with-socks5[=PATH]              Compile with SOCKS5 (libsocks with socks.h) firewall traversal support.],
713[ case "$withval" in
714  no)
715	AC_MSG_RESULT(no)
716	;;
717  *)
718	if test "x$withval" != "xyes"; then
719		LIBS="$LIBS -L$withval"
720		CFLAGS="$CFLAGS -I$withval/../include/"
721	fi
722
723	AC_MSG_RESULT(yes)
724	LIBS="$LIBS -lsocks"
725	AC_DEFINE([SOCKS], 1, [Define this if you wanted to use SOCKS])
726	AC_DEFINE([USE_SOCKS5], 1, [Define this if you wanted to use SOCKS5])
727	;;
728  esac ],
729  AC_MSG_RESULT(no)
730)
731
732
733dnl ----------------------------------------------------------
734dnl
735dnl Iconv support?
736dnl
737AC_ARG_WITH(iconv,
738[  --with-iconv[=PATH]               Include iconv support (PATH is (eg) /usr/local).],[
739	if test -z "$withval"; then
740		with_iconv="/usr"
741	fi
742])
743
744AC_MSG_CHECKING(whether to include iconv support)
745if test "x$with_iconv" = "xno"; then
746	AC_MSG_RESULT([Iconv support is required; I'm afraid I must insist.])
747	AC_MSG_CHECKING([whether to include iconv support])
748	with_iconv=yes
749fi
750
751	saved_LIBS="$LIBS"
752	saved_CFLAGS="$CFLAGS"
753
754	dnl First try to see if it's in libc
755	AC_LINK_IFELSE([AC_LANG_PROGRAM([[
756		#include <iconv.h>
757	]],[[
758		iconv_open(0, 0);
759	]])],
760		have_iconv="yes")
761
762	dnl If it's not in libc, look in -liconv
763	if test "x$have_iconv" = "x"; then
764	   LIBS="$saved_LIBS -liconv"
765	   CFLAGS="$saved_CFLAGS"
766	   AC_LINK_IFELSE([AC_LANG_PROGRAM([[
767		#include <iconv.h>
768	   ]],[[
769		iconv_open(0, 0);
770	   ]])],
771		have_iconv="yes")
772	fi
773
774	dnl whatever.
775	if test "x$with_iconv" = "xyes" ; then
776		unset with_iconv
777	fi
778
779	dnl Otherwise, go hunting for it.
780	if test "x$have_iconv" = "x"; then
781	    for iconvdir in "$with_iconv" "$prefix" $localdir /usr/local /usr/pkg /opt /usr/opt; do
782		if test "x$have_iconv" != "x"; then
783			break
784		fi
785
786		if test "x$iconvdir" = "x"; then
787			continue
788		fi
789
790dnl		if test -f "$iconvdir/include/iconv.h" &&
791dnl			test -f "$iconvdir/lib/libiconv.a"; then
792		if test -f "$iconvdir/include/iconv.h" ; then
793		    CFLAGS="$saved_CFLAGS -I$iconvdir/include"
794		    LIBS="$saved_LIBS -L$iconvdir/lib -liconv"
795		    AC_LINK_IFELSE([AC_LANG_PROGRAM([[
796			#include <iconv.h>
797	   	    ]],[[
798			iconv_open(0, 0);
799	   	    ]])],
800			have_iconv="yes")
801		fi
802
803		if test "x$with_iconv" != "x"; then
804			break
805		fi
806	    done
807	fi
808
809# If we found it somewhere, great!  Otherwise, revert.
810if test "x$have_iconv" = "x"; then
811	LIBS="$saved_LIBS"
812	CFLAGS="$saved_CFLAGS"
813	AC_MSG_RESULT(looked but did not find it)
814	if test "x$with_iconv" != "x" ; then
815		AC_MSG_ERROR([You specified --with-iconv=$with_iconv but that directory did not contain files include/iconv.h and lib/iconv.a.  Either specify a different directory or let me auto-detect it for you])
816	else
817		AC_MSG_ERROR([Iconv support is required.  I could not find your system's iconv support.  If you have iconv installed, please re-run configure with the --with-iconv=/path/to/dir option where include/iconv.h and lib/iconv.a exist.])
818	fi
819else
820	AC_MSG_RESULT(yes)
821	AC_DEFINE([HAVE_ICONV], 1, [Define this if you have a useful iconv()])
822fi
823
824dnl #sigh#
825dnl AC_CHECK_FUNC(iconv_open, AC_DEFINE([HAVE_ICONV], 1, [Define this if you have a useful iconv())],)
826
827
828dnl ----------------------------------------------------------
829dnl
830dnl Job Control / Wserv support?
831dnl
832AC_MSG_CHECKING(whether you have posix-like job control)
833if test "x$ac_cv_func_tcsetpgrp" = "xyes" -a "x$ac_cv_func_setsid" = "xyes"; then
834	AC_MSG_RESULT(yes)
835else
836	AC_MSG_RESULT(no)
837	AC_DEFINE([NO_JOB_CONTROL], 1, [Define this if you don't have job control])
838	no_job_control=1
839fi
840
841AC_MSG_CHECKING(whether to include wserv support)
842include_wserv="yes"
843AC_ARG_WITH(wserv,
844[  --without-wserv                   Refuse to support wserv (for multiple screens)],[
845	if test -z "$withval"; then
846		include_wserv="yes"
847	else
848		include_wserv="$withval"
849	fi
850])
851if test "x$no_job_control" = "x1" ; then
852	include_wserv="no"
853fi
854AC_MSG_RESULT($include_wserv)
855if test "x$include_wserv" = "xyes" ; then
856	WSERV_BIN="wserv4"
857	WSERV_INSTALL="installwserv4"
858fi
859
860dnl ----------------------------------------------------------
861dnl
862dnl Valgrind assistance support?
863dnl
864AC_MSG_CHECKING(whether to include Valgrind Memcheck support)
865AC_ARG_WITH(valgrind,
866[  --with-valgrind                   Include support for Valgrind Memcheck ],
867[],
868[with_valgrind=no])
869if test "x$with_valgrind" != "xno"; then
870	AC_MSG_RESULT(yes)
871	AC_CHECK_HEADERS([valgrind/memcheck.h])
872else
873	AC_MSG_RESULT(no)
874fi
875
876
877dnl ----------------------------------------------------------
878dnl
879dnl Perl support?
880dnl
881AC_ARG_WITH([perl],
882[  --with-perl=[PATH_TO_PERL_EXE]    Compile with perl support.],
883	[], [with_perl=maybe])
884if test "x$with_perl" = "xno" ; then
885	AC_MSG_CHECKING(whether to support Perl)
886	AC_MSG_RESULT(no)
887else
888	with_perl_errormsg="You specified --with-perl=$with_perl but I could not find a working perl. Please run ./configure with --without-perl or specify a path to a working perl executable."
889	if test "x$with_perl" = "xyes" -o "x$with_perl" = "xmaybe" ; then
890		perlexe=perl
891	else
892		perlexe="$with_perl"
893	fi
894	dnl Allow a full path to be specified in --with-perl
895	if test -x "$perlexe" ; then
896		PERLPROG=yes
897	else
898		AC_CHECK_PROG(PERLPROG, $perlexe, "yes", "no")
899	fi
900	AC_MSG_CHECKING([whether to support Perl])
901	if test $PERLPROG != "yes" ; then
902		if test "x$with_perl" != "xmaybe" ; then
903			AC_MSG_ERROR([$with_perl_errormsg])
904		fi
905		AC_MSG_RESULT(no)
906	else
907		AC_MSG_RESULT(yes)
908		PERLCFLAGS=`$perlexe -MExtUtils::Embed -e ccopts`
909		PERLLIBS=`$perlexe -MExtUtils::Embed -e ldopts`
910
911		AC_MSG_CHECKING(whether embedded perl works the way I expect)
912		have_embedded_perl="no"
913		old_CFLAGS="$CFLAGS"
914		old_LIBS="$LIBS"
915		CFLAGS="$CFLAGS $PERLCFLAGS"
916		LIBS="$LIBS $PERLLIBS"
917		AC_RUN_IFELSE([AC_LANG_SOURCE([[
918#include <EXTERN.h>
919#include <perl.h>
920#include <XSUB.h>
921int dummy_retval = -1;
922
923/* I "borrowed" this from the perlembed(1) man page */
924PerlInterpreter *my_perl;
925int startup_perl(int argc, char **argv, char **env)
926{
927	char *embedding[] = {"", "-e", "0" };
928
929	my_perl = perl_alloc();
930	perl_construct(my_perl);
931	PL_exit_flags |= PERL_EXIT_DESTRUCT_END;
932	perl_parse(my_perl, NULL, 3, embedding, NULL);
933	if (SvTRUE(ERRSV))
934	   (void)SvPV_nolen(ERRSV);
935	perl_run(my_perl);
936	if (SvTRUE(ERRSV))
937	   (void)SvPV_nolen(ERRSV);
938	perl_destruct(my_perl);
939	perl_free(my_perl);
940	PERL_SYS_TERM();
941	dummy_retval = 0;
942	return 0;
943}
944
945int main (int argc, char **argv, char **environ)
946{
947	startup_perl(argc, argv, environ);
948	return dummy_retval;
949}
950]])],
951have_embedded_perl="yes",
952have_embedded_perl="no",:)
953
954		CFLAGS="$old_CFLAGS"
955		LIBS="$old_LIBS"
956		if test $have_embedded_perl = "yes" ; then
957			AC_MSG_RESULT(yes)
958			AC_DEFINE([HAVE_PERL], 1, [Define this if you have perl])
959			AC_DEFINE([PERLCFLAGS], 1, [Add this to CLFAGS for perl support])
960			AC_DEFINE([PERLLIBS], 1, [Add this to LDFLAGS for perl support])
961			PERLDOTOH="perl.o"
962		else
963			if test "x$with_perl" != "xmaybe"; then
964				AC_MSG_ERROR([$with_perl_errormsg])
965			fi
966			PERLCFLAGS=""
967			PERLLIBS=""
968			AC_MSG_RESULT(no, sorry)
969			PERLCFLAGS=""
970			PERLLIBS=""
971		fi
972	fi
973fi
974
975dnl ----------------------------------------------------------
976dnl
977dnl Tcl support?
978dnl
979AC_ARG_WITH([tcl],
980[  --with-tcl[=PATH_TO_tclConfig.sh] Compile with tcl support.],
981	[], [with_tcl=maybe])
982
983AC_MSG_CHECKING(whether to support TCL)
984if test "x$with_tcl" = "xno"; then
985	AC_MSG_RESULT(no)
986else
987	with_tcl_errormsg="You specified --with-tcl=$with_tcl but I could not find TCL. Please specify --with-tcl=/path/to/tclConfig.sh or remove --with-tcl from ./configure's commandline."
988	if test "x$with_tcl" = "xmaybe" -o "x$with_tcl" = "xyes"; then
989		for i in /usr/lib /usr/local/lib /usr/local/lib/tcl8.4 ; do
990			if test -r "$i"/tclConfig.sh ; then
991				tclconfig="$i"/tclConfig.sh
992				break;
993			fi
994		done
995	else
996		tclconfig="$with_tcl"
997	fi
998	if test ! -r "$tclconfig" ; then
999		dnl Avoid being automagic unless if the user wants us to be.
1000		if test "x$with_tcl" != "xmaybe" ; then
1001			AC_MSG_ERROR([$with_tcl_errormsg])
1002		fi
1003		AC_MSG_RESULT(no)
1004	else
1005		AC_MSG_RESULT(yes)
1006		TCLCFLAGS=`(. "$tclconfig" && echo $TCL_INCLUDE_SPEC)`
1007		TCLLIBS=`(. "$tclconfig" && echo $TCL_LIB_SPEC $TCL_LIBS)`
1008		TCLDOTOH="tcl.o"
1009
1010		AC_MSG_CHECKING(whether embedded tcl works the way I expect)
1011		have_embedded_tcl="no"
1012		old_CFLAGS="$CFLAGS"
1013		old_LIBS="$LIBS"
1014		CFLAGS="$CFLAGS $TCLCFLAGS"
1015		LIBS="$LIBS $TCLLIBS"
1016		AC_LINK_IFELSE([AC_LANG_PROGRAM([[
1017			#include <tcl.h>
1018			Tcl_Interp *my_tcl;
1019			int Tcl_echoCmd (ClientData clientData, Tcl_Interp *interp, int objc, const char **objv)
1020			{
1021				return TCL_OK;
1022			}
1023		]],[[
1024			my_tcl = Tcl_CreateInterp();
1025			Tcl_Init(my_tcl);
1026			Tcl_CreateCommand(my_tcl, "echo", Tcl_echoCmd,
1027				(ClientData)NULL, (void (*)()) NULL);
1028			Tcl_DeleteInterp(my_tcl);
1029		]])],
1030			have_embedded_tcl="yes")
1031
1032		CFLAGS="$old_CFLAGS"
1033		LIBS="$old_LIBS"
1034		if test $have_embedded_tcl = "yes" ; then
1035		    AC_MSG_RESULT(yes)
1036		    AC_DEFINE([HAVE_TCL], 1, [Define this if you want to add tcl support])
1037		    AC_DEFINE([TCLCFLAGS], 1, [Stuff to add to CFLAGS to support tcl])
1038		    AC_DEFINE([TCLLIBS], 1, [Stuff to add to LDFLAGS to support tcl])
1039		else
1040			if test "$with_tcl" != "xmaybe" ; then
1041				AC_MSG_ERROR([$with_tcl_errormsg])
1042			fi
1043			AC_MSG_RESULT(no, sorry)
1044		fi
1045	fi
1046fi
1047
1048dnl ----------------------------------------------------------
1049dnl
1050dnl Ruby support?
1051dnl
1052AC_ARG_WITH([ruby],
1053[  --with-ruby[=PATH_TO_RUBY_EXE]    Compile with ruby support.],
1054       [], [with_ruby=maybe])
1055
1056with_ruby_errormsg="--with-ruby was specified but I could not locate ruby. Please try specifying --with-ruby=/path/to/ruby or --without-ruby."
1057AC_MSG_CHECKING([whether to support Ruby])
1058if test "x$with_ruby" = "xno" ; then
1059	AC_MSG_CHECKING(whether to support Ruby)
1060	AC_MSG_RESULT(no)
1061else
1062	AC_MSG_RESULT(yes)
1063	if test "x$with_ruby" = "xyes" -o "x$with_ruby" = "xmaybe" ; then
1064		rubyexe=ruby
1065	else
1066		rubyexe="$with_ruby"
1067	fi
1068	dnl Support --with-ruby being passed a full path instead of just an executable name.
1069	if test -x "$rubyexe" ; then
1070		RUBYPROG=yes
1071	else
1072		AC_CHECK_PROG([RUBYPROG], [$rubyexe], [yes], [no])
1073	fi
1074	if test "x$RUBYPROG" = xno ; then
1075		if test "x$with_ruby" != "xmaybe" ; then
1076			AC_MSG_ERROR([$with_ruby_errormsg])
1077		fi
1078	else
1079	    dnl ----
1080	    dnl Look first for Ruby 1.9
1081	    incdir=`$rubyexe -rrbconfig -e 'puts RbConfig::CONFIG[["rubyhdrdir"]]'`
1082	    archincdir=`$rubyexe -rrbconfig -e 'puts RbConfig::CONFIG[["rubyarchhdrdir"]]'`
1083	    dnl -- Ruby 1.8
1084	    if test "x$incdir" = "xnil" ; then
1085	       incdir=`$rubyexe -rrbconfig -e 'puts RbConfig::CONFIG[["archdir"]]'`
1086	       RUBYCFLAGS="-I$incdir"
1087	    dnl -- Ruby 1.9 and 2.0
1088	    else
1089	       arch=`$rubyexe -rrbconfig -e 'puts RbConfig::CONFIG[["arch"]]'`
1090	       RUBYCFLAGS="-I$incdir -I$incdir/$arch/ -I$archincdir"
1091	    fi
1092
1093	    rubylibs=`$rubyexe -rrbconfig -e 'puts RbConfig::CONFIG[["LIBRUBYARG"]]'`
1094	    extralibs=`$rubyexe -rrbconfig -e 'puts RbConfig::CONFIG[["LIBS"]]'`
1095	    RUBYLIBS="$rubylibs $extralibs"
1096	    RUBYDOTOH="ruby.o"
1097
1098	    AC_MSG_CHECKING(whether embedded ruby works the way I expect)
1099	    have_embedded_ruby="no"
1100	    old_CFLAGS="$CFLAGS"
1101	    old_LIBS="$LIBS"
1102	    CFLAGS="$CFLAGS $RUBYCFLAGS"
1103	    LIBS="$LIBS $RUBYLIBS"
1104	    AC_LINK_IFELSE([AC_LANG_PROGRAM([[
1105		#include <ruby.h>
1106		VALUE epic_echo (VALUE module, VALUE string)
1107		{
1108			VALUE x;
1109			char *my_string;
1110			x = rb_obj_as_string(string);
1111			my_string = StringValuePtr(x);
1112			return Qnil;
1113		}
1114	    ]], [[
1115		VALUE rubyclass;
1116
1117		ruby_init();
1118		ruby_init_loadpath();
1119		rubyclass = rb_define_class("EPIC", rb_cObject);
1120		rb_define_singleton_method(rubyclass, "echo", epic_echo, 1);
1121		rb_gc_register_address(&rubyclass);
1122	    ]])],
1123		have_embedded_ruby="yes")
1124
1125	    if ! test $have_embedded_ruby = "yes" ; then
1126		AC_MSG_RESULT(no)
1127		AC_MSG_CHECKING(whether ruby requires -pthread to link)
1128		RUBYCFLAGS="$RUBYCFLAGS -pthread"
1129		RUBYLIBS="$RUBYLIBS -pthread"
1130		CFLAGS="$old_CFLAGS $RUBYCFLAGS"
1131		LIBS="$old_LIBS $RUBYLIBS"
1132
1133		AC_LINK_IFELSE([AC_LANG_PROGRAM([[
1134			#include <ruby.h>
1135			VALUE epic_echo (VALUE module, VALUE string)
1136			{
1137				VALUE x;
1138				char *my_string;
1139				x = rb_obj_as_string(string);
1140				my_string = StringValuePtr(x);
1141				return Qnil;
1142			}
1143		]], [[
1144			VALUE rubyclass;
1145
1146			ruby_init();
1147			ruby_init_loadpath();
1148			rubyclass = rb_define_class("EPIC", rb_cObject);
1149			rb_define_singleton_method(rubyclass, "echo", epic_echo, 1);
1150			rb_gc_register_address(&rubyclass);
1151		]])],
1152			have_embedded_ruby="yes")
1153	    fi
1154
1155	    CFLAGS="$old_CFLAGS"
1156	    LIBS="$old_LIBS"
1157	    if test $have_embedded_ruby = "yes" ; then
1158		AC_MSG_RESULT(yes)
1159		AC_DEFINE([HAVE_RUBY], 1, [Define this if you want to suppor ruby])
1160		AC_DEFINE([RUBYCFLAGS], 1, [Stuff to add to CFLAGS to support ruby])
1161		AC_DEFINE([RUBYLIBS], 1, [Stuff to add to LDFLAGS to support ruby])
1162	    else
1163		if test "x$with_ruby" != "xmaybe" ; then
1164			AC_MSG_ERROR([$with_ruby_errormsg])
1165		fi
1166	        RUBYDOTOH=""
1167		HAVE_RUBY=""
1168		RUBYCFLAGS=""
1169		RUBYLIBS=""
1170		AC_MSG_RESULT(no, sorry)
1171	    fi
1172	fi
1173fi
1174
1175dnl ----------------------------------------------------------
1176dnl
1177dnl Python support?
1178dnl
1179AC_ARG_WITH([python],
1180[  --with-python[=PATH_TO_PYTHON_CONFIG_EXE]   Compile with Python support.],
1181       [], [with_python=maybe])
1182
1183with_python_errormsg="--with-python was specified but I could not locate python3-config. Please try specifying --with-path=/path/to/python3-config or --without-python."
1184AC_MSG_CHECKING([whether to support Python])
1185if test "x$with_python" = "xno" ; then
1186	AC_MSG_CHECKING(whether to support Python)
1187	AC_MSG_RESULT(no)
1188else
1189	AC_MSG_RESULT(yes)
1190	if test "x$with_python" = "xyes" -o "x$with_python" = "xmaybe" ; then
1191		python_cfg_exe=python3-config
1192	else
1193		python_cfg_exe="$with_python"
1194	fi
1195	dnl Support --with-python being passed a full path instead of just an executable name.
1196	if test -x "$python_cfg_exe" ; then
1197		PYTHON_CFG_EXE=yes
1198	else
1199		AC_CHECK_PROG([PYTHON_CFG_EXE], [$python_cfg_exe], [yes], [no])
1200	fi
1201	if test "x$PYTHON_CFG_EXE" = xno ; then
1202		if test "x$with_python" != "xmaybe" ; then
1203			AC_MSG_ERROR([$with_python_errormsg])
1204		fi
1205	else
1206	    dnl ---
1207            dnl First, we have to determine if this is 3.7 or lower; or 3.8 or higher
1208	    dnl The 3.8 or higher versions require --embed and 3.7 or lower versions
1209	    dnl forbid it.  What fun!
1210	    dnl
1211	    if $python_cfg_exe --cflags --embed > /dev/null ; then
1212		use_embed="--embed"
1213	    else
1214		use_embed=""
1215	    fi
1216
1217	    dnl ----
1218	    dnl Look first for Python 3
1219            PYTHON_CFLAGS=`$python_cfg_exe --cflags $use_embed`
1220            PYTHON_LDFLAGS=`$python_cfg_exe --ldflags $use_embed`
1221	    PYTHON_O="python.o"
1222
1223	    AC_MSG_CHECKING(whether embedded Python works the way I expect)
1224	    have_embedded_python="no"
1225	    old_CFLAGS="$CFLAGS"
1226	    old_LIBS="$LIBS"
1227	    CFLAGS="$CFLAGS $PYTHON_CFLAGS"
1228	    LIBS="$LIBS $PYTHON_LDFLAGS"
1229	    AC_LINK_IFELSE([AC_LANG_PROGRAM([[
1230		#include <Python.h>
1231		static  PyObject *      epic_null (PyObject *self, PyObject *args)
1232		{
1233			char *  str;
1234			if (!PyArg_ParseTuple(args, "s", &str)) {
1235				return PyLong_FromLong(-1);
1236			}
1237			return Py_BuildValue("s", "");
1238		}
1239
1240		static  PyMethodDef     epicMethods[] = {
1241			{ "null",       epic_null,      METH_VARARGS,   "null" },
1242			{ NULL,         NULL,           0,              NULL }
1243		};
1244
1245		static  PyModuleDef     epicModule = {
1246			PyModuleDef_HEAD_INIT,
1247			"_epic",        NULL,           -1,             epicMethods,
1248			NULL,           NULL,           NULL,           NULL
1249		};
1250
1251		static  PyObject *      PyInit_epic (void)
1252		{
1253			return PyModule_Create(&epicModule);
1254		}
1255	    ]], [[
1256		PyImport_AppendInittab("_epic", &PyInit_epic);
1257		Py_Initialize();
1258	    ]])],
1259		have_embedded_python="yes")
1260
1261	    if test $have_embedded_python = "yes" ; then
1262		AC_MSG_RESULT(yes)
1263		AC_DEFINE([PYTHON_O], 1, [Define this add stuff....])
1264		AC_DEFINE([HAVE_PYTHON], 1, [Define this to support python])
1265		AC_DEFINE([PYTHON_CFLAGS], 1, [Stuff to add to CFLAGS to support python])
1266		AC_DEFINE([PYTHON_LDFLAGS], 1, [Stuff to add to LDFLAGS to support python])
1267            else
1268		if test "x$with_python" != "xmaybe" ; then
1269			AC_MSG_ERROR([$with_python_errormsg])
1270		fi
1271	        PYTHON_O=""
1272		HAVE_PYTHON=""
1273		PYTHON_CFLAGS=""
1274		PYTHON_LDFLAGS=""
1275		AC_MSG_RESULT(no, sorry)
1276            fi
1277
1278	    CFLAGS="$old_CFLAGS"
1279	    LIBS="$old_LIBS"
1280	fi
1281fi
1282
1283dnl ----------------------------------------------------------
1284dnl ----------------------------------------------------------
1285dnl
1286dnl closing stuff
1287dnl
1288dnl ----------------------------------------------------------
1289dnl ----------------------------------------------------------
1290
1291
1292dnl ----------------------------------------------------------
1293dnl
1294dnl set some last minute sanity defaults
1295dnl
1296
1297if test -z "$CFLAGS"; then CFLAGS="-g -O"; fi
1298if test -z "$LDFLAGS"; then LDFLAGS= ; fi
1299if test -z "$PERLDOTOH"; then PERLDOTOH= ; fi
1300if test -z "$TCLDOTOH"; then TCLDOTOH= ; fi
1301if test -z "$RUBYDOTOH"; then RUBYDOTOH= ; fi
1302if test -z "$PYTHON_O"; then PYTHON_OH= ; fi
1303if test -z "$WSERV_BIN"; then WSERV_BIN= ; fi
1304if test -z "$WSERV_INSTALL"; then WSERV_INSTALL= ; fi
1305if test -z "$bindir"; then bindir=\${prefix}/bin; fi
1306if test -z "$libdir"; then libdir=\${prefix}/lib; fi
1307if test -z "$irclibdir"; then irclibdir=\${libdir}/irc; fi
1308if test -z "$libexecdir"; then libexecdir=\${prefix}/libexec; fi
1309
1310epic5=`echo "epic5" | sed -e "$program_transform_name"`
1311if test "$program_prefix" = "NONE" ; then
1312	program_prefix=
1313fi
1314
1315AC_MSG_CHECKING(whether your compiler supports -Wno-pointer-sign)
1316old_cflags="$CFLAGS"
1317CFLAGS="$CFLAGS -Wno-pointer-sign"
1318AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]],[[ return 0; ]])],
1319	[AC_MSG_RESULT(yes)],
1320        [AC_MSG_RESULT(no)
1321	CFLAGS="$old_cflags"])
1322
1323AC_MSG_CHECKING(whether your compiler supports -fno-strict-aliasing)
1324old_cflags="$CFLAGS"
1325CFLAGS="$CFLAGS -fno-strict-aliasing"
1326AC_COMPILE_IFELSE([AC_LANG_PROGRAM( [[]],[[ return 0; ]])],
1327	[AC_MSG_RESULT(yes)],
1328        [AC_MSG_RESULT(no)])
1329
1330AC_MSG_CHECKING(whether your compiler supports __attribute__((fallthrough)))
1331AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
1332	]],[[
1333		int x = 1;
1334		switch (x) {
1335			case 1:
1336				x++;
1337				__attribute__((fallthrough));
1338			case 0:
1339				x++;
1340		}
1341	]])],
1342        [have_attribute_fallthrough=1],
1343        [have_attribute_fallthrough=0])
1344
1345if test "x$have_attribute_fallthrough" = "x1" ; then
1346	AC_MSG_RESULT(yes)
1347	AC_DEFINE([HAVE_ATTRIBUTE_FALLTHROUGH], 1, [Define if you can use __attribute__((fallthrough))])
1348else
1349	AC_MSG_RESULT(no)
1350fi
1351
1352
1353AC_SUBST(CFLAGS)
1354AC_SUBST(LDFLAGS)
1355AC_SUBST(RUBYDOTOH)
1356AC_SUBST(RUBYCFLAGS)
1357AC_SUBST(RUBYLIBS)
1358AC_SUBST(TCLDOTOH)
1359AC_SUBST(TCLCFLAGS)
1360AC_SUBST(TCLLIBS)
1361AC_SUBST(PERLDOTOH)
1362AC_SUBST(PERLCFLAGS)
1363AC_SUBST(PERLLIBS)
1364AC_SUBST(PYTHON_O)
1365AC_SUBST(PYTHON_CFLAGS)
1366AC_SUBST(PYTHON_LDFLAGS)
1367AC_SUBST(WSERV_BIN)
1368AC_SUBST(WSERV_INSTALL)
1369AC_SUBST(bindir)
1370AC_SUBST(irclibdir)
1371AC_SUBST(libexecdir)
1372AC_SUBST(srcdir)
1373AC_SUBST(includedir)
1374AC_SUBST(epic5)
1375AC_SUBST(program_transform_name)
1376AC_SUBST(program_prefix)
1377AC_SUBST(mandir)
1378
1379AC_CONFIG_FILES([Makefile source/Makefile source/info.c.sh])
1380AC_OUTPUT
1381
1382dnl ----------------------------------------------------------
1383dnl
1384dnl Commencement
1385dnl
1386
1387echo
1388echo "There you go.  Look at include/config.h for any options that "
1389echo "you might want to change before you 'make'.  Don't forget to "
1390echo "do a 'make install' before you're done."
1391echo
1392
1393if test "x$warn_again" != "x0" ; then
1394   echo '@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@'
1395   echo '@@@              IMPORTANT WARNING!                 @@@'
1396   echo '@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@'
1397   echo ''
1398   echo 'I was unable to find tgetent() which means the build will fail.'
1399   echo 'If you are using linux, you _MUST_ install the ncurses-dev'
1400   echo 'or ncurses-devel package and then "make distclean" and '
1401   echo 'then run configure again.'
1402   echo ''
1403   echo '@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@'
1404   echo '@@@              IMPORTANT WARNING!                 @@@'
1405   echo '@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@'
1406fi
1407
1408