summaryrefslogtreecommitdiff
path: root/build/find_apr.m4
blob: cab64635ffed7f2aa6d9fd1690a6bf9395210f6b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
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"
  preserve_CFLAGS="$CFLAGS"

  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

    if test -x $withval/bin/apr-config; then
       CFLAGS="$CFLAGS `$withval/bin/apr-config --cflags`"
       LIBS="$LIBS `$withval/bin/apr-config --libs`"
       LDFLAGS="$LDFLAGS `$withval/bin/apr-config --ldflags`"
    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

  AC_MSG_RESULT($apr_found)
  CFLAGS="$preserve_CFLAGS"
  LIBS="$preserve_LIBS"
  LDFLAGS="$preserve_LDFLAGS"
])