2021-04-09 14:39:49 -04:00
|
|
|
# owntone_checks.m4 serial 2
|
2017-01-06 03:44:18 -05:00
|
|
|
dnl Copyright (c) Scott Shambarger <devel@shambarger.net>
|
|
|
|
dnl
|
|
|
|
dnl Copying and distribution of this file, with or without modification, are
|
|
|
|
dnl permitted in any medium without royalty provided the copyright notice
|
|
|
|
dnl and this notice are preserved. This file is offered as-is, without any
|
|
|
|
dnl warranty.
|
|
|
|
|
2021-04-09 14:39:49 -04:00
|
|
|
dnl _OWNTONE_FUNC_MERGE
|
2017-02-19 09:21:00 -05:00
|
|
|
dnl ----------------
|
2021-04-09 14:39:49 -04:00
|
|
|
dnl Internal only. Defines function used by OWNTONE_VAR_PREPEND
|
|
|
|
AC_DEFUN([_OWNTONE_FUNC_MERGE], [[
|
2017-02-19 09:21:00 -05:00
|
|
|
# fork_fn_merge(before, after)
|
|
|
|
# create wordlist removing duplicates
|
|
|
|
fork_fn_merge() {
|
|
|
|
fork_fn_var_result=$][1
|
|
|
|
for element in $][2; do
|
|
|
|
fork_fn_var_haveit=
|
|
|
|
for x in $fork_fn_var_result; do
|
2017-01-10 13:10:09 -05:00
|
|
|
if test "X$x" = "X$element"; then
|
2017-02-19 09:21:00 -05:00
|
|
|
fork_fn_var_haveit=1
|
2017-01-10 13:10:09 -05:00
|
|
|
break
|
|
|
|
fi
|
|
|
|
done
|
2017-02-19 09:21:00 -05:00
|
|
|
if test -z "$fork_fn_var_haveit"; then
|
|
|
|
fork_fn_var_result="${fork_fn_var_result}${fork_fn_var_result:+ }$element"
|
2017-01-10 13:10:09 -05:00
|
|
|
fi
|
|
|
|
done
|
2017-02-19 09:21:00 -05:00
|
|
|
echo "$fork_fn_var_result"
|
|
|
|
unset fork_fn_var_haveit
|
|
|
|
unset fork_fn_var_result
|
|
|
|
}]])
|
|
|
|
|
2021-04-09 14:39:49 -04:00
|
|
|
dnl OWNTONE_VAR_PREPEND(VARNAME, BEFORE)
|
2017-02-19 09:21:00 -05:00
|
|
|
dnl ---------------------------------
|
|
|
|
dnl Prepends words in BEFORE to the contents of VARNAME, skipping any
|
|
|
|
dnl duplicate words.
|
2021-04-09 14:39:49 -04:00
|
|
|
AC_DEFUN([OWNTONE_VAR_PREPEND],
|
|
|
|
[AC_REQUIRE([_OWNTONE_FUNC_MERGE])dnl
|
2017-02-19 09:21:00 -05:00
|
|
|
[ $1=$(fork_fn_merge "$2" "$$1")]])
|
2017-01-10 13:10:09 -05:00
|
|
|
|
2021-04-09 14:39:49 -04:00
|
|
|
dnl OWNTONE_VARS_PREPEND(TARGET, LIBS_ENV, CFLAGS_ENV)
|
2017-02-19 09:21:00 -05:00
|
|
|
dnl -----------------------------------------------
|
2017-01-10 13:10:09 -05:00
|
|
|
dnl Prepend LIBS_ENV to LIBS and TARGET_LIBS
|
|
|
|
dnl Append CFLAGS_ENV to CPPFLAGS and TARGET_CPPFLAGS.
|
2021-04-09 14:39:49 -04:00
|
|
|
AC_DEFUN([OWNTONE_VARS_PREPEND],
|
2017-01-10 13:10:09 -05:00
|
|
|
[[
|
|
|
|
LIBS="$$2 $LIBS"
|
|
|
|
$1_LIBS="$$2 $$1_LIBS"]
|
2021-04-09 14:39:49 -04:00
|
|
|
OWNTONE_VAR_PREPEND([CPPFLAGS], [$$3])
|
|
|
|
OWNTONE_VAR_PREPEND([$1_CPPFLAGS], [$$3])
|
2017-01-10 13:10:09 -05:00
|
|
|
])
|
|
|
|
|
2021-04-09 14:39:49 -04:00
|
|
|
dnl _OWNTONE_VARS_ADD_PREFIX(TARGET)
|
2017-01-10 13:10:09 -05:00
|
|
|
dnl -----------------------------
|
|
|
|
dnl Internal use only. Add libdir prefix to {TARGET_}LIBS and
|
|
|
|
dnl includedir prefix to {TARGET_}CPPFLAGS as fallback search paths
|
|
|
|
dnl expanding all variables.
|
2021-04-09 14:39:49 -04:00
|
|
|
AC_DEFUN([_OWNTONE_VARS_ADD_PREFIX],
|
2017-01-10 13:10:09 -05:00
|
|
|
[AC_REQUIRE([AC_LIB_PREPARE_PREFIX])
|
|
|
|
AC_LIB_WITH_FINAL_PREFIX([[
|
|
|
|
eval LIBS=\"-L$libdir $LIBS\"
|
|
|
|
eval $1_LIBS=\"-L$libdir $$1_LIBS\"
|
|
|
|
eval fork_tmp_cppflags=\"-I$includedir\"]
|
2021-04-09 14:39:49 -04:00
|
|
|
OWNTONE_VAR_PREPEND([CPPFLAGS], [$fork_tmp_cppflags])
|
|
|
|
OWNTONE_VAR_PREPEND([$1_CPPFLAGS], [$fork_tmp_cppflags])
|
2017-01-10 13:10:09 -05:00
|
|
|
])
|
2017-01-06 03:44:18 -05:00
|
|
|
])
|
|
|
|
|
2021-04-09 14:39:49 -04:00
|
|
|
dnl OWNTONE_CHECK_DECLS(SYMBOLS, INCLUDE, [ACTION-IF-FOUND],
|
2017-02-19 09:21:00 -05:00
|
|
|
dnl [ACTION-IF-NOT-FOUND])
|
|
|
|
dnl -----------------------------------------------------
|
|
|
|
dnl Expands AC_CHECK_DECLS with SYMBOLS and INCLUDE appended to
|
|
|
|
dnl AC_INCLUDES_DEFAULT.
|
|
|
|
dnl NOTE: Remember that AC_CHECK_DECLS defines HAVE_* to 1 or 0
|
|
|
|
dnl (not 1 or undefined!)
|
2021-04-09 14:39:49 -04:00
|
|
|
AC_DEFUN([OWNTONE_CHECK_DECLS],
|
2017-02-19 09:21:00 -05:00
|
|
|
[AC_CHECK_DECLS([$1], [$3], [$4], [AC_INCLUDES_DEFAULT
|
|
|
|
[@%:@include <$2>]])
|
|
|
|
])
|
|
|
|
|
2021-04-09 14:39:49 -04:00
|
|
|
dnl OWNTONE_FUNC_REQUIRE(TARGET, DESCRIPTION, ENV, LIBRARY, FUNCTION, [HEADER],
|
2017-01-06 03:44:18 -05:00
|
|
|
dnl [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
|
2017-01-10 13:10:09 -05:00
|
|
|
dnl ------------------------------------------------------------------------
|
|
|
|
dnl Check for software which lacks pkg-config support, setting TARGET_CPPFLAGS
|
|
|
|
dnl and TARGET_LIBS with working values if FUNCTION found, or failing if
|
|
|
|
dnl it's not. If ENV_CFLAGS and ENV_LIBS overrides are set (ENV is prefix),
|
|
|
|
dnl tries to link FUNCTION/include HEADER with them. Without overrides,
|
|
|
|
dnl expands like AC_SEARCH_LIBS on FUNCTION (trying without and with LIBRARY),
|
|
|
|
dnl adding $prefix paths if necessary. If FUNCTION found, verifies optional
|
|
|
|
dnl HEADER can be included (or fails with error), and expands optional
|
|
|
|
dnl ACTION-IF-FOUND with working CPPFLAGS/LIBS for additional checks.
|
|
|
|
dnl DESCRIPTION used as friendly name in error messages to help user
|
|
|
|
dnl identify software to install. If FUNCTION not found, either displays
|
|
|
|
dnl error suggested use of ENV_* overrides, or if ENV_* were not set
|
|
|
|
dnl expands optional ACTION-IF-NOT-FOUND in place of error.
|
|
|
|
dnl Restores original CPPFLAGS and LIBS when done.
|
2021-04-09 14:39:49 -04:00
|
|
|
AC_DEFUN([OWNTONE_FUNC_REQUIRE],
|
|
|
|
[AS_VAR_PUSHDEF([OWNTONE_MSG], [fork_msg_$3])
|
2017-01-06 03:44:18 -05:00
|
|
|
AC_ARG_VAR([$3_CFLAGS], [C compiler flags for $2, overriding search])
|
|
|
|
AC_ARG_VAR([$3_LIBS], [linker flags for $2, overriding search])
|
2017-01-10 13:10:09 -05:00
|
|
|
[fork_save_$3_LIBS=$LIBS; fork_save_$3_CPPFLAGS=$CPPFLAGS
|
|
|
|
fork_found_$3=yes]
|
|
|
|
AS_IF([[test -n "$$3_CFLAGS" && test -n "$$3_LIBS"]],
|
|
|
|
[dnl ENV variables provided, just verify they work
|
2021-04-09 14:39:49 -04:00
|
|
|
AS_VAR_SET([OWNTONE_MSG], [["
|
2017-01-06 03:44:18 -05:00
|
|
|
Library specific environment variables $3_LIBS and
|
|
|
|
$3_CFLAGS were used, verify they are correct..."]])
|
2021-04-09 14:39:49 -04:00
|
|
|
OWNTONE_VARS_PREPEND([$1], [$3_LIBS], [$3_CFLAGS])
|
2017-01-10 13:10:09 -05:00
|
|
|
AC_CHECK_FUNC([[$5]], [],
|
2021-04-09 14:39:49 -04:00
|
|
|
[AC_MSG_FAILURE([[Unable to link function $5 with $2.$]OWNTONE_MSG])])],
|
2017-01-10 13:10:09 -05:00
|
|
|
[dnl Search w/o LIBRARY, w/ LIBRARY, and finally adding $prefix path
|
2021-04-09 14:39:49 -04:00
|
|
|
AS_VAR_SET([OWNTONE_MSG], [["
|
2017-01-06 03:44:18 -05:00
|
|
|
Install $2 in the default include path, or alternatively set
|
|
|
|
library specific environment variables $3_CFLAGS
|
|
|
|
and $3_LIBS."]])
|
2017-01-10 13:10:09 -05:00
|
|
|
AC_MSG_CHECKING([[for library containing $5...]])
|
|
|
|
AC_TRY_LINK_FUNC([[$5]], [AC_MSG_RESULT([[none required]])],
|
|
|
|
[[LIBS="-l$4 $LIBS"
|
|
|
|
$1_LIBS="-l$4 $$1_LIBS"]
|
|
|
|
AC_TRY_LINK_FUNC([[$5]], [AC_MSG_RESULT([[-l$4]])],
|
2021-04-09 14:39:49 -04:00
|
|
|
[_OWNTONE_VARS_ADD_PREFIX([$1])
|
2017-01-10 13:10:09 -05:00
|
|
|
AC_TRY_LINK_FUNC([[$5]], [AC_MSG_RESULT([[-l$4]])],
|
2017-01-06 03:44:18 -05:00
|
|
|
[AC_MSG_RESULT([[no]])
|
2017-01-10 13:10:09 -05:00
|
|
|
fork_found_$3=no])])
|
2017-01-06 03:44:18 -05:00
|
|
|
])
|
|
|
|
])
|
2017-01-10 13:10:09 -05:00
|
|
|
AS_IF([[test "$fork_found_$3" != "no"]],
|
|
|
|
[dnl check HEADER, then expand FOUND
|
|
|
|
m4_ifval([$6], [AC_CHECK_HEADER([[$6]], [],
|
2021-04-09 14:39:49 -04:00
|
|
|
[AC_MSG_FAILURE([[Unable to find header $6 for $2.$]OWNTONE_MSG])])])
|
2017-01-10 13:10:09 -05:00
|
|
|
$7])
|
|
|
|
[LIBS=$fork_save_$3_LIBS; CPPFLAGS=$fork_save_$3_CPPFLAGS]
|
|
|
|
dnl Expand NOT-FOUND after restoring saved flags to allow recursive expansion
|
|
|
|
AS_IF([[test "$fork_found_$3" = "no"]],
|
|
|
|
[m4_default_nblank([$8],
|
2021-04-09 14:39:49 -04:00
|
|
|
[AC_MSG_FAILURE([[Function $5 in lib$4 not found.$]OWNTONE_MSG])])])
|
|
|
|
AS_VAR_POPDEF([OWNTONE_MSG])
|
2017-01-06 03:44:18 -05:00
|
|
|
])
|
|
|
|
|
2021-04-09 14:39:49 -04:00
|
|
|
dnl OWNTONE_MODULES_CHECK(TARGET, ENV, MODULES, [FUNCTION], [HEADER],
|
2017-01-06 03:44:18 -05:00
|
|
|
dnl [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
|
|
|
|
dnl --------------------------------------------------------------
|
|
|
|
dnl Expands PKG_CHECK_MODULES, but when found also attempt to link
|
|
|
|
dnl FUNCTION and include HEADER. Appends working package values to
|
|
|
|
dnl TARGET_CPPFLAGS and TARGET_LIBS. Expands optional ACTION-IF-FOUND with
|
|
|
|
dnl working CPPFLAGS/LIBS for additional checks. Expands
|
|
|
|
dnl ACTION-IF-NOT-FOUND only if package not found (not link/include failures)
|
2017-01-06 15:49:57 -05:00
|
|
|
dnl overriding default error. Restores original CPPFLAGS and LIBS when done.
|
2021-04-09 14:39:49 -04:00
|
|
|
AC_DEFUN([OWNTONE_MODULES_CHECK],
|
2017-01-06 03:44:18 -05:00
|
|
|
[PKG_CHECK_MODULES([$2], [[$3]],
|
2017-01-10 13:10:09 -05:00
|
|
|
[[fork_save_$2_LIBS=$LIBS; fork_save_$2_CPPFLAGS=$CPPFLAGS]
|
2021-04-09 14:39:49 -04:00
|
|
|
OWNTONE_VARS_PREPEND([$1], [$2_LIBS], [$2_CFLAGS])
|
2017-01-06 03:44:18 -05:00
|
|
|
m4_ifval([$4], [AC_CHECK_FUNC([[$4]], [],
|
|
|
|
[AC_MSG_ERROR([[Unable to link function $4]])])])
|
|
|
|
m4_ifval([$5], [AC_CHECK_HEADER([[$5]], [],
|
|
|
|
[AC_MSG_ERROR([[Unable to find header $5]])])])
|
|
|
|
$6
|
2017-01-10 13:10:09 -05:00
|
|
|
[LIBS=$fork_save_$2_LIBS; CPPFLAGS=$fork_save_$2_CPPFLAGS]],
|
2017-01-06 15:49:57 -05:00
|
|
|
m4_default_nblank_quoted([$7]))
|
2017-01-06 03:44:18 -05:00
|
|
|
])
|
|
|
|
|
2021-04-09 14:39:49 -04:00
|
|
|
dnl OWNTONE_ARG_WITH_CHECK(TARGET, DESCRIPTION, OPTION, ENV, MODULES, [FUNCTION],
|
2017-01-06 03:44:18 -05:00
|
|
|
dnl [HEADER], [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
|
|
|
|
dnl --------------------------------------------------------------------------
|
|
|
|
dnl Create an --with-OPTION with a default of "check" (include MODULES
|
2021-04-09 14:39:49 -04:00
|
|
|
dnl if they are available). Expands OWNTONE_MODULES_CHECK with remaining
|
2017-01-06 03:44:18 -05:00
|
|
|
dnl arguments. Defines HAVE_ENV to 1 if package found. DESCRIPTION is used
|
|
|
|
dnl in option help. Shell variable with_OPTION set to yes before
|
|
|
|
dnl ACTION-IF-FOUND. Default ACTION-IF-NOT-FOUND will fail
|
2017-01-06 15:49:57 -05:00
|
|
|
dnl if --with-OPTION given and MODULES not found, or sets shell var
|
|
|
|
dnl with_OPTION to no if option was check. A non-empty ACTION-IF-NOT-FOUND
|
|
|
|
dnl overrides this behavior to allow alternate checks.
|
2021-04-09 14:39:49 -04:00
|
|
|
AC_DEFUN([OWNTONE_ARG_WITH_CHECK],
|
2017-01-06 03:44:18 -05:00
|
|
|
[AC_ARG_WITH([[$3]], [AS_HELP_STRING([--with-$3],
|
|
|
|
[with $2 (default=check)])], [],
|
|
|
|
[[with_$3=check]])
|
|
|
|
AS_IF([[test "x$with_$3" != "xno"]],
|
2021-04-09 14:39:49 -04:00
|
|
|
[OWNTONE_MODULES_CHECK([$1], [$4], [$5], [$6], [$7],
|
2017-01-06 03:44:18 -05:00
|
|
|
[[with_$3=yes]
|
2017-01-10 13:10:09 -05:00
|
|
|
AC_DEFINE([HAVE_$4], 1, [Define to 1 to build with $2])
|
2017-01-06 03:44:18 -05:00
|
|
|
$8],
|
2017-01-10 13:10:09 -05:00
|
|
|
[m4_default_nblank([$9],
|
|
|
|
[AS_IF([[test "x$with_$3" != "xcheck"]],
|
|
|
|
[AC_MSG_FAILURE([[--with-$3 was given, but test for $5 failed]])])
|
2017-01-06 15:49:57 -05:00
|
|
|
[with_$3=no]])
|
|
|
|
])
|
2017-01-06 03:44:18 -05:00
|
|
|
])
|
|
|
|
])
|
|
|
|
|
2021-04-09 14:39:49 -04:00
|
|
|
dnl OWNTONE_ARG_ENABLE(DESCRIPTION, OPTION, DEFINE, [ACTION-IF-ENABLE])
|
2017-01-06 03:44:18 -05:00
|
|
|
dnl ----------------------------------------------------------------
|
|
|
|
dnl Create an --enable-OPTION, setting shell variable enable_OPTION
|
|
|
|
dnl to no by default. If feature is enabled, defines DEFINE to 1
|
|
|
|
dnl and expand ACTION-IF_ENABLE. DESCRIPTION is used in option help.
|
2021-04-09 14:39:49 -04:00
|
|
|
AC_DEFUN([OWNTONE_ARG_ENABLE],
|
2017-01-06 03:44:18 -05:00
|
|
|
[AC_ARG_ENABLE([[$2]], [AS_HELP_STRING([--enable-$2],
|
|
|
|
[enable $1 (default=no)])])
|
|
|
|
AS_IF([[test "x$enable_$2" = "xyes"]],
|
|
|
|
[AC_DEFINE([$3], 1, [Define to 1 to enable $1])
|
|
|
|
$4],
|
|
|
|
[[enable_$2=no]])
|
|
|
|
])
|
|
|
|
|
2021-04-09 14:39:49 -04:00
|
|
|
dnl OWNTONE_ARG_DISABLE(DESCRIPTION, OPTION, DEFINE, [ACTION-IF-ENABLE])
|
2017-01-06 03:44:18 -05:00
|
|
|
dnl ----------------------------------------------------------------
|
|
|
|
dnl Create an --disable-OPTION, setting shell variable enable_OPTION
|
|
|
|
dnl to yes by default. If feature is enabled, defines DEFINE to 1
|
|
|
|
dnl and expand ACTION-IF_ENABLE. DESCRIPTION is used in option help.
|
2021-04-09 14:39:49 -04:00
|
|
|
AC_DEFUN([OWNTONE_ARG_DISABLE],
|
2017-01-06 03:44:18 -05:00
|
|
|
[AC_ARG_ENABLE([[$2]], [AS_HELP_STRING([--disable-$2],
|
|
|
|
[disable $1 (default=no)])])
|
|
|
|
AS_IF([[test "x$enable_$2" = "x" || test "x$enable_$2" = "xyes"]],
|
|
|
|
[AC_DEFINE([$3], 1, [Define to 1 to enable $1])
|
|
|
|
[enable_$2=yes]
|
|
|
|
$4],
|
|
|
|
[[enable_$2=no]])
|
|
|
|
])
|