Debian Codegraph @

ext/tls/tls.ac

raw
1 dnl
2 dnl Configure ext/tls
3 dnl This file is included by the toplevel configure.ac
4 dnl
5
6 dnl with-tls option
7 dnl
8 dnl --with-tls=TYPE,TYPE,... # include TLS library TYPE, ...
9 dnl --with-tls=no # do not include any TLS library support
10 dnl
11
12 TLSLIBS=mbedtls
13 tls_explicitly_disabled=no
14 AC_ARG_WITH(tls,
15 AS_HELP_STRING([--with-tls=TLSLIB,...],
16 [Select which TLS libraries to be compiled. Currently we support 'mbedtls'
17 (to use MbedLS in the system library), or 'mbedtls-internal' (to use mbed TLS
18 compiled with Gauche).
19 By default, we use the system's mbedtls library if it's avaialble. If not,
20 no TLS support is compiled. You can specify --with-tls=no to exclude
21 TLS support explicitly.]),
22 [
23 AS_CASE([$with_tls],
24 [no|none], [TLSLIBS=""
25 tls_explicitly_disabled=yes],
26 [yes], [], dnl Use the default
27 [TLSLIBS="$with_tls"])
28 ])
29
30 dnl Scan TLSLIB
31
32 use_mbed=no
33 use_mbed_internal=no
34
35 GAUCHE_TLS_SWITCH_MBEDTLS_INTERNAL_yes="@%:@"
36 GAUCHE_TLS_SWITCH_MBEDTLS_INTERNAL_no=
37
38 for tls in `echo $TLSLIBS | tr ',' ' '`
39 do
40 AS_CASE([$tls],
41 [mbedtls],
42 [AS_IF([test $use_mbed_internal = yes], [
43 AC_MSG_ERROR([You can only specify either one of 'mbedtls' or
44 'mbedtls-internal' in --with-tls option])
45 ], [
46 use_mbed=yes
47 ])],
48 [mbedtls-internal],
49 [AS_IF([test $use_mbed = yes], [
50 AC_MSG_ERROR([You can only specify either one of 'mbedtls' or
51 'mbedtls-internal' in --with-tls option])
52 ], [
53 use_mbed=yes
54 use_mbed_internal=yes
55 MBEDTLS_CFLAGS="-I ../../tools/tls/include"
56 MBEDTLS_LDFLAGS="-L ../../tools/tls"
57 GAUCHE_TLS_SWITCH_MBEDTLS_INTERNAL_yes=
58 GAUCHE_TLS_SWITCH_MBEDTLS_INTERNAL_no="@%:@"
59 AS_CASE([$host],
60 [*mingw*], [
61 AS_IF([cmake -G 2>&1 | grep -q 'MSYS Makefiles'], [
62 MBEDTLS_CMAKE_OPTIONS="-G'MSYS Makefiles'"
63 ])
64 ])
65 ])],
66 dnl otherwise:
67 [
68 AC_MSG_ERROR([Invalid ---with-tls choice; it must be either
69 mbedtls or mbedtls-internal.])
70 ])
71 done
72
73 AC_SUBST(GAUCHE_TLS_SWITCH_MBEDTLS_INTERNAL_yes)
74 AC_SUBST(GAUCHE_TLS_SWITCH_MBEDTLS_INTERNAL_no)
75
76 dnl For the backward compatibility
77 AC_ARG_ENABLE(tls,
78 AS_HELP_STRING([--enable-tls=TLSLIB,...],
79 [Obsoleted. Same as --with-tls=TLSLIB,... for the compatibility.]),
80 [
81 AC_MSG_WARN([--enable-tls is obsoleted. Use --with-tls.])
82 AS_CASE([$enableval],
83 [no|none], [TLSLIBS=""],
84 [yes], [], dnl Use the default
85 [TLSLIBS="$enableval"])
86 ])
87
88 dnl Check for tls library availability.
89
90 GAUCHE_TLS_SWITCH_MBEDTLS="@%:@"
91 GAUCHE_TLS_SWITCH_NONE=
92
93 dnl mbedtls
94 AS_IF([test $use_mbed = yes], [
95 AS_IF([test $use_mbed_internal = yes], [
96 dnl We'll extract MbedTLS source tree under tools/tls by 'make'.
97 dnl We don't have the source tree during ./configure, so we can't
98 dnl run tests for it. Since we know the version of MbedTLS we use
99 dnl (see MBEDTLS_VERSION in tools/tls/Makefile.in), we assume
100 dnl those libraries are available.
101 MBEDTLS_LIBS="${MBEDTLS_LDFLAGS} -lmbedtls -lmbedx509 -lmbedcrypto"
102 ], [
103 CFLAGS_SAVE=$CFLAGS
104 CFLAGS="$MBEDTLS_CFLAGS $CFLAGS"
105 AC_CHECK_HEADER([mbedtls/version.h], [], [mbedtls_unavailable=yes])
106 CFLAGS=${CFLAGS_SAVE}
107
108 dnl We don't want to include mbedtls libraries in generic LIBS
109 LDFLAGS_SAVE=${LDFLAGS}
110 LIBS_SAVE=${LIBS}
111 LDFLAGS="${LDFLAGS} ${MBEDTLS_LDFLAGS}"
112 MBEDTLS_LIBS=""
113 AC_SEARCH_LIBS([mbedtls_ctr_drbg_init], [mbedcrypto],
114 [MBEDTLS_LIBS="-lmbedcrypto ${MBEDTLS_LIBS}"],
115 [mbedtls_unavailable=yes])
116 AC_SEARCH_LIBS([mbedtls_x509_crt_init], [mbedx509],
117 [MBEDTLS_LIBS="-lmbedx509 ${MBEDTLS_LIBS}"],
118 [mbedtls_unavailable=yes])
119 AC_SEARCH_LIBS([mbedtls_ssl_init], [mbedtls],
120 [MBEDTLS_LIBS="-lmbedtls ${MBEDTLS_LIBS}"],
121 [mbedtls_unavailable=yes])
122 LDFLAGS=${LDFLAGS_SAVE}
123 LIBS=${LIBS_SAVE}
124 MBEDTLS_LIBS="${MBEDTLS_LDFLAGS} ${MBEDTLS_LIBS}"
125 EXT_LIBS="$EXT_LIBS $MBEDTLS_LIBS"
126 ])
127
128 AS_IF([test "$mbedtls_unavailable" = yes], [
129 AC_MSG_NOTICE([Can't find mbedtls headers and/or libraries.])
130 ],[
131 AC_DEFINE(GAUCHE_USE_MBEDTLS, 1, [Define if you use mbed TLS])
132 AC_SUBST(MBEDTLS_CFLAGS)
133 AC_SUBST(MBEDTLS_LIBS)
134 AC_SUBST(MBEDTLS_CMAKE_OPTIONS)
135 GAUCHE_TLS_TYPES="mbedtls $GAUCHE_TLS_TYPES"
136 GAUCHE_TLS_SWITCH_MBEDTLS=
137 GAUCHE_TLS_SWITCH_NONE="@%:@"
138 ])
139 ])
140
141 AC_SUBST(GAUCHE_TLS_SWITCH_MBEDTLS)
142 AC_SUBST(GAUCHE_TLS_SWITCH_NONE)
143
144 dnl Check system CA store support
145 dnl AC_SEARCH_LIBS doesn't seem to work well in cross-compiling mingw-w64
146 dnl binary on Linux, so we just treat mingw build specially.
147 AS_IF([test -n "$TLSLIBS"], [
148 SYSTEM_CERT_LIBS=""
149 AS_CASE([$host],
150 [*mingw*], [
151 AC_DEFINE(HAVE_WINCRYPT_H, 1, [Define if you have wincrypt.h])
152 SYSTEM_CERT_LIBS="-lcrypt32"
153 ])
154 EXT_LIBS="$EXT_LIBS $SYSTEM_CERT_LIBS"
155 AC_SUBST(SYSTEM_CERT_LIBS)
156 ])
157
158 AC_ARG_WITH([ca-bundle],
159 AS_HELP_STRING([--with-ca-bundle=/path/to/ca-bundle.crt],
160 [Specify the default CA certificate bundle file path for
161 TLS certificate validation. This file is required to use
162 mbed TLS. If set "check", check the availability at runtime.
163 If set "system", use system certificate store.
164 Default is "check".]),
165 [
166 AS_CASE([$with_ca_bundle],
167 [check], [AC_DEFINE([GAUCHE_CA_BUNDLE_CHECK], 1, [Define to check system CA availability at runtime])
168 TLS_CA_TYPE=check
169 TLS_CA_PATH=
170 ],
171 [no], [AC_DEFINE([GAUCHE_CA_BUNDLE_NONE], 1, [Define not to use CA])
172 TLS_CA_TYPE=none
173 TLS_CA_PATH=
174 ],
175 [system], [AC_DEFINE([GAUCHE_CA_BUNDLE_SYSTEM], 1, [Define to use system CA])
176 TLS_CA_TYPE=system
177 TLS_CA_PATH=
178 ],
179 [AC_DEFINE([GAUCHE_CA_BUNDLE_FILE], 1, [Define to use file CA])
180 AC_DEFINE_UNQUOTED([GAUCHE_CA_BUNDLE], ["$with_ca_bundle"], [CA file path])
181 TLS_CA_TYPE=file
182 TLS_CA_PATH=$with_ca_bundle
183 ]
184 )
185 ], [
186 AC_DEFINE([GAUCHE_CA_BUNDLE_CHECK], 1)
187 TLS_CA_TYPE=check
188 TLS_CA_PATH=
189 ])
190
191 dnl Local variables:
192 dnl mode: autoconf
193 dnl end: