]> git.draconx.ca Git - liblbx.git/blob - m4/dxutils.m4
build: Split out core logic from libpng detection.
[liblbx.git] / m4 / dxutils.m4
1 dnl Copyright (C) 2010 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 m4_pattern_forbid([^_?DX_])
8
9 dnl DX_PKG_CONFIG(env-base, [pkg-id], [pkg-help])
10 AC_DEFUN([DX_PKG_CONFIG], [dnl
11 AC_ARG_VAR(m4_toupper([$1])[_CFLAGS], [C compiler flags for ]ifelse(
12         [$3], [], [$1], [$3]))dnl
13 AC_ARG_VAR(m4_toupper([$1])[_LIBS],   [linker flags for ]ifelse(
14         [$3], [], [$1], [$3]))dnl
15
16 ifelse([$2], [], [], [dnl
17 AC_REQUIRE([PKG_PROG_PKG_CONFIG])dnl
18 if test x"$PKG_CONFIG" != x; then
19         AC_MSG_CHECKING([pkg-config database for $2])
20         _PKG_CONFIG(m4_tolower([$1])[_cflags], [cflags], [$2])
21         _PKG_CONFIG(m4_tolower([$1])[_libs],   [libs],   [$2])
22         if test x$pkg_failed = xyes; then
23                 errors=`$PKG_CONFIG --errors-to-stdout --print-errors $2`
24                 echo "$errors" >&AS_MESSAGE_LOG_FD
25                 AC_MSG_RESULT([no])
26         else
27                 AC_MSG_RESULT([yes])
28         fi
29 fi])])
30
31 dnl _DX_CHECK_LIB([env-base], [test-program], [cflags], [libs], [test])
32 AC_DEFUN([_DX_CHECK_LIB], [dnl
33 if test x"$dx_cv_[]m4_tolower([$1])_found" = x"no"; then
34 if ifelse([$5], [], [:], [$5]); then
35         CFLAGS="$3 $dx_old_cflags"
36         LIBS="$4 $dx_old_libs"
37
38         AC_LINK_IFELSE([$2], [dnl
39                 dx_cv_[]m4_tolower([$1])_found="yes"
40                 dx_cv_[]m4_tolower([$1])_cflags="$3"
41                 dx_cv_[]m4_tolower([$1])_libs="$4"
42                 ], [:])
43 fi
44 fi
45 ])
46
47 dnl DX_CHECK_LIB([env-base], [message], [test-program],
48 dnl              [[[cflags1],[libs1],[test1]],[[cflags2],[libs2],[test2]],...])
49 AC_DEFUN([DX_CHECK_LIB], [dnl
50 AC_LANG_PUSH([C])
51 dx_old_cflags=$CFLAGS
52 dx_old_libs=$LIBS
53
54 AC_CACHE_CHECK([$2], [dx_cv_]m4_tolower([$1])[_found], [dnl
55 AC_CACHE_VAL([dx_cv_]m4_tolower([$1])[_libs],   [dnl
56 AC_CACHE_VAL([dx_cv_]m4_tolower([$1])[_cflags], [dnl
57         dx_cv_[]m4_tolower([$1])_found=no
58         m4_foreach([dx_tuple], [$4], [_DX_CHECK_LIB([$1], [$3], dx_tuple)])
59 ])])])
60
61 if test x"$dx_cv_[]m4_tolower([$1])_found" = x"yes"; then
62         m4_toupper([$1])_CFLAGS=$dx_cv_[]m4_tolower([$1])_cflags
63         m4_toupper([$1])_LIBS=$dx_cv_[]m4_tolower([$1])_libs
64         AC_SUBST(m4_toupper([$1])[_CFLAGS])
65         AC_SUBST(m4_toupper([$1])[_LIBS])
66 fi
67
68 CFLAGS=$dx_old_cflags
69 LIBS=$dx_old_libs
70 AC_LANG_POP([C])
71 ])