--- /dev/null
+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])
+])
-dnl Copyright (C) 2009 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.
+dnl Copyright © 2011 Nick Bowler
+dnl
+dnl License WTFPL2: Do What The Fuck You Want To Public License, version 2.
+dnl This is free software: you are free to do what the fuck you want to.
+dnl There is NO WARRANTY, to the extent permitted by law.
-AC_DEFUN([_LIBMODPLUG_TEST], [dnl
-AC_CACHE_CHECK([whether libmodplug works],
- [libmodplug_cv_works],
- [AC_LINK_IFELSE([AC_LANG_PROGRAM([dnl
+AC_DEFUN([_DX_LIBMODPLUG_TEST_PROGRAM], [AC_LANG_PROGRAM([dnl
#include <modplug.h>
], [dnl
unsigned char buf@<:@128@:>@ = {0};
ModPlugFile *f = ModPlug_Load(buf, sizeof buf);
ModPlug_Unload(f);
-])], [libmodplug_cv_works=yes], [libmodplug_cv_works=no])])
-])
-
-dnl CHECK_LIBMODPLUG([action-if-ok], [action-if-fail])
-AC_DEFUN([CHECK_LIBMODPLUG],
-[AC_REQUIRE([PKG_PROG_PKG_CONFIG])dnl
-AC_ARG_VAR([LIBMODPLUG_CFLAGS], [C compiler flags for libmodplug])dnl
-AC_ARG_VAR([LIBMODPLUG_LIBS], [linker flags for libmodplug])dnl
-
-if test x"$PKG_CONFIG" != x; then
- AC_MSG_CHECKING([pkg-config database for libmodplug])
- _PKG_CONFIG([libmodplug_cflags], [cflags], [libmodplug])
- _PKG_CONFIG([libmodplug_libs], [libs], [libmodplug])
- if test x$pkg_failed = xyes; then
- errors=`$PKG_CONFIG --errors-to-stdout --print-errors libmodplug`
- echo "$errors" >&AS_MESSAGE_LOG_FD
- AC_MSG_RESULT([no])
- else
- if test x"$LIBMODPLUG_CFLAGS" = x; then
- LIBMODPLUG_CFLAGS=$pkg_cv_libmodplug_cflags
- fi
- if test x"$LIBMODPLUG_LIBS" = x; then
- LIBMODPLUG_LIBS=$pkg_cv_libmodplug_libs
- fi
-
- AC_MSG_RESULT([yes])
- fi
-fi
-
-if test x"$LIBMODPLUG_CFLAGS" = x; then
- LIBMODPLUG_CFLAGS="-I$includedir/libmodplug"
-fi
-
-if test x"$LIBMODPLUG_LIBS" = x; then
- LIBMODPLUG_LIBS=-lmodplug
-fi
-
-AC_LANG_PUSH([C])
-old_cflags=$CFLAGS
-old_libs=$LIBS
-CFLAGS="$LIBMODPLUG_CFLAGS $CFLAGS"
-LIBS="$LIBMODPLUG_LIBS $LIBS"
-
-_LIBMODPLUG_TEST
-
-CFLAGS=$old_cflags
-LIBS=$old_libs
-AC_LANG_POP([C])
-
-if test x"$libmodplug_cv_works" = x"yes"; then
- AC_SUBST([LIBMODPLUG_CFLAGS])
- AC_SUBST([LIBMODPLUG_LIBS])
- ifelse([$1], [], [true], [$1])
+])])
+
+dnl DX_CHECK_LIBMODPLUG([action-if-ok], [action-if-fail])
+AC_DEFUN([DX_CHECK_LIBMODPLUG],
+[DX_PKG_CONFIG([libmodplug], [libmodplug], [libmodplug])
+
+DX_CHECK_LIB([libmodplug],
+ [for libmodplug], [_DX_LIBMODPLUG_TEST_PROGRAM], [dnl
+ [[$LIBMODPLUG_CFLAGS], [$LIBMODPLUG_LIBS]],
+ [[$pkg_cv_libmodplug_cflags], [$pkg_cv_libmodplug_libs],
+ [test ! x"$pkg_failed" = x"yes"]],
+ [[], [-lmodplug]],
+ ])
+
+if test x"$dx_cv_libmodplug_found" = x"yes"; then
+ ifelse([$1], [], [:], [$1])
else
ifelse([$2], [], [AC_MSG_FAILURE([dnl
-libmodplug is required. The latest version can be
-obtained from http://modplug-xmms.sourceforge.net/.
+libmodplug is required. The latest
+version can be obtained from http://modplug-xmms.sourceforge.net/.
If libmodplug is installed but was not found by this configure script,
consider adjusting LIBMODPLUG_CFLAGS and/or LIBMODPLUG_LIBS as necessary.
-If pkg-config is installed, it may help to adjust PKG_CONFIG_PATH
-if libmodplug is installed in a non-standard prefix.
+If pkg-config is installed, it may help to adjust PKG_CONFIG_PATH if
+libmodplug is installed in a non-standard prefix.
])], [$2])
fi
])