Re: checking for headers

2003-01-22 Thread Dan Nelson
In the last episode (Jan 22), edscott wilson garcia said:
>   I'm trying to get a "configure" program to check for dbh.h, but the
> following line only checks in /usr/include:
> 
> AC_CHECK_HEADERS(dbh.h, ac_cv_dbh_library=yes, ac_cv_dbh_library=no)
> 
> The generated configure in Linux searches both /usr/include and
> /usr/local/include, but not in FreeBSD. What do I have to add so that
> it will search /usr/local/include in FreeBSD?

You are usually better off simply telling your users to add required
include and lib paths to CPPFLAGS and LDFLAGS.  You can manually add
paths by appending to CPPFLAGS at the top of your configure.in, but gcc
will complain if you add a directory that's already in the system's
path, and you risk not including common locations on other systems
(lots of Solaris stuff installs in /opt, for example).  There is no
simple autoconf command for "add this include path if it exists and the
compiler doesn't complain".  I have attached the autoconf code that the
Pike configure script uses; it will detect most common include and lib
paths.  It probably won't work on its own, but it's an example of how
complicated it is when done right.

-- 
Dan Nelson
[EMAIL PROTECTED]

#

## Search for some popular places where libraries may be hidden.

#

if test x$"pike_cv_sys_os" != xWindows_NT ; then

echo Searching for include-file directories...

#Don't add include dirs if they give us warnings...
OLD_ac_c_preproc_warn_flag="$ac_c_preproc_warn_flag"
ac_c_preproc_warn_flag=yes

if test $cppflags_is_set = no -a x${C_INCLUDE_PATH-} = x ; then
  real_include_dirs=''
  for d in `echo ${with_include_path} | sed 's/:/ /g'` \
`echo "${with_site_prefixes}/include"|sed -e 's/:/\/include /g'` \
`echo $prefix | sed "s@^NONE@$with_root$ac_default_prefix@g"`/include \
$with_root/usr/local/include $with_root/sw/local/include \
$with_root/usr/gnu/include $with_root/opt/gnu/include \
$with_root/sw/gnu/include $with_root/sw/include \
$with_root/usr/freeware/include $with_root/usr/pkg/include \
$with_root/opt/sfw/include \
`echo $with_root/opt/gnome*/include | sort -r` \
`echo $with_root/usr/X11*/include | sort -r`
  do
AC_MSG_CHECKING($d)
case x$d in
  x/usr/include | x/usr//include)
  ;;
  *)
if test -d "$d/." ; then
  REALDIR="`cd $d/. ; /bin/pwd`"
  if test "x$REALDIR" = x ; then
REALDIR=UNKNOWN
  else
:
  fi

  case " $CPPFLAGS $real_include_dirs " in
*\ -I$d\ * | *\ -I$REALDIR\ *)
   AC_MSG_RESULT(already added)
;;
*)
  OLD_CPPFLAGS="${CPPFLAGS}"
  CPPFLAGS="${CPPFLAGS} -I$d"
  AC_TRY_CPP([#include ], [
AC_MSG_RESULT(added)
if test "x$REALDIR" != xUNKNOWN; then
  real_include_dirs="${real_include_dirs} -I$REALDIR"
else
  :
fi
  ], [
AC_MSG_RESULT(fails)
CPPFLAGS="${OLD_CPPFLAGS}"
  ])
;;
  esac
else
  AC_MSG_RESULT(no)
fi
  ;;
esac
  done
else
  :
fi

#Restore preprocessor warning sensitivity
ac_c_preproc_warn_flag="$OLD_ac_c_preproc_warn_flag"

#CPPFLAGS="${CPPFLAGS} -I$srcdir -I`pwd`"

echo Searching for library directories...
if test $ldflags_is_set = no ; then
  for dd in `echo ${with_lib_path} | sed 's/:/ /g'` \
`echo "${with_site_prefixes}/lib"|sed -e 's/:/\/lib /g'` \
`echo $exec_prefix | sed "s@^NONE@$prefix/lib@g" | sed 
"s@^NONE@$with_root$ac_default_prefix@g"` \
$with_root/usr/local/lib $with_root/sw/local/lib $with_root/sw/lib \
$with_root/usr/gnu/lib $with_root/opt/gnu/lib $with_root/sw/gnu/lib \
$with_root/usr/freeware/lib $with_root/usr/pkg/lib \
$with_root/opt/sfw/lib $with_root/opt/gnome-1.4/lib \
`echo $with_root/usr/X11*/lib | sort -r`
  do
if test "$dd" = "/lib"; then continue; fi
if test "$dd" = "/usr/lib"; then continue; fi
for suff in '' 32 64 '/64'; do
  d="$dd$suff"
  AC_MSG_CHECKING($d)
  if test -d "$d/." ; then
case " $LDFLAGS " in
  *\ -L$d\ -R$d\ * | *\ -R$d\ -L$d\ *)
AC_MSG_RESULT(already added)
  ;;
  *)
OLD_LDFLAGS="${LDFLAGS}"
LDFLAGS="${LDFLAGS} -R$d -L$d -lm"
AC_TRY_RUN([
#include 
#include 
int main(int argc, char **argv)
{
  double (*foo)(double) = ceil;
  exit(0);
}
],[ LDFLAGS="$OLD_LDFLAGS -R$d -L$d"
AC_MSG_RESULT(yes)
],[ LDFLAGS="$OLD_LDFLAGS"
AC_MSG_RESULT(no)
],[AC_TRY_LINK([
#include 
#include 
   ],[
 double (*foo)(double) = ceil;
 exit(0);
   

checking for headers

2003-01-22 Thread edscott wilson garcia


Hi,

  I'm trying to get a "configure" program to check for dbh.h, but the
following line only checks in /usr/include:

AC_CHECK_HEADERS(dbh.h, ac_cv_dbh_library=yes, ac_cv_dbh_library=no)

The generated configure in Linux searches both /usr/include and
/usr/local/include, but not in FreeBSD. What do I have to add so that it
will search /usr/local/include in FreeBSD?

MTIA,


Edscott Wilson Garcia


To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-questions" in the body of the message