X-Git-Url: https://git.draconx.ca/gitweb/upkg.git/blobdiff_plain/747fcfe8bf9256425c373f7a6d0822b6f655a459..53803e139d0e3ea06810cf1187d50b496be3b278:/m4/dxutils.m4 diff --git a/m4/dxutils.m4 b/m4/dxutils.m4 new file mode 100644 index 0000000..6df2438 --- /dev/null +++ b/m4/dxutils.m4 @@ -0,0 +1,78 @@ +dnl Copyright (C) 2010 Nick Bowler +dnl Copying and distribution of this file, with or without modification, +dnl are permitted in any medium without royalty provided the copyright +dnl notice and this notice are preserved. This file is offered as-is, +dnl without any warranty. + +m4_pattern_forbid([^_?DX_]) + +dnl DX_PKG_CONFIG(env-base, [pkg-id], [pkg-help]) +AC_DEFUN([DX_PKG_CONFIG], [dnl +AC_ARG_VAR(m4_toupper([$1])[_CFLAGS], [C compiler flags for ]ifelse( + [$3], [], [$1], [$3]))dnl +AC_ARG_VAR(m4_toupper([$1])[_LIBS], [linker flags for ]ifelse( + [$3], [], [$1], [$3]))dnl + +ifelse([$2], [], [], [dnl +AC_REQUIRE([PKG_PROG_PKG_CONFIG])dnl +if test x"$PKG_CONFIG" != x; then + AC_MSG_CHECKING([pkg-config database for $2]) + pkg_failed=no + _PKG_CONFIG(m4_tolower([$1])[_cflags], [cflags], [$2]) + _PKG_CONFIG(m4_tolower([$1])[_libs], [libs], [$2]) + if test x$pkg_failed = xyes; then + errors=`$PKG_CONFIG --errors-to-stdout --print-errors $2` + echo "$errors" >&AS_MESSAGE_LOG_FD + AC_MSG_RESULT([no]) + else + AC_MSG_RESULT([yes]) + fi +fi])]) + +dnl _DX_CHECK_LIB(env-base, check-func, [cflags], [libs], [test]) +AC_DEFUN([_DX_CHECK_LIB], [dnl +if test x"$dx_cv_[]m4_tolower([$1])_found" = x"no"; then +if ifelse([$5], [], [:], [$5]); then + CFLAGS="$3 $dx_old_cflags" + LIBS="$4 $dx_old_libs" + + $2([dnl + dx_cv_[]m4_tolower([$1])_found="yes" + dx_cv_[]m4_tolower([$1])_cflags="$3" + dx_cv_[]m4_tolower([$1])_libs="$4" + ]) +fi +fi +]) + +dnl DX_CHECK_LIB_EXT(env-base, message, check-func, +dnl [[[cflags1],[libs1],[test1]],[[cflags2],[libs2],[test2]],...]) +AC_DEFUN([DX_CHECK_LIB_EXT], [dnl +AC_LANG_PUSH([C]) +dx_old_cflags=$CFLAGS +dx_old_libs=$LIBS + +AC_CACHE_CHECK([$2], [dx_cv_]m4_tolower([$1])[_found], [dnl +AC_CACHE_VAL([dx_cv_]m4_tolower([$1])[_libs], [dnl +AC_CACHE_VAL([dx_cv_]m4_tolower([$1])[_cflags], [dnl + dx_cv_[]m4_tolower([$1])_found=no + m4_foreach([dx_tuple], [$4], [_DX_CHECK_LIB([$1], [$3], dx_tuple)]) +])])]) + +if test x"$dx_cv_[]m4_tolower([$1])_found" = x"yes"; then + m4_toupper([$1])_CFLAGS=$dx_cv_[]m4_tolower([$1])_cflags + m4_toupper([$1])_LIBS=$dx_cv_[]m4_tolower([$1])_libs + AC_SUBST(m4_toupper([$1])[_CFLAGS]) + AC_SUBST(m4_toupper([$1])[_LIBS]) +fi + +CFLAGS=$dx_old_cflags +LIBS=$dx_old_libs +AC_LANG_POP([C]) +]) + +dnl DX_CHECK_LIB(env-base, message, test-program, +dnl [[[cflags1],[libs1],[test1]],[[cflags2],[libs2],[test2]],...]) +AC_DEFUN([DX_CHECK_LIB], [dnl + DX_CHECK_LIB_EXT([$1], [$2], [m4_curry([AC_LINK_IFELSE], [$3])], [$4]) +])