-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathconfigure.ac
197 lines (167 loc) · 7.73 KB
/
configure.ac
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
AC_PREREQ([2.64])
AC_INIT([sqtop], [2015-02-08], [[email protected]])
AC_CONFIG_AUX_DIR(cfgaux)
m4_include([cfgaux/ax_lib_socket_nsl.m4])
AC_CONFIG_SRCDIR([src/sqtop.cpp])
AC_CONFIG_HEADERS([src/config.h])
AM_INIT_AUTOMAKE([foreign])
AC_CANONICAL_HOST
AC_GNU_SOURCE
AC_ARG_ENABLE(ui,
[ --enable-ui build with ncurses user interface],
[case "${enableval}" in
yes) enable_ui=true ;;
no) enable_ui=false ;;
*) AC_MSG_ERROR(bad value ${enableval} for --enable-ui) ;;
esac],[enable_ui=true])
if test x$enable_ui = xtrue; then
AC_DEFINE(ENABLE_UI, 1, [build with ncurses user interface])
fi
AM_CONDITIONAL(ENABLE_UI, test x$enable_ui = xtrue)
AC_ARG_WITH(resolver,
[ --with-resolver=TYPE technique sqtop should use for name resolution.
netdb use gethostbyaddr_r in multiple threads
netdb_getnameinfo use getnameinfo (guess single or multiple threads)
netdb_gethostbyaddr use gethostbyaddr in single thread
guess try to guess reasonable value (default).],
[resolver=$withval],
[resolver=guess])
if test x$resolver = xyes; then
resolver=guess
fi
AC_LANG([C++])
AC_PROG_CXX
AC_PROG_INSTALL
# Checks for header files.
AC_CHECK_HEADERS([arpa/inet.h netdb.h netinet/in.h getopt.h sys/socket.h], [], [AC_MSG_ERROR([Unable to find some C headers]); break;])
AC_CHECK_HEADERS([sstream iomanip algorithm iostream string vector map cstdlib cstring cerrno climits], [], [AC_MSG_ERROR([Unable to find some C++ headers]); break;])
# Checks for library functions.
AX_LIB_SOCKET_NSL
AC_SEARCH_LIBS([hstrerror], [resolv])
AC_CHECK_FUNCS([gethostbyname memset socket strerror], [], [AC_MSG_ERROR([Unable to find some C functions]); break;])
test_pthread=no
if test x$enable_ui = xtrue; then
AC_CHECK_HEADERS(ncurses.h, [], [
AC_CHECK_HEADERS(ncurses/ncurses.h, [
AC_DEFINE([NCURSES_IN_SUBDIR], [ncurses/], [Look for ncurses headers in subdir])
], [AC_MSG_ERROR([Unable to find the ncurses headers]); break;])
])
AC_CHECK_LIB([ncurses], [initscr], [], [AC_MSG_ERROR([Unable to find the ncurses library]); break;])
AC_CHECK_FUNCS([clear refresh endwin mvaddstr mvchgat mvhline getch beep initscr nonl keypad noecho cbreak halfdelay addnstr], [], [AC_MSG_ERROR([Unable to find some ncurses functions]); break;])
test_pthread=yes
fi
dnl From iftop's configure.in:
if test x$resolver != xno; then
specified_resolver=$resolver
if test x$resolver = xguess; then
resolver=netdb
fi
if test x$resolver = xnetdb ; then
AC_SEARCH_LIBS(gethostbyaddr_r, [nsl], , [resolver=guess])
if test x$resolver = xguess && test x$specified_resolver != xguess ; then
dnl They wanted gethostbyaddr_r, but they can't have it, so stop.
AC_MSG_ERROR([no library defines gethostbyaddr_r])
fi
fi
dnl We still might do gethostbyaddr_r. Figure out whether we have
dnl glibc-style or Solaris-style gethostbyaddr_r (or neither...).
dnl Separate determining how to call gethostbyaddr_r from testing
dnl whether it works so we can support cross-compilation.
if test x$resolver = xnetdb ; then
AC_MSG_CHECKING([how to call gethostbyaddr_r])
dnl Try 7 arguments returning a struct hostent*.
AC_LINK_IFELSE([AC_LANG_SOURCE([`cat cfgaux/hostentp_ghba_r.c`])],
[AC_MSG_RESULT([7 args])
ghba_args=7
AC_DEFINE(GETHOSTBYADDR_R_RETURNS_HOSTENT_P, 1,
[7-argument gethostbyaddr_r returns struct hostent*])],
[dnl Try 8 arguments returning an int.
AC_LINK_IFELSE([AC_LANG_SOURCE([`cat cfgaux/int_ghba_r.c`])],
[AC_MSG_RESULT([8 args, int return])
ghba_args=8
AC_DEFINE(GETHOSTBYADDR_R_RETURNS_INT, 1,
[8-argument gethostbyaddr_r returns int])],
[dnl Neither.
AC_MSG_RESULT([don't know how])
resolver=guess])])
if test x$resolver = xguess && test x$specified_resolver != xguess ; then
dnl They wanted gethostbyaddr_r, but they can't have it, so stop.
AC_MSG_ERROR([gethostbyaddr_r has no known calling convention])
fi
fi
dnl If we still want to do gethostbyaddr_r, and we aren't
dnl cross-compiling, test it.
if test x$resolver = xnetdb ; then
if test x$ghba_args = x8 ; then
testfile=int_ghba_r
else
testfile=hostentp_ghba_r
fi
AC_MSG_CHECKING(gethostbyaddr_r usability)
AC_RUN_IFELSE([AC_LANG_SOURCE(`cat cfgaux/$testfile.c`)],
[AC_MSG_RESULT([yes])],
[AC_MSG_RESULT([no])
resolver=guess],
[AC_MSG_RESULT([can't test because we are cross-compiling])])
if test x$resolver = xguess ; then
if test x$specified_resolver = xguess ; then
AC_MSG_RESULT([gethostbyaddr_r doesn't work, so we'll try something else])
else
dnl They wanted gethostbyaddr_r, but it doesn't work, so stop.
AC_MSG_ERROR([gethostbyaddr_r doesn't work])
fi
fi
fi
if test x$resolver = xnetdb ; then
AC_DEFINE(USE_GETHOSTBYADDR_R, 1, [use gethostbyaddr_r for name resolution])
fi
if test x$resolver = xguess ; then
resolver=netdb_getnameinfo
fi
if test x$resolver = xnetdb_getnameinfo ; then
AC_SEARCH_LIBS(getnameinfo, [nsl], , [resolver=guess])
if test x$resolver = xguess && test x$specified_resolver != xguess ; then
dnl They wanted getnameinfo, but they can't have it, so stop.
AC_MSG_ERROR([no library defines getnameinfo])
fi
fi
if test x$resolver = xnetdb_getnameinfo ; then
AC_DEFINE(USE_GETNAMEINFO, 1, [use getnameinfo for name resolution])
case "$host_os" in
darwin10.[[0-4]]*) threadsafe_getnameinfo=0 ;;
darwin1[[0-1]].*) threadsafe_getnameinfo=1 ;;
linux*) threadsafe_getnameinfo=1 ;;
*) threadsafe_getnameinfo=0 ;;
esac
if test $threadsafe_getnameinfo = 1; then
AC_DEFINE(THREADSAFE_GETNAMEINFO, 1, [resolving via getnameinfo can be done in multiple threads])
fi
fi
if test x$resolver = xguess ; then
resolver=netdb_gethostbyaddr
fi
if test x$resolver = xnetdb_gethostbyaddr; then
AC_SEARCH_LIBS(gethostbyaddr, [nsl], , [resolver=guess])
if test x$resolver = xguess && test x$specified_resolver != xguess ; then
dnl They wanted gethostbyaddr, but they can't have it, so stop.
AC_MSG_ERROR([no library defines gethostbyaddr])
fi
fi
if test x$resolver = xnetdb_gethostbyaddr; then
AC_DEFINE(USE_GETHOSTBYADDR, 1, [use gethostbyaddr for name resolution])
fi
if test x$resolver = xguess; then
AC_MSG_NOTICE([failed to find reasonable resolver, name resolution will not be available!!!])
else
AC_DEFINE(WITH_RESOLVER, 1, [use name resolution])
fi
test_pthread=yes
fi
AM_CONDITIONAL(WITH_RESOLVER, test x$resolver != xno)
if test x$test_pthread = xyes; then
AC_CHECK_HEADERS([pthread.h csignal], [], [AC_MSG_ERROR([Unable to find the threading headers]); break;])
AC_CHECK_LIB([pthread], [pthread_create], [], [AC_MSG_ERROR([Unable to find the pthread library]); break;])
AC_CHECK_FUNCS([pthread_mutex_lock pthread_mutexattr_init pthread_mutexattr_settype pthread_mutex_init pthread_mutexattr_destroy pthread_mutex_destroy pthread_mutex_unlock pthread_create pthread_cancel], [], [AC_MSG_ERROR([Unable to find some pthread functions]); break;])
fi
AC_CONFIG_FILES([Makefile src/Makefile doc/Makefile])
AC_OUTPUT