@@ -30,6 +30,8 @@ AC_INIT([libmodbus],
3030AC_CONFIG_SRCDIR ( [ src/modbus.c] )
3131AC_CONFIG_AUX_DIR ( [ build-aux] )
3232AM_INIT_AUTOMAKE ( [ check-news foreign 1.11 silent-rules tar-pax subdir-objects] )
33+ AM_PROG_CC_C_O
34+ AC_PROG_CPP
3335AC_PROG_CC
3436AC_USE_SYSTEM_EXTENSIONS
3537AC_SYS_LARGEFILE
@@ -89,7 +91,6 @@ AC_CHECK_HEADERS([ \
8991 linux/serial.h \
9092 netdb.h \
9193 netinet/in.h \
92- netinet/ip.h \
9394 netinet/tcp.h \
9495 sys/ioctl.h \
9596 sys/params.h \
@@ -101,6 +102,17 @@ AC_CHECK_HEADERS([ \
101102 unistd.h \
102103] )
103104
105+ dnl On some platforms like FreeBSD and OpenIndiana (illumos) the
106+ dnl netinet/ip.h requires netinet/in.h explicitly included first:
107+ AC_CHECK_HEADERS ( [ \
108+ netinet/ip.h \
109+ ] , [ ] , [ ] , [
110+ AC_INCLUDES_DEFAULT
111+ #if HAVE_NETINET_IN_H
112+ # include <netinet/in.h>
113+ #endif
114+ ] )
115+
104116# Cygwin defines IPTOS_LOWDELAY but can't handle that flag so it's necessary to
105117# workaround that problem and Cygwin doesn't define MSG_DONTWAIT.
106118AC_CHECK_DECLS ( [ __CYGWIN__] )
@@ -109,7 +121,7 @@ AC_CHECK_DECLS([__CYGWIN__])
109121AC_SEARCH_LIBS ( accept , network socket )
110122
111123# Checks for library functions.
112- AC_CHECK_FUNCS ( [ accept4 gai_strerror getaddrinfo gettimeofday inet_pton inet_ntop select socket strerror strlcpy] )
124+ AC_CHECK_FUNCS ( [ accept4 gai_strerror getaddrinfo gettimeofday select socket strerror strlcpy] )
113125
114126# Required for MinGW with GCC v4.8.1 on Win7
115127AC_DEFINE ( WINVER , 0x0501 , _ )
@@ -129,12 +141,19 @@ AC_TYPE_UINT32_T
129141AC_TYPE_UINT8_T
130142
131143if test "$os_cygwin" = "false"; then
144+ AC_CHECK_HEADERS ( [ windows.h] , HAVE_WINDOWS_H=yes )
145+
132146 # Required for getaddrinfo (TCP IP - IPv6)
133147 AC_CHECK_HEADERS ( [ winsock2.h] , HAVE_WINSOCK2_H=yes )
134148 if test "x$HAVE_WINSOCK2_H" = "xyes"; then
135149 LIBS="$LIBS -lws2_32"
136- AC_SUBST ( LIBS )
150+ AC_SUBST ( LIBS )
137151 fi
152+
153+ dnl Can bring inet_ntop()/inet_pton()... or not, depending on distro
154+ dnl (e.g. mingw "native" with MSYS2 or cross-built from Linux); that
155+ dnl is further checked below:
156+ AC_CHECK_HEADERS ( [ ws2tcpip.h] , HAVE_WS2TCPIP_H=yes )
138157fi
139158
140159if test "$os_sunos" = "true"; then
@@ -153,7 +172,99 @@ WARNING_CFLAGS="-Wall \
153172-Wsign-compare -Wchar-subscripts \
154173-Wstrict-prototypes -Wshadow \
155174-Wformat-security"
156- AC_SUBST ( [ WARNING_CFLAGS] )
175+
176+ dnl FIXME: define more thoroughly if C++ code ever appears here
177+ WARNING_CXXFLAGS="$WARNING_CFLAGS"
178+
179+ dnl Adapted from NUT v2.8.2 configure.ac :
180+ myCFLAGS="$CFLAGS"
181+ AS_IF ( [ test "${GCC}" = "yes"] ,
182+ [ CFLAGS="$myCFLAGS -Werror -Werror=implicit-function-declaration"] ,
183+ [ dnl # Don't know what to complain about for unknown compilers
184+ dnl # FIXME: We presume here they have at least a "-Werror" option
185+ CFLAGS="$myCFLAGS -Werror"
186+ ] )
187+
188+ AC_CACHE_CHECK ( [ for inet_ntop() with IPv4 and IPv6 support] ,
189+ [ ac_cv_func_inet_ntop] ,
190+ [ AC_LANG_PUSH ( [ C] )
191+ AC_LINK_IFELSE (
192+ [ AC_LANG_PROGRAM ( [ [
193+ #if HAVE_WINDOWS_H
194+ # undef inline
195+ # ifndef WIN32_LEAN_AND_MEAN
196+ # define WIN32_LEAN_AND_MEAN
197+ # endif
198+ # include <windows.h>
199+ # if HAVE_WINSOCK2_H
200+ # include <winsock2.h>
201+ # endif
202+ # if HAVE_WS2TCPIP_H
203+ # include <ws2tcpip.h>
204+ # endif
205+ #else
206+ # include <arpa/inet.h>
207+ #endif
208+ #include <stdio.h>
209+ ] ] ,
210+ [ [ /* const char* inet_ntop(int af, const void* src, char* dst, size_t cnt); */
211+ char buf[ 128] ;
212+ printf("%s", inet_ntop(AF_INET, "1.2.3.4", buf, 10));
213+ printf("%s", inet_ntop(AF_INET6, "::1", buf, 10))
214+ /* autoconf adds ";return 0;" */
215+ ] ] ) ] ,
216+ [ ac_cv_func_inet_ntop=yes] , [ ac_cv_func_inet_ntop=no]
217+ )
218+ AC_LANG_POP ( [ C] )
219+ ] )
220+ AS_IF ( [ test x"${ac_cv_func_inet_ntop}" = xyes] ,
221+ [ AC_DEFINE ( [ HAVE_INET_NTOP] , 1 , [ defined if system has the inet_ntop() method] ) ] ,
222+ [ AC_MSG_WARN ( [ Required C library routine inet_ntop() not found] )
223+ AS_IF ( [ test "${os_win32}" = "true"] , [ AC_MSG_WARN ( [ Windows antivirus might block this test] ) ] )
224+ ]
225+ )
226+
227+ AC_CACHE_CHECK ( [ for inet_pton() with IPv4 and IPv6 support] ,
228+ [ ac_cv_func_inet_pton] ,
229+ [ AC_LANG_PUSH ( [ C] )
230+ AC_LINK_IFELSE (
231+ [ AC_LANG_PROGRAM ( [ [
232+ #if HAVE_WINDOWS_H
233+ # undef inline
234+ # ifndef WIN32_LEAN_AND_MEAN
235+ # define WIN32_LEAN_AND_MEAN
236+ # endif
237+ # include <windows.h>
238+ # if HAVE_WINSOCK2_H
239+ # include <winsock2.h>
240+ # endif
241+ # if HAVE_WS2TCPIP_H
242+ # include <ws2tcpip.h>
243+ # endif
244+ #else
245+ # include <arpa/inet.h>
246+ #endif
247+ #include <stdio.h>
248+ ] ] ,
249+ [ [ /* int inet_pton(int af, const char *src, char *dst); */
250+ struct in_addr ipv4;
251+ struct in6_addr ipv6;
252+ printf("%i ", inet_pton(AF_INET, "1.2.3.4", &ipv4));
253+ printf("%i ", inet_pton(AF_INET6, "::1", &ipv6))
254+ /* autoconf adds ";return 0;" */
255+ ] ] ) ] ,
256+ [ ac_cv_func_inet_pton=yes] , [ ac_cv_func_inet_pton=no]
257+ )
258+ AC_LANG_POP ( [ C] )
259+ ] )
260+ AS_IF ( [ test x"${ac_cv_func_inet_pton}" = xyes] ,
261+ [ AC_DEFINE ( [ HAVE_INET_PTON] , 1 , [ defined if system has the inet_pton() method] ) ] ,
262+ [ AC_MSG_WARN ( [ Required C library routine inet_pton() not found] )
263+ AS_IF ( [ test "${os_win32}" = "true"] , [ AC_MSG_WARN ( [ Windows antivirus might block this test] ) ] )
264+ ]
265+ )
266+ CFLAGS="$myCFLAGS"
267+
157268
158269# Check for libusb-1.0
159270AC_ARG_WITH ( [ libusb] ,
@@ -221,6 +332,22 @@ AS_IF([test "x$enable_debug" = "xyes"], [
221332 CXXFLAGS="-O2"
222333] )
223334
335+ dnl NOTE: Do not pass these among C(XX)FLAGS to the configure script itself,
336+ dnl they can break common tests unexpectedly. Variants below should work for
337+ dnl GCC and CLANG, and other compilers that emulate them in terms of CLI API.
338+ AC_ARG_ENABLE ( [ Werror] ,
339+ [ AS_HELP_STRING ( [ --enable-Werror] ,
340+ [ Enable compilation failure on warnings (default is no)] ) ] ,
341+ [ enable_Werror=$enableval] ,
342+ [ enable_Werror=no] )
343+ AS_IF ( [ test "x$enable_Werror" = "xyes"] , [
344+ WARNING_CFLAGS="$WARNING_CFLAGS -Werror"
345+ WARNING_CXXFLAGS="$WARNING_CXXFLAGS -Werror"
346+ ] )
347+
348+ AC_SUBST ( [ WARNING_CFLAGS] )
349+ AC_SUBST ( [ WARNING_CXXFLAGS] )
350+
224351AC_OUTPUT
225352AC_MSG_RESULT ( [
226353 $PACKAGE $VERSION
0 commit comments