Move make-manuf to the tools directory.
[obnox/wireshark/wip.git] / aclocal-fallback / libsmi.m4
1 # Configure paths for libsmi
2 # Shamelessly stolen from http://autoconf-archive.cryp.to/ax_lib_sqlite3.html
3
4 # Synopsis: AX_LIBSMI([minimum library version])
5 # The default minimum library version is 2
6
7 # This macro sets/substitutes the following:
8 # AC_DEFINE(HAVE_LIBSMI)
9 # AC_SUBST(LIBSMI_CFLAGS)
10 # AC_SUBST(LIBSMI_LDFLAGS)
11 # AC_SUBST(LIBSMI_VERSION)
12 # $libsmi_message is set to "yes" or "no"
13
14 AC_DEFUN([AX_LIBSMI],
15 [
16     AC_ARG_WITH([libsmi],
17         AC_HELP_STRING(
18             [--with-libsmi=@<:@DIR@:>@],
19             [use libsmi MIB/PIB library @<:@default=yes@:>@, optionally specify the prefix for libsmi]
20         ),
21         [
22         if test "$withval" = "no"; then
23             WANT_LIBSMI="no"
24         elif test "$withval" = "yes"; then
25             WANT_LIBSMI="yes"
26             ac_libsmi_path=""
27         else
28             WANT_LIBSMI="yes"
29             ac_libsmi_path="$withval"
30         fi
31         ],
32         [WANT_LIBSMI="yes"]
33     )
34
35     libsmi_message="no"
36     LIBSMI_CFLAGS=""
37     LIBSMI_LDFLAGS=""
38     LIBSMI_VERSION=""
39
40     if test "x$WANT_LIBSMI" = "xyes"; then
41
42         ac_libsmi_header="smi.h"
43
44         libsmi_version_req=ifelse([$1], [], [2], [$1])
45
46         AC_MSG_CHECKING([for libsmi >= $libsmi_version_req])
47
48         if test "$ac_libsmi_path" != ""; then
49             ac_libsmi_ldflags="-L$ac_libsmi_path/lib"
50             ac_libsmi_cflags="-I$ac_libsmi_path/include"
51         else
52             for ac_libsmi_path_tmp in /usr /usr/local /opt $prefix; do
53                 if test -f "$ac_libsmi_path_tmp/include/$ac_libsmi_header" \
54                     && test -r "$ac_libsmi_path_tmp/include/$ac_libsmi_header"; then
55                     ac_libsmi_path=$ac_libsmi_path_tmp
56                     ac_libsmi_ldflags="-L$ac_libsmi_path_tmp/lib"
57                     ac_libsmi_cflags="-I$ac_libsmi_path_tmp/include"
58                     break;
59                 fi
60             done
61         fi
62
63         ac_libsmi_ldflags="$ac_libsmi_ldflags -lsmi"
64
65         saved_CFLAGS="$CFLAGS"
66         CFLAGS="$CFLAGS $ac_libsmi_cflags"
67
68         AC_LANG_PUSH(C)
69         AC_COMPILE_IFELSE(
70             [
71             AC_LANG_PROGRAM([[@%:@include <smi.h>]],
72                 [[
73   int current, revision, age, n;
74   const int required = $libsmi_version_req;
75   if (smiInit(""))
76     exit(1);
77   if (strcmp(SMI_LIBRARY_VERSION, smi_library_version))
78     exit(2);
79   n = sscanf(smi_library_version, "%d:%d:%d", &current, &revision, &age);
80   if (n != 3)
81     exit(3);
82   if (required < current - age || required > current)
83     exit(4);
84                 ]]
85             )
86             ],
87             [
88             AC_MSG_RESULT([yes])
89             libsmi_message="yes"
90             ],
91             [
92             AC_MSG_RESULT([not found])
93             libsmi_message="no"
94             ]
95         )
96         AC_LANG_POP([C])
97
98         CFLAGS="$saved_CFLAGS"
99
100         if test "$libsmi_message" = "yes"; then
101
102             LIBSMI_CFLAGS="$ac_libsmi_cflags"
103             LIBSMI_LDFLAGS="$ac_libsmi_ldflags"
104
105             ac_libsmi_header_path="$ac_libsmi_path/include/$ac_libsmi_header"
106
107             dnl Retrieve libsmi release version
108             if test "x$ac_libsmi_header_path" != "x"; then
109                 ac_libsmi_version=`cat $ac_libsmi_header_path \
110                     | grep '#define.*SMI_LIBRARY_VERSION.*\"' | sed -e 's/.* "//' \
111                         | sed -e 's/"//'`
112                 if test $ac_libsmi_version != ""; then
113                     LIBSMI_VERSION=$ac_libsmi_version
114                 else
115                     AC_MSG_WARN([Can not find SMI_LIBRARY_VERSION macro in smi.h header to retrieve libsmi version!])
116                 fi
117             fi
118
119             AC_SUBST(LIBSMI_CFLAGS)
120             AC_SUBST(LIBSMI_LDFLAGS)
121             AC_SUBST(LIBSMI_VERSION)
122             AC_DEFINE(HAVE_LIBSMI, 1, [Define to 1 if you have the `smi' library (-lsmi).])
123         fi
124     fi
125 ])
126
127