You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@apr.apache.org by gs...@apache.org on 2001/12/11 00:53:47 UTC

cvs commit: apr/build find_apr.m4

gstein      01/12/10 15:53:47

  Added:       build    find_apr.m4
  Log:
  Checkpointing a script that apps can use to find an installed or
  bundled copy of APR. If an app uses this from their ./configure, then
  they will have a consistent mechanism for locating APR.
  
  Note: this is incomplete work. Checkpointing into CVS. Justin is going
  to help out.
  
  Note #2: apr-util will also want a very similar script. TBD.
  
  Revision  Changes    Path
  1.1                  apr/build/find_apr.m4
  
  Index: find_apr.m4
  ===================================================================
  dnl
  dnl find_apr.m4 : locate the APR include files and libraries
  dnl
  dnl This macro file can be used by applications to find and use the APR
  dnl library. It provides a standardized mechanism for using APR. It supports
  dnl embedding APR into the application source, or locating an installed
  dnl copy of APR.
  dnl
  dnl APR_FIND_APR([srcdir])
  dnl
  dnl   where srcdir is the location of the bundled APR source directory, or
  dnl   empty if source is not bundled.
  dnl
  dnl
  dnl Sets the following variables on exit:
  dnl
  dnl   apr_libdir : A custom directory to use for linking (the -L switch).
  dnl                If APR exists in a standard location, this variable
  dnl                will be empty
  dnl
  dnl   apr_la_file : If a libtool .la file exists, this will refer to it. If
  dnl                 there is no .la file, then this variable will be empty.
  dnl
  dnl   apr_includes : Where the APR includes are located, if a non-standard
  dnl                  location. This variable has the format "-Idir -Idir".
  dnl                  It may specify more than one directory.
  dnl
  dnl   apr_srcdir : If an APR source tree is available and needs to be
  dnl                (re)configured, this refers to it.
  dnl
  dnl   apr_config : If the APR config file (APRVARS) exists, this refers to it.
  dnl
  dnl   apr_found : "yes", "no", "reconfig"
  dnl
  dnl Note: At this time, we cannot find *both* a source dir and a build dir.
  dnl       If both are available, the build directory should be passed to
  dnl       the --with-apr switch (apr_srcdir will be empty).
  dnl
  dnl Note: the installation layout is presumed to follow the standard
  dnl       PREFIX/lib and PREFIX/include pattern. If the APR config file
  dnl       is available (and can be found), then non-standard layouts are
  dnl       possible, since it will be described in the config file.
  dnl
  dnl If apr_found is "yes" or "reconfig", then the caller should link using
  dnl apr_la_file, if available; otherwise, -lapr should be used (and if
  dnl apr_libdir is not null, then -L$apr_libdir). If apr_includes is not null,
  dnl then it should be used during compilation.
  dnl
  dnl If a source directory is available and needs to be (re)configured, then
  dnl apr_srcdir specifies the directory and apr_found is "reconfig".
  dnl
  
  AC_DEFUN(APR_FIND_APR, [
    apr_found="no"
  
    preserve_LIBS="$LIBS"
    preserve_LDFLAGS="$LDFLAGS"
  
    AC_MSG_CHECKING(for APR)
    AC_ARG_WITH(apr,
    [  --with-apr=DIR          prefix for installed APR, or path to APR build tree],
    [
      if test "$withval" = "no" || test "$withval" = "yes"; then
        AC_MSG_ERROR([--with-apr requires a directory to be provided])
      fi
  
      LIBS="$LIBS -lapr"
      LDFLAGS="$preserve_LDFLAGS -L$withval/lib"
      AC_TRY_LINK_FUNC(apr_initialize, [
        if test -f "$withval/include/apr.h"; then
          dnl found an installed version of APR
          apr_found="yes"
          apr_libdir="$withval/lib"
          apr_includes="-I$withval/include"
        fi
      ], [
        dnl look for a build tree (note: already configured/built)
        if test -f "$withval/libapr.la"; then
          apr_found="yes"
          apr_libdir=""
          apr_la_file="$withval/libapr.la"
          apr_config="$withval/APRVARS"
          apr_includes="-I$withval/include"
          if test ! -f "$withval/APRVARS.in"; then
            dnl extract the APR source directory without polluting our
            dnl shell variable space
            apr_srcdir="`sed -n '/APR_SOURCE_DIR/s/.*"\(.*\)"/\1/p' $apr_config`"
            apr_includes="$apr_includes -I$apr_srcdir/include"
          fi
        fi
      ])
  
      dnl if --with-apr is used, then the target prefix/directory must be valid
      if test "$apr_found" != "yes"; then
        AC_MSG_ERROR([
  The directory given to --with-apr does not specify a prefix for an installed
  APR, nor an APR build directory.])
      fi
    ],[
      dnl always look in the builtin/default places
      LIBS="$LIBS -lapr"
      AC_TRY_LINK_FUNC(apr_initialize, [apr_libdir=""], [
        dnl look in the some standard places (apparently not in builtin/default)
        for lookdir in /usr /usr/local ; do
          LDFLAGS="$preserve_LDFLAGS -L$lookdir/lib"
          AC_TRY_LINK_FUNC(apr_initialize, [
            apr_libdir="$lookdir" ; break
          ])
        done
      ])
    ])
  
    if test "$apr_found" != "no" && test "$apr_libdir" != ""; then
      if test "$apr_config" = "" && test -f "$apr_libdir/APRVARS"; then
        apr_config="$apr_libdir/APRVARS"
      fi
      if test "$apr_la_file" = "" && test -f "$apr_libdir/libapr.la"; then
        apr_la_file="$apr_libdir/libapr.la"
      fi
    fi
  
    LIBS="$preserve_LIBS"
    LDFLAGS="$preserve_LDFLAGS"
  ])