1# LIBSSH_CHECK_CONFIG ([DEFAULT-ACTION])
2# ----------------------------------------------------------
3#    Alexander Vladishev                      Oct-26-2009
4#    Dmitry Borovikov                         Feb-13-2010
5#          --version control added (1.0.0)
6#
7# Checks for ssh.  DEFAULT-ACTION is the string yes or no to
8# specify whether to default to --with-ssh or --without-ssh.
9# If not supplied, DEFAULT-ACTION is no.
10#
11# The minimal supported SSH library version is 0.6.0.
12#
13# This macro #defines HAVE_SSH if a required header files are
14# found, and sets @SSH_LDFLAGS@, @SSH_CFLAGS@ and @SSH_LIBS@
15# to the necessary values.
16#
17# Users may override the detected values by doing something like:
18# SSH_LIBS="-lssh" SSH_CFLAGS="-I/usr/myinclude" ./configure
19#
20# This macro is distributed in the hope that it will be useful,
21# but WITHOUT ANY WARRANTY; without even the implied warranty of
22# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
23
24AC_DEFUN([LIBSSH_TRY_LINK],
25[
26AC_TRY_LINK(
27[
28#include <libssh/libssh.h>
29],
30[
31	ssh_session my_ssh_session;
32	my_ssh_session = ssh_new();
33],
34found_ssh="yes",)
35])dnl
36
37AC_DEFUN([LIBSSH_ACCEPT_VERSION],
38[
39	# Zabbix minimal major supported version of libssh:
40	minimal_libssh_major_version=0
41	minimal_libssh_minor_version=6
42
43	# get the major version
44	found_ssh_version_major=`cat $1 | $EGREP \#define.*'LIBSSH_VERSION_MAJOR ' | $AWK '{print @S|@3;}'`
45	found_ssh_version_minor=`cat $1 | $EGREP \#define.*'LIBSSH_VERSION_MINOR ' | $AWK '{print @S|@3;}'`
46
47	if test $((found_ssh_version_major)) -gt $((minimal_libssh_major_version)); then
48		accept_ssh_version="yes"
49	elif test $((found_ssh_version_major)) -lt $((minimal_libssh_major_version)); then
50		accept_ssh_version="no"
51	elif test $((found_ssh_version_minor)) -ge $((minimal_libssh_minor_version)); then
52		accept_ssh_version="yes"
53	else
54		accept_ssh_version="no"
55	fi;
56])dnl
57
58AC_DEFUN([LIBSSH_CHECK_CONFIG],
59[
60  AC_ARG_WITH(ssh,[
61If you want to use SSH based checks:
62AC_HELP_STRING([--with-ssh@<:@=DIR@:>@],[use SSH package @<:@default=no@:>@, DIR is the SSH library install directory.])],
63    [
64	if test "$withval" = "no"; then
65	    want_ssh="no"
66	    _libssh_dir="no"
67	elif test "$withval" = "yes"; then
68	    want_ssh="yes"
69	    _libssh_dir="no"
70	else
71	    want_ssh="yes"
72	    _libssh_dir=$withval
73	fi
74	accept_ssh_version="no"
75    ],[want_ssh=ifelse([$1],,[no],[$1])]
76  )
77
78  if test "x$want_ssh" = "xyes"; then
79     AC_MSG_CHECKING(for SSH support)
80     if test "x$_libssh_dir" = "xno"; then
81       if test -f /usr/include/libssh/libssh.h; then
82         SSH_CFLAGS=-I/usr/include
83         SSH_LDFLAGS=-L/usr/lib
84         SSH_LIBS="-lssh"
85         found_ssh="yes"
86	 LIBSSH_ACCEPT_VERSION([/usr/include/libssh/libssh.h])
87       elif test -f /usr/local/include/libssh/libssh.h; then
88         SSH_CFLAGS=-I/usr/local/include
89         SSH_LDFLAGS=-L/usr/local/lib
90         SSH_LIBS="-lssh"
91         found_ssh="yes"
92	 LIBSSH_ACCEPT_VERSION([/usr/local/include/libssh/libssh.h])
93       else #libraries are not found in default directories
94         found_ssh="no"
95         AC_MSG_RESULT(no)
96       fi # test -f /usr/include/libssh/libssh.h; then
97     else # test "x$_libssh_dir" = "xno"; then
98       if test -f $_libssh_dir/include/libssh/libssh.h; then
99	 SSH_CFLAGS=-I$_libssh_dir/include
100         SSH_LDFLAGS=-L$_libssh_dir/lib
101         SSH_LIBS="-lssh"
102         found_ssh="yes"
103	 LIBSSH_ACCEPT_VERSION([$_libssh_dir/include/libssh/libssh.h])
104       else #if test -f $_libssh_dir/include/libssh/libssh.h; then
105         found_ssh="no"
106         AC_MSG_RESULT(no)
107       fi #test -f $_libssh_dir/include/libssh/libssh.h; then
108     fi #if test "x$_libssh_dir" = "xno"; then
109  fi # if test "x$want_ssh" != "xno"; then
110
111  if test "x$found_ssh" = "xyes"; then
112    am_save_cflags="$CFLAGS"
113    am_save_ldflags="$LDFLAGS"
114    am_save_libs="$LIBS"
115
116    CFLAGS="$CFLAGS $SSH_CFLAGS"
117    LDFLAGS="$LDFLAGS $SSH_LDFLAGS"
118    LIBS="$LIBS $SSH_LIBS"
119
120    found_ssh="no"
121    LIBSSH_TRY_LINK([no])
122
123    CFLAGS="$am_save_cflags"
124    LDFLAGS="$am_save_ldflags"
125    LIBS="$am_save_libs"
126
127    if test "x$found_ssh" = "xyes"; then
128      AC_DEFINE([HAVE_SSH], 1, [Define to 1 if you have the 'libssh' library (-lssh)])
129      AC_MSG_RESULT(yes)
130    else
131      AC_MSG_RESULT(no)
132      SSH_CFLAGS=""
133      SSH_LDFLAGS=""
134      SSH_LIBS=""
135    fi
136  fi
137
138  AC_SUBST(SSH_CFLAGS)
139  AC_SUBST(SSH_LDFLAGS)
140  AC_SUBST(SSH_LIBS)
141
142])dnl
143