Skip to content
Snippets Groups Projects
Select Git revision
  • e4cff0e5bca70eddb7469e069354479ad256de19
  • master default protected
  • releases
  • releases/3.0.3
4 results

check-package.m4

Blame
  • check-package.m4 3.59 KiB
    dnl
    dnl Check for a library + header files
    dnl 
    dnl
    dnl Arguments:
    dnl
    dnl $1: symbolic name (fancy)
    dnl $2: library name (base name, lib$2[.so|.a]
    dnl $3: library path (-L$3)
    dnl $4: additional libraries needed (e.g. -lm -lGL)
    dnl $5: header name
    dnl $6: include path (-I$6)
    dnl $7 \in \{optional, required\}, bail out if required, warning otherwise
    dnl
    AC_DEFUN([ALBERT_CHECK_PKG_OPT],
    [AC_ARG_WITH($1,
    AC_HELP_STRING([--without-$1], [disable use of package $1
                          (default: autodetect)]),
    	[case "$withval" in
    		yes)
    			;;
    		no)
    			m4_bpatsubst([$1],-,_)_DISABLE=yes
    			;;
    		*)
    	AC_MSG_ERROR(["$withval" should have been either "yes" or "no"])
    			  ;;
    	esac],
    	[m4_bpatsubst([$1],-,_)_DISABLE=no])
    ])
    AC_DEFUN(ALBERT_CHECK_PACKAGE,
    [AC_REQUIRE([AC_SET_PREFIX])
    dnl
    m4_if($7, optional,[ALBERT_CHECK_PKG_OPT([$1])])
    dnl if test "$7" = "optional"; then
    dnl 	ALBERT_CHECK_PKG_OPT([$1])
    dnl fi
    
    if test "${m4_bpatsubst([$1],-,_)_DISABLE}" = yes; then
    	:
    else
    
    if test -z "$3"; then
    	DEFAULT_LIBDIR=`eval eval echo ${libdir}`
    else
    	DEFAULT_LIBDIR=$3
    fi
    AC_ARG_WITH($1-lib,
    AC_HELP_STRING([--with-$1-lib=DIR],
                   [use $1 library below directory DIR (default: $3)]),
    [case "$withval" in
        yes) AC_MSG_ERROR("option \"--with-$1-lib\" requires an argument")
    	;;
        no) AC_MSG_ERROR("option \"--with-$1-lib\" requires an argument")
    	;;
        *) m4_bpatsubst([$1],-,_)_LIB_PATH=$withval
    	;;
    esac],
    m4_bpatsubst([$1],-,_)_LIB_PATH=$DEFAULT_LIBDIR)
    dnl
    dnl now for the header file
    dnl
    if test -z "$6"; then
    	DEFAULT_INCDIR=`eval eval echo ${includedir}`
    else
    	DEFAULT_INCDIR=$6
    fi
    AC_ARG_WITH($1-headers,
    AC_HELP_STRING([--with-$1-headers=DIR],
                   [use $1 include files below directory DIR (default: $6)]),
    [case "$withval" in
        yes) AC_MSG_ERROR("option \"--with-$1-headers\" requires an argument")
    	;;
        no) AC_MSG_ERROR("option \"--with-$1-headers\" requires an argument")
    	;;
        *) m4_bpatsubst([$1],-,_)_INCLUDE_PATH=$withval
    	;;
    esac],
    m4_bpatsubst([$1],-,_)_INCLUDE_PATH=$DEFAULT_INCDIR)
    dnl
    dnl now check if the library and header files exist
    dnl
    if test "$7" = "optional" ; then
      AC_CHECK_LIB($2, main,
        [m4_bpatsubst([$1],-,_)_LIB="-L${m4_bpatsubst([$1],-,_)_LIB_PATH} -l$2"],
        [m4_bpatsubst([$1],-,_)_LIB=""
         m4_bpatsubst([$1],-,_)_LIB_PATH=""
         m4_bpatsubst([$1],-,_)_INCLUDE_PATH=""],
        -L${m4_bpatsubst([$1],-,_)_LIB_PATH} $4)
    else
      AC_CHECK_LIB($2, main,
        [m4_bpatsubst([$1],-,_)_LIB="-L${m4_bpatsubst([$1],-,_)_LIB_PATH} -l$2 $4"],
        [AC_MSG_ERROR([Library "lib$2" was not found])],
        -L$m4_bpatsubst([$1],-,_)_LIB_PATH $4)
    fi
    if test "x${m4_bpatsubst([$1],-,_)_LIB}" = "x" ; then
    	:
    else
      dnl
      dnl  check for the header file
      dnl
      [ac_]m4_bpatsubst([$1],-,_)_save_CPPFLAGS="$CPPFLAGS"
      CPPFLAGS="-I${m4_bpatsubst([$1],-,_)_INCLUDE_PATH} $CPPFLAGS"
      if test "$7" = "optional" ; then
        AC_CHECK_HEADERS($5,, [m4_bpatsubst([$1],-,_)_LIB=""
                               m4_bpatsubst([$1],-,_)_LIB_PATH=""
                               m4_bpatsubst([$1],-,_)_INCLUDE_PATH=""])
      else
        AC_CHECK_HEADERS($5,, AC_MSG_ERROR([Header file "$5" was not found]))
      fi
      CPPCLAGS="${[ac_]m4_bpatsubst([$1],-,_)_save_CPPFLAGS}"
      dnl
      dnl define makefile substitutions and config.h macros
      dnl
      if test "x${m4_bpatsubst([$1],-,_)_LIB}" = "x" ; then
    	:
      else
        AC_DEFINE(m4_bpatsubst(m4_toupper([HAVE_LIB$2]),-,_),
                  1, Define to 1 if you have lib$2)
      fi
    fi
    
    fi dnl disable fi
    
    AM_CONDITIONAL(m4_bpatsubst([$1],-,_), test -n "${m4_bpatsubst([$1],-,_)_LIB}")
    AC_SUBST(m4_bpatsubst([$1],-,_)_INCLUDE_PATH)
    AC_SUBST(m4_bpatsubst([$1],-,_)_LIB_PATH)
    AC_SUBST(m4_bpatsubst([$1],-,_)_LIB)
    ])