Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

m4: revise libmodbus detection #2731

Merged
merged 2 commits into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion m4/nut_check_libavahi.m4
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ AC_DEFUN([NUT_CHECK_LIBAVAHI],
[
if test -z "${nut_have_avahi_seen}"; then
nut_have_avahi_seen=yes
NUT_CHECK_PKGCONFIG
AC_REQUIRE([NUT_CHECK_PKGCONFIG])
dnl save CFLAGS and LIBS
CFLAGS_ORIG="${CFLAGS}"
Expand Down
2 changes: 1 addition & 1 deletion m4/nut_check_libfreeipmi.m4
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ AC_DEFUN([NUT_CHECK_LIBFREEIPMI],
[
if test -z "${nut_have_libfreeipmi_seen}"; then
nut_have_libfreeipmi_seen=yes
NUT_CHECK_PKGCONFIG
AC_REQUIRE([NUT_CHECK_PKGCONFIG])
dnl save CFLAGS and LIBS
CFLAGS_ORIG="${CFLAGS}"
Expand Down
2 changes: 1 addition & 1 deletion m4/nut_check_libgd.m4
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ AC_DEFUN([NUT_CHECK_LIBGD],
[
if test -z "${nut_have_libgd_seen}"; then
nut_have_libgd_seen=yes
NUT_CHECK_PKGCONFIG
AC_REQUIRE([NUT_CHECK_PKGCONFIG])
CFLAGS_ORIG="${CFLAGS}"
LDFLAGS_ORIG="${LDFLAGS}"
Expand Down
2 changes: 1 addition & 1 deletion m4/nut_check_libgpiod.m4
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ AC_DEFUN([NUT_CHECK_LIBGPIO],
[
if test -z "${nut_have_gpio_seen}"; then
nut_have_gpio_seen=yes
NUT_CHECK_PKGCONFIG
AC_REQUIRE([NUT_CHECK_PKGCONFIG])
dnl save CFLAGS and LIBS
CFLAGS_ORIG="${CFLAGS}"
Expand Down
46 changes: 26 additions & 20 deletions m4/nut_check_libmodbus.m4
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ AC_DEFUN([NUT_CHECK_LIBMODBUS],
[
if test -z "${nut_have_libmodbus_seen}"; then
nut_have_libmodbus_seen=yes
NUT_CHECK_PKGCONFIG
AC_REQUIRE([NUT_CHECK_PKGCONFIG])

dnl save CFLAGS and LIBS
CFLAGS_ORIG="${CFLAGS}"
Expand Down Expand Up @@ -73,29 +73,35 @@ if test -z "${nut_have_libmodbus_seen}"; then
CFLAGS="${CFLAGS_ORIG} ${depCFLAGS}"
LIBS="${LIBS_ORIG} ${depLIBS}"
AC_CHECK_HEADERS(modbus.h, [nut_have_libmodbus=yes], [nut_have_libmodbus=no], [AC_INCLUDES_DEFAULT])
AC_CHECK_FUNCS(modbus_new_rtu, [], [nut_have_libmodbus=no])
AC_CHECK_FUNCS(modbus_new_tcp, [], [nut_have_libmodbus=no])
AC_CHECK_FUNCS(modbus_set_byte_timeout, [], [nut_have_libmodbus=no])
AC_CHECK_FUNCS(modbus_set_response_timeout, [], [nut_have_libmodbus=no])
AS_IF([test x"${nut_have_libmodbus}" = xyes ], [
AC_CHECK_FUNCS(modbus_new_rtu, [], [nut_have_libmodbus=no])
AC_CHECK_FUNCS(modbus_new_tcp, [], [nut_have_libmodbus=no])
AC_CHECK_FUNCS(modbus_set_byte_timeout, [], [nut_have_libmodbus=no])
AC_CHECK_FUNCS(modbus_set_response_timeout, [], [nut_have_libmodbus=no])
])

AC_CHECK_FUNCS(modbus_new_rtu_usb, [nut_have_libmodbus_usb=yes], [
nut_have_libmodbus_usb=no
AS_IF([test x"${nut_with_usb}" != xno && test x"${nut_with_modbus}" != xno && test x"${nut_have_libmodbus}" = xyes ], [
dnl Retry with LibUSB dependency settings if we
dnl know we are not opposed to pulling it in.
dnl Static libmodbus builds do not refer to
dnl (shared) libusb for example.
NUT_CHECK_LIBUSB
AC_MSG_NOTICE([Retry detection of libmodbus USB support])
CFLAGS="$CFLAGS $LIBUSB_CFLAGS"
LIBS="$LIBS $LIBUSB_LIBS"
unset ac_cv_func_modbus_new_rtu_usb
AC_CHECK_FUNCS(modbus_new_rtu_usb, [nut_have_libmodbus_usb=yes], [
AS_IF([test x"${nut_with_usb}" = xyes && test x"${nut_with_modbus}" = xyes && test x"${nut_have_libmodbus}" = xyes ], [
AC_MSG_WARN([Both --with-modbus and --with-usb were requested, and a libmodbus was found, but it seems to not support USB. You may require a custom build per https://github.com/networkupstools/nut/wiki/APC-UPS-with-Modbus-protocol])
AS_IF([test x"${nut_have_libmodbus}" = xyes ], [
AC_CHECK_FUNCS(modbus_new_rtu_usb, [nut_have_libmodbus_usb=yes], [
nut_have_libmodbus_usb=no
AS_IF([test x"${nut_with_usb}" != xno && test x"${nut_with_modbus}" != xno && test x"${nut_have_libmodbus}" = xyes ], [
dnl Retry with LibUSB dependency settings if we
dnl know we are not opposed to pulling it in.
dnl Static libmodbus builds do not refer to
dnl (shared) libusb for example.
AC_REQUIRE([NUT_CHECK_LIBUSB])
AC_MSG_NOTICE([Retry detection of libmodbus USB support])
CFLAGS="$CFLAGS $LIBUSB_CFLAGS"
LIBS="$LIBS $LIBUSB_LIBS"
unset ac_cv_func_modbus_new_rtu_usb
AC_CHECK_FUNCS(modbus_new_rtu_usb, [nut_have_libmodbus_usb=yes], [
AS_IF([test x"${nut_with_usb}" = xyes && test x"${nut_with_modbus}" = xyes && test x"${nut_have_libmodbus}" = xyes ], [
AC_MSG_WARN([Both --with-modbus and --with-usb were requested, and a libmodbus was found, but it seems to not support USB. You may require a custom build per https://github.com/networkupstools/nut/wiki/APC-UPS-with-Modbus-protocol])
])
])
])
])
], [
nut_have_libmodbus_usb=no
])

dnl modbus_set_byte_timeout() and modbus_set_response_timeout()
Expand Down
2 changes: 1 addition & 1 deletion m4/nut_check_libneon.m4
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ AC_DEFUN([NUT_CHECK_LIBNEON],
[
if test -z "${nut_have_neon_seen}"; then
nut_have_neon_seen=yes
NUT_CHECK_PKGCONFIG
AC_REQUIRE([NUT_CHECK_PKGCONFIG])
dnl save CFLAGS and LIBS
CFLAGS_ORIG="${CFLAGS}"
Expand Down
2 changes: 1 addition & 1 deletion m4/nut_check_libnetsnmp.m4
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ AC_DEFUN([NUT_CHECK_LIBNETSNMP],
[
if test -z "${nut_have_libnetsnmp_seen}"; then
nut_have_libnetsnmp_seen=yes
NUT_CHECK_PKGCONFIG
AC_REQUIRE([NUT_CHECK_PKGCONFIG])
AC_LANG_PUSH([C])
dnl save CFLAGS and LIBS
Expand Down
2 changes: 1 addition & 1 deletion m4/nut_check_libnss.m4
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ AC_DEFUN([NUT_CHECK_LIBNSS],
[
if test -z "${nut_have_libnss_seen}"; then
nut_have_libnss_seen=yes
NUT_CHECK_PKGCONFIG
AC_REQUIRE([NUT_CHECK_PKGCONFIG])
dnl save CFLAGS and LIBS
CFLAGS_ORIG="${CFLAGS}"
Expand Down
2 changes: 1 addition & 1 deletion m4/nut_check_libopenssl.m4
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ AC_DEFUN([NUT_CHECK_LIBOPENSSL],
[
if test -z "${nut_have_libopenssl_seen}"; then
nut_have_libopenssl_seen=yes
NUT_CHECK_PKGCONFIG
AC_REQUIRE([NUT_CHECK_PKGCONFIG])
dnl save CFLAGS and LIBS
CFLAGS_ORIG="${CFLAGS}"
Expand Down
2 changes: 1 addition & 1 deletion m4/nut_check_libpowerman.m4
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ AC_DEFUN([NUT_CHECK_LIBPOWERMAN],
[
if test -z "${nut_have_libpowerman_seen}"; then
nut_have_libpowerman_seen=yes
NUT_CHECK_PKGCONFIG
AC_REQUIRE([NUT_CHECK_PKGCONFIG])
dnl save CFLAGS and LIBS
CFLAGS_ORIG="${CFLAGS}"
Expand Down
2 changes: 1 addition & 1 deletion m4/nut_check_libregex.m4
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ AC_DEFUN([NUT_CHECK_LIBREGEX],
[
if test -z "${nut_have_libregex_seen}"; then
nut_have_libregex_seen=yes
NUT_CHECK_PKGCONFIG
AC_REQUIRE([NUT_CHECK_PKGCONFIG])
dnl save CFLAGS and LIBS
CFLAGS_ORIG="${CFLAGS}"
Expand Down
2 changes: 1 addition & 1 deletion m4/nut_check_libsystemd.m4
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ AC_DEFUN([NUT_CHECK_LIBSYSTEMD],
[
if test -z "${nut_have_libsystemd_seen}"; then
nut_have_libsystemd_seen=yes
NUT_CHECK_PKGCONFIG
AC_REQUIRE([NUT_CHECK_PKGCONFIG])
dnl save CFLAGS and LIBS
CFLAGS_ORIG="${CFLAGS}"
Expand Down
4 changes: 2 additions & 2 deletions m4/nut_check_libusb.m4
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ AC_DEFUN([NUT_CHECK_LIBUSB],
[
if test -z "${nut_have_libusb_seen}"; then
nut_have_libusb_seen=yes
NUT_CHECK_PKGCONFIG
AC_REQUIRE([NUT_CHECK_PKGCONFIG])
dnl Our USB matching relies on regex abilities
NUT_CHECK_LIBREGEX
AC_REQUIRE([NUT_CHECK_LIBREGEX])
dnl save CFLAGS and LIBS
CFLAGS_ORIG="${CFLAGS}"
Expand Down
Loading