# LIBMODBUS_CHECK_CONFIG ([DEFAULT-ACTION])
# Copyright (C) 2001-2025 Zabbix SIA
# This program is free software: you can redistribute it and/or modify it under the terms of
# the GNU Affero General Public License as published by the Free Software Foundation, version 3.
# 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 Affero General Public License for more details.
# You should have received a copy of the GNU Affero General Public License along with this program.
# If not, see <https://www.gnu.org/licenses/>.
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"
AC_DEFUN([LIBMODBUS_CHECK_CONFIG],
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.])],