Welcome to mirror list, hosted at ThFree Co, Russian Federation.

libssh.m4 « m4 - github.com/zabbix/zabbix.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 657ec208b461c8c70f7686f2841fd97affb94104 (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
133
134
135
136
137
138
139
140
141
142
# LIBSSH_CHECK_CONFIG ([DEFAULT-ACTION])
# ----------------------------------------------------------
#
# Checks for ssh.  DEFAULT-ACTION is the string yes or no to
# specify whether to default to --with-ssh or --without-ssh.
# If not supplied, DEFAULT-ACTION is no.
#
# The minimal supported SSH library version is 0.6.0.
#
# This macro #defines HAVE_SSH if a required header files are
# found, and sets @SSH_LDFLAGS@, @SSH_CFLAGS@ and @SSH_LIBS@
# to the necessary values.
#
# Users may override the detected values by doing something like:
# SSH_LIBS="-lssh" SSH_CFLAGS="-I/usr/myinclude" ./configure
#
# This macro is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

AC_DEFUN([LIBSSH_TRY_LINK],
[
AC_LINK_IFELSE([AC_LANG_PROGRAM([[
#include <libssh/libssh.h>
]], [[
	ssh_session my_ssh_session;
	my_ssh_session = ssh_new();
]])],[found_ssh="yes"],[])
])dnl

AC_DEFUN([LIBSSH_ACCEPT_VERSION],
[
	# Zabbix minimal major supported version of libssh:
	minimal_libssh_major_version=0
	minimal_libssh_minor_version=6

	# get the major version
	found_ssh_version_major=`cat $1 | $EGREP \#define.*'LIBSSH_VERSION_MAJOR ' | $AWK '{print @S|@3;}'`
	found_ssh_version_minor=`cat $1 | $EGREP \#define.*'LIBSSH_VERSION_MINOR ' | $AWK '{print @S|@3;}'`

	if test $((found_ssh_version_major)) -gt $((minimal_libssh_major_version)); then
		accept_ssh_version="yes"
	elif test $((found_ssh_version_major)) -lt $((minimal_libssh_major_version)); then
		accept_ssh_version="no"
	elif test $((found_ssh_version_minor)) -ge $((minimal_libssh_minor_version)); then
		accept_ssh_version="yes"
	else
		accept_ssh_version="no"
	fi;
])dnl

AC_DEFUN([LIBSSH_CHECK_CONFIG],
[
  AC_ARG_WITH(ssh,[
If you want to use SSH based checks:
AS_HELP_STRING([--with-ssh@<:@=DIR@:>@],[use SSH package @<:@default=no@:>@, DIR is the SSH library install directory.])],
    [
	if test "$withval" = "no"; then
	    want_ssh="no"
	    _libssh_dir="no"
	elif test "$withval" = "yes"; then
	    want_ssh="yes"
	    _libssh_dir="no"
	else
	    want_ssh="yes"
	    _libssh_dir=$withval
	fi
	accept_ssh_version="no"
    ],[want_ssh=ifelse([$1],,[no],[$1])]
  )

  if test "x$want_ssh" = "xyes"; then
     AC_MSG_CHECKING(for SSH support)
     if test "x$_libssh_dir" = "xno"; then
       if test -f /usr/include/libssh/libssh_version.h; then
         SSH_CFLAGS=-I/usr/include
         SSH_LDFLAGS=-L/usr/lib
         SSH_LIBS="-lssh"
         found_ssh="yes"
	 LIBSSH_ACCEPT_VERSION([/usr/include/libssh/libssh_version.h])
       elif test -f /usr/include/libssh/libssh.h; then
         SSH_CFLAGS=-I/usr/include
         SSH_LDFLAGS=-L/usr/lib
         SSH_LIBS="-lssh"
         found_ssh="yes"
	 LIBSSH_ACCEPT_VERSION([/usr/include/libssh/libssh.h])
       elif test -f /usr/local/include/libssh/libssh.h; then
         SSH_CFLAGS=-I/usr/local/include
         SSH_LDFLAGS=-L/usr/local/lib
         SSH_LIBS="-lssh"
         found_ssh="yes"
	 LIBSSH_ACCEPT_VERSION([/usr/local/include/libssh/libssh.h])
       else #libraries are not found in default directories
         found_ssh="no"
         AC_MSG_RESULT(no)
       fi # test -f /usr/include/libssh/libssh.h; then
     else # test "x$_libssh_dir" = "xno"; then
       if test -f $_libssh_dir/include/libssh/libssh.h; then
	 SSH_CFLAGS=-I$_libssh_dir/include
         SSH_LDFLAGS=-L$_libssh_dir/lib
         SSH_LIBS="-lssh"
         found_ssh="yes"
	 LIBSSH_ACCEPT_VERSION([$_libssh_dir/include/libssh/libssh.h])
       else #if test -f $_libssh_dir/include/libssh/libssh.h; then
         found_ssh="no"
         AC_MSG_RESULT(no)
       fi #test -f $_libssh_dir/include/libssh/libssh.h; then
     fi #if test "x$_libssh_dir" = "xno"; then
  fi # if test "x$want_ssh" != "xno"; then

  if test "x$found_ssh" = "xyes"; then
    am_save_cflags="$CFLAGS"
    am_save_ldflags="$LDFLAGS"
    am_save_libs="$LIBS"

    CFLAGS="$CFLAGS $SSH_CFLAGS"
    LDFLAGS="$LDFLAGS $SSH_LDFLAGS"
    LIBS="$LIBS $SSH_LIBS"

    found_ssh="no"
    LIBSSH_TRY_LINK([no])

    CFLAGS="$am_save_cflags"
    LDFLAGS="$am_save_ldflags"
    LIBS="$am_save_libs"

    if test "x$found_ssh" = "xyes"; then
      AC_DEFINE([HAVE_SSH], 1, [Define to 1 if you have the 'libssh' library (-lssh)])
      AC_MSG_RESULT(yes)
    else
      AC_MSG_RESULT(no)
      SSH_CFLAGS=""
      SSH_LDFLAGS=""
      SSH_LIBS=""
    fi
  fi

  AC_SUBST(SSH_CFLAGS)
  AC_SUBST(SSH_LDFLAGS)
  AC_SUBST(SSH_LIBS)

])dnl