autoconf: modernize and modularize
[tftp-hpa.git] / configure.ac
blobbe2a50056e43198905f62cb81c598808f6957c78
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 TFTPD_LIBS="$LIBS $XTRALIBS"
179 LIBS="$common_libs"
182 dnl These libraries apply to the client only
185 AH_TEMPLATE([WITH_READLINE],
186 [Define if we are compiling with readline/editline command-line editing.])
188 PA_ARG_DISABLED([readline],
189  [disable the use of readline command-line editing], [],
191   AC_CHECK_HEADER(readline/readline.h,
192         [
193                 dnl readline may need libtermcap or somesuch...
194                 AC_SEARCH_LIBS(tputs, [termcap terminfo])
196                 AC_SEARCH_LIBS(readline, [readline history],
197                 [AC_DEFINE(WITH_READLINE)])
198                 AC_CHECK_HEADERS(readline/history.h)
199         ],
200         [AC_CHECK_HEADER(editline/readline.h,
201         [
202                 dnl editline may need libtermcap or somesuch...
203                 AC_SEARCH_LIBS(tputs, [termcap terminfo])
205                 AC_SEARCH_LIBS(editline, [edit],
206                 [AC_DEFINE(WITH_READLINE)])
207         ])])
208 ],:)
210 TFTP_LIBS="$LIBS $XTRALIBS"
211 LIBS="$common_libs"
214 dnl   Check for IPV6 and disable-ipv6
217 AC_CHECK_MEMBERS(struct sockaddr_in6.sin6_addr)
218 AC_MSG_CHECKING([for IPv6 support])
219 PA_ARG_DISABLED([ipv6],
220  [disable support for IPv6],
221  [AC_MSG_RESULT(disabled)],
222  [AS_IF([test x"$ac_cv_member_struct_sockaddr_in6_sin6_addr$ac_cv_member_struct_addrinfo_ai_addr" = xyesyes],
223  [AC_MSG_RESULT(yes)
224   AC_DEFINE(HAVE_IPV6, 1, [define if IPv6 support is enabled])],
225  [AC_MSG_RESULT(no)
226   AC_MSG_WARN([*** we do not have required IPv6 structs - IPv6 will be disabled])])])
228 AC_SUBST(SRCROOT)
229 AC_SUBST(OBJROOT)
231 AC_SUBST(TFTP_LIBS)
232 AC_SUBST(TFTPD_LIBS)
233 AC_SUBST(TFTPDOBJS)
235 AC_PROG_LN_S
236 AC_PROG_RANLIB
239 dnl Make sure the install program has an absolute path if it
240 dnl has a path at all.  autoconf doesn't do this "in order
241 dnl to not pollute the cache."  Sigh.
242 dnl Note: the $ needs to be double-quoted for reasons unknown.
244 AC_PROG_INSTALL
245 [if echo "$INSTALL" | grep '^[^/].*/' > /dev/null 2>&1; then
246    INSTALL='\${SRCROOT}'/"$INSTALL"
249 PA_ADD_CFLAGS(-W)
250 PA_ADD_CFLAGS(-Wall)
251 PA_ADD_CFLAGS(-Wpointer-arith)
252 PA_ADD_CFLAGS(-Wbad-function-cast)
253 PA_ADD_CFLAGS(-Wcast-equal)
254 PA_ADD_CFLAGS(-Wstrict-prototypes)
255 PA_ADD_CFLAGS(-Wmissing-prototypes)
256 PA_ADD_CFLAGS(-Wmissing-declarations)
257 PA_ADD_CFLAGS(-Wnested-externs)
258 PA_ADD_CFLAGS(-Winline)
259 PA_ADD_CFLAGS(-Wwrite-strings)
260 PA_ADD_CFLAGS(-Wundef)
261 PA_ADD_CFLAGS(-Wshadow)
262 PA_ADD_CFLAGS(-Wsign-compare)
263 PA_ADD_CFLAGS(-fno-strict-aliasing)
266 dnl Test compiler features. On some compilers, this can be affected
267 dnl by -Werror options, so run this *after* those options are added.
269 PA_CHECK_BAD_STDC_INLINE
270 PA_C_TYPEOF
272 AC_CONFIG_HEADERS([config/config.h])
273 AC_CONFIG_FILES([config/MCONFIG])
274 AC_OUTPUT