# KL_CHECK_LIB([LIBRARY-NAME], [ACTION-IF-NOT-FOUND]) # ---------------------------------------------------------------------- # # If configure option --with-LIBRARY-NAME=path/to/library is ommited then # this macro searches specified library using Unix Dpt Automake System rules. # # Expected source tree hierarchy below: # # project1 # project1/libs # project1/libs/lib1 # project1/libs/... # project1/libs/libN # project1/libs/contrib/clib1 # project1/libs/contrib/... # project1/libs/contrib/clibM # # To use this macro just add the following lines in the configure.in file of 'project1' : # KL_CHECK_LIB([lib1]) # KL_CHECK_LIB([libN]) # KL_CHECK_LIB([clib1]) # KL_CHECK_LIB([clibN]) # # The following shell variables are set if the library is found: # # libname_PATH= # libname_INCLUDES=$libname_path/include # libname_LIBS=$libname_path/lib # libname_CPPFLAGS=-I$libname_path/include # libname_LDFLAGS=-L$libname_path/lib # # To control behavior in case of library not found you can # specify the second parameter of this macro. # Default: AC_MSG_ERROR([not found]) # # Note: If you want this macro to search in another directories of your system # just set KL_LIBS_SEARCH env variable. I.e.: # KL_LIBS_SEARCH="/usr/local/libspath1 /usr/local/libspath2" # KL_CHECK_LIB([library_located_in_libspath1]) # KL_CHECK_LIB([library_located_in_libspath2]) # AC_DEFUN([KL_CHECK_LIB], [ AC_ARG_WITH( [$1], AS_HELP_STRING( [--with-$1], [Path to $1 library (default: libs/$1 or libs/contrib/$1) ], ), [ac_$1_path=$withval], [ac_$1_path=no] ) AC_MSG_CHECKING([for $1]) if test "X$ac_$1_path" = "Xno" || test "X$ac_$1_path" = "Xyes"; then KL_CHK_LIB__FOUND_LIB([$1]) else KL_CHK_LIB__SET_VARS([$1], [$ac_$1_path]) test -d "$$1_PATH" || AC_MSG_WARN([Directory $$1_PATH currently not exists]) fi if test -n "$$1_PATH"; then AC_MSG_RESULT([$$1_PATH]) else $2 test len($2) -eq 0 && AC_MSG_ERROR([Missing library: $1 not found]) fi ]) #----------------- # Helper macros #----------------- AC_DEFUN([KL_CHK_LIB__SET_VARS], [ ac_path_val="$2" if test "${ac_path_val#/}" = "$ac_path_val"; then ac_path_val="$(cd $ac_path_val && pwd && cd - >/dev/null)" fi export $1_PATH=$ac_path_val export $1_INCLUDES=$ac_path_val/include export $1_LIBS=$ac_path_val/lib export $1_CPPFLAGS=-I$ac_path_val/include export $1_LDFLAGS=-L$ac_path_val/lib ]) AC_DEFUN([KL_CHK_LIB__FOUND_LIB], [ # Variable $1_PATH could be defined in upper level configure # so don't do anything in this case if test -n "$1_PATH"; then case $srcdir in [\/]?*) ac_pwd=$srcdir ;; # absolute path .) ac_pwd=$(pwd) ;; # no --srcdir *) ac_pwd=$(pwd)/$srcdir ;; # relative path esac for DIR in $ac_pwd/libs/$1 \ $ac_pwd/libs/contrib/$1 \ $ac_pwd/../$1 \ $ac_pwd/../contrib/$1 \ $KL_LIBS_SEARCH do # get abspath cause "test -d" gives 1 for ../foo paths DIR="$(cd $DIR 2>/dev/null && pwd && cd - >/dev/null )" if test -n "$DIR" -a -z "$$1_PATH" -a -d "$DIR"; then KL_CHK_LIB__SET_VARS([$1], [$DIR]) fi done fi ])