1 dnl Copyright (C) 2011 Vincent Torri <vtorri at univ-evry dot fr>
2 dnl That code is public domain and can be freely used or copied.
4 dnl Macro that check if a library is in a specified directory.
6 dnl Usage: OPJ_CHECK_LIB_WITH_PREFIX(prefix, header, lib, func [, ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND]])
7 dnl Call AC_SUBST(THELIB_CFLAGS)
8 dnl Call AC_SUBST(THELIB_LIBS)
9 dnl where THELIB is the uppercase value of 'lib'
11 AC_DEFUN([OPJ_CHECK_LIB_WITH_PREFIX],
14 m4_pushdef([UP], m4_toupper([$3]))
15 m4_pushdef([DOWN], m4_tolower([$3]))
23 save_CPPFLAGS=${CPPFLAGS}
26 if test "x$UP[_CFLAGS]" != "x"; then
27 CPPFLAGS="${CPPFLAGS} $UP[_CFLAGS]"
29 if test "x${__opj_prefix}" != "x" ; then
30 __opj_CPPFLAGS="-I${__opj_prefix}/include"
34 CPPFLAGS="${CPPFLAGS} ${__opj_CPPFLAGS}"
37 if test "x$UP[_LIBS]" != "x"; then
38 LIBS="${LIBS} $UP[_LIBS]"
40 if test "x${__opj_prefix}" != "x" ; then
41 __opj_LIBS="-L${__opj_prefix}/lib -l${__opj_lib}"
43 __opj_LIBS="-l${__opj_lib}"
45 LIBS="${LIBS} ${__opj_LIBS}"
51 #include <${__opj_header}>
56 [__opj_have_dep="yes"],
57 [__opj_have_dep="no"])
59 CPPFLAGS=${save_CPPFLAGS}
62 if test "x${__opj_prefix}" = "x" ; then
63 AC_MSG_CHECKING([whether ]UP[ library is available in standard or predefined directories])
65 AC_MSG_CHECKING([whether ]UP[ library is available in ${__opj_prefix}])
67 AC_MSG_RESULT([${__opj_have_dep}])
69 if test "x${__opj_have_dep}" = "xyes"; then
70 if test "x${UP[]_CFLAGS}" = "x" ; then
71 UP[]_CFLAGS="${__opj_CPPFLAGS}"
73 if test "x${UP[]_LIBS}" = "x" ; then
74 UP[]_LIBS="${__opj_LIBS}"
78 AS_IF([test "x${__opj_have_dep}" = "xyes"], [$5], [$6])
85 dnl Macro that check if a library is in a set of directories.
87 dnl Usage: OPJ_CHECK_LIB(header, lib, func [, ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND]])
89 AC_DEFUN([OPJ_CHECK_LIB],
92 m4_pushdef([UP], m4_toupper([$2]))
96 OPJ_CHECK_LIB_WITH_PREFIX([],
100 [__opj_have_dep="yes"],
101 [__opj_have_dep="no"])
103 if ! test "x${__opj_have_dep}" = "xyes" ; then
104 OPJ_CHECK_LIB_WITH_PREFIX([/usr],
108 [__opj_have_dep="yes"],
109 [__opj_have_dep="no"])
112 if ! test "x${__opj_have_dep}" = "xyes" ; then
113 OPJ_CHECK_LIB_WITH_PREFIX([/usr/local],
117 [__opj_have_dep="yes"],
118 [__opj_have_dep="no"])
121 if ! test "x${__opj_have_dep}" = "xyes" ; then
122 OPJ_CHECK_LIB_WITH_PREFIX([/opt/local],
126 [__opj_have_dep="yes"],
127 [__opj_have_dep="no"])
130 AC_ARG_VAR(UP[_CFLAGS], [preprocessor flags for lib$2])
131 AC_SUBST(UP[_CFLAGS])
132 AC_ARG_VAR(UP[_LIBS], [linker flags for lib$2])
135 AS_IF([test "x${__opj_have_dep}" = "xyes"], [$4], [$5])