summaryrefslogtreecommitdiff
path: root/config/ac-macros/ssl.m4
blob: fc55f93d8d678f78192e868f14ca2dde4072c3ef (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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
dnl ===========================================================================
dnl Support for SSL
dnl ===========================================================================
dnl
dnl

dnl ---------------------------------------------------------------------------
dnl Macro: MYSQL_USE_BUNDLED_YASSL
dnl
dnl SYNOPSIS
dnl   MYSQL_USE_BUNDLED_YASSL()
dnl
dnl DESCRIPTION
dnl  Add defines so yassl is built and linked with
dnl ---------------------------------------------------------------------------
AC_DEFUN([MYSQL_USE_BUNDLED_YASSL], [

  with_bundled_yassl="yes"

  yassl_dir="yassl"
  AC_SUBST([yassl_dir])

  yassl_libs="\$(top_builddir)/extra/yassl/src/libyassl.la \
              \$(top_builddir)/extra/yassl/taocrypt/src/libtaocrypt.la"
  AC_SUBST(yassl_libs)

  AC_DEFINE([HAVE_OPENSSL], [1], [Defined by configure. Using yaSSL for SSL.])
  AC_DEFINE([HAVE_YASSL], [1], [Defined by configure. Using yaSSL for SSL.])

  # System specific checks
  yassl_integer_extra_cxxflags=""
  case $host_cpu--$CXX_VERSION in
      sparc*--*Sun*C++*5.6*)
	# Disable inlining when compiling taocrypt/src/
	yassl_taocrypt_extra_cxxflags="+d"
        AC_MSG_NOTICE([disabling inlining for yassl/taocrypt/src/])
        ;;
  esac
  AC_SUBST([yassl_taocrypt_extra_cxxflags])

  # Thread safe check
  yassl_thread_cxxflags=""
  yassl_thread_safe=""
  if test "$with_server" != "no" -o "$THREAD_SAFE_CLIENT" != "no"; then
    yassl_thread_cxxflags="-DYASSL_THREAD_SAFE"
    yassl_thread_safe="(thread-safe)"
  fi
  AC_SUBST([yassl_thread_cxxflags])

  # Link extra/yassl/include/openssl subdir to include/
  yassl_h_ln_cmd="\$(LN) -s \$(top_srcdir)/extra/yassl/include/openssl openssl"
  AC_SUBST(yassl_h_ln_cmd)

  AC_MSG_RESULT([using bundled yaSSL $yassl_thread_safe])
])


dnl ---------------------------------------------------------------------------
dnl Macro: MYSQL_CHECK_SSL_DIR
dnl
dnl SYNOPSIS
dnl   MYSQL_CHECK_SSL_DIR(includes, libs)
dnl
dnl DESCRIPTION
dnl  Auxiliary macro to check for ssl at given path
dnl
dnl ---------------------------------------------------------------------------

AC_DEFUN([MYSQL_CHECK_SSL_DIR], [
ssl_incs="$1"
ssl_libs="$2"
save_CPPFLAGS="$CPPFLAGS"
save_LIBS="$LIBS"
CPPFLAGS="$ssl_incs $CPPFLAGS"
LIBS="$LIBS $ssl_libs"
AC_TRY_LINK([#include <openssl/ssl.h>],
    [return SSL_library_init();],
    [mysql_ssl_found="yes"],
    [mysql_ssl_found="no"])
CPPFLAGS="$save_CPPFLAGS"
LIBS="$save_LIBS"
])


dnl ---------------------------------------------------------------------------
dnl Macro: MYSQL_FIND_OPENSSL
dnl
dnl SYNOPSIS
dnl   MYSQL_FIND_OPENSSL(location)
dnl
dnl DESCRIPTION
dnl  Search the location for OpenSSL support
dnl
dnl ---------------------------------------------------------------------------
AC_DEFUN([MYSQL_FIND_OPENSSL], [
  location="$1"

  #
  # Set include paths
  #
  openssl_include="$location/include"
  openssl_includes=""

  # Don't set ssl_includes to /usr/include as this gives us a lot of
  # compiler warnings when using gcc 3.x
  if test "$openssl_include" != "/usr/include"
  then
    openssl_includes="-I$openssl_include"
  fi

  #
  # Try to link with openSSL libs in <location>
  #
  openssl_libs="-L$location/lib/ -lssl -lcrypto"
  MYSQL_CHECK_SSL_DIR([$openssl_includes], [$openssl_libs])

  if test "$mysql_ssl_found" == "no"
  then
    #
    # BUG 764: Compile failure with OpenSSL on Red Hat Linux (krb5.h missing)
    # Try to link with include paths to kerberos set
    #
    openssl_includes="$openssl_includes -I/usr/kerberos/include"
    MYSQL_CHECK_SSL_DIR([$openssl_includes], [$openssl_libs])
  fi

  if test "$mysql_ssl_found" == "no"
  then
    AC_MSG_ERROR([Could not link with SSL libs at $location])
  fi

  # openssl-devel-0.9.6 requires dlopen() and we can't link staticly
  # on many platforms (We should actually test this here, but it's quite
  # hard to do as we are doing libtool for linking.)
  case "$CLIENT_EXTRA_LDFLAGS $MYSQLD_EXTRA_LDFLAGS" in
    *-all-static*)
    AC_MSG_ERROR([You can't use the --all-static link option when using openssl.])
    ;;
  esac

  AC_SUBST(openssl_includes)
  AC_SUBST(openssl_libs)

  NON_THREADED_CLIENT_LIBS="$NON_THREADED_CLIENT_LIBS $openssl_libs"

  AC_DEFINE([HAVE_OPENSSL], [1], [OpenSSL])
  AC_MSG_RESULT([using openSSL from $location])
])



dnl ------------------------------------------------------------------------
dnl Macro: MYSQL_CHECK_SSL
dnl
dnl SYNOPSIS
dnl   MYSQL_CHECK_SSL
dnl
dnl Provides the following configure options:
dnl --with-ssl=DIR
dnl Possible DIR values are:
dnl - no - the macro will disable use of ssl
dnl - bundled, empty or not specified - means use ssl lib
dnl   bundled along with MySQL sources
dnl - ssl location prefix - given location prefix, the macro expects
dnl   to find the header files in $prefix/include/, and libraries in
dnl   $prefix/lib. If headers or libraries weren't found at $prefix, the
dnl   macro bails out with error.
dnl
dnl ------------------------------------------------------------------------
AC_DEFUN([MYSQL_CHECK_SSL], [

  AC_CONFIG_FILES(extra/yassl/Makefile dnl
    extra/yassl/taocrypt/Makefile dnl
    extra/yassl/taocrypt/benchmark/Makefile dnl
    extra/yassl/taocrypt/src/Makefile dnl
    extra/yassl/taocrypt/test/Makefile dnl
    extra/yassl/src/Makefile dnl
    extra/yassl/testsuite/Makefile)

AC_MSG_CHECKING(for SSL)
  AC_ARG_WITH([ssl],
              [  --with-ssl[=DIR]    Include SSL support],
              [mysql_ssl_dir="$withval"],
              [mysql_ssl_dir=no])

  if test "$with_yassl"
  then
    AC_MSG_ERROR([The flag --with-yassl is deprecated, use --with-ssl])
  fi

  if test "$with_openssl"
  then
    AC_MSG_ERROR([The flag --with-openssl is deprecated, use --with-ssl])
  fi

  case "$mysql_ssl_dir" in
    "no")
      #
      # Don't include SSL support
      #
      AC_MSG_RESULT([disabled])
      ;;

    "bundled"|"yes")
      #
      # Use the bundled SSL implementation (yaSSL)
      #
      MYSQL_USE_BUNDLED_YASSL
      ;;

     *)
      #
      # A location where to search for OpenSSL was specified
      #
      MYSQL_FIND_OPENSSL([$mysql_ssl_dir])
      ;;
  esac
  AM_CONDITIONAL([HAVE_YASSL], [ test "$with_bundled_yassl" = "yes" ])
])