1dnl #
2dnl #  Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005 James Antill
3dnl #
4dnl #  This program is free software; you can redistribute it and/or modify
5dnl #  it under the terms of the GNU General Public License as published by
6dnl #  the Free Software Foundation; either version 2 of the License, or
7dnl #  (at your option) any later version.
8dnl #
9dnl #  This program is distributed in the hope that it will be useful,
10dnl #  but WITHOUT ANY WARRANTY; without even the implied warranty of
11dnl #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12dnl #  GNU General Public License for more details.
13dnl #
14dnl #  You should have received a copy of the GNU General Public License
15dnl #  along with this program; if not, write to the Free Software
16dnl #  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17dnl #
18dnl # email: james@and.org
19dnl #
20
21
22dnl Configure script...
23dnl
24
25AC_INIT(include/vstr.h)
26
27AC_PREREQ(2.12)dnl
28AC_REVISION(1.0)
29
30
31AM_CONFIG_HEADER(include/autoconf.h)
32
33
34dnl define a msg macro...
35
36define(TWOCAN_CONF_MSG,[dnl
37AC_MSG_RESULT()
38AC_MSG_RESULT(${T_MD}$1:${T_ME})
39])dnl
40
41
42
43
44# Scary shtool stuff... borowed from pth-1.0
45if test ".`echo dummy $@ | grep help`" = .; then
46    ac_shtool="$srcdir/shtool"
47    T_MD="`$ac_shtool echo -n -e %B 2>/dev/null`"
48    T_ME="`$ac_shtool echo -n -e %b 2>/dev/null`"
49    echo "Configuring ${T_MD}vstr${T_ME}, (Library)${T_ME}"
50    echo "Copyright (c) 1999-2005 James Antill <james@and.org>"
51    echo "                   See ${T_MD}AUTHORS${T_ME} file for more info."
52
53# Could just del this, but it looks cool and like I know what I'm doing :)
54    PLATFORM=`$ac_shtool guessos`
55    echo "Platform: ${T_MD}${PLATFORM}${T_ME}"
56fi
57
58TWOCAN_CONF_MSG(Initial phase)
59
60AC_SUBST(CFLAGS)
61AC_SUBST(CPPFLAGS)
62AC_SUBST(LDFLAGS)
63
64# Seriously butchered from glib...
65
66# inc. mico.
67#   inc. interface on no additions
68#   zero interface on additions
69#   inc. binary if compat.
70
71VSTR_MAJOR_VERSION=1
72VSTR_MINOR_VERSION=0
73VSTR_MICRO_VERSION=15
74VSTR_INTERFACE_AGE=2
75VSTR_BINARY_AGE=15
76VSTR_VERSION=$VSTR_MAJOR_VERSION.$VSTR_MINOR_VERSION.$VSTR_MICRO_VERSION
77
78# libtool versioning
79LT_RELEASE=$VSTR_MAJOR_VERSION.$VSTR_MINOR_VERSION
80LT_CURRENT=`expr $VSTR_MICRO_VERSION - $VSTR_INTERFACE_AGE`
81LT_REVISION=$VSTR_INTERFACE_AGE
82LT_AGE=`expr $VSTR_BINARY_AGE - $VSTR_INTERFACE_AGE`
83AC_SUBST(LT_RELEASE)
84AC_SUBST(LT_CURRENT)
85AC_SUBST(LT_REVISION)
86AC_SUBST(LT_AGE)
87
88VERSION=$VSTR_VERSION
89PACKAGE=vstr
90
91AM_INIT_AUTOMAKE($PACKAGE, $VERSION)
92
93
94#
95# FIXME: Need to be able to check for ASCII and if not set... HAVE_NON_ASCII
96#
97
98AC_ISC_POSIX
99
100AC_PROG_MAKE_SET
101AC_PROG_CC
102AC_EXEEXT
103
104# This could be better...
105CCAS=$CC
106AC_SUBST(CCAS)
107CCASFLAGS="\$(DEFAULT_INCLUDES) \$(INCLUDES)"
108AC_SUBST(CCASFLAGS)
109
110
111TWOCAN_CONF_MSG(Libtool stuff)
112
113AM_PROG_LIBTOOL
114AC_SUBST(LIBTOOL_DEPS)
115
116TWOCAN_CONF_MSG(Checking location of programs)
117
118AC_PATH_PROG(TRUE_PATH, true, /dev/null,
119             $PATH:/bin:/usr/bin:/bin:/usr/local/bin:/usr/gnu/bin:/usr/local/gnu/bin:/opt/gnu/bin)
120
121# Ignore autoheader
122AUTOHEADER="$TRUE_PATH"
123
124AC_PATH_PROG(GZIP_PATH, gzip, $TRUE_PATH,
125             $PATH:/usr/bin:/bin:/usr/local/bin:/usr/gnu/bin:/usr/local/gnu/bin:/opt/gnu/bin)
126AC_PATH_PROG(BZIP2_PATH, bzip2, $TRUE_PATH,
127             $PATH:/usr/bin:/bin:/usr/local/bin:/usr/gnu/bin:/usr/local/gnu/bin:/opt/gnu/bin)
128
129AC_PATH_PROG(SENDMAIL_PATH, sendmail, $TRUE_PATH,
130             $PATH:/usr/sbin:/usr/lib)
131
132AC_PATH_PROG(MAKE_PATH, gmake, make,
133             $PATH:/usr/bin:/bin:/usr/local/bin:/usr/gnu/bin:/usr/local/gnu/bin:/opt/gnu/bin)
134
135AC_PATH_PROG(ETAGS_PATH, etags, $TRUE_PATH,
136             $PATH:/usr/bin:/bin:/usr/local/bin:/usr/gnu/bin:/usr/local/gnu/bin:/opt/gnu/bin)
137
138AC_PATH_PROG(SED_PATH, sed, $TRUE_PATH,
139             $PATH:/usr/bin:/bin:/usr/local/bin:/usr/gnu/bin:/usr/local/gnu/bin:/opt/gnu/bin)
140
141AC_PATH_PROG(PERL_PATH, perl, $TRUE_PATH,
142             $PATH:/usr/bin:/bin:/usr/local/bin:/usr/local/perl:/usr/gnu/bin:/usr/local/gnu/bin:/opt/gnu/bin)
143
144if test "x$PERL_CONFIG" = "x/usr/bin/perl" ; then
145  AM_CONDITIONAL(PERL_USR_BIN_AVAIL, false)
146else
147  AM_CONDITIONAL(PERL_USR_BIN_AVAIL, true)
148fi
149
150AC_PATH_PROG(TAR_PATH, tar, $TRUE_PATH,
151             $PATH:/usr/bin:/bin:/usr/local/bin:/usr/gnu/bin:/usr/local/gnu/bin:/opt/gnu/bin)
152
153AC_PATH_PROG(CHMOD_PATH, chmod, $TRUE_PATH,
154             $PATH:/usr/bin:/bin:/usr/local/bin:/usr/gnu/bin:/usr/local/gnu/bin:/opt/gnu/bin)
155
156#
157# Find pkg-config
158#
159AC_PATH_PROG(PKG_CONFIG, pkg-config, no)
160if test x$PKG_CONFIG = xno ; then
161  AC_MSG_WARN([*** pkg-config not found. See http://www.freedesktop.org/software/pkgconfig/])
162fi
163
164if $PKG_CONFIG --atleast-pkgconfig-version 0.5 ; then
165  :
166else
167  AC_MSG_WARN([*** pkg-config too old; version 0.5 or better required. See http://www.freedesktop.org/software/pkgconfig/])
168fi
169
170if $PKG_CONFIG --exists timer_q ; then
171  AM_CONDITIONAL(TIMER_Q_AVAIL, true)
172  TIMER_Q_CFLAGS="`$PKG_CONFIG --cflags timer_q`"
173  TIMER_Q_LDLIBS="`$PKG_CONFIG --libs   timer_q`"
174  AC_SUBST(TIMER_Q_CFLAGS)
175  AC_SUBST(TIMER_Q_LDLIBS)
176else
177  AM_CONDITIONAL(TIMER_Q_AVAIL, false)
178fi
179
180if $PKG_CONFIG --exists socket_poll ; then
181  AM_CONDITIONAL(SOCKET_POLL_AVAIL, true)
182  SOCKET_POLL_CFLAGS="`$PKG_CONFIG --cflags socket_poll`"
183  SOCKET_POLL_LDLIBS="`$PKG_CONFIG --libs   socket_poll`"
184  AC_SUBST(SOCKET_POLL_CFLAGS)
185  AC_SUBST(SOCKET_POLL_LDLIBS)
186else
187  AM_CONDITIONAL(SOCKET_POLL_AVAIL, false)
188fi
189
190if $PKG_CONFIG --exists openssl ; then
191  AM_CONDITIONAL(OPENSSL_AVAIL, true)
192  OPENSSL_CFLAGS="`$PKG_CONFIG --cflags openssl`"
193  OPENSSL_LDLIBS="`$PKG_CONFIG --libs   openssl`"
194  AC_SUBST(OPENSSL_CFLAGS)
195  AC_SUBST(OPENSSL_LDLIBS)
196else
197  AM_CONDITIONAL(OPENSSL_AVAIL, false)
198fi
199
200if $PKG_CONFIG --exists glib-2.0 ; then
201  AM_CONDITIONAL(GLIB20_AVAIL, true)
202  GLIB20_CFLAGS="`$PKG_CONFIG --cflags glib-2.0`"
203  GLIB20_LDLIBS="`$PKG_CONFIG --libs   glib-2.0`"
204  AC_SUBST(GLIB20_CFLAGS)
205  AC_SUBST(GLIB20_LDLIBS)
206else
207  AM_CONDITIONAL(GLIB20_AVAIL, false)
208fi
209
210WARNS=""
211AC_ARG_ENABLE(debug, [  --enable-debug          turn on debugging (assumes gcc/gdb) [[default=no]]],[ WARNS="-W -Wall -Wundef -Wshadow -Wpointer-arith -Wbad-function-cast -Wcast-align -Wwrite-strings -Waggregate-return -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations -Wnested-externs -Wno-format-zero-length -Wformat-nonliteral -Wformat-security -Wfloat-equal -O1 -ggdb3"; AM_CONDITIONAL(NDEBUG, false) ],[ AC_DEFINE(NDEBUG) AM_CONDITIONAL(NDEBUG, true) ])
212AC_ARG_ENABLE(ansi, [  --enable-ansi           turn on ansi stuff (assumes gcc/gdb) [[default=no]]],WARNS="$WARNS -ansi -pedantic",)
213AC_ARG_ENABLE(tst-noopt, [  --enable-tst-noopt      turn on no optomizations (assumes gcc/gdb) [[default=no]]],WARNS="$WARNS -O0",)
214AC_SUBST(WARNS)
215
216AC_ARG_ENABLE(noposix-host, [  --enable-noposix-host   turn off all the POSIX extentions [[default=no]]], local_cv_have_posix_host=false,local_cv_have_posix_host=true)
217AM_CONDITIONAL(HAVE_POSIX_HOST, $local_cv_have_posix_host)
218case x$local_cv_have_posix_host in
219 xtrue) AC_DEFINE(HAVE_POSIX_HOST) ;;
220esac
221
222AC_ARG_ENABLE(linker-script, [  --enable-linker-script  turn on linker version script [[default=no]]], local_cv_linker_have_version_script=true,local_cv_linker_have_version_script=false)
223AM_CONDITIONAL(HAVE_LINKER_VERSION_SCRIPT, $local_cv_linker_have_version_script)
224case x$local_cv_linker_have_version_script in
225xtrue) AC_DEFINE(HAVE_LINKER_SCRIPT) ;;
226esac
227
228
229AC_ARG_ENABLE(tst-noinline, [  --enable-tst-noinline   turn off use of inline [[default=no]]], local_cv_have_tst_noinline=true,local_cv_have_tst_noinline=false)
230AC_ARG_ENABLE(tst-noattr-visibility, [  --enable-tst-noattr-visibility turn off use of attribute visibility [[default=no]]], local_cv_have_tst_noattr_visibility=true,local_cv_have_tst_noattr_visibility=false)
231AC_ARG_ENABLE(tst-noattr-alias, [  --enable-tst-noattr-alias turn off use of attribute alias [[default=no]]], local_cv_have_tst_noattr_alias=true,local_cv_have_tst_noattr_alias=false)
232AC_ARG_ENABLE(tst-nosyscall-asm, [  --enable-tst-nosyscall-asm turn off use of asm syscalls in version [[default=no]]],,AC_DEFINE(USE_SYSCALL_ASM))
233AC_ARG_ENABLE(tst-noassert-loop, [  --enable-tst-noassert-loop changes asserts from looping to raise SIGABRT [[default=no]]],AM_CONDITIONAL(USE_ASSERT_LOOP, false),[ AC_DEFINE(USE_ASSERT_LOOP) AM_CONDITIONAL(USE_ASSERT_LOOP, true)])
234
235AC_ARG_ENABLE(wrap-memcpy, [  --enable-wrap-memcpy    turn on wrapper memcpy [[default=no]]], local_cv_linker_use_wrap_memcpy=true,local_cv_linker_use_wrap_memcpy=false)
236AM_CONDITIONAL(USE_WRAP_MEMCPY, $local_cv_linker_use_wrap_memcpy)
237case x$local_cv_linker_use_wrap_memcpy in
238xtrue) AC_DEFINE(USE_WRAP_MEMCPY) ;;
239esac
240AC_ARG_ENABLE(wrap-memcmp, [  --enable-wrap-memcmp    turn on wrapper for memcmp [[default=no]]], local_cv_linker_use_wrap_memcmp=true,local_cv_linker_use_wrap_memcmp=false)
241AM_CONDITIONAL(USE_WRAP_MEMCMP, $local_cv_linker_use_wrap_memcmp)
242case x$local_cv_linker_use_wrap_memcmp in
243xtrue) AC_DEFINE(USE_WRAP_MEMCMP) ;;
244esac
245AC_ARG_ENABLE(wrap-memchr, [  --enable-wrap-memchr    turn on wrapper for memchr [[default=no]]], local_cv_linker_use_wrap_memchr=true,local_cv_linker_use_wrap_memchr=false)
246AM_CONDITIONAL(USE_WRAP_MEMCHR, $local_cv_linker_use_wrap_memchr)
247case x$local_cv_linker_use_wrap_memchr in
248xtrue) AC_DEFINE(USE_WRAP_MEMCHR) ;;
249esac
250AC_ARG_ENABLE(wrap-memrchr, [  --enable-wrap-memrchr   turn on wrapper for memrchr [[default=no]]], local_cv_linker_use_wrap_memrchr=true,local_cv_linker_use_wrap_memrchr=false)
251AM_CONDITIONAL(USE_WRAP_MEMRCHR, $local_cv_linker_use_wrap_memrchr)
252case x$local_cv_linker_use_wrap_memrchr in
253xtrue) AC_DEFINE(USE_WRAP_MEMRCHR) ;;
254esac
255AC_ARG_ENABLE(wrap-memset, [  --enable-wrap-memset    turn on wrapper for memset [[default=no]]], local_cv_linker_use_wrap_memset=true,local_cv_linker_use_wrap_memset=false)
256AM_CONDITIONAL(USE_WRAP_MEMSET, $local_cv_linker_use_wrap_memset)
257case x$local_cv_linker_use_wrap_memset in
258xtrue) AC_DEFINE(USE_WRAP_MEMSET) ;;
259esac
260AC_ARG_ENABLE(wrap-memmove, [  --enable-wrap-memmove   turn on wrapper for memmove [[default=no]]], local_cv_linker_use_wrap_memmove=true,local_cv_linker_use_wrap_memmove=false)
261AM_CONDITIONAL(USE_WRAP_MEMMOVE, $local_cv_linker_use_wrap_memmove)
262case x$local_cv_linker_use_wrap_memmove in
263xtrue) AC_DEFINE(USE_WRAP_MEMMOVE) ;;
264esac
265
266AC_ARG_ENABLE(examples, [  --enable-examples   turn on compilation of example program binaries [[default=no]]], AM_CONDITIONAL(USE_COMPILE_EXAMPLES, true),AM_CONDITIONAL(USE_COMPILE_EXAMPLES, false))
267
268LOCAL_EX_PROG_LIBS="-L../src -lvstr"
269AC_ARG_ENABLE(examples-static, [  --enable-examples-static   turn on static compilation of example program binaries [[default=no]]], local_cv_ex_static=true,local_cv_ex_static=false)
270AM_CONDITIONAL(USE_EX_STATIC_LIBS, $local_cv_ex_static)
271case x$local_cv_ex_static in
272xtrue) LOCAL_EX_PROG_LIBS="../src/.libs/libvstr.a" ;;
273esac
274AC_SUBST(LOCAL_EX_PROG_LIBS)
275
276LOCAL_TST_PROG_LIBS="-L../src -lvstr"
277AC_ARG_ENABLE(tsts-static, [  --enable-tsts-static   turn on static compilation of test suite binaries [[default=no]]], local_cv_tst_static=true,local_cv_tst_static=false)
278case x$local_cv_tst_static in
279xtrue) LOCAL_TST_PROG_LIBS="../src/.libs/libvstr.a" ;;
280esac
281AC_SUBST(LOCAL_TST_PROG_LIBS)
282
283AC_ARG_WITH(fmt-float, [  --with-fmt-float=TYPE   float conversion (glibc,none,host) [[default=host]]], local_cv_fmt_float=$withval,local_cv_fmt_float=host)
284case x$local_cv_fmt_float in
285xhost)
286   AM_CONDITIONAL(FMT_DBL_host,  true)
287   AM_CONDITIONAL(FMT_DBL_none,  false)
288   AM_CONDITIONAL(FMT_DBL_glibc, false)
289   AC_DEFINE(FMT_DBL_host) ;;
290xnone)
291   AM_CONDITIONAL(FMT_DBL_host,  false)
292   AM_CONDITIONAL(FMT_DBL_none,  true)
293   AM_CONDITIONAL(FMT_DBL_glibc, false)
294   AC_DEFINE(FMT_DBL_none) ;;
295xglibc)
296   AM_CONDITIONAL(FMT_DBL_host,  false)
297   AM_CONDITIONAL(FMT_DBL_none,  false)
298   AM_CONDITIONAL(FMT_DBL_glibc, true)
299   AC_DEFINE(FMT_DBL_glibc) ;;
300*)
301   AC_MSG_ERROR(fmt float value "$local_cv_fmt_float" unknown) ;;
302esac
303
304
305TWOCAN_CONF_MSG(Checking for headers)
306
307AC_HEADER_STDC
308AC_HEADER_TIME
309
310# AC_ARG_PROGRAM
311
312AC_CHECK_HEADER(malloc.h, AC_DEFINE(HAVE_MALLOC_H))
313
314# This needs to be a _lot_ better
315#  For instance... doesn't work on 2.0.x kernels, with glibc-2.x.x
316AC_CHECK_HEADER(poll.h, AC_DEFINE(HAVE_POLL_H))
317
318AC_CHECK_HEADER(sys/epoll.h, AC_DEFINE(HAVE_SYS_EPOLL_H))
319
320AC_CHECK_HEADER(sys/mman.h, AC_DEFINE(HAVE_SYS_MMAN_H))
321
322AC_CHECK_HEADER(dlfcn.h, AC_DEFINE(HAVE_DLFCN_H))
323
324AC_CHECK_HEADER(termcap.h, AC_DEFINE(HAVE_TERMCAP_H))
325
326# Assume we can use if it is there
327AC_CHECK_HEADER(sys/filio.h, AC_DEFINE(HAVE_SYS_FILIO_H))
328
329AC_CHECK_HEADER(sys/uio.h, AC_DEFINE(HAVE_SYS_UIO_H))
330
331AC_CHECK_HEADER(sys/un.h, AC_DEFINE(HAVE_SYS_UN_H))
332
333AC_CHECK_HEADER(zlib.h, AC_DEFINE(HAVE_ZLIB_H))
334
335AC_CHECK_HEADER(sys/prctl.h, AC_DEFINE(HAVE_SYS_PRCTL_H))
336
337#  This needs to be improved. -- as we probably want to support the
338# crappy FreeBSD version too (don't argue the interface is sick --
339# hello TCP_CORK).
340AC_CHECK_HEADER(sys/sendfile.h, AC_DEFINE(HAVE_SENDFILE))
341
342AC_CHECK_HEADER(gmp.h, [
343AM_CONDITIONAL(GMP_AVAIL, true)
344GMP_CFLAGS="";      AC_SUBST(GMP_CFLAGS)
345GMP_LDLIBS="-lgmp"; AC_SUBST(GMP_LDLIBS)
346],AM_CONDITIONAL(GMP_AVAIL, false))
347
348AC_CHECK_HEADER(zlib.h, [
349AM_CONDITIONAL(ZLIB_AVAIL, true)
350ZLIB_CFLAGS="";    AC_SUBST(ZLIB_CFLAGS)
351ZLIB_LDLIBS="-lz"; AC_SUBST(ZLIB_LDLIBS)
352],AM_CONDITIONAL(ZLIB_AVAIL, false))
353
354AC_CHECK_HEADER(bzlib.h, [
355AM_CONDITIONAL(BZ2_AVAIL, true)
356BZ2_CFLAGS="";      AC_SUBST(BZ2_CFLAGS)
357BZ2_LDLIBS="-lbz2"; AC_SUBST(BZ2_LDLIBS)
358],AM_CONDITIONAL(BZ2_AVAIL, false))
359
360TWOCAN_CONF_MSG(Checking for types, and defing if needed)
361
362AC_C_CONST
363
364AC_TYPE_SIGNAL
365
366AC_TYPE_MODE_T
367
368AC_TYPE_OFF_T
369
370# New autoconf goodness... or not
371XCFLAGS=$CFLAGS
372CFLAGS="-D_LARGEFILE64_SOURCE $CFLAGS"
373AC_CHECK_TYPE(off64_t, AC_DEFINE(HAVE_OFF64_T), AC_DEFINE_UNQUOTED(off64_t, off_t))
374CFLAGS=$XCFLAGS
375
376AC_TYPE_PID_T
377
378AC_TYPE_SIZE_T
379
380AC_TYPE_UID_T
381
382AC_DEFUN(AC_TYPE_SOCKLEN_T,
383[AC_CACHE_CHECK(for socklen_t in sys/socket.h, ac_cv_type_socklen_t,
384[AC_EGREP_HEADER(socklen_t, sys/socket.h,
385  ac_cv_type_socklen_t=yes, ac_cv_type_socklen_t=no)])
386if test $ac_cv_type_socklen_t = no; then
387  AC_DEFINE(socklen_t, int)
388fi
389])
390
391AC_TYPE_SOCKLEN_T
392
393# New autoconf goodness
394AC_CHECK_TYPE(intmax_t, long)
395AC_CHECK_TYPE(uintmax_t, unsigned long)
396AC_CHECK_TYPE(uintptr_t, unsigned long)
397
398AC_CHECK_TYPE(uint_least16_t, unsigned short)
399AC_CHECK_TYPE(uint_least32_t, unsigned long)
400
401AC_MSG_CHECKING(for long long)
402AC_CACHE_VAL(local_cv_has_long_long,[
403AC_TRY_RUN([
404#include <stdlib.h>
405
406long long a = 0;
407
408int main() {
409 unsigned long long b = (unsigned long long)a;
410 return (0);
411}],
412local_cv_has_long_long=yes,
413local_cv_has_long_long=no,
414)])
415AC_MSG_RESULT($local_cv_has_long_long)
416case x$local_cv_has_long_long in
417xyes) AC_DEFINE(HAVE_LONG_LONG) ;;
418esac
419
420TWOCAN_CONF_MSG(Checking for libraries to link against)
421
422
423# AC_CHECK_LIB(m, log10)
424AC_SUBST(LIBS)
425
426TWOCAN_CONF_MSG(Checking for functions)
427
428AC_FUNC_MMAP
429
430AC_FUNC_ALLOCA
431AC_FUNC_STRFTIME
432AC_FUNC_VFORK
433
434# L_IBOBJS is spelt with an _ because autoconf uses grep and doesn't know
435# the below are in comments...
436# now autoconf barfs on the L_IBOBJS stuff below...
437AC_CHECK_FUNCS(memcmp, AC_DEFINE(HAVE_MEMCMP),)
438# L_IBOBJS=""
439# AC_FUNC_MEMCMP
440# if test "x$L_IBOBJS" = "x"; then
441#  AC_DEFINE(HAVE_MEMCMP)
442# fi
443# L_IBOBJS=""
444
445# C String functions...
446AC_CHECK_FUNCS(memchr, AC_DEFINE(HAVE_MEMCHR),)
447AC_CHECK_FUNCS(memrchr, AC_DEFINE(HAVE_MEMRCHR),)
448AC_CHECK_FUNCS(memcpy, AC_DEFINE(HAVE_MEMCPY),)
449AC_CHECK_FUNCS(mempcpy, AC_DEFINE(HAVE_MEMPCPY),)
450AC_CHECK_FUNCS(memmem, AC_DEFINE(HAVE_MEMMEM),)
451AC_CHECK_FUNCS(strspn, AC_DEFINE(HAVE_STRSPN),)
452AC_CHECK_FUNCS(strcspn, AC_DEFINE(HAVE_STRCSPN),)
453AC_CHECK_FUNCS(stpcpy, AC_DEFINE(HAVE_STPCPY),)
454AC_CHECK_FUNCS(strncmp, AC_DEFINE(HAVE_STRNCMP),)
455AC_CHECK_FUNCS(strcasecmp, AC_DEFINE(HAVE_STRCASECMP),)
456AC_CHECK_FUNCS(strncasecmp, AC_DEFINE(HAVE_STRNCASECMP),)
457AC_CHECK_FUNCS(strnlen, AC_DEFINE(HAVE_STRNLEN),)
458AC_CHECK_FUNCS(asprintf, AC_DEFINE(HAVE_ASPRINTF),)
459AC_CHECK_FUNCS(strerror_r, AC_DEFINE(HAVE_STRERROR_R),)
460
461# Other functions...
462AC_CHECK_FUNCS(mmap64, AC_DEFINE(HAVE_MMAP64),)
463AC_CHECK_FUNCS(open64, AC_DEFINE(HAVE_OPEN64),)
464AC_CHECK_FUNCS(wcsnrtombs, AC_DEFINE(HAVE_WCSNRTOMBS),)
465AC_CHECK_FUNCS(wcrtomb, AC_DEFINE(USE_WIDE_CHAR_T),)
466AC_CHECK_FUNCS(getopt_long, AC_DEFINE(HAVE_GETOPT_LONG),)
467AC_CHECK_FUNCS(sigemptyset, AC_DEFINE(HAVE_SIGEMPTYSET),)
468AC_CHECK_FUNCS(difftime, AC_DEFINE(HAVE_DIFFTIME),)
469AC_CHECK_FUNCS(sigaction, AC_DEFINE(HAVE_SIGACTION),
470                          AC_MSG_ERROR(Need sigaction))
471
472AC_CHECK_FUNCS(inet_ntop, AC_DEFINE(HAVE_INET_NTOP),
473AC_CHECK_LIB(nsl, inet_ntop,
474                  [ LIBS="-lnsl $LIBS"; AC_DEFINE(HAVE_INET_NTOP) ]),
475AC_CHECK_FUNCS(inet_ntoa, AC_DEFINE(HAVE_INET_NTOA),
476AC_CHECK_LIB(nsl, inet_ntoa,
477                  [ LIBS="-lnsl $LIBS"; AC_DEFINE(HAVE_INET_NTOA) ])))
478
479AC_CHECK_FUNCS(inet_pton, AC_DEFINE(HAVE_INET_PTON),
480AC_CHECK_LIB(nsl, inet_pton,
481                  [ LIBS="-lnsl $LIBS"; AC_DEFINE(HAVE_INET_PTON) ]),
482AC_CHECK_FUNCS(inet_aton, AC_DEFINE(HAVE_INET_ATON),
483AC_CHECK_LIB(nsl, inet_aton,
484                  [ LIBS="-lnsl $LIBS"; AC_DEFINE(HAVE_INET_ATON) ]),
485AC_CHECK_FUNCS(inet_addr, AC_DEFINE(HAVE_INET_ADDR),
486AC_CHECK_LIB(nsl, inet_addr,
487                  [ LIBS="-lnsl $LIBS"; AC_DEFINE(HAVE_INET_ADDR) ]))))
488
489AC_CHECK_FUNCS(pread, AC_DEFINE(HAVE_PREAD),)
490
491# mmap repeated above for autoconf...
492AC_CHECK_FUNCS(mmap64,, AC_DEFINE(mmap64, mmap))
493AC_CHECK_FUNCS(open64,, AC_DEFINE(mmap64, open))
494AC_CHECK_FUNCS(lseek64,,AC_DEFINE(lseek64, lseek))
495AC_CHECK_FUNCS(fstat64,,AC_DEFINE(fstat64, fstat))
496# NOTE: this does the struct ... sick but works.
497AC_CHECK_FUNCS(stat64,,AC_DEFINE(stat64, stat))
498
499TWOCAN_CONF_MSG(Checking custom stuff, mainly does stuff exist/work)
500
501# Custom stuff from glibc...
502AC_CACHE_CHECK(for assembler global-symbol directive,
503               libc_cv_asm_global_directive, [dnl
504libc_cv_asm_global_directive=UNKNOWN
505for ac_globl in .globl .global .EXPORT; do
506  cat > conftest.s <<EOF
507        ${libc_cv_dot_text}
508        ${ac_globl} foo
509foo:
510EOF
511  if ${CC-cc} $CFLAGS -c conftest.s 2>/dev/null; then
512    libc_cv_asm_global_directive=${ac_globl}
513  fi
514  rm -f conftest*
515  test $libc_cv_asm_global_directive != UNKNOWN && break
516done])
517if test $libc_cv_asm_global_directive = UNKNOWN; then
518  AC_MSG_WARN(cannot determine asm global directive)
519else
520  AC_DEFINE_UNQUOTED(ASM_GLOBAL_DIRECTIVE, ${libc_cv_asm_global_directive})
521fi
522
523# My Custom stuff...
524AC_MSG_CHECKING(for an implementation of offsetof)
525AC_CACHE_VAL(local_cv_has_offsetof,[
526AC_TRY_RUN([
527#include <stddef.h>
528typedef struct abcd { int a; int b; } abcd;
529
530int main() {
531 int tmp = offsetof(abcd, b);
532 return (0);
533}],
534local_cv_has_offsetof=yes,
535local_cv_has_offsetof=no,
536)])
537AC_MSG_RESULT($local_cv_has_offsetof)
538case x$local_cv_has_offsetof in
539xyes) AC_DEFINE(HAVE_OFFSETOF) ;;
540xno) AC_MSG_WARN(Trying local offsetof -- it might not work though)
541esac
542
543AC_MSG_CHECKING(for an implementation of strerror)
544AC_CACHE_VAL(local_cv_has_strerror,[
545AC_TRY_RUN([
546#include <stddef.h>
547#include <stdlib.h>
548#include <errno.h>
549const char *msg = NULL;
550
551int main() {
552 msg = strerror(0);
553 return (0);
554}],
555local_cv_has_strerror=yes,
556local_cv_has_strerror=no,
557)])
558AC_MSG_RESULT($local_cv_has_strerror)
559case x$local_cv_has_strerror in
560xyes) AC_DEFINE(HAVE_STRERROR) ;;
561xno) AC_MSG_WARN(You won't get errno error messages.)
562esac
563
564AC_MSG_CHECKING(for an implementation of va_copy())
565AC_CACHE_VAL(local_cv_has_va_copy,[
566AC_TRY_RUN([
567#include <stdarg.h>
568void f (int i, ...)
569{
570va_list args1, args2;
571va_start (args1, i);
572va_copy (args2, args1);
573if (va_arg (args2, int) != 42 || va_arg (args1, int) != 42)
574  exit (1);
575va_end (args1); va_end (args2);
576}
577int main()
578{
579  f (0, 42);
580  return 0;
581}],
582local_cv_has_va_copy=yes,
583local_cv_has_va_copy=no,
584)])
585AC_MSG_RESULT($local_cv_has_va_copy)
586case x$local_cv_has_va_copy in
587xyes) AC_DEFINE(HAVE_VA_COPY)
588esac
589
590AC_MSG_CHECKING(for an implementation of __va_copy())
591AC_CACHE_VAL(local_cv_has___va_copy,[
592AC_TRY_RUN([
593#include <stdarg.h>
594void f (int i, ...)
595{
596va_list args1, args2;
597va_start (args1, i);
598__va_copy (args2, args1);
599if (va_arg (args2, int) != 42 || va_arg (args1, int) != 42)
600  exit (1);
601va_end (args1); va_end (args2);
602}
603int main()
604{
605  f (0, 42);
606  return 0;
607}],
608local_cv_has___va_copy=yes,
609local_cv_has___va_copy=no,
610)])
611AC_MSG_RESULT($local_cv_has___va_copy)
612case x$local_cv_has___va_copy in
613xyes) AC_DEFINE(HAVE___VA_COPY)
614esac
615
616AC_MSG_CHECKING(for a _WORKING_ implementation of poll())
617AC_CACHE_VAL(local_cv_has_poll,[
618AC_TRY_RUN([
619#include <poll.h>
620int main() {
621 struct pollfd fds[3];
622 fds[0].fd = 1;
623 fds[1].fd = 2;
624 fds[2].fd = 9999; /* some emulations don't work, Ie. glibc */
625 fds[0].events = fds[1].events = fds[2].events = POLLIN|POLLOUT;
626 fds[0].revents = fds[1].revents = fds[2].revents = 0;
627 if (poll(fds, 3, 0) == -1)
628   exit (1);
629 if (!(fds[0].revents & POLLOUT))
630   exit (2);
631 if (fds[0].revents & (POLLERR|POLLNVAL|POLLHUP))
632   exit (3);
633 if (!(fds[1].revents & POLLOUT))
634   exit (4);
635 if (fds[1].revents & (POLLERR|POLLNVAL|POLLHUP))
636   exit (5);
637 if (!(fds[2].revents & (POLLERR|POLLNVAL|POLLHUP)))
638   exit (6);
639 return 0;
640}],
641local_cv_has_poll=yes,
642local_cv_has_poll=no,
643)])
644
645AC_MSG_RESULT($local_cv_has_poll)
646case x$local_cv_has_poll in
647xyes) AC_DEFINE(HAVE_POLL)
648esac
649
650AC_MSG_CHECKING(for a RTLD_GLOBAL def)
651AC_CACHE_VAL(local_cv_has_dl_rtld_global,[
652AC_TRY_RUN([
653#include <stdlib.h>
654#ifdef HAVE_DLFCN_H
655#include <dlfcn.h>
656#endif
657
658int main() {
659 int tmp = RTLD_GLOBAL;
660 return 0;
661}],
662local_cv_has_dl_rtld_global=yes,
663local_cv_has_dl_rtld_global=no,
664)])
665AC_MSG_RESULT($local_cv_has_dl_rtld_global)
666case x$local_cv_has_dl_rtld_global in
667xyes) AC_DEFINE(HAVE_DL_RTLD_GLOBAL)
668esac
669
670# This is complicated because many sprintf()'s are broken...
671AC_MSG_CHECKING(for a C9x snprintf() return)
672AC_CACHE_VAL(local_cv_has_C9x_snprintf_ret,[
673AC_TRY_RUN([
674#define _GNU_SOURCE
675#include <stdlib.h>
676#include <stdio.h>
677
678int main() {
679 char buffer[4];
680 int tmp = snprintf(buffer, 4, "%s", "123456");
681
682 if (tmp != 6)
683  exit (1);
684
685 if (!( (buffer[0] == '1') && (buffer[1] == '2') && (buffer[2] == '3') &&
686        (buffer[3] == 0) ))
687  exit (1);
688 return 0;
689}],
690local_cv_has_C9x_snprintf_ret=yes,
691local_cv_has_C9x_snprintf_ret=no,
692)])
693AC_MSG_RESULT($local_cv_has_C9x_snprintf_ret)
694case x$local_cv_has_C9x_snprintf_ret in
695xyes) AC_DEFINE(HAVE_C9X_SNPRINTF_RET)
696esac
697
698AC_MSG_CHECKING(for a C9x sprintf() format F)
699AC_CACHE_VAL(local_cv_has_C9x_sprintf_fmt_F,[
700AC_TRY_RUN([
701#define _GNU_SOURCE
702#include <stdlib.h>
703#include <stdio.h>
704
705int main() {
706 char buffer[1024];
707
708 sprintf(buffer, "%F", 0.0);
709
710 if (!( (buffer[0] == '0') && (buffer[1] == '.') && (buffer[2] == '0') &&
711        (buffer[3] == '0') && (buffer[4] == '0') && (buffer[5] == '0') &&
712        (buffer[6] == '0') && (buffer[7] == '0') &&
713        (buffer[8] == 0) ))
714  exit (1);
715 return 0;
716}],
717local_cv_has_C9x_sprintf_fmt_F=yes,
718local_cv_has_C9x_sprintf_fmt_F=no,
719)])
720AC_MSG_RESULT($local_cv_has_C9x_sprintf_fmt_F)
721case x$local_cv_has_C9x_sprintf_fmt_F in
722xyes) AC_DEFINE(HAVE_C9X_SPRINTF_FMT_F)
723esac
724
725AC_MSG_CHECKING(for a C9x sprintf() format A)
726AC_CACHE_VAL(local_cv_has_C9x_sprintf_fmt_A,[
727AC_TRY_RUN([
728#define _GNU_SOURCE
729#include <stdlib.h>
730#include <stdio.h>
731
732int main() {
733 char buffer[1024];
734
735 sprintf(buffer, "%A", 0.0);
736
737 if (!( (buffer[0] == '0') && (buffer[1] == 'X') && (buffer[2] == '0') &&
738        (buffer[3] == 'P') && (buffer[4] == '+') && (buffer[5] == '0') &&
739        (buffer[6] == 0) ))
740  exit (1);
741 return 0;
742}],
743local_cv_has_C9x_sprintf_fmt_A=yes,
744local_cv_has_C9x_sprintf_fmt_A=no,
745)])
746AC_MSG_RESULT($local_cv_has_C9x_sprintf_fmt_A)
747case x$local_cv_has_C9x_sprintf_fmt_A in
748xyes) AC_DEFINE(HAVE_C9X_SPRINTF_FMT_A)
749esac
750
751AC_MSG_CHECKING(for a C9x sprintf() format a)
752AC_CACHE_VAL(local_cv_has_C9x_sprintf_fmt_a,[
753AC_TRY_RUN([
754#define _GNU_SOURCE
755#include <stdlib.h>
756#include <stdio.h>
757
758int main() {
759 char buffer[1024];
760
761 sprintf(buffer, "%a", 0.0);
762
763 if (!( (buffer[0] == '0') && (buffer[1] == 'x') && (buffer[2] == '0') &&
764        (buffer[3] == 'p') && (buffer[4] == '+') && (buffer[5] == '0') &&
765        (buffer[6] == 0) ))
766  exit (1);
767 return 0;
768}],
769local_cv_has_C9x_sprintf_fmt_a=yes,
770local_cv_has_C9x_sprintf_fmt_a=no,
771)])
772AC_MSG_RESULT($local_cv_has_C9x_sprintf_fmt_a)
773case x$local_cv_has_C9x_sprintf_fmt_a in
774xyes) AC_DEFINE(HAVE_C9X_SPRINTF_FMT_a)
775esac
776
777AC_MSG_CHECKING(if char works as a bitflag type)
778AC_CACHE_VAL(local_cv_has_char_bitflag,[
779AC_TRY_RUN([
780#define _GNU_SOURCE
781#include <stdlib.h>
782#include <stdio.h>
783
784typedef struct abcd {
785 int num;
786
787 unsigned char one : 1;
788 unsigned char two : 1;
789 unsigned char three : 1;
790 unsigned char four : 1;
791 unsigned char five : 1;
792 unsigned char six : 1;
793 unsigned char seven : 1;
794 unsigned char eight : 1;
795} abcd;
796
797int main() {
798  abcd tmp = {8, 0, 0, 0, 0, 1, 1, 1, 1};
799
800 if ((tmp.num != 8) || tmp.one || tmp.two || tmp.three || tmp.four
801     || !tmp.five || !tmp.six || !tmp.seven || !tmp.eight)
802  exit (1);
803
804 return 0;
805}],
806local_cv_has_char_bitflag=yes,
807local_cv_has_char_bitflag=no,
808)])
809AC_MSG_RESULT($local_cv_has_char_bitflag)
810case x$local_cv_has_char_bitflag in
811xyes) AC_DEFINE(HAVE_CHAR_BITFLAG)
812esac
813
814AC_MSG_CHECKING(if setrlimit/getrlimit work)
815AC_CACHE_VAL(local_cv_has_setrlimit,[
816AC_TRY_RUN([
817#define _GNU_SOURCE
818#include <stdlib.h>
819#include <stdio.h>
820#include <sys/time.h>
821#include <sys/resource.h>
822#include <unistd.h>
823
824int main() {
825
826 struct rlimit tmp;
827 getrlimit(RLIMIT_CORE, &tmp);
828 tmp.rlim_cur = RLIM_INFINITY;
829 setrlimit(RLIMIT_CORE, &tmp);
830}],
831local_cv_has_setrlimit=yes,
832local_cv_has_setrlimit=no,
833)])
834AC_MSG_RESULT($local_cv_has_setrlimit)
835case x$local_cv_has_setrlimit in
836xyes) AC_DEFINE(HAVE_SETRLIMIT)
837esac
838
839AC_MSG_CHECKING(for prctl)
840AC_CACHE_VAL(local_cv_has_prctl,[
841AC_TRY_RUN([
842#define _GNU_SOURCE
843#include <stdlib.h>
844#include <stdio.h>
845
846#define PR_SET_PDEATHSIG 1
847
848int main() {
849 prctl(PR_SET_PDEATHSIG, 9, 0, 0, 0);
850 return (0);
851}],
852local_cv_has_prctl=yes,
853local_cv_has_prctl=no,
854)])
855AC_MSG_RESULT($local_cv_has_prctl)
856case x$local_cv_has_prctl in
857xyes) AC_DEFINE(HAVE_PRCTL)
858esac
859
860AC_MSG_CHECKING(for linux compat sigcontext)
861AC_CACHE_VAL(local_cv_has_sigcontext,[
862AC_TRY_RUN([
863#define _GNU_SOURCE
864#include <stdlib.h>
865#include <sys/time.h>
866#include <signal.h>
867
868int main() {
869  struct sigcontext con;
870
871       con.gs = 0; con.__gsh = 0;
872       con.fs = 0; con.__fsh = 0;
873       con.es = 0; con.__esh = 0;
874       con.ds = 0; con.__dsh = 0;
875       con.edi = 0;
876       con.esi = 0;
877       con.ebp = 0;
878       con.esp = 0;
879       con.ebx = 0;
880       con.edx = 0;
881       con.ecx = 0;
882       con.eax = 0;
883       con.trapno = 0;
884       con.err = 0;
885       con.eip = 0;
886       con.cs = 0; con.__csh = 0;
887       con.eflags = 0;
888       con.esp_at_signal = 0;
889       con.ss = 0; con.__ssh = 0;
890       con.fpstate = 0;
891       con.fpstate ?
892        (con.fpstate->status = 0) : 0;
893       con.oldmask = 0;
894       con.cr2 = 0;
895
896
897 return 0;
898}],
899local_cv_has_sigcontext=yes,
900local_cv_has_sigcontext=no,
901)])
902AC_MSG_RESULT($local_cv_has_sigcontext)
903case x$local_cv_has_sigcontext in
904xyes) AC_DEFINE(HAVE_SIGCONTEXT)
905esac
906
907AC_MSG_CHECKING(for _old_ linux compat sigcontext)
908AC_CACHE_VAL(local_cv_has_old_sigcontext,[
909AC_TRY_RUN([
910#define _GNU_SOURCE
911#include <stdlib.h>
912#include <sys/time.h>
913#include <signal.h>
914#include <asm/sigcontext.h>
915
916#define sigcontext sigcontext_struct
917
918int main() {
919  struct sigcontext con;
920
921       con.gs = 0; con.__gsh = 0;
922       con.fs = 0; con.__fsh = 0;
923       con.es = 0; con.__esh = 0;
924       con.ds = 0; con.__dsh = 0;
925       con.edi = 0;
926       con.esi = 0;
927       con.ebp = 0;
928       con.esp = 0;
929       con.ebx = 0;
930       con.edx = 0;
931       con.ecx = 0;
932       con.eax = 0;
933       con.trapno = 0;
934       con.err = 0;
935       con.eip = 0;
936       con.cs = 0; con.__csh = 0;
937       con.eflags = 0;
938       con.esp_at_signal = 0;
939       con.ss = 0; con.__ssh = 0;
940       con.fpstate = 0;
941       con.fpstate ?
942        (con.fpstate->status = 0) : 0;
943       con.oldmask = 0;
944       con.cr2 = 0;
945
946
947 return 0;
948}],
949local_cv_has_old_sigcontext=yes,
950local_cv_has_old_sigcontext=no,
951)])
952AC_MSG_RESULT($local_cv_has_old_sigcontext)
953case x$local_cv_has_old_sigcontext in
954xyes) AC_DEFINE(HAVE_OLD_SIGCONTEXT)
955esac
956
957AC_MSG_CHECKING(for mallinfo)
958AC_CACHE_VAL(local_cv_has_mallinfo,[
959AC_TRY_RUN([
960#define _GNU_SOURCE
961#include <stdlib.h>
962#include <malloc.h>
963
964int main() {
965 struct mallinfo mem_info = mallinfo(); /* produces a warning */
966 mem_info.arena = 0;
967 mem_info.ordblks = 0;
968 mem_info.smblks = 0;
969 mem_info.hblks = 0;
970 mem_info.hblkhd = 0;
971 mem_info.usmblks = 0;
972 mem_info.fsmblks = 0;
973 mem_info.uordblks = 0;
974 mem_info.fordblks = 0;
975 mem_info.keepcost = 0;
976
977 return (0);
978}],
979local_cv_has_mallinfo=yes,
980local_cv_has_mallinfo=no,
981)])
982AC_MSG_RESULT($local_cv_has_mallinfo)
983case x$local_cv_has_mallinfo in
984xyes) AC_DEFINE(HAVE_MALLINFO)
985      AM_CONDITIONAL(MALLINFO_AVAIL, true)
986      ;;
987xno)  AM_CONDITIONAL(MALLINFO_AVAIL, false)
988esac
989
990AC_MSG_CHECKING(for termcap variables)
991AC_CACHE_VAL(local_cv_has_decl_termcap_vars,[
992AC_TRY_RUN([
993#define _GNU_SOURCE
994#include <stdlib.h>
995
996#include <termcap.h>
997
998int main() {
999 PC = 0;
1000 ospeed = 0;
1001
1002 return (0);
1003}],
1004local_cv_has_decl_termcap_vars=yes,
1005local_cv_has_decl_termcap_vars=no,
1006)])
1007AC_MSG_RESULT($local_cv_has_decl_termcap_vars)
1008case x$local_cv_has_decl_termcap_vars in
1009xyes) AC_DEFINE(HAVE_DECL_TERMCAP_VARS)
1010esac
1011
1012AC_MSG_CHECKING(for time_t as int's)
1013AC_CACHE_VAL(local_cv_use_quick_add_time,[
1014AC_TRY_RUN([
1015#define _GNU_SOURCE
1016#include <stdlib.h>
1017#include <sys/time.h>
1018#include <time.h>
1019
1020int main() {
1021 time_t abcd = time(NULL);
1022 time_t abcd2 = abcd + 234;
1023 struct tm *tm = localtime(&abcd);
1024
1025 tm->tm_sec += 234;
1026 if (abcd2 != mktime(tm)) exit (1);
1027
1028 return 0;
1029}],
1030local_cv_use_quick_add_time=yes,
1031local_cv_use_quick_add_time=no,
1032)])
1033AC_MSG_RESULT($local_cv_use_quick_add_time)
1034case x$local_cv_use_quick_add_time in
1035xyes) AC_DEFINE(USE_QUICK_ADD_TIME)
1036esac
1037
1038AC_MSG_CHECKING(for usable sigaltstack)
1039AC_CACHE_VAL(local_cv_have_sigaltstack,[
1040AC_TRY_RUN([
1041#define _GNU_SOURCE
1042#include <stdlib.h>
1043#include <signal.h>
1044
1045int main() {
1046 char buffer[SIGSTKSZ];
1047 struct sigaltstack alt_stack;
1048 int abcd = SA_ONSTACK;
1049
1050 alt_stack.ss_size = SIGSTKSZ;
1051 alt_stack.ss_sp = buffer;
1052
1053 sigaltstack(&alt_stack, NULL);
1054
1055 return (0);
1056}],
1057local_cv_have_sigaltstack=yes,
1058local_cv_have_sigaltstack=no,
1059)])
1060AC_MSG_RESULT($local_cv_have_sigaltstack)
1061case x$local_cv_have_sigaltstack in
1062xyes) AC_DEFINE(HAVE_SIGALTSTACK)
1063esac
1064
1065AC_MSG_CHECKING(for C9x struct hack support)
1066AC_CACHE_VAL(local_cv_have_C9x_struct_hack,[
1067AC_TRY_RUN([
1068#define _GNU_SOURCE
1069#include <stddef.h>
1070#include <stdlib.h>
1071#include <stdio.h>
1072
1073struct abcd
1074{
1075 int len;
1076 char buffer[];
1077};
1078
1079int main() {
1080 struct abcd *abcd = malloc(sizeof(struct abcd) + 256);
1081
1082 abcd->len = 256;
1083 memset(abcd->buffer, 0, 256);
1084 return (0);
1085}],
1086local_cv_have_C9x_struct_hack=yes,
1087local_cv_have_C9x_struct_hack=no,
1088)])
1089AC_MSG_RESULT($local_cv_have_C9x_struct_hack)
1090case x$local_cv_have_C9x_struct_hack in
1091xyes) AC_DEFINE(HAVE_C9x_STRUCT_HACK)
1092esac
1093
1094AC_MSG_CHECKING(for cmsghdr struct)
1095AC_CACHE_VAL(local_cv_have_struct_cmsghdr,[
1096AC_TRY_RUN([
1097#define _GNU_SOURCE
1098#include <sys/types.h>
1099#include <sys/socket.h>
1100
1101struct abcd
1102{
1103 struct cmsghdr cmsg;
1104 int fd;
1105};
1106
1107int main() {
1108 struct abcd abcd;
1109
1110 abcd.cmsg.cmsg_len = 0;
1111 abcd.cmsg.cmsg_level = SOL_SOCKET;
1112 abcd.cmsg.cmsg_type = 0;
1113
1114 return (0);
1115}],
1116local_cv_have_struct_cmsghdr=yes,
1117local_cv_have_struct_cmsghdr=no,
1118)])
1119AC_MSG_RESULT($local_cv_have_struct_cmsghdr)
1120case x$local_cv_have_struct_cmsghdr in
1121xyes) AC_DEFINE(HAVE_CMSGHDR_STRUCT)
1122esac
1123
1124AC_MSG_CHECKING(for fd passing in cmsghdr)
1125AC_CACHE_VAL(local_cv_have_cmsghdr_rights,[
1126AC_TRY_RUN([
1127#define _GNU_SOURCE
1128#include <sys/types.h>
1129#include <sys/socket.h>
1130
1131struct abcd
1132{
1133 struct cmsghdr cmsg;
1134 int fd;
1135};
1136
1137int main() {
1138 struct abcd abcd;
1139
1140 abcd.cmsg.cmsg_len = 0;
1141 abcd.cmsg.cmsg_level = SOL_SOCKET;
1142 abcd.cmsg.cmsg_type = SCM_RIGHTS;
1143
1144 return (0);
1145}],
1146local_cv_have_cmsghdr_rights=yes,
1147local_cv_have_cmsghdr_rights=no,
1148)])
1149AC_MSG_RESULT($local_cv_have_cmsghdr_rights)
1150case x$local_cv_have_cmsghdr_rights in
1151xyes) AC_DEFINE(HAVE_CMSGHDR_RIGHTS)
1152esac
1153
1154AC_MSG_CHECKING(for credentials passing in cmsghdr)
1155AC_CACHE_VAL(local_cv_have_cmsghdr_credentials,[
1156AC_TRY_RUN([
1157#define _GNU_SOURCE
1158#include <sys/types.h>
1159#include <sys/socket.h>
1160
1161struct abcd
1162{
1163 struct cmsghdr cmsg;
1164 int fd;
1165};
1166
1167int main() {
1168 struct abcd abcd;
1169
1170 abcd.cmsg.cmsg_len = 0;
1171 abcd.cmsg.cmsg_level = SOL_SOCKET;
1172 abcd.cmsg.cmsg_type = SCM_CREDENTIALS;
1173
1174 return (0);
1175}],
1176local_cv_have_cmsghdr_credentials=yes,
1177local_cv_have_cmsghdr_credentials=no,
1178)])
1179AC_MSG_RESULT($local_cv_have_cmsghdr_credentials)
1180case x$local_cv_have_cmsghdr_credentials in
1181xyes) AC_DEFINE(HAVE_CMSGHDR_CREDENTIALS)
1182esac
1183
1184AC_MSG_CHECKING(for credentials passing in setsockopt)
1185AC_CACHE_VAL(local_cv_have_so_peercreds,[
1186AC_TRY_RUN([
1187#define _GNU_SOURCE
1188#include <sys/types.h>
1189#include <sys/socket.h>
1190
1191int main() {
1192 int val1 = SOL_SOCKET;
1193 int val2 = SO_PEERCRED;
1194
1195 return (0);
1196}],
1197local_cv_have_so_peercreds=yes,
1198local_cv_have_so_peercreds=no,
1199)])
1200AC_MSG_RESULT($local_cv_have_so_peercreds)
1201case x$local_cv_have_so_peercreds in
1202xyes) AC_DEFINE(HAVE_SO_PEERCREDS)
1203esac
1204
1205AC_MSG_CHECKING(for CMSG_DATA macro)
1206AC_CACHE_VAL(local_cv_have_cmsg_data,[
1207AC_TRY_RUN([
1208#define _GNU_SOURCE
1209#include <sys/types.h>
1210#include <sys/socket.h>
1211
1212struct abcd
1213{
1214 struct cmsghdr cmsg;
1215 int fd;
1216};
1217
1218int main() {
1219 struct abcd abcd;
1220 char *tmp = CMSG_DATA(&abcd.cmsg);
1221
1222 return (0);
1223}],
1224local_cv_have_cmsg_data=yes,
1225local_cv_have_cmsg_data=no,
1226)])
1227AC_MSG_RESULT($local_cv_have_cmsg_data)
1228case x$local_cv_have_cmsg_data in
1229xyes) AC_DEFINE(HAVE_CMSG_DATA)
1230esac
1231
1232AC_MSG_CHECKING(for TCP_CORK socket option)
1233AC_CACHE_VAL(local_cv_have_tcp_cork,[
1234AC_TRY_RUN([
1235#define _GNU_SOURCE
1236#include <stddef.h>
1237#include <stdlib.h>
1238#include <stdio.h>
1239#include <sys/socket.h>
1240#include <netinet/tcp.h>
1241
1242int main() {
1243 int val1 = SOL_TCP;
1244 int val2 = TCP_CORK;
1245
1246 return (0);
1247}],
1248local_cv_have_tcp_cork=yes,
1249local_cv_have_tcp_cork=no,
1250)])
1251AC_MSG_RESULT($local_cv_have_tcp_cork)
1252case x$local_cv_have_tcp_cork in
1253xyes) AC_DEFINE(HAVE_TCP_CORK)
1254esac
1255
1256AC_MSG_CHECKING(for ipv6 sockaddr structure)
1257AC_CACHE_VAL(local_cv_have_sockaddr_in6,[
1258AC_TRY_RUN([
1259#define _GNU_SOURCE
1260#include <stddef.h>
1261#include <sys/socket.h>
1262#include <netinet/in.h>
1263
1264int main() {
1265 struct sockaddr_in6 sa_in6;
1266 return (0);
1267}],
1268local_cv_have_sockaddr_in6=yes,
1269local_cv_have_sockaddr_in6=no,
1270)])
1271AC_MSG_RESULT($local_cv_have_sockaddr_in6)
1272case x$local_cv_have_sockaddr_in6 in
1273xyes) AC_DEFINE(HAVE_SOCKADDR_IN6)
1274esac
1275
1276XLDFLAGS="$LDFLAGS"
1277LDFLAGS="$LDFLAGS -Wl,-e,relocated_main"
1278
1279AC_MSG_CHECKING(for linker main symbol redirection)
1280AC_CACHE_VAL(local_cv_linker_have_relocationable_main,[
1281AC_TRY_RUN([
1282#define _GNU_SOURCE
1283
1284int relocated_main() {
1285 _exit (0);
1286}
1287int main() {
1288 return (1);
1289}],
1290local_cv_linker_have_relocationable_main=true,
1291local_cv_linker_have_relocationable_main=false,
1292)])
1293AC_MSG_RESULT($local_cv_linker_have_relocationable_main)
1294AM_CONDITIONAL(HAVE_LINKER_MAIN_RELOCATE, $local_cv_linker_have_relocationable_main)
1295
1296LDFLAGS="$XLDFLAGS"
1297
1298
1299AC_MSG_CHECKING(for the length of ULONG_MAX as a string)
1300AC_CACHE_VAL(local_cv_has_ULONG_MAX_len_sprintf,[
1301AC_TRY_RUN([
1302#include <stdlib.h>
1303#include <stdio.h>
1304#include <string.h>
1305#include <limits.h>
1306
1307int main() {
1308 char buffer[1024 + (CHAR_BIT * sizeof(unsigned long))];
1309 int len;
1310 sprintf(buffer, "%lu", ULONG_MAX);
1311 len = strlen(buffer);
1312 { FILE *f = fopen("conftestval", "w");
1313   if (!f) exit (1);
1314   fprintf(f, "%d\n", len);
1315 }
1316 return 0;
1317}],
1318[local_cv_has_ULONG_MAX_len_sprintf=`cat conftestval`],
1319local_cv_has_ULONG_MAX_len_sprintf="nope",
1320)])
1321AC_MSG_RESULT($local_cv_has_ULONG_MAX_len_sprintf)
1322case x$local_cv_has_ULONG_MAX_len_sprintf in
1323xnope) ;;
1324*) AC_DEFINE_UNQUOTED(ULONG_MAX_LEN, $local_cv_has_ULONG_MAX_len_sprintf)
1325esac
1326
1327
1328case x$local_cv_have_tst_noinline in
1329 xfalse)
1330AC_MSG_CHECKING(if inline is a valid keyword)
1331AC_CACHE_VAL(local_cv_has_inline,[
1332AC_TRY_RUN([
1333#include <stdlib.h>
1334#include <stdio.h>
1335
1336inline int func(void) { return (0); }
1337
1338int main() {
1339 return func();
1340}],
1341local_cv_has_inline=yes,
1342local_cv_has_inline=no,
1343)])
1344AC_MSG_RESULT($local_cv_has_inline)
1345;;
1346esac
1347case x$local_cv_has_inline in
1348xyes) AC_DEFINE(HAVE_INLINE) ;;
1349esac
1350
1351# Beg testing attributes ... turn warnings into errors...
1352XCFLAGS=$CFLAGS
1353CFLAGS="-Werror $CFLAGS"
1354
1355
1356case x$local_cv_have_tst_noattr_alias in
1357 xfalse)
1358AC_MSG_CHECKING(if alias is a valid attribute)
1359AC_CACHE_VAL(local_cv_has_attrib_alias,[
1360AC_TRY_RUN([
1361#include <stdlib.h>
1362#include <stdio.h>
1363
1364int abcd(void) { return (0); }
1365extern int func(void) __attribute__((alias("abcd"))) ;
1366
1367int main() {
1368 return func();
1369}],
1370local_cv_has_attrib_alias=yes,
1371local_cv_has_attrib_alias=no,
1372)])
1373AC_MSG_RESULT($local_cv_has_attrib_alias)
1374;;
1375esac
1376case x$local_cv_has_attrib_alias in
1377xyes) AC_DEFINE(HAVE_ATTRIB_ALIAS) ;;
1378esac
1379
1380AC_MSG_CHECKING(if deprecated is a valid attribute)
1381AC_CACHE_VAL(local_cv_has_attrib_deprecated,[
1382AC_TRY_RUN([
1383#include <stdlib.h>
1384#include <stdio.h>
1385
1386int abcd(void) { return (0); }
1387extern int func(void) __attribute__((deprecated)) ;
1388
1389int main() {
1390 return abcd();
1391}],
1392local_cv_has_attrib_deprecated=yes,
1393local_cv_has_attrib_deprecated=no,
1394)])
1395AC_MSG_RESULT($local_cv_has_attrib_deprecated)
1396case x$local_cv_has_attrib_deprecated in
1397xyes) AC_DEFINE(HAVE_ATTRIB_DEPRECATED) ;;
1398esac
1399
1400AC_MSG_CHECKING(if malloc is a valid attribute)
1401AC_CACHE_VAL(local_cv_has_attrib_malloc,[
1402AC_TRY_RUN([
1403#include <stdlib.h>
1404#include <stdio.h>
1405
1406int abcd(void *p) { return (!p); }
1407void *func(void) __attribute__((malloc)) ;
1408void *func(void) { return (malloc(4)); }
1409
1410int main() {
1411 return abcd(func());
1412}],
1413local_cv_has_attrib_malloc=yes,
1414local_cv_has_attrib_malloc=no,
1415)])
1416AC_MSG_RESULT($local_cv_has_attrib_malloc)
1417case x$local_cv_has_attrib_malloc in
1418xyes) AC_DEFINE(HAVE_ATTRIB_MALLOC) ;;
1419esac
1420
1421AC_MSG_CHECKING(if nonnull is a valid attribute)
1422AC_CACHE_VAL(local_cv_has_attrib_nonnull,[
1423AC_TRY_RUN([
1424#include <stdlib.h>
1425#include <stdio.h>
1426
1427int func(char *) __attribute__((nonnull)) ;
1428int func(char *abcd) { return (!abcd); }
1429
1430int main() {
1431 return func("abcd");
1432}],
1433local_cv_has_attrib_nonnull=yes,
1434local_cv_has_attrib_nonnull=no,
1435)])
1436AC_MSG_RESULT($local_cv_has_attrib_nonnull)
1437case x$local_cv_has_attrib_nonnull in
1438xyes) AC_DEFINE(HAVE_ATTRIB_NONNULL) ;;
1439esac
1440
1441AC_MSG_CHECKING(if pure is a valid attribute)
1442AC_CACHE_VAL(local_cv_has_attrib_pure,[
1443AC_TRY_RUN([
1444#include <stdlib.h>
1445#include <stdio.h>
1446#include <string.h>
1447
1448int abcd(int n)  __attribute__((__pure__)) ;
1449int abcd(int n) { return (!n); }
1450
1451int main() {
1452 return abcd(2);
1453}],
1454local_cv_has_attrib_pure=yes,
1455local_cv_has_attrib_pure=no,
1456)])
1457AC_MSG_RESULT($local_cv_has_attrib_pure)
1458case x$local_cv_has_attrib_pure in
1459xyes) AC_DEFINE(HAVE_ATTRIB_PURE) ;;
1460esac
1461
1462AC_MSG_CHECKING(if const is a valid attribute)
1463AC_CACHE_VAL(local_cv_has_attrib_const,[
1464AC_TRY_RUN([
1465#include <stdlib.h>
1466#include <stdio.h>
1467#include <string.h>
1468
1469int abcd(int n)  __attribute__((__const__)) ;
1470int abcd(int n) { return (!n); }
1471
1472int main() {
1473 return abcd(2);
1474}],
1475local_cv_has_attrib_const=yes,
1476local_cv_has_attrib_const=no,
1477)])
1478AC_MSG_RESULT($local_cv_has_attrib_const)
1479case x$local_cv_has_attrib_const in
1480xyes) AC_DEFINE(HAVE_ATTRIB_CONST) ;;
1481esac
1482
1483case x$local_cv_have_tst_noattr_visibility in
1484 xfalse)
1485AC_MSG_CHECKING(if visibility is a valid attribute)
1486AC_CACHE_VAL(local_cv_has_attrib_visibility,[
1487AC_TRY_RUN([
1488#include <stdlib.h>
1489#include <stdio.h>
1490
1491int func(void) __attribute__((visibility("hidden"))) ;
1492int func(void) { return (0); }
1493
1494int main() {
1495 return func();
1496}],
1497local_cv_has_attrib_visibility=yes,
1498local_cv_has_attrib_visibility=no,
1499)])
1500AC_MSG_RESULT($local_cv_has_attrib_visibility)
1501;;
1502esac
1503case x$local_cv_has_attrib_visibility in
1504xyes) AC_DEFINE(HAVE_ATTRIB_VISIBILITY) ;;
1505esac
1506
1507AC_MSG_CHECKING(if warn_unused_result is a valid attribute)
1508AC_CACHE_VAL(local_cv_has_attrib_warn_unused_ret,[
1509AC_TRY_RUN([
1510#include <stdlib.h>
1511#include <stdio.h>
1512
1513int func(char *) __attribute__((warn_unused_result)) ;
1514int func(char *abcd) { return (!abcd); }
1515
1516int main() {
1517 return func("abcd");
1518}],
1519local_cv_has_attrib_warn_unused_ret=yes,
1520local_cv_has_attrib_warn_unused_ret=no,
1521)])
1522AC_MSG_RESULT($local_cv_has_attrib_warn_unused_ret)
1523case x$local_cv_has_attrib_warn_unused_ret in
1524xyes) AC_DEFINE(HAVE_ATTRIB_WARN_UNUSED_RET) ;;
1525esac
1526
1527
1528CFLAGS=$XCFLAGS
1529# End testing attributes ... turn CFLAGS back to normal
1530
1531AC_MSG_CHECKING(if __typeof is a valid keyword)
1532AC_CACHE_VAL(local_cv_has___typeof,[
1533AC_TRY_RUN([
1534#include <stdlib.h>
1535#include <stdio.h>
1536
1537int func(void) { return (0); }
1538extern __typeof(func) abcd;
1539
1540int main() {
1541 return func();
1542}],
1543local_cv_has___typeof=yes,
1544local_cv_has___typeof=no,
1545)])
1546AC_MSG_RESULT($local_cv_has___typeof)
1547case x$local_cv_has___typeof in
1548xyes) AC_DEFINE(HAVE___TYPEOF) ;;
1549esac
1550
1551TWOCAN_CONF_MSG(Output Substitution)
1552
1553AC_OUTPUT([Makefile
1554           vstr.pc
1555           vstr-debug.pc
1556           src/Makefile
1557           include/Makefile
1558           Documentation/Makefile
1559           tst/Makefile
1560           examples/Makefile
1561           examples/init.d/jechod
1562           src/vstr_version.c
1563           vstr.spec
1564           VERSION
1565])
1566
1567$SED_PATH 's%^#define *%#define VSTR_AUTOCONF_%' < include/autoconf.h > include/vstr-conf.h
1568