forked from google/hiba
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfigure.ac
324 lines (289 loc) · 8.72 KB
/
configure.ac
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
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
# Copyright (c) 2020 The HIBA Authors All rights reserved.
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.
m4_define([MAJOR], 1)
m4_define([MINOR], 2)
AC_PREREQ([2.69])
AC_INIT([HIBA], [MAJOR.MINOR], [[email protected]])
AC_CONFIG_SRCDIR([hiba.h])
AC_CONFIG_HEADERS([config.h])
AC_CONFIG_MACRO_DIRS([m4])
AC_LANG([C])
AC_PROG_CC([cc gcc clang])
LT_INIT
AM_INIT_AUTOMAKE([foreign no-dependencies])
AM_SILENT_RULES([yes])
# Values for SONAME. See -version-info for details.
AC_SUBST(SONAME_CURRENT, 0)
AC_SUBST(SONAME_REVISION, 0)
AC_SUBST(SONAME_AGE, 0)
save_CFLAGS="$CFLAGS"
save_CPPFLAGS="$CPPFLAGS"
save_LDFLAGS="$LDFLAGS"
save_LIBS="$LIBS"
# Check for required CFLAGS & CPPFLAGS availability
for f in -fstack-protector-strong -fstack-protector-all -fstack-protector; do
AC_MSG_CHECKING(whether $CC supports $f options)
CFLAGS="$CFLAGS $extra_CFLAGS $f -Werror"
LDFLAGS="$LDFLAGS $extra_LDFLAGS $f"
AC_LINK_IFELSE(
[AC_LANG_PROGRAM()], [
extra_LDFLAGS="$extra_LDFLAGS $f"
extra_CFLAGS="$extra_CFLAGS $f"
AC_MSG_RESULT([yes])
break
], [AC_MSG_RESULT([no])],
)
# Restore CFLAGS & LDFLAGS in the loop as options are exclusive.
LDFLAGS="$save_LDFLAGS"
CFLAGS="$save_CFLAGS"
done
for f in -fpie -fPIE -fpic -fPIC; do
AC_MSG_CHECKING(whether compiler supports $f)
CFLAGS="$CFLAGS $extra_CFLAGS $f -Werror"
AC_COMPILE_IFELSE(
[AC_LANG_PROGRAM()], [
extra_CFLAGS="$extra_CFLAGS $f"
AC_MSG_RESULT([yes])
break
], [AC_MSG_RESULT([no])],
)
# Restore CFLAGS in the loop as options are exclusive.
CFLAGS="$save_CFLAGS"
done
for f in -ansi -Wall -Wextra -Werror -Wno-attributes -Wno-unused-parameter -Wformat-security -Wuninitialized; do
AC_MSG_CHECKING(whether $CC supports $f options)
CFLAGS="$CFLAGS $extra_CFLAGS $f"
AC_COMPILE_IFELSE(
[AC_LANG_PROGRAM()], [
extra_CFLAGS="$extra_CFLAGS $f"
AC_MSG_RESULT([yes])
], [AC_MSG_RESULT([no])],
)
done
CFLAGS="$save_CFLAGS"
AC_MSG_CHECKING(whether preprocessor supports _DEFAULT_SOURCE)
CPPFLAGS="$CPPFLAGS $extra_CPPFLAGS -D_DEFAULT_SOURCE"
AC_COMPILE_IFELSE(
[AC_LANG_PROGRAM()], [
extra_CPPFLAGS="$extra_CPPFLAGS -D_DEFAULT_SOURCE"
AC_MSG_RESULT([yes])
], [AC_MSG_ERROR([no])],
)
CPPFLAGS="$save_CPPFLAGS"
AC_MSG_CHECKING(whether preprocessor supports _FORTIFY_SOURCE)
CPPFLAGS="$CPPFLAGS $extra_CPPFLAGS -D_FORTIFY_SOURCE=2"
AC_COMPILE_IFELSE(
[AC_LANG_PROGRAM()], [
extra_CPPFLAGS="$extra_CPPFLAGS -D_FORTIFY_SOURCE=2"
AC_MSG_RESULT([yes])
], [AC_MSG_RESULT([no])],
)
CPPFLAGS="$save_CPPFLAGS"
AC_MSG_CHECKING(whether compiler supports no-strict-aliasing option)
CFLAGS="$CFLAGS $extra_CFLAGS -fno-strict-aliasing -Werror"
AC_COMPILE_IFELSE(
[AC_LANG_PROGRAM()], [
extra_CFLAGS="$extra_CFLAGS -fno-strict-aliasing"
AC_MSG_RESULT([yes])
], [AC_MSG_RESULT([no])],
)
CFLAGS="$save_CFLAGS"
AC_MSG_CHECKING(whether compiler supports hardening options)
CPPFLAGS="$CPPFLAGS $extra_CPPFLAGS -Wa,--noexecstack -Werror"
AC_COMPILE_IFELSE(
[AC_LANG_PROGRAM()], [
extra_CPPFLAGS="$extra_CPPFLAGS -Wa,--noexecstack"
AC_MSG_RESULT([yes])
], [AC_MSG_RESULT([no])],
)
CPPFLAGS="$save_CPPFLAGS"
# Check for required LDFLAGS availability
AC_MSG_CHECKING(whether linker supports hardening options)
LDFLAGS="$LDFLAGS $extra_LDFLAGS -Wl,-z,relro,-z,now"
AC_LINK_IFELSE(
[AC_LANG_PROGRAM()], [
extra_LDFLAGS="$extra_LDFLAGS -Wl,-z,relro,-z,now"
AC_MSG_RESULT([yes])
], [AC_MSG_RESULT([no])],
)
LDFLAGS="$save_LDFLAGS"
# Check for definition of max hostname length
AC_CHECK_DECL(
[HOST_NAME_MAX], [], [AC_DEFINE([HOST_NAME_MAX], [64], [
Maximum supported hostname size if not already defined by OS.
])], [#include <limits.h>],
)
# Update flags.
CFLAGS="$CFLAGS $extra_CFLAGS"
CPPFLAGS="$CPPFLAGS $extra_CPPFLAGS"
LDFLAGS="$LDFLAGS $extra_LDFLAGS"
case "$host" in
*-*-cygwin*)
# We can't generate dynamic libraries on cygwin since openssh only builds a static libssh.
AS_VAR_IF([enable_shared], [yes], [
AC_DISABLE_SHARED AC_MSG_WARN([Only static libraries can be buit using cygwin])
], [],
)
;;
esac
# Checks for OpenSSH sources
AC_ARG_WITH(
[opensshdir], [AS_HELP_STRING(
[--with-opensshdir=DIR], [OpenSSH source directory],
)], [opensshdir=$withval], [AC_MSG_ERROR([
unable to find the OpenSSH sources. Set --with-opensshdir=<path to OpenSSH sources>
])],
)
# Update flags with OpenSSH location
CFLAGS="$CFLAGS -I$opensshdir"
LDFLAGS="$LDFLAGS -L$opensshdir -L$opensshdir/openbsd-compat"
# Check for OpenSSH use of OpenSSL
AC_MSG_CHECKING(whether OpenSSH is configured with OpenSSL)
AC_COMPILE_IFELSE(
[AC_LANG_PROGRAM([
#include "$opensshdir/config.h"
], [
#ifdef WITH_OPENSSL
#if WITH_OPENSSL != 0
#error 1
#endif
#endif
])], [
need_openssl=false
AC_MSG_RESULT([no])
], [
need_openssl=true
AC_MSG_RESULT([yes])
],
)
AM_CONDITIONAL([NEED_OPENSSL], [test "x$need_openssl" = xtrue])
# Checks for optional OpenSSL sources
AC_ARG_WITH(
[openssldir], [AS_HELP_STRING(
[--with-openssldir=DIR], [OpenSSL source directory],
)], [openssldir=$withval], [],
)
AM_CONDITIONAL([OPENSSLDIR], [test "x$openssldir" != x])
# Maybe checks for OpenSSL library.
# First in openssldir if provided, then in sysroot.
AM_COND_IF(
[NEED_OPENSSL], [
# Check whether user specified a custom location:
AC_MSG_CHECKING(whether custom OpenSSL folder is set)
AM_COND_IF(
[OPENSSLDIR], [
CFLAGS="$CFLAGS -I$openssldir/include"
LDFLAGS="$LDFLAGS -L$openssldir"
AC_MSG_RESULT(yes)
], [
AC_MSG_RESULT(no)
],
)
# In case of static libcrypto, we need explicit linking.
AC_MSG_CHECKING(whether OpenSSL requires explicit linking)
for l in '' '-ldl' '-lpthread' '-ldl -lpthread'; do
LIBS="-lcrypto $l"
AC_LINK_IFELSE(
[AC_LANG_CALL([], [RSA_new])], [
libcrypto_LIBS=$l
break
], [],
)
done
LIBS="$save_LIBS"
if test "x$libcrypto_LIBS" = x; then
AC_MSG_RESULT(no)
else
AC_MSG_RESULT($libcrypto_LIBS)
fi
# Add the OpenSSL library.
AC_SEARCH_LIBS(
[RSA_new], [crypto], [], [
AC_MSG_ERROR([unable to find a working OpenSSL library])
], [$libcrypto_LIBS])
LIBS="$LIBS $libcrypto_LIBS"
], [],
)
# Checks for Zlib library
AC_ARG_ENABLE(
[extension-compression], [AS_HELP_STRING(
[--enable-extension-compression], [enable extension compression support],
)], [zlib=$enableval], [zlib=yes])
AM_CONDITIONAL([WANT_ZLIB], [test "x$zlib" = xyes])
AC_ARG_WITH(
[zlibdir], [AS_HELP_STRING(
[--with-zlibdir=DIR], [path to source directory],
)], [zlibdir=$withval], [zlibdir=])
AM_CONDITIONAL([CUSTOM_ZLIB], [test "x$zlibdir" != x])
# If we want Zlib, we need to sources and libraries available
AC_MSG_CHECKING(for compressed extensions support)
AM_COND_IF(
[WANT_ZLIB], [
AC_DEFINE([WITH_EXTENSION_COMPRESSION], [1], [
Define to 1 if you have support for extension compression.
])
AC_MSG_RESULT(yes)
AM_COND_IF(
[CUSTOM_ZLIB], [
LIBS="$LIBS -lz"
CFLAGS="$CFLAGS -I$zlibdir"
LDFLAGS="$LDFLAGS -L$zlibdir"
AC_MSG_CHECKING(for zlib.h)
AC_COMPILE_IFELSE(
[AC_LANG_PROGRAM([#include "zlib.h"], [])], [
AC_MSG_RESULT([yes])
], [
AC_MSG_ERROR([missing from custom directory $zlibdir])])
AC_MSG_CHECKING(for library containing inflate)
AC_LINK_IFELSE(
[AC_LANG_CALL([], [inflate])], [
AC_MSG_RESULT(yes)
], [
AC_MSG_ERROR([no, make sure to compile it in $zlibdir])
])
], [
AC_CHECK_HEADER([zlib.h], , [
AC_MSG_ERROR([Missing zlib.h, please install it to sysroot or use --with-zlibdir=path]),
])
AC_SEARCH_LIBS(
[inflate], [z], [], [
AC_MSG_ERROR([unable to find a working zlib library])
])
],
)
], [
AC_MSG_RESULT(no)
])
# Checks for OpenBSD compat library (part of OpenSSH).
AC_SEARCH_LIBS([ssh_get_progname], [openbsd-compat], [], [
AC_MSG_ERROR([/!\ Make sure to configure and build OpenSSH before HIBA.])],
)
# Checks for OpenSSH compat library.
AC_SEARCH_LIBS([sshbuf_new], [ssh], [], [
AC_MSG_ERROR([/!\ Make sure to configure and build OpenSSH before HIBA.])],
)
AC_SUBST([extra_LIBS], [$LIBS])
LIBS="$save_LIBS"
# Checks for header files.
AC_CHECK_HEADERS([inttypes.h limits.h stdint.h stdlib.h string.h sys/types.h unistd.h])
# Checks for typedefs, structures, and compiler characteristics.
AC_C_INLINE
AC_TYPE_SIZE_T
# Checks for library functions.
AC_CHECK_FUNCS([gethostname memset strdup strerror strspn strtol])
AC_CONFIG_FILES([Makefile])
AC_OUTPUT
# Print configuration summary
echo ""
echo "HIBA has been configure with the following options:"
echo ""
echo " Host: $host"
echo " Compiler: $CC"
echo " Compiler flags: $CFLAGS"
echo "Preprocessor flags: $CPPFLAGS"
echo " Linker: $LD"
echo " Linker flags: $LDFLAGS"
echo " Libraries: $LIBS $extra_LIBS"
echo " Shared library: $enable_shared"
echo " Static library: $enable_static"