forked from zabbix/zabbix
-
Notifications
You must be signed in to change notification settings - Fork 0
/
libmodbus.m4
155 lines (141 loc) · 5.3 KB
/
libmodbus.m4
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
# LIBMODBUS_CHECK_CONFIG ([DEFAULT-ACTION])
#
# Zabbix
# Copyright (C) 2001-2023 Zabbix SIA
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
AC_DEFUN([LIBMODBUS30_TRY_LINK],
[
AC_LINK_IFELSE([AC_LANG_PROGRAM([[
#include "modbus.h"
]], [[
modbus_t *mdb_ctx;
mdb_ctx = modbus_new_tcp("127.0.0.1", 502);
modbus_set_response_timeout(mdb_ctx, NULL);
]])],[found_libmodbus="30"],[])
])dnl
AC_DEFUN([LIBMODBUS31_TRY_LINK],
[
AC_LINK_IFELSE([AC_LANG_PROGRAM([[
#include "modbus.h"
]], [[
modbus_t *mdb_ctx;
mdb_ctx = modbus_new_tcp("127.0.0.1", 502);
modbus_set_response_timeout(mdb_ctx, 1, 0)
]])],[found_libmodbus="31"],[])
])dnl
AC_DEFUN([LIBMODBUS_ACCEPT_VERSION],
[
AC_PROG_AWK
_lib_version_parse="eval $AWK '{split(\$NF,A,\".\"); X=256*256*A[[1]]+256*A[[2]]+A[[3]]; print X;}'"
_lib_version=`echo ifelse([$1],,[0],[$1]) | $_lib_version_parse`
_lib_wanted=`echo ifelse([$2],,[0],[$2]) | $_lib_version_parse`
if test $_lib_wanted -gt 0; then
AC_CACHE_CHECK([for libmodbus $1 >= version $2],
[libmodbus_cv_version_ok],[
if test $_lib_version -lt $_lib_wanted; then
AC_MSG_ERROR([libmodbus version mismatch])
else
libmodbus_cv_version_ok="yes"
fi
]
)
fi
])dnl
AC_DEFUN([LIBMODBUS_CHECK_CONFIG],
[
AC_ARG_WITH(libmodbus,[
If you want to use MODBUS based checks:
AS_HELP_STRING([--with-libmodbus@<:@=DIR@:>@],[use MODBUS package @<:@default=no@:>@, DIR is the MODBUS library install directory.])],
[
if test "$withval" = "no"; then
want_libmodbus="no"
_libmodbus_dir="no"
elif test "$withval" = "yes"; then
want_libmodbus="yes"
_libmodbus_dir="no"
else
want_libmodbus="yes"
_libmodbus_dir=$withval
fi
_libmodbus_version_wanted=ifelse([$1],,[3.0.0],[$1])
],[
want_libmodbus="no"
]
)
if test "x$want_libmodbus" = "xyes"; then
AC_REQUIRE([PKG_PROG_PKG_CONFIG])
m4_ifdef([PKG_PROG_PKG_CONFIG], [PKG_PROG_PKG_CONFIG()], [:])
test -z "$PKG_CONFIG" && AC_MSG_ERROR([Not found pkg-config library])
m4_pattern_allow([^PKG_CONFIG_LIBDIR$])
if test "x$_libmodbus_dir" = "xno"; then
m4_ifdef([PKG_CHECK_EXISTS], [
PKG_CHECK_EXISTS(libmodbus,[
LIBMODBUS_LIBS=`$PKG_CONFIG --libs libmodbus`
],[
AC_MSG_ERROR([Not found libmodbus package])
])
], [:])
LIBMODBUS_CFLAGS=`$PKG_CONFIG --cflags libmodbus`
LIBMODBUS_LDFLAGS=""
_libmodbus_version=`$PKG_CONFIG --modversion libmodbus`
else
AC_RUN_LOG([PKG_CONFIG_LIBDIR="$_libmodbus_dir/lib/pkgconfig" $PKG_CONFIG --exists --print-errors libmodbus]) || AC_MSG_ERROR(["Not found libmodbus package in $_libmodbus_dir/lib/pkgconfig"])
LIBMODBUS_LDFLAGS="-L$_libmodbus_dir/lib"
LIBMODBUS_LIBS=`PKG_CONFIG_LIBDIR="$_libmodbus_dir/lib/pkgconfig" $PKG_CONFIG --libs libmodbus`
LIBMODBUS_CFLAGS=`PKG_CONFIG_LIBDIR="$_libmodbus_dir/lib/pkgconfig" $PKG_CONFIG --cflags libmodbus`
_libmodbus_version=`PKG_CONFIG_LIBDIR="$_libmodbus_dir/lib/pkgconfig" $PKG_CONFIG --modversion libmodbus`
fi
LIBMODBUS_ACCEPT_VERSION($_libmodbus_version,$_libmodbus_version_wanted)
if test "x$enable_static_libs" = "xyes"; then
if test "x$static_linking_support" = "xno"; then
LIBMODBUS_LIBS=`echo "$LIBMODBUS_LIBS"|sed "s|-lmodbus|$_libmodbus_dir/lib/libmodbus.a|g"`
else
LIBMODBUS_LIBS=`echo "$LIBMODBUS_LIBS"|sed "s/-lmodbus/${static_linking_support}static -lmodbus ${static_linking_support}dynamic/g"`
fi
fi
am_save_cflags="$CFLAGS"
am_save_ldflags="$LDFLAGS"
am_save_libs="$LIBS"
CFLAGS="$CFLAGS $LIBMODBUS_CFLAGS"
LDFLAGS="$LDFLAGS $LIBMODBUS_LDFLAGS"
LIBS="$LIBS $LIBMODBUS_LIBS"
found_libmodbus="no"
LIBMODBUS31_TRY_LINK([no])
if test "x$found_libmodbus" = "xno"; then
LIBMODBUS30_TRY_LINK([no])
fi
CFLAGS="$am_save_cflags"
LDFLAGS="$am_save_ldflags"
LIBS="$am_save_libs"
AC_MSG_CHECKING(for libmodbus support)
if test "x$found_libmodbus" != "xno"; then
AC_DEFINE([HAVE_LIBMODBUS], 1, [Define to 1 if you have the 'libmodbus' library (-lmodbus)])
if test "x$found_libmodbus" = "x30"; then
AC_DEFINE([HAVE_LIBMODBUS_3_0], 1, [Define to 1 if you have the 'libmodbus' library version 3.0.x (-lmodbus)])
elif test "x$found_libmodbus" = "x31"; then
AC_DEFINE([HAVE_LIBMODBUS_3_1], 1, [Define to 1 if you have the 'libmodbus' library version 3.1.x (-lmodbus)])
fi
found_libmodbus="yes"
AC_MSG_RESULT(yes)
else
AC_MSG_ERROR([Not compatible libmodbus library])
fi
fi
AC_SUBST(LIBMODBUS_CFLAGS)
AC_SUBST(LIBMODBUS_LDFLAGS)
AC_SUBST(LIBMODBUS_LIBS)
])dnl