summaryrefslogtreecommitdiffstats
path: root/nbase/configure.ac
blob: 37069da422323c460cb8589814b255010453501e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
dnl # -*- mode: fundamental; -*-
dnl # Autoconf configuration file for Nbase
dnl #
dnl # Process this file with autoconf to produce a configure script.
dnl # $Id$

# Because nbase is usually distributed with Nmap, the necessary files
# config.guess, config.guess, and install-sh are not distributed with
# nbase. Rather they are gotten from Nmap.

# Require autoconf 2.13
AC_PREREQ(2.13)

# Include my own macros
m4_include([acinclude.m4])

AC_INIT(nbase.h)

AC_ARG_WITH(localdirs,
  [  --with-localdirs        Explicitly ask compiler to use /usr/local/{include,libs} if they exist ],
  [ case "$with_localdirs" in
      yes)
        user_localdirs=1
        ;;
      no)
        user_localdirs=0
        ;;
    esac
    ],
  [ user_localdirs=0 ] )

if test "$user_localdirs" = 1; then
   if test -d /usr/local/lib; then
     LDFLAGS="$LDFLAGS -L/usr/local/lib"
     fi
   if test -d /usr/local/include; then
     CPPFLAGS="$CPPFLAGS -I/usr/local/include"
   fi
fi

dnl use config.h instad of -D macros
AC_CONFIG_HEADER(nbase_config.h)

dnl Checks for programs.
AC_PROG_CC

 if test -n "$GCC"; then
      CFLAGS="$CFLAGS -Wall "
 fi
AC_PROG_RANLIB
dnl AC_PROG_INSTALL
dnl AC_PATH_PROG(MAKEDEPEND, makedepend)

dnl Host specific hacks
AC_CANONICAL_HOST

dnl equiv to '#define inline' to 'inline', '__inline__', '__inline' or ''
AC_C_INLINE

case "$host" in
  *-sgi-irix5* | *-sgi-irix6*)
    if test -z "$GCC"; then
      AC_DEFINE(inline, )
    fi
    ;;
esac

dnl Checks for header files.
AC_HEADER_STDC
AC_CHECK_HEADERS( string.h getopt.h strings.h sys/param.h sys/time.h unistd.h errno.h sys/select.h sys/types.h sys/socket.h netinet/in.h arpa/inet.h sys/stat.h netdb.h sys/wait.h fcntl.h sys/resource.h inttypes.h mach-o/dyld.h)
AC_HEADER_TIME
dnl A special check required for <net/if.h> on Darwin. See
dnl http://www.gnu.org/software/autoconf/manual/html_node/Header-Portability.html.
AC_CHECK_HEADERS([sys/socket.h])
AC_CHECK_HEADERS([net/if.h], [], [],
[#include <stdio.h>
#ifdef STDC_HEADERS
# include <stdlib.h>
# include <stddef.h>
#else
# ifdef HAVE_STDLIB_H
#  include <stdlib.h>
# endif
#endif
#ifdef HAVE_SYS_SOCKET_H
# include <sys/socket.h>
#endif
])

AC_MSG_CHECKING(for __attribute__)
AC_CACHE_VAL(ac_cv___attribute__, [
  AC_TRY_COMPILE(
	[
	#include <stdlib.h>

	static void foo(void) __attribute__ ((noreturn));

	static void
	foo(void)
	{
	  exit(1);
	}
	],
	[
	  foo();
	],
	ac_cv___attribute__=yes,
	ac_cv___attribute__=no
  )
])
if test "$ac_cv___attribute__" = "yes"; then
  AC_DEFINE(HAVE___ATTRIBUTE__, 1, [define if your compiler has __attribute__])
fi
AC_MSG_RESULT($ac_cv___attribute__)

AC_SUBST(CFLAGS)


dnl This test is from the configure.in of Unix Network Programming second
dnl edition example code by W. Richard Stevens
dnl ##################################################################
dnl Check if sockaddr{} has sa_len member.
dnl
AC_CACHE_CHECK(if sockaddr{} has sa_len member, ac_cv_sockaddr_has_sa_len,
        AC_TRY_COMPILE([
               #include <sys/types.h>
               #include <sys/socket.h>],
                [unsigned int i = sizeof(((struct sockaddr *)0)->sa_len)],
        ac_cv_sockaddr_has_sa_len=yes,
        ac_cv_sockaddr_has_sa_len=no))
if test $ac_cv_sockaddr_has_sa_len = yes ; then
        AC_DEFINE(HAVE_SOCKADDR_SA_LEN, 1, [define if sockaddr has sa_len member])
fi

dnl check endedness
AC_C_BIGENDIAN

dnl determine types so nbase can export u32, u16, etc.
AC_TYPE_INT8_T
AC_TYPE_INT16_T
AC_TYPE_INT32_T
AC_TYPE_INT64_T
AC_TYPE_UINT8_T
AC_TYPE_UINT16_T
AC_TYPE_UINT32_T
AC_TYPE_UINT64_T

dnl Checks for library functions.
AC_CHECK_FUNCS( snprintf vsnprintf nanosleep strerror strcasestr strcasecmp strncasecmp signal )

needsnprintf=no
AC_CHECK_FUNCS(vsnprintf snprintf asprintf asnprintf vasprintf vasnprintf,,
        [needsnprintf=yes])
if test $needsnprintf = yes; then
        AC_LIBOBJ([snprintf])
fi

AC_CHECK_FUNCS( getopt getopt_long_only)

AC_CHECK_FUNCS(usleep gettimeofday sleep localtime_s localtime_r)
dnl Some of these time functions are always needed
AC_LIBOBJ([nbase_time])

AC_CHECK_FUNC(getopt_long_only, , 
  [ AC_LIBOBJ([getopt]) ])

AC_CHECK_FUNCS(strcasecmp strncasecmp, , 
  [ AC_LIBOBJ([strcasecmp]) ])

dnl We always want some of our files
AC_LIBOBJ([nbase_str])
AC_LIBOBJ([nbase_misc])
AC_LIBOBJ([nbase_memalloc])
AC_LIBOBJ([nbase_rnd])
AC_LIBOBJ([nbase_addrset])

# Check for IPv6 support -- modified from Apache 2.0.40:

AC_ARG_ENABLE(ipv6,
  [  --disable-ipv6          Disable IPv6 support ],
  [ if test "$enableval" = "no"; then
        user_disabled_ipv6=1
    fi ],
  [ user_disabled_ipv6=0 ] )

AC_SEARCH_LIBS(getaddrinfo, [inet6 socket])
AC_SEARCH_LIBS(gai_strerror, [inet6 socket])
AC_SEARCH_LIBS(getnameinfo, [inet6 socket])
AC_SEARCH_LIBS(inet_ntop, [nsl resolv network], [],
               [AC_LIBOBJ(inet_ntop)
               ])
AC_SEARCH_LIBS(inet_pton, [nsl resolv network], [],
               [AC_LIBOBJ(inet_pton)
               ])
AC_CHECK_FUNCS([gai_strerror inet_pton inet_ntop])
APR_CHECK_WORKING_GETADDRINFO
# The inet_addr function is used by APR_CHECK_WORKING_GETNAMEINFO.
AC_SEARCH_LIBS(inet_addr, [nsl])
APR_CHECK_WORKING_GETNAMEINFO
APR_CHECK_SOCKADDR_IN6
APR_CHECK_SOCKADDR_STORAGE
CHECK_AF_INET6_DEFINE

AC_MSG_CHECKING(for IPv6 support)
have_ipv6="0"
if test "$user_disabled_ipv6" = 1; then
    AC_MSG_RESULT("no -- disabled by user")
else
    if test "x$have_sockaddr_in6" = "x1"; then
        if test "x$ac_cv_working_getaddrinfo" = "xyes"; then
            if test "x$ac_cv_working_getnameinfo" = "xyes"; then
                have_ipv6="1"
                AC_MSG_RESULT(yes)
            else
                AC_MSG_RESULT("no -- no working getnameinfo")
            fi
        else
            AC_MSG_RESULT("no -- no working getaddrinfo")
        fi
    else
        AC_MSG_RESULT("no -- no sockaddr_in6");
    fi
fi

if test "x$ac_cv_working_getaddrinfo" != "xyes"; then
AC_LIBOBJ([getaddrinfo])
fi

if test "x$ac_cv_working_getnameinfo" != "xyes"; then
AC_LIBOBJ([getnameinfo])
fi

if test "$have_ipv6" = "1"; then
  AC_DEFINE(HAVE_IPV6, 1, [define if IPv6 is available])
fi

# First we test whether they specified openssl desires explicitly
use_openssl="yes"
specialssldir=""

AC_ARG_WITH(openssl,
[  --with-openssl=DIR    Use optional openssl libs and includes from [DIR]/lib/ 
and [DIR]/include/openssl/)],
[  case "$with_openssl" in
  yes)
    ;;
  no)
    use_openssl="no"
    ;;
  *)
    specialssldir="$with_openssl"
    ;;
  esac]
)


# If they didn't specify it, we try to find it
if test "$use_openssl" = "yes" -a -z "$specialssldir"; then
  AC_CHECK_HEADER(openssl/ssl.h,,
  [ use_openssl="no"
    AC_MSG_WARN([Failed to find openssl/ssl.h so OpenSSL will not be used. If it
 is installed you can try the --with-openssl=DIR argument]) ])

 if test "$use_openssl" = "yes"; then
   AC_CHECK_HEADER(openssl/err.h,,
    [ use_openssl="no"
    AC_MSG_WARN([Failed to find openssl/err.h so OpenSSL will not be used. If it
 is installed you can try the --with-openssl=DIR argument]) ])
 fi

 if test "$use_openssl" = "yes"; then
   AC_CHECK_HEADER(openssl/rand.h,,
    [ use_openssl="no"
    AC_MSG_WARN([Failed to find openssl/rand.h so OpenSSL will not be used. If i
t is installed you can try the --with-openssl=DIR argument]) ])
 fi

 if test "$use_openssl" = "yes"; then
   AC_CHECK_LIB(crypto, BIO_int_ctrl,
    [],
    [ use_openssl="no"
    AC_MSG_WARN([Failed to find libcrypto so OpenSSL will not be used. If it is installed you can try the --with-openssl=DIR argument]) ])
 fi

 if test "$use_openssl" = "yes"; then
   AC_CHECK_LIB(ssl, SSL_new,
    [],
    [ use_openssl="no"
    AC_MSG_WARN([Failed to find libssl so OpenSSL will not be used. If it is ins
talled you can try the --with-openssl=DIR argument]) ])
 fi
fi

if test "$use_openssl" = "yes"; then
  AC_DEFINE(HAVE_OPENSSL, 1, [define if libssl is available])
fi

CHECK_PROC_SELF_EXE

AC_OUTPUT(Makefile)