forked from stephane/libmodbus
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathconfigure.ac
More file actions
447 lines (393 loc) · 12.8 KB
/
configure.ac
File metadata and controls
447 lines (393 loc) · 12.8 KB
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
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
# libmodbus package version number, (as distinct from shared library version)
# An odd micro number indicates in-progress development from Git
# An even micro number indicates a released version
#
# Making a point release:
# - increase libmodbus_version_micro to the next even number
#
# After the release:
# - increase libmodbus_version_minor to the next odd number
#
# Take care to update the libtool versioning when required (LIBMODBUS_LD_*).
# http://www.gnu.org/software/libtool/manual/html_node/Libtool-versioning.html
#
m4_define([libmodbus_version_major], [3])
m4_define([libmodbus_version_minor], [1])
m4_define([libmodbus_version_micro], [11])
m4_define([libmodbus_release_status],
[m4_if(m4_eval(libmodbus_version_minor % 2), [1], [snapshot], [release])])
m4_define([libmodbus_version],
[libmodbus_version_major.libmodbus_version_minor.libmodbus_version_micro])
AC_PREREQ([2.63])
AC_INIT([libmodbus],
[libmodbus_version],
[https://github.com/stephane/libmodbus/issues],
[libmodbus],
[http://libmodbus.org/])
AC_CONFIG_SRCDIR([src/modbus.c])
AC_CONFIG_AUX_DIR([build-aux])
AM_INIT_AUTOMAKE([check-news foreign 1.11 silent-rules tar-pax subdir-objects])
AC_PROG_CPP
AC_PROG_CC
AM_PROG_CC_C_O
AC_USE_SYSTEM_EXTENSIONS
AC_SYS_LARGEFILE
AC_CONFIG_MACRO_DIR([m4])
dnl This feature seems to require automake-1.13 or newer (1.11+ by other info)
dnl On very old systems can comment it away with little loss (then automake-1.10
dnl is known to suffice):
m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])],
[AC_MSG_NOTICE([Silent Rules feature not defined in this automake version, skipped])])
LIBMODBUS_VERSION_MAJOR=libmodbus_version_major
LIBMODBUS_VERSION_MINOR=libmodbus_version_minor
LIBMODBUS_VERSION_MICRO=libmodbus_version_micro
LIBMODBUS_VERSION=libmodbus_version
AC_SUBST(LIBMODBUS_VERSION_MAJOR)
AC_SUBST(LIBMODBUS_VERSION_MINOR)
AC_SUBST(LIBMODBUS_VERSION_MICRO)
AC_SUBST(LIBMODBUS_VERSION)
# ABI version
# http://www.gnu.org/software/libtool/manual/html_node/Updating-version-info.html
LIBMODBUS_LD_CURRENT=6
LIBMODBUS_LD_REVISION=0
LIBMODBUS_LD_AGE=1
LIBMODBUS_LT_VERSION_INFO=$LIBMODBUS_LD_CURRENT:$LIBMODBUS_LD_REVISION:$LIBMODBUS_LD_AGE
AC_SUBST(LIBMODBUS_LT_VERSION_INFO)
AC_CANONICAL_HOST
# OS check
os_win32="false"
os_cygwin="false"
os_qnx="false"
os_sunos="false"
case "${host_os}" in
*mingw32*)
os_win32="true"
;;
*nto-qnx*)
os_qnx="true"
;;
*cygwin*)
os_cygwin="true"
;;
*solaris*)
os_sunos="true"
;;
esac
AM_CONDITIONAL(OS_WIN32, test "$os_win32" = "true")
AM_CONDITIONAL(OS_QNX, test "$os_qnx" = "true")
m4_pattern_forbid([^LT_INIT])dnl
LT_INIT([disable-static win32-dll pic-only])
AC_CHECK_HEADERS([ \
arpa/inet.h \
byteswap.h \
errno.h \
fcntl.h \
limits.h \
linux/serial.h \
netdb.h \
netinet/in.h \
netinet/tcp.h \
sys/ioctl.h \
sys/params.h \
sys/socket.h \
sys/time.h \
sys/types.h \
termios.h \
time.h \
unistd.h \
])
dnl On some platforms like FreeBSD and OpenIndiana (illumos) the
dnl netinet/ip.h requires netinet/in.h explicitly included first:
AC_CHECK_HEADERS([ \
netinet/ip.h \
], [], [], [
AC_INCLUDES_DEFAULT
#if HAVE_NETINET_IN_H
# include <netinet/in.h>
#endif
])
# Cygwin defines IPTOS_LOWDELAY but can't handle that flag so it's necessary to
# workaround that problem and Cygwin doesn't define MSG_DONTWAIT.
AC_CHECK_DECLS([__CYGWIN__])
# Check for network function in libnetwork for Haiku
AC_SEARCH_LIBS(accept, network socket)
# Checks for library functions.
AC_CHECK_FUNCS([accept4 gai_strerror getaddrinfo gettimeofday select socket strerror strlcpy])
# Required for MinGW with GCC v4.8.1 on Win7
AC_DEFINE(WINVER, 0x0501, _)
# Required for bswap
AC_C_INLINE
# libtool
AC_PROG_CXX
# Various types
AC_TYPE_INT64_T
AC_TYPE_SIZE_T
AC_TYPE_SSIZE_T
AC_TYPE_UINT16_T
AC_TYPE_UINT32_T
AC_TYPE_UINT8_T
if test "$os_cygwin" = "false"; then
AC_CHECK_HEADERS([windows.h], HAVE_WINDOWS_H=yes)
# Required for getaddrinfo (TCP IP - IPv6)
AC_CHECK_HEADERS([winsock2.h], HAVE_WINSOCK2_H=yes)
if test "x$HAVE_WINSOCK2_H" = "xyes"; then
LIBS="$LIBS -lws2_32"
AC_SUBST(LIBS)
fi
dnl Can bring inet_ntop()/inet_pton()... or not, depending on distro
dnl (e.g. mingw "native" with MSYS2 or cross-built from Linux); that
dnl is further checked below:
AC_CHECK_HEADERS([ws2tcpip.h], HAVE_WS2TCPIP_H=yes)
fi
if test "$os_sunos" = "true"; then
LIBS="$LIBS -lnsl -lsocket"
AC_SUBST(LIBS)
fi
# Check for RS485 support (Linux kernel version 2.6.28+)
AC_CHECK_DECLS([TIOCSRS485], [], [], [[#include <sys/ioctl.h>]])
# Check for RTS flags
AC_CHECK_DECLS([TIOCM_RTS], [], [], [[#include <sys/ioctl.h>]])
WARNING_CFLAGS="-Wall \
-Wmissing-declarations -Wmissing-prototypes \
-Wnested-externs -Wpointer-arith \
-Wsign-compare -Wchar-subscripts \
-Wstrict-prototypes -Wshadow \
-Wformat-security"
dnl FIXME: define more thoroughly if C++ code ever appears here
WARNING_CXXFLAGS="$WARNING_CFLAGS"
dnl Adapted from NUT v2.8.2 configure.ac :
myCFLAGS="$CFLAGS"
AS_IF([test "${GCC}" = "yes"],
[CFLAGS="$myCFLAGS -Werror -Werror=implicit-function-declaration"],
[dnl # Don't know what to complain about for unknown compilers
dnl # FIXME: We presume here they have at least a "-Werror" option
CFLAGS="$myCFLAGS -Werror"
])
AC_CACHE_CHECK([for inet_ntop() with IPv4 and IPv6 support],
[ac_cv_func_inet_ntop],
[AC_LANG_PUSH([C])
AC_LINK_IFELSE(
[AC_LANG_PROGRAM([[
#if HAVE_WINDOWS_H
# undef inline
# ifndef WIN32_LEAN_AND_MEAN
# define WIN32_LEAN_AND_MEAN
# endif
# include <windows.h>
# if HAVE_WINSOCK2_H
# include <winsock2.h>
# endif
# if HAVE_WS2TCPIP_H
# include <ws2tcpip.h>
# endif
#else
# include <arpa/inet.h>
#endif
#include <stdio.h>
]],
[[/* const char* inet_ntop(int af, const void* src, char* dst, size_t cnt); */
char buf[128];
printf("%s", inet_ntop(AF_INET, "1.2.3.4", buf, 10));
printf("%s", inet_ntop(AF_INET6, "::1", buf, 10))
/* autoconf adds ";return 0;" */
]])],
[ac_cv_func_inet_ntop=yes], [ac_cv_func_inet_ntop=no]
)
AC_LANG_POP([C])
])
AS_IF([test x"${ac_cv_func_inet_ntop}" = xyes],
[AC_DEFINE([HAVE_INET_NTOP], 1, [defined if system has the inet_ntop() method])],
[AC_MSG_WARN([Required C library routine inet_ntop() not found])
AS_IF([test "${os_win32}" = "true"], [AC_MSG_WARN([Windows antivirus might block this test])])
]
)
AC_CACHE_CHECK([for inet_pton() with IPv4 and IPv6 support],
[ac_cv_func_inet_pton],
[AC_LANG_PUSH([C])
AC_LINK_IFELSE(
[AC_LANG_PROGRAM([[
#if HAVE_WINDOWS_H
# undef inline
# ifndef WIN32_LEAN_AND_MEAN
# define WIN32_LEAN_AND_MEAN
# endif
# include <windows.h>
# if HAVE_WINSOCK2_H
# include <winsock2.h>
# endif
# if HAVE_WS2TCPIP_H
# include <ws2tcpip.h>
# endif
#else
# include <arpa/inet.h>
#endif
#include <stdio.h>
]],
[[/* int inet_pton(int af, const char *src, char *dst); */
struct in_addr ipv4;
struct in6_addr ipv6;
printf("%i ", inet_pton(AF_INET, "1.2.3.4", &ipv4));
printf("%i ", inet_pton(AF_INET6, "::1", &ipv6))
/* autoconf adds ";return 0;" */
]])],
[ac_cv_func_inet_pton=yes], [ac_cv_func_inet_pton=no]
)
AC_LANG_POP([C])
])
AS_IF([test x"${ac_cv_func_inet_pton}" = xyes],
[AC_DEFINE([HAVE_INET_PTON], 1, [defined if system has the inet_pton() method])],
[AC_MSG_WARN([Required C library routine inet_pton() not found])
AS_IF([test "${os_win32}" = "true"], [AC_MSG_WARN([Windows antivirus might block this test])])
]
)
CFLAGS="$myCFLAGS"
# Check for libusb-1.0
AC_ARG_WITH([libusb],
AS_HELP_STRING([--with-libusb],[Use libusb-1.0 for RTU USB support (default is auto)]),,
[with_libusb=auto])
have_libusb=no
LIBUSB_LIBS=""
LIBUSB_CFLAGS=""
dnl FIXME: Pass paths and flags on command line or find via pkg-config
AS_IF([test "x$with_libusb" != "xno"], [
SAVED_CFLAGS="${CFLAGS}"
SAVED_LIBS="${LIBS}"
AC_MSG_CHECKING([whether pkg-config knows about libusb-1.0 in its PKG_CONFIG_PATH])
LIBUSB_LIBS="`pkg-config --libs libusb-1.0`" \
&& LIBUSB_CFLAGS="`pkg-config --cflags libusb-1.0`"
AS_IF([test x"${LIBUSB_LIBS}" != x], [
AC_MSG_RESULT([yes])
dnl # Extract the name from pkg-config data, if we can
LIBUSB_LIB_TRYNAME="usb-1.0"
for TOKEN in ${LIBUSB_LIBS} ; do
case "${TOKEN}" in
-lusb*) LIBUSB_LIB_TRYNAME="`echo "${TOKEN}" | sed 's,^-l,,'`" ;;
esac
done
CFLAGS="${SAVED_CFLAGS} ${LIBUSB_CFLAGS}"
LIBS="${SAVED_LIBS} ${LIBUSB_LIBS}"
AC_CHECK_LIB(${LIBUSB_LIB_TRYNAME}, libusb_init, [:], [LIBUSB_LIBS=""])
],[
AC_MSG_RESULT([no, try fallback search])
LIBUSB_LIB_TRYNAME="usb-1.0"
AC_CHECK_LIB(${LIBUSB_LIB_TRYNAME}, libusb_init, [
LIBUSB_LIBS="-l${LIBUSB_LIB_TRYNAME}"
], [
LIBUSB_LIB_TRYNAME="usb"
AC_CHECK_LIB(${LIBUSB_LIB_TRYNAME}, libusb_init, [
LIBUSB_LIBS="-l${LIBUSB_LIB_TRYNAME}"
], [
LIBUSB_LIB_TRYNAME="none"
])
])
LIBS="${SAVED_LIBS} ${LIBUSB_LIBS}"
])
AS_IF([test x"${LIBUSB_LIBS}" != x], [
AC_CHECK_LIB(${LIBUSB_LIB_TRYNAME}, libusb_get_parent, [
AC_DEFINE([HAVE_LIBUSB_GET_PARENT], 1, [defined if libusb_get_parent is available])
])
])
AS_IF([test x"${LIBUSB_LIBS}" != x], [
CFLAGS="${SAVED_CFLAGS} ${LIBUSB_CFLAGS}"
LIBS="${SAVED_LIBS} ${LIBUSB_LIBS}"
AC_CHECK_HEADERS([libusb-1.0/libusb.h], [HAVE_LIBUSB_1_0_LIBUSB_H=yes])
AC_CHECK_HEADERS([libusb.h], [HAVE_LIBUSB_H=yes])
])
AS_IF([test x"${LIBUSB_LIBS}" != x && test x"${HAVE_LIBUSB_1_0_LIBUSB_H}" = xyes -o x"${HAVE_LIBUSB_H}" = xyes], [
AC_DEFINE(HAVE_LIBUSB, 1, [defined if libusb is available])
have_libusb=yes
AC_MSG_CHECKING([for libusb pollfd accessibility])
AC_LANG_PUSH([C])
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([
#if HAVE_LIBUSB_1_0_LIBUSB_H
# include <libusb-1.0/libusb.h>
#else
# if HAVE_LIBUSB_H
# include <libusb.h>
# endif
#endif
],[
libusb_context *ctx = NULL;
const struct libusb_pollfd** list = libusb_get_pollfds(ctx);
/* Do not care about actual return value in this test,
* normally check for non-zero meaning to look in errno */
]
)],
[AC_DEFINE(HAVE_LIBUSB_POLLFD, 1, [defined if libusb pollfd is available])
AC_MSG_RESULT([ok])
],
[AC_MSG_RESULT([no])]
)
], [
AS_IF([test "x$with_libusb" = "xyes"], [
AC_MSG_ERROR(["libusb-1.0 not found. Please install libusb-1.0."])
], [
AC_MSG_WARN(["libusb-1.0 not found. Please install libusb-1.0 if you want to use it."])
])
])
CFLAGS="${SAVED_CFLAGS}"
LIBS="${SAVED_LIBS}"
])
AC_SUBST(LIBUSB_LIBS)
AC_SUBST(LIBUSB_CFLAGS)
AM_CONDITIONAL(WITH_LIBUSB, [test x"${have_libusb}" = x"yes"])
# Build options
AC_ARG_ENABLE(tests,
AS_HELP_STRING([--disable-tests],
[Build tests (default: yes)]),,
[enable_tests=yes])
AM_CONDITIONAL(BUILD_TESTS, [test $enable_tests != no])
AC_CONFIG_HEADERS([config.h tests/unit-test.h src/modbus-config.h])
AC_CONFIG_FILES([
Makefile
src/Makefile
src/modbus-version.h
src/win32/modbus.dll.manifest
tests/Makefile
libmodbus.pc
])
AC_ARG_ENABLE([debug],
[AS_HELP_STRING([--enable-debug],
[Enable debug symbols (default is no)])],
[enable_debug=$enableval],
[enable_debug=no])
AS_IF([test "x$enable_debug" = "xyes"], [
CFLAGS="-g -O0"
CXXFLAGS="-g -O0"
], [
CFLAGS="-O2"
CXXFLAGS="-O2"
])
dnl NOTE: Do not pass these among C(XX)FLAGS to the configure script itself,
dnl they can break common tests unexpectedly. Variants below should work for
dnl GCC and CLANG, and other compilers that emulate them in terms of CLI API.
AC_ARG_ENABLE([Werror],
[AS_HELP_STRING([--enable-Werror],
[Enable compilation failure on warnings (default is no)])],
[enable_Werror=$enableval],
[enable_Werror=no])
AS_IF([test "x$enable_Werror" = "xyes"], [
WARNING_CFLAGS="$WARNING_CFLAGS -Werror"
WARNING_CXXFLAGS="$WARNING_CXXFLAGS -Werror"
])
AC_SUBST([WARNING_CFLAGS])
AC_SUBST([WARNING_CXXFLAGS])
_PKG_VER_TITLE="$PACKAGE $VERSION"
_PKG_VER_SEPARATOR="`echo "${_PKG_VER_TITLE}" | sed 's,.,=,g'`" \
&& test x"${_PKG_VER_SEPARATOR}" != x || _PKG_VER_SEPARATOR="================"
AC_OUTPUT
AC_MSG_RESULT([
${_PKG_VER_TITLE}
${_PKG_VER_SEPARATOR}
prefix: ${prefix}
sysconfdir: ${sysconfdir}
libdir: ${libdir}
includedir: ${includedir}
compiler: ${CC}
cflags: ${CFLAGS} ${WARNING_CFLAGS}
ldflags: ${LDFLAGS}
build shared lib: ${enable_shared}
build static lib: ${enable_static}
tests: ${enable_tests}
RTU USB: ${have_libusb}
])