]> git.draconx.ca Git - upkg.git/blob - m4/libmodplug.m4
package: Get rid of separate mechanisms for opening packages.
[upkg.git] / m4 / libmodplug.m4
1 dnl Copyright (C) 2009 Nick Bowler
2 dnl Copying and distribution of this file, with or without modification,
3 dnl are permitted in any medium without royalty provided the copyright
4 dnl notice and this notice are preserved.  This file is offered as-is,
5 dnl without any warranty.
6
7 AC_DEFUN([_LIBMODPLUG_TEST], [dnl
8 AC_CACHE_CHECK([whether libmodplug works],
9         [libmodplug_cv_works],
10         [AC_LINK_IFELSE([AC_LANG_PROGRAM([dnl
11 #include <modplug.h>
12 ], [dnl
13 unsigned char buf@<:@128@:>@ = {0};
14 ModPlugFile *f = ModPlug_Load(buf, sizeof buf);
15 ModPlug_Unload(f);
16 ])], [libmodplug_cv_works=yes], [libmodplug_cv_works=no])])
17 ])
18
19 dnl CHECK_LIBMODPLUG([action-if-ok], [action-if-fail])
20 AC_DEFUN([CHECK_LIBMODPLUG],
21 [AC_REQUIRE([PKG_PROG_PKG_CONFIG])dnl
22 AC_ARG_VAR([LIBMODPLUG_CFLAGS], [C compiler flags for libmodplug])dnl
23 AC_ARG_VAR([LIBMODPLUG_LIBS],   [linker flags for libmodplug])dnl
24
25 if test x"$PKG_CONFIG" != x; then
26         AC_MSG_CHECKING([pkg-config database for libmodplug])
27         _PKG_CONFIG([libmodplug_cflags], [cflags], [libmodplug])
28         _PKG_CONFIG([libmodplug_libs],   [libs],   [libmodplug])
29         if test x$pkg_failed = xyes; then
30                 errors=`$PKG_CONFIG --errors-to-stdout --print-errors libmodplug`
31                 echo "$errors" >&AS_MESSAGE_LOG_FD
32                 AC_MSG_RESULT([no])
33         else
34                 if test x"$LIBMODPLUG_CFLAGS" = x; then
35                         LIBMODPLUG_CFLAGS=$pkg_cv_libmodplug_cflags
36                 fi
37                 if test x"$LIBMODPLUG_LIBS" = x; then
38                         LIBMODPLUG_LIBS=$pkg_cv_libmodplug_libs
39                 fi
40
41                 AC_MSG_RESULT([yes])
42         fi
43 fi
44
45 if test x"$LIBMODPLUG_CFLAGS" = x; then
46         LIBMODPLUG_CFLAGS="-I$includedir/libmodplug"
47 fi
48
49 if test x"$LIBMODPLUG_LIBS" = x; then
50         LIBMODPLUG_LIBS=-lmodplug
51 fi
52
53 AC_LANG_PUSH([C])
54 old_cflags=$CFLAGS
55 old_libs=$LIBS
56 CFLAGS="$LIBMODPLUG_CFLAGS $CFLAGS"
57 LIBS="$LIBMODPLUG_LIBS $LIBS"
58
59 _LIBMODPLUG_TEST
60
61 CFLAGS=$old_cflags
62 LIBS=$old_libs
63 AC_LANG_POP([C])
64
65 if test x"$libmodplug_cv_works" = x"yes"; then
66         AC_SUBST([LIBMODPLUG_CFLAGS])
67         AC_SUBST([LIBMODPLUG_LIBS])
68         ifelse([$1], [], [true], [$1])
69 else
70         ifelse([$2], [], [AC_MSG_FAILURE([dnl
71 libmodplug is required.  The latest version can be
72 obtained from http://modplug-xmms.sourceforge.net/.
73
74 If libmodplug is installed but was not found by this configure script,
75 consider adjusting LIBMODPLUG_CFLAGS and/or LIBMODPLUG_LIBS as necessary.
76
77 If pkg-config is installed, it may help to adjust PKG_CONFIG_PATH
78 if libmodplug is installed in a non-standard prefix.
79 ])], [$2])
80 fi
81 ])