# LIBMODBUS_CHECK_CONFIG ([DEFAULT-ACTION])
# 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([[
mdb_ctx = modbus_new_tcp("127.0.0.1", 502);
modbus_set_response_timeout(mdb_ctx, NULL);
]])],[found_libmodbus="30"],[])
AC_DEFUN([LIBMODBUS31_TRY_LINK],
AC_LINK_IFELSE([AC_LANG_PROGRAM([[
mdb_ctx = modbus_new_tcp("127.0.0.1", 502);
modbus_set_response_timeout(mdb_ctx, 1, 0)
]])],[found_libmodbus="31"],[])
AC_DEFUN([LIBMODBUS_ACCEPT_VERSION],
_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])
libmodbus_cv_version_ok="yes"