f2c2d2fdcd63d73b1c4d89f9fc121af98363ca77
[supertux.git] / mk / autoconf / np_findlib.m4
1 #  NP_FINDLIB(VARNAME, NAME, STRING, TESTAPP, CFLAGS, LIBS, ACTION_IF_FOUND,
2 #             ACTION_IF_NOT_FOUND, EXTRACFLAGS, EXTRALIBS)
3 AC_DEFUN([NP_FINDLIB], [
4     AC_ARG_WITH([lib$2], [AC_HELP_STRING([--with-lib$2=dir],
5         [specify location of lib$2 if not detected automatically; uses
6         dir, dir/include and dir/lib])])
7             
8     save_CFLAGS="$CFLAGS"
9     save_CPPFLAGS="$CPPFLAGS"
10     save_LIBS="$LIBS"
11
12     RESCFLAGS="$5"
13     RESLIBS="$6"
14     CFLAGS="$CFLAGS $5 $9"
15     CPPFLAGS="$CPPFLAGS $5 $9"
16     LIBS="$LIBS $6 $10"
17
18     AS_IF([test -n "$with_lib$2"], [
19         CFLAGS="-I$with_lib$2/include $CFLAGS"
20         CPPFLAGS="-I$with_lib$2/include $CPPFLAGS"
21         LIBS="-L$with_lib$2/lib $LIBS"
22         RESCFLAGS="-I$with_lib$2/include $RESCFLAGS"
23         RESLIBS="-L$with_lib$2/lib $RESLIBS"
24     ])
25
26     AC_MSG_CHECKING([for $3])
27
28     AC_LINK_IFELSE([$4], [buildok=yes], [buildok=no])
29
30     LIBS=$save_LIBS
31     CPPFLAGS=$save_CPPFLAGS
32     CFLAGS=$save_CFLAGS
33
34     AS_IF([test $buildok = yes],
35         [AC_MSG_RESULT([found])
36          $1_AVAILABLE=yes
37          $1_CFLAGS="$RESCFLAGS"
38          $1_LIBS="$RESLIBS"],
39         [AC_MSG_RESULT([not found])
40          $1_AVAILABLE=no
41          $1_CFLAGS=""
42          $1_LIBS=""])
43     
44     AC_SUBST([$1_AVAILABLE])
45     AC_SUBST([$1_CFLAGS])
46     AC_SUBST([$1_LIBS])
47
48     AS_IF([test $buildok = yes],
49         [ifelse([$7], , :, [$7])],
50         [ifelse([$8], , :, [$8])])
51 ])