remap: *actually* build, and fix masked logic errors
[tftp-hpa.git] / configure.ac
blobdeaa4fc9231257bfacb8cc627062cea5d5cebdcb
1 dnl Process this file with autoconf 2.71 or later to produce
2 dnl a configure script.
3 AC_PREREQ([2.71])
4 AC_INIT
5 AC_CONFIG_SRCDIR([MRULES])
6 AC_PREFIX_DEFAULT([/usr])
7 AC_CONFIG_AUX_DIR([autoconf/helpers])
9 dnl This prevents us from running Wine and thinking we are not
10 dnl cross-compiling when in fact we are; running Wine here is at
11 dnl the best very slow and doesn't buy us a single thing at all.
12 PA_CROSS_COMPILE
14 dnl Enable any available C extensions
15 PA_PROG_CC
16 AC_USE_SYSTEM_EXTENSIONS
18 dnl Options for debugging and profiling
19 PA_OPTION_DEBUG
20 PA_OPTION_PROFILING
22 dnl LLVM doesn't error out on invalid -W options unless this option is
23 dnl specified first.  Enable this so this script can actually discover
24 dnl which -W options are possible for this compiler.
25 PA_ADD_CFLAGS([-Werror=unknown-warning-option])
27 dnl Force gcc and gcc-compatible compilers treat signed integers
28 dnl as 2's complement
29 PA_ADD_CFLAGS([-fwrapv])
31 dnl Force clang to behave in a predictable manner, in order to make bugs
32 dnl possible to track down. gcc appears to have this behavior by default.
33 PA_ADD_CFLAGS([-ftrivial-auto-var-init=zero])
35 dnl Some environments abuse __STRICT_ANSI__ to disable some
36 dnl function declarations
37 PA_ADD_CFLAGS([-U__STRICT_ANSI__])
39 dnl Don't put things in common if we can avoid it.  We don't want to
40 dnl assume all compilers support common, and this will help find those
41 dnl problems.  This also works around an OSX linker problem.
42 PA_ADD_CFLAGS([-fno-common])
44 dnl Tests which may trigger warnings on some compilers
45 AC_C_CONST
46 AC_C_INLINE
47 AC_C_RESTRICT
49 dnl Checks for header files.
50 AC_CHECK_INCLUDES_DEFAULT
52 dnl See if we need extra libraries
53 XTRA=false
55 AC_SEARCH_LIBS([strerror],[cposix])
57 AC_CHECK_HEADERS_ONCE(inttypes.h)
58 AC_CHECK_HEADERS_ONCE(stdint.h)
59 AC_CHECK_HEADERS_ONCE(grp.h)
60 AC_CHECK_HEADERS_ONCE(libgen.h)
61 AC_CHECK_HEADERS_ONCE(setjmp.h)
62 AC_CHECK_HEADERS_ONCE(strings.h)
63 AC_CHECK_HEADERS_ONCE(sysexits.h)
64 AC_CHECK_HEADERS_ONCE(unistd.h)
65 AC_CHECK_HEADERS_ONCE(sys/filio.h)
66 AC_CHECK_HEADERS_ONCE(sys/stat.h)
67 AC_CHECK_HEADERS_ONCE(sys/time.h)
68 PA_CHECK_INTTYPES_H_SANE
70 dnl This is needed on some versions of FreeBSD...
71 AC_CHECK_HEADERS_ONCE(machine/param.h)
73 dnl Windows...
74 PA_ADD_HEADERS(windows.h)
75 PA_ADD_HEADERS(winsock2.h)
76 AS_IF([test "x$ac_cv_header_winsock2_h" != xyes],
77       [PA_ADD_HEADERS(winsock.h)])
79 PA_ADD_HEADERS(fcntl.h)
80 PA_ADD_HEADERS(sys/types.h)
81 PA_ADD_HEADERS(arpa/inet.h)
82 PA_ADD_HEADERS(sys/socket.h)
83 PA_ADD_HEADERS(sys/file.h)
84 PA_ADD_HEADERS(netinet/in.h)
85 PA_ADD_HEADERS(sys/uio.h)
86 PA_ADD_HEADERS(netdb.h)
88 AC_TYPE_OFF_T
89 AC_TYPE_PID_T
90 AC_TYPE_MODE_T
91 AC_TYPE_SIZE_T
92 AC_CHECK_TYPES(intmax_t)
93 AC_CHECK_TYPES(long long)
94 AC_CHECK_TYPES(uint16_t)
95 AC_CHECK_TYPES(uint32_t)
96 AC_CHECK_TYPES(u_short)
97 AC_CHECK_TYPES(u_long)
99 AC_CHECK_TYPES(socklen_t)
101 AC_SEARCH_LIBS(socket, [socket ws2_32 wsock32], ,
102  [AC_MSG_ERROR(socket library not found)])
104 AC_CHECK_FUNCS(fcntl)
105 AC_CHECK_FUNCS(flock)
106 AC_CHECK_FUNCS(setsid)
107 AC_CHECK_FUNCS(recvmsg)
108 AC_CHECK_FUNCS(ftruncate)
109 AC_CHECK_FUNCS(setresuid)
110 AC_CHECK_FUNCS(setreuid)
111 AC_CHECK_FUNCS(setresgid)
112 AC_CHECK_FUNCS(setregid)
113 AC_CHECK_FUNCS(initgroups)
114 AC_CHECK_FUNCS(setgroups)
115 AC_CHECK_TYPES(sighandler_t)
117 dnl Solaris 8 has [u]intmax_t but not strtoumax().  How utterly braindamaged.
118 AC_CHECK_FUNCS(strtoumax)
119 AC_CHECK_FUNCS(strtoull)
121 AC_CHECK_MEMBERS(struct msghdr.msg_control)
122 AC_CHECK_MEMBERS(struct in_pktinfo.ipi_addr)
123 AC_CHECK_MEMBERS(struct addrinfo.ai_addr)
125 AC_CHECK_DECLS([O_NONBLOCK, O_BINARY, O_TEXT])
126 AC_CHECK_DECLS([F_SETLK])
127 AC_CHECK_DECLS([LOCK_SH, LOCK_EX])
129 PA_SIGSETJMP
132 dnl Get common paths
134 SRCROOT=`cd $srcdir && pwd`
135 OBJROOT=`pwd`
137 PA_SEARCH_LIBS_AND_ADD(xmalloc, iberty)
138 PA_SEARCH_LIBS_AND_ADD(xstrdup, iberty)
139 PA_SEARCH_LIBS_AND_ADD(getopt_long, getopt, getopt_long)
140 PA_SEARCH_LIBS_AND_ADD(getaddrinfo, [nsl resolv])
141 AS_IF([$pa_add_getaddrinfo],
142 [AC_SEARCH_LIBS(gethostbyname, [nsl resolv],
143       [AC_SEARCH_LIBS(herror, [nsl resolv], ,
144          [AC_MSG_ERROR(herror not found)])],
145       [AC_MSG_ERROR(gethostbyname not found)])],
146 [AC_SEARCH_LIBS(freeaddrinfo, [nsl resolv], ,
147       [AC_MSG_ERROR(getaddrinfo but not freeaddrinfo found)])
148     AC_SEARCH_LIBS(gai_strerror, [nsl resolv], ,
149       [AC_MSG_ERROR(getaddrinfo but not gai_strerror found)])])
151 PA_SEARCH_LIBS_AND_ADD(inet_ntop, [nsl resolv])
152 AS_IF([$pa_add_inet_ntop],
153   [AC_SEARCH_LIBS(inet_ntoa, [nsl resolv], ,
154    [AC_MSG_ERROR(inet_ntoa not found)])])
156 AC_SEARCH_LIBS(inet_aton, [nsl resolv], ,[AC_MSG_ERROR(inet_aton not found)])
158 PA_SEARCH_LIBS_AND_ADD(daemon)
159 PA_SEARCH_LIBS_AND_ADD(dup2)
161 AS_IF([$XTRA], [XTRALIBS="$OBJROOT/lib/libxtra.a $XTRALIBS"])
164 dnl These libraries apply to the server only
167 common_libs="$LIBS"
169 AC_CHECK_DECLS(IPPORT_TFTP)
171 PA_ARG_DISABLED([tcpwrappers],
172   [disable tcpwrapper permissions checking], [],
173   [
174         AC_SEARCH_LIBS(yp_get_default_domain, [nsl resolv])
175         PA_HAVE_TCPWRAPPERS
176   ])
178 AC_CHECK_HEADERS_ONCE([regex.h])
179 PA_ARG_DISABLED([remap],
180  [disable regex-based filename remapping], [],
181  [AS_IF([test x"$ac_cv_header_regex_h" = xyes],
182   [AC_SEARCH_LIBS(regcomp, [regex rx],
183    [AC_DEFINE([WITH_REGEX], 1,
184              [Define if we are compiling with regex filename remapping.])
185     TFTPDOBJS="remap.\$(O) $TFTPOBJS"])])])
187 TFTPD_LIBS="$LIBS $XTRALIBS"
188 LIBS="$common_libs"
191 dnl These libraries apply to the client only
194 AH_TEMPLATE([WITH_READLINE],
195 [Define if we are compiling with readline/editline command-line editing.])
197 PA_ARG_DISABLED([readline],
198  [disable the use of readline command-line editing], [],
200   AC_CHECK_HEADER([readline/readline.h],
201         [
202                 dnl readline may need libtermcap or somesuch...
203                 AC_SEARCH_LIBS(tputs, [termcap terminfo])
205                 AC_SEARCH_LIBS(readline, [readline history],
206                 [AC_DEFINE(WITH_READLINE)])
207                 AC_CHECK_HEADERS(readline/history.h)
208         ],
209         [AC_CHECK_HEADER([editline/readline.h],
210         [
211                 dnl editline may need libtermcap or somesuch...
212                 AC_SEARCH_LIBS(tputs, [termcap terminfo])
214                 AC_SEARCH_LIBS(editline, [edit],
215                 [AC_DEFINE(WITH_READLINE)])
216         ])])
217 ],:)
219 TFTP_LIBS="$LIBS $XTRALIBS"
220 LIBS="$common_libs"
223 dnl   Check for IPV6 and disable-ipv6
226 AC_CHECK_MEMBERS(struct sockaddr_in6.sin6_addr)
227 AC_MSG_CHECKING([for IPv6 support])
228 PA_ARG_DISABLED([ipv6],
229  [disable support for IPv6],
230  [AC_MSG_RESULT(disabled)],
231  [AS_IF([test x"$ac_cv_member_struct_sockaddr_in6_sin6_addr$ac_cv_member_struct_addrinfo_ai_addr" = xyesyes],
232  [AC_MSG_RESULT(yes)
233   AC_DEFINE(HAVE_IPV6, 1, [define if IPv6 support is enabled])],
234  [AC_MSG_RESULT(no)
235   AC_MSG_WARN([*** we do not have required IPv6 structs - IPv6 will be disabled])])])
237 AC_SUBST(SRCROOT)
238 AC_SUBST(OBJROOT)
240 AC_SUBST(TFTP_LIBS)
241 AC_SUBST(TFTPD_LIBS)
242 AC_SUBST(TFTPDOBJS)
244 AC_PROG_LN_S
245 AC_PROG_RANLIB
248 dnl Make sure the install program has an absolute path if it
249 dnl has a path at all.  autoconf doesn't do this "in order
250 dnl to not pollute the cache."  Sigh.
251 dnl Note: the $ needs to be double-quoted for reasons unknown.
253 AC_PROG_INSTALL
254 [if echo "$INSTALL" | grep '^[^/].*/' > /dev/null 2>&1; then
255    INSTALL='\${SRCROOT}'/"$INSTALL"
258 PA_ADD_CFLAGS(-W)
259 PA_ADD_CFLAGS(-Wall)
260 PA_ADD_CFLAGS(-Wpointer-arith)
261 PA_ADD_CFLAGS(-Wbad-function-cast)
262 PA_ADD_CFLAGS(-Wcast-equal)
263 PA_ADD_CFLAGS(-Wstrict-prototypes)
264 PA_ADD_CFLAGS(-Wmissing-prototypes)
265 PA_ADD_CFLAGS(-Wmissing-declarations)
266 PA_ADD_CFLAGS(-Wnested-externs)
267 PA_ADD_CFLAGS(-Winline)
268 PA_ADD_CFLAGS(-Wwrite-strings)
269 PA_ADD_CFLAGS(-Wundef)
270 PA_ADD_CFLAGS(-Wshadow)
271 PA_ADD_CFLAGS(-Wsign-compare)
272 PA_ADD_CFLAGS(-fno-strict-aliasing)
275 dnl Test compiler features. On some compilers, this can be affected
276 dnl by -Werror options, so run this *after* those options are added.
278 PA_CHECK_BAD_STDC_INLINE
279 PA_C_TYPEOF
281 AC_CONFIG_HEADERS([config/config.h])
282 AC_CONFIG_FILES([config/MCONFIG])
283 AC_OUTPUT