aboutsummaryrefslogtreecommitdiff
path: root/libtls-standalone/configure.ac
diff options
context:
space:
mode:
Diffstat (limited to 'libtls-standalone/configure.ac')
-rw-r--r--libtls-standalone/configure.ac246
1 files changed, 21 insertions, 225 deletions
diff --git a/libtls-standalone/configure.ac b/libtls-standalone/configure.ac
index babb266..d52e22a 100644
--- a/libtls-standalone/configure.ac
+++ b/libtls-standalone/configure.ac
@@ -1,3 +1,17 @@
1# Copyright (c) 2014-2015 Brent Cook
2#
3# Permission to use, copy, modify, and distribute this software for any
4# purpose with or without fee is hereby granted, provided that the above
5# copyright notice and this permission notice appear in all copies.
6#
7# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
8# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
10# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
12# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
13# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
14
1AC_INIT([libtls], m4_esyscmd([tr -d '\n' < VERSION])) 15AC_INIT([libtls], m4_esyscmd([tr -d '\n' < VERSION]))
2 16
3AC_CANONICAL_HOST 17AC_CANONICAL_HOST
@@ -15,238 +29,20 @@ AM_PROG_CC_C_O
15AC_PROG_LIBTOOL 29AC_PROG_LIBTOOL
16LT_INIT 30LT_INIT
17 31
18CFLAGS="$CFLAGS -Wall -std=gnu99" 32CHECK_OS_OPTIONS
19
20case $host_os in
21 *aix*)
22 HOST_OS=aix
23 if test "`echo $CC | cut -d ' ' -f 1`" != "gcc" ; then
24 CFLAGS="$USER_CFLAGS"
25 fi
26 ;;
27 *cygwin*)
28 HOST_OS=cygwin
29 ;;
30 *darwin*)
31 HOST_OS=darwin
32 HOST_ABI=macosx
33 ;;
34 *freebsd*)
35 HOST_OS=freebsd
36 HOST_ABI=elf
37 ;;
38 *hpux*)
39 HOST_OS=hpux;
40 if test "`echo $CC | cut -d ' ' -f 1`" = "gcc" ; then
41 CFLAGS="$CFLAGS -mlp64"
42 else
43 CFLAGS="-g -O2 +DD64 $USER_CFLAGS"
44 fi
45 CPPFLAGS="$CPPFLAGS -D_XOPEN_SOURCE=600 -D__STRICT_ALIGNMENT"
46 AC_SUBST([PLATFORM_LDADD], ['-lpthread'])
47 ;;
48 *linux*)
49 HOST_OS=linux
50 HOST_ABI=elf
51 CPPFLAGS="$CPPFLAGS -D_DEFAULT_SOURCE -D_BSD_SOURCE -D_POSIX_SOURCE -D_GNU_SOURCE"
52 ;;
53 *netbsd*)
54 HOST_OS=netbsd
55 CPPFLAGS="$CPPFLAGS -D_OPENBSD_SOURCE"
56 ;;
57 *openbsd*)
58 HOST_ABI=elf
59 AC_DEFINE([HAVE_ATTRIBUTE__BOUNDED__], [1], [OpenBSD gcc has bounded])
60 ;;
61 *mingw*)
62 HOST_OS=win
63 CPPFLAGS="$CPPFLAGS -D_GNU_SOURCE -D_POSIX -D_POSIX_SOURCE -D__USE_MINGW_ANSI_STDIO"
64 CPPFLAGS="$CPPFLAGS -D_REENTRANT -D_POSIX_THREAD_SAFE_FUNCTIONS"
65 CPPFLAGS="$CPPFLAGS -DWIN32_LEAN_AND_MEAN -D_WIN32_WINNT=0x0600"
66 CPPFLAGS="$CPPFLAGS -DOPENSSL_NO_SPEED -DNO_SYSLOG"
67 CFLAGS="$CFLAGS -static-libgcc"
68 LDFLAGS="$LDFLAGS -static-libgcc"
69 AC_SUBST([PLATFORM_LDADD], ['-lws2_32'])
70 ;;
71 *solaris*)
72 HOST_OS=solaris
73 HOST_ABI=elf
74 CPPFLAGS="$CPPFLAGS -D__EXTENSIONS__ -D_XOPEN_SOURCE=600 -DBSD_COMP"
75 AC_SUBST([PLATFORM_LDADD], ['-lnsl -lsocket'])
76 ;;
77 *) ;;
78esac
79
80AM_CONDITIONAL([HOST_AIX], [test x$HOST_OS = xaix])
81AM_CONDITIONAL([HOST_CYGWIN], [test x$HOST_OS = xcygwin])
82AM_CONDITIONAL([HOST_DARWIN], [test x$HOST_OS = xdarwin])
83AM_CONDITIONAL([HOST_FREEBSD], [test x$HOST_OS = xfreebsd])
84AM_CONDITIONAL([HOST_HPUX], [test x$HOST_OS = xhpux])
85AM_CONDITIONAL([HOST_LINUX], [test x$HOST_OS = xlinux])
86AM_CONDITIONAL([HOST_NETBSD], [test x$HOST_OS = xnetbsd])
87AM_CONDITIONAL([HOST_SOLARIS], [test x$HOST_OS = xsolaris])
88AM_CONDITIONAL([HOST_WIN], [test x$HOST_OS = xwin])
89
90AC_MSG_CHECKING([if compiling with clang])
91AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [[
92#ifndef __clang__
93 not clang
94#endif
95 ]])],
96 [CLANG=yes],
97 [CLANG=no]
98)
99AC_MSG_RESULT([$CLANG])
100AS_IF([test "x$CLANG" = "xyes"], [CLANG_FLAGS=-Qunused-arguments])
101
102CFLAGS="$CFLAGS $CLANG_FLAGS"
103LDFLAGS="$LDFLAGS $CLANG_FLAGS"
104 33
105# We want to check for compiler flag support. Prior to clang v5.1, there was no 34CHECK_C_HARDENING_OPTIONS
106# way to make clang's "argument unused" warning fatal. So we invoke the
107# compiler through a wrapper script that greps for this message.
108saved_CC="$CC"
109saved_LD="$LD"
110flag_wrap="$srcdir/scripts/wrap-compiler-for-flag-check"
111CC="$flag_wrap $CC"
112LD="$flag_wrap $LD"
113
114AC_ARG_ENABLE([hardening],
115 [AS_HELP_STRING([--disable-hardening],
116 [Disable options to frustrate memory corruption exploits])],
117 [], [enable_hardening=yes])
118
119AC_ARG_ENABLE([windows-ssp],
120 [AS_HELP_STRING([--enable-windows-ssp],
121 [Enable building the stack smashing protection on
122 Windows. This currently distributing libssp-0.dll.])])
123
124AC_DEFUN([CHECK_CFLAG], [
125 AC_LANG_ASSERT(C)
126 AC_MSG_CHECKING([if $saved_CC supports "$1"])
127 old_cflags="$CFLAGS"
128 CFLAGS="$1 -Wall -Werror"
129 AC_TRY_LINK([
130 #include <stdio.h>
131 ],
132 [printf("Hello")],
133 AC_MSG_RESULT([yes])
134 CFLAGS=$old_cflags
135 HARDEN_CFLAGS="$HARDEN_CFLAGS $1",
136 AC_MSG_RESULT([no])
137 CFLAGS=$old_cflags
138 [$2])
139])
140
141AC_DEFUN([CHECK_LDFLAG], [
142 AC_LANG_ASSERT(C)
143 AC_MSG_CHECKING([if $saved_LD supports "$1"])
144 old_ldflags="$LDFLAGS"
145 LDFLAGS="$1 -Wall -Werror"
146 AC_TRY_LINK([
147 #include <stdio.h>
148 ],
149 [printf("Hello")],
150 AC_MSG_RESULT([yes])
151 LDFLAGS=$old_ldflags
152 HARDEN_LDFLAGS="$HARDEN_LDFLAGS $1",
153 AC_MSG_RESULT([no])
154 LDFLAGS=$old_ldflags
155 [$2])
156])
157 35
158AS_IF([test "x$enable_hardening" = "xyes"], [ 36DISABLE_COMPILER_WARNINGS
159 # Tell GCC to NOT optimize based on signed arithmetic overflow
160 CHECK_CFLAG([[-fno-strict-overflow]])
161 37
162 # _FORTIFY_SOURCE replaces builtin functions with safer versions. 38CHECK_LIBC_COMPAT
163 CHECK_CFLAG([[-D_FORTIFY_SOURCE=2]]) 39CHECK_LIBC_CRYPTO_COMPAT
164
165 # Enable read only relocations
166 CHECK_LDFLAG([[-Wl,-z,relro]])
167 CHECK_LDFLAG([[-Wl,-z,now]])
168
169 # Windows security flags
170 AS_IF([test "x$HOST_OS" = "xwin"], [
171 CHECK_LDFLAG([[-Wl,--nxcompat]])
172 CHECK_LDFLAG([[-Wl,--dynamicbase]])
173 CHECK_LDFLAG([[-Wl,--high-entropy-va]])
174 ])
175
176 # Use stack-protector-strong if available; if not, fallback to
177 # stack-protector-all which is considered to be overkill
178 AS_IF([test "x$enable_windows_ssp" = "xyes" -o "x$HOST_OS" != "xwin"], [
179 CHECK_CFLAG([[-fstack-protector-strong]],
180 CHECK_CFLAG([[-fstack-protector-all]],
181 AC_MSG_WARN([compiler does not appear to support stack protection])
182 )
183 )
184 AS_IF([test "x$HOST_OS" = "xwin"], [
185 AC_SEARCH_LIBS([__stack_chk_guard],[ssp])
186 ])
187 ])
188])
189
190
191# Restore CC, LD
192CC="$saved_CC"
193LD="$saved_LD"
194
195CFLAGS="$CFLAGS $HARDEN_CFLAGS"
196LDFLAGS="$LDFLAGS $HARDEN_LDFLAGS"
197
198# Removing the dependency on -Wno-pointer-sign should be a goal
199save_cflags="$CFLAGS"
200CFLAGS=-Wno-pointer-sign
201AC_MSG_CHECKING([whether CC supports -Wno-pointer-sign])
202AC_COMPILE_IFELSE([AC_LANG_PROGRAM([])],
203 [AC_MSG_RESULT([yes])]
204 [AM_CFLAGS=-Wno-pointer-sign],
205 [AC_MSG_RESULT([no])]
206)
207CFLAGS="$save_cflags $AM_CFLAGS"
208
209save_cflags="$CFLAGS"
210CFLAGS=
211AC_MSG_CHECKING([whether AS supports .note.GNU-stack])
212AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
213__asm__(".section .note.GNU-stack,\"\",@progbits");]])],
214 [AC_MSG_RESULT([yes])]
215 [AM_CFLAGS=-DHAVE_GNU_STACK],
216 [AC_MSG_RESULT([no])]
217)
218CFLAGS="$save_cflags $AM_CFLAGS"
219AM_PROG_AS
220
221AC_CHECK_FUNCS([explicit_bzero strsep])
222AM_CONDITIONAL([HAVE_EXPLICIT_BZERO], [test "x$ac_cv_func_explicit_bzero" = xyes])
223AM_CONDITIONAL([HAVE_STRSEP], [test "x$ac_cv_func_strsep" = xyes])
224
225#AC_CHECK_FUNCS([arc4random_buf asprintf explicit_bzero funopen getauxval])
226#AC_CHECK_FUNCS([getentropy memmem poll reallocarray])
227#AC_CHECK_FUNCS([strlcat strlcpy strndup strnlen strtonum])
228#AC_CHECK_FUNCS([symlink])
229#AC_CHECK_FUNCS([timingsafe_bcmp timingsafe_memcmp])
230#
231## Share test results with automake
232#AM_CONDITIONAL([HAVE_ARC4RANDOM_BUF], [test "x$ac_cv_func_arc4random_buf" = xyes])
233#AM_CONDITIONAL([HAVE_ASPRINTF], [test "x$ac_cv_func_asprintf" = xyes])
234#AM_CONDITIONAL([HAVE_GETENTROPY], [test "x$ac_cv_func_getentropy" = xyes])
235#AM_CONDITIONAL([HAVE_MEMMEM], [test "x$ac_cv_func_memmem" = xyes])
236#AM_CONDITIONAL([HAVE_POLL], [test "x$ac_cv_func_poll" = xyes])
237#AM_CONDITIONAL([HAVE_REALLOCARRAY], [test "x$ac_cv_func_reallocarray" = xyes])
238#AM_CONDITIONAL([HAVE_STRLCAT], [test "x$ac_cv_func_strlcat" = xyes])
239#AM_CONDITIONAL([HAVE_STRLCPY], [test "x$ac_cv_func_strlcpy" = xyes])
240#AM_CONDITIONAL([HAVE_STRNDUP], [test "x$ac_cv_func_strndup" = xyes])
241#AM_CONDITIONAL([HAVE_STRNLEN], [test "x$ac_cv_func_strnlen" = xyes])
242#AM_CONDITIONAL([HAVE_STRTONUM], [test "x$ac_cv_func_strtonum" = xyes])
243#AM_CONDITIONAL([HAVE_TIMINGSAFE_BCMP], [test "x$ac_cv_func_timingsafe_bcmp" = xyes])
244#AM_CONDITIONAL([HAVE_TIMINGSAFE_MEMCMP], [test "x$ac_cv_func_timingsafe_memcmp" = xyes])
245#AM_CONDITIONAL([BUILD_CERTHASH], [test "x$ac_cv_func_symlink" = xyes])
246 40
247AC_CONFIG_FILES([ 41AC_CONFIG_FILES([
248 Makefile 42 Makefile
249 include/Makefile 43 include/Makefile
44 app/Makefile
45 compat/Makefile
250 src/Makefile 46 src/Makefile
251 libtls.pc 47 libtls.pc
252]) 48])