xref: /isa-l_crypto/configure.ac (revision 3aa2266bba7e1bce04a3fdb96386b1daf42fb065)
1#                                               -*- Autoconf -*-
2# Process this file with autoconf to produce a configure script.
3
4AC_PREREQ(2.69)
5AC_INIT([libisal_crypto],
6        [2.25.0],
7        [https://github.com/intel/isa-l_crypto/issues],
8        [isa-l_crypto])
9AC_CONFIG_SRCDIR([])
10AC_CONFIG_AUX_DIR([build-aux])
11AM_INIT_AUTOMAKE([
12	foreign
13	1.11
14	-Wall
15	-Wno-portability
16	silent-rules
17	tar-pax
18	no-dist-gzip
19	dist-xz
20	subdir-objects
21])
22AM_PROG_AS
23
24AC_CANONICAL_HOST
25CPU=""
26AS_CASE([$host_cpu],
27  [x86_64], [CPU="x86_64"],
28  [amd64], [CPU="x86_64"],
29  [i?86], [CPU="x86_32"],
30  [aarch64], [CPU="aarch64"],
31  [arm64], [CPU="aarch64"],
32)
33AM_CONDITIONAL([CPU_X86_64], [test "$CPU" = "x86_64"])
34AM_CONDITIONAL([CPU_X86_32], [test "$CPU" = "x86_32"])
35AM_CONDITIONAL([CPU_AARCH64], [test "$CPU" = "aarch64"])
36AM_CONDITIONAL([CPU_UNDEFINED], [test "x$CPU" = "x"])
37AM_CONDITIONAL([SAFE_PARAM], [test x"$SAFE_PARAM" = x"yes"])
38
39if test "$CPU" = "x86_64"; then
40   is_x86=yes
41else
42   if test "$CPU" = "x86_32"; then
43      is_x86=yes
44   else
45      is_x86=no
46   fi
47fi
48
49# Check for programs
50AC_PROG_CC_STDC
51AC_USE_SYSTEM_EXTENSIONS
52AM_SILENT_RULES([yes])
53LT_INIT
54AC_PREFIX_DEFAULT([/usr])
55AC_PROG_SED
56AC_PROG_MKDIR_P
57
58# Options
59AC_ARG_ENABLE([debug],
60        AS_HELP_STRING([--enable-debug], [enable debug messages @<:@default=disabled@:>@]),
61        [], [enable_debug=no])
62AS_IF([test "x$enable_debug" = "xyes"], [
63        AC_DEFINE(ENABLE_DEBUG, [1], [Debug messages.])
64])
65
66AC_ARG_ENABLE([fips-mode],
67        AS_HELP_STRING([--enable-fips-mode], [enable FIPS mode @<:@default=disabled@:>@]),
68        [enable_fips_mode=yes], [enable_fips_mode=no])
69AS_IF([test "x$enable_fips_mode" = "xyes"], [
70        AC_DEFINE(FIPS_MODE, [1], [FIPS mode.])
71])
72
73AC_ARG_ENABLE([safe-data],
74        AS_HELP_STRING([--disable-safe-data], [clear sensitive data @<:@default=enabled@:>@]),
75        [safe_data=no], [safe_data=yes])
76AS_IF([test "x$safe_data" = "xyes"], [
77        AC_DEFINE(SAFE_DATA, [1], [Clear sensitive data.])
78])
79
80AC_ARG_ENABLE([safe-param],
81        AS_HELP_STRING([--disable-safe-param], [enable parameter checking @<:@default=enabled@:>@]),
82        [safe_param=no], [safe_param=yes])
83AS_IF([test "x$safe_param" = "xyes"], [
84        AC_DEFINE(SAFE_PARAM, [1], [Enable parameter checking.])
85])
86
87if test x"$CPU" = x"aarch64"; then
88   AC_ARG_ENABLE([sve2],
89        AS_HELP_STRING([--disable-sve2], [disable usage of SVE2]),
90        , enable_sve2=yes)
91   if test "$enable_sve2" = "yes"; then
92      AC_MSG_CHECKING([whether compiler supports sve2])
93      AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],
94                                         [asm(".arch armv8.2-a+sve2");])],
95                        [cc_support_sve2=yes],
96                        [cc_support_sve2=no])
97      if test x"$cc_support_sve2" = xyes ; then
98         AC_MSG_RESULT([yes])
99      else
100         AC_MSG_RESULT([no])
101         AC_MSG_ERROR([upgrade your compiler to support SVE2, or run \"./configure --disable-sve2\"])
102      fi
103   else
104	 AC_DEFINE(NO_SVE2, 1, [Define to 1 if the compiler does not supports SVE2.])
105   fi
106fi
107
108# If this build is for x86, look for nasm
109if test x"$is_x86" = x"yes"; then
110  AC_MSG_CHECKING([whether Intel CET is enabled])
111  AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[
112#ifndef __CET__
113# error CET is not enabled
114#endif]])],[AC_MSG_RESULT([yes])
115                  intel_cet_enabled=yes],[AC_MSG_RESULT([no])
116                  intel_cet_enabled=no])
117AS_IF([test "x$intel_cet_enabled" = "xyes"], [
118        AC_DEFINE(INTEL_CET_ENABLED, [1], [Intel CET enabled.])
119])
120
121# check if LD -z options are supported
122LDFLAGS="\
123-Wl,-z,noexecstack \
124-Wl,-z,relro \
125-Wl,-z,now \
126"
127AC_MSG_CHECKING([if $LD supports $LDFLAGS])
128AC_LINK_IFELSE([AC_LANG_PROGRAM([[]], [[
129int main(int argc, char **argv)
130{
131       return 0;
132}]])],
133       [AC_MSG_RESULT([yes])],
134       [AC_MSG_RESULT([no])
135               LDFLAGS=""]
136)
137
138  # Pick NASM assembler
139  if test x"$AS" = x""; then
140    # Check for nasm and nasm features
141    nasm_feature_level=0
142    AC_CHECK_PROG(HAVE_NASM, nasm, yes, no)
143    if test "$HAVE_NASM" = "yes"; then
144       nasm_feature_level=1
145    else
146       AC_MSG_RESULT([no nasm])
147    fi
148
149    if test x"$nasm_feature_level" = x"1"; then
150      AC_MSG_CHECKING([for modern nasm])
151      AC_LANG_CONFTEST([AC_LANG_SOURCE([[pblendvb xmm2, xmm1;]])])
152      sed -i -e '/pblendvb/!d' conftest.c
153      if nasm -f elf64 conftest.c 2> /dev/null; then
154        AC_MSG_RESULT([yes])
155        nasm_feature_level=4
156      else
157        AC_MSG_RESULT([no])
158      fi
159    fi
160    if test x"$nasm_feature_level" = x"4"; then
161      AC_MSG_CHECKING([for optional nasm AVX512 support])
162      AC_LANG_CONFTEST([AC_LANG_SOURCE([[vinserti32x8 zmm0, ymm1, 1;]])])
163      sed -i -e '/vinsert/!d' conftest.c
164      if nasm -f elf64  conftest.c 2> /dev/null; then
165        AC_MSG_RESULT([yes])
166        nasm_feature_level=6
167      else
168        AC_MSG_RESULT([no])
169      fi
170    fi
171    if test x"$nasm_feature_level" = x"6"; then
172      AC_MSG_CHECKING([for additional nasm AVX512 support])
173      AC_LANG_CONFTEST([AC_LANG_SOURCE([[vpcompressb zmm0 {k1}, zmm1;]])])
174      sed -i -e '/vpcompressb/!d' conftest.c
175      if nasm -f elf64  conftest.c 2> /dev/null; then
176        AC_MSG_RESULT([yes])
177        nasm_feature_level=10
178      else
179        AC_MSG_RESULT([no])
180      fi
181    fi
182
183    AS=nasm
184    as_feature_level=$nasm_feature_level
185
186  else
187    # Check for $AS supported features
188    as_feature_level=0
189    AC_CHECK_PROG(HAVE_AS, $AS, yes, no)
190    if test "$HAVE_AS" = "yes"; then
191       as_feature_level=1
192    else
193       AC_MSG_ERROR([no $AS])
194    fi
195
196    if test x"$as_feature_level" = x"1"; then
197      AC_MSG_CHECKING([for modern $AS])
198      AC_LANG_CONFTEST([AC_LANG_SOURCE([[pblendvb xmm2, xmm1;]])])
199      sed -i -e '/pblendvb/!d' conftest.c
200      if $AS -f elf64 conftest.c 2> /dev/null; then
201        AC_MSG_RESULT([yes])
202        as_feature_level=4
203      else
204        AC_MSG_RESULT([no])
205      fi
206    fi
207    if test x"$as_feature_level" = x"4"; then
208      AC_MSG_CHECKING([for optional as AVX512 support])
209      AC_LANG_CONFTEST([AC_LANG_SOURCE([[vinserti32x8 zmm0, ymm1, 1;]])])
210      sed -i -e '/vinsert/!d' conftest.c
211      if $AS -f elf64  conftest.c 2> /dev/null; then
212        AC_MSG_RESULT([yes])
213        as_feature_level=6
214      else
215        AC_MSG_RESULT([no])
216      fi
217    fi
218    if test x"$as_feature_level" = x"6"; then
219      AC_MSG_CHECKING([for additional as AVX512 support])
220      AC_LANG_CONFTEST([AC_LANG_SOURCE([[vpcompressb zmm0, k1, zmm1;]])])
221      sed -i -e '/vpcompressb/!d' conftest.c
222      if $AS -f elf64  conftest.c 2> /dev/null; then
223        AC_MSG_RESULT([yes])
224        as_feature_level=10
225      else
226        AC_MSG_RESULT([no])
227      fi
228    fi
229
230    AC_MSG_CHECKING([for optional nasm SHA-NI support])
231    AC_LANG_CONFTEST([AC_LANG_SOURCE([[sha256rnds2 xmm2,xmm1,xmm0;]])])
232    sed -i -e '/sha256rnds2/!d' conftest.c
233    if $AS -f elf64  conftest.c 2> /dev/null; then
234      AC_MSG_RESULT([yes])
235      as_knows_shani=yes
236    else
237      AC_MSG_RESULT([no])
238    fi
239
240  fi
241
242  if test $as_feature_level -lt 10 ; then
243    AC_MSG_ERROR([No modern nasm found as required. Nasm should be v2.14.01 or later.])
244  fi
245
246  if test x"$as_knows_shani" = x"yes"; then
247    AC_DEFINE(HAVE_AS_KNOWS_SHANI, [1], [Assembler can do SHANI.])
248    have_as_knows_shani=yes
249  else
250    AC_MSG_RESULT([Assembler does not understand SHANI opcodes.  Consider upgrading for best performance.])
251  fi
252
253  case $host_os in
254       *linux*)  arch=linux   asm_args="-f elf64";;
255       *darwin*) arch=darwin  asm_args="-f macho64 --prefix=_ ";;
256       *netbsd*) arch=netbsd  asm_args="-f elf64";;
257       *mingw*)  arch=mingw   asm_args="-f win64";;
258       *)        arch=unknown asm_args="-f elf64";;
259  esac
260
261  AC_DEFINE_UNQUOTED(AS_FEATURE_LEVEL, [$as_feature_level], [Assembler feature level.])
262  if test $as_feature_level -ge 6 ; then
263    AC_DEFINE(HAVE_AS_KNOWS_AVX512, [1], [Assembler can do AVX512.])
264    have_as_knows_avx512=yes
265  else
266    AC_MSG_RESULT([Assembler does not understand AVX512 opcodes.  Consider upgrading for best performance.])
267  fi
268
269  AM_CONDITIONAL(SAFE_DATA, test x"$SAFE_DATA" = x"yes")
270  AM_CONDITIONAL(FIPS_MODE, test x"$FIPS_MODE" = x"yes")
271  AM_CONDITIONAL(USE_NASM, test x"$AS" = x"nasm")
272  AM_CONDITIONAL(WITH_AVX512, test x"$have_as_knows_avx512" = x"yes")
273  AM_CONDITIONAL(WITH_SHANI, test x"$have_as_knows_shani" = x"yes")
274  AC_SUBST([asm_args])
275  AM_CONDITIONAL(DARWIN, test x"$arch" = x"darwin")
276  AC_MSG_RESULT([Using $AS args target "$arch" "$asm_args"])
277else
278  # Disable below conditionals if not x86
279  AM_CONDITIONAL(SAFE_DATA, test "x" = "y")
280  AM_CONDITIONAL(FIPS_MODE, test "x" = "y")
281  AM_CONDITIONAL(USE_NASM, test "x" = "y")
282  AM_CONDITIONAL(WITH_AVX512, test "x" = "y")
283  AM_CONDITIONAL(WITH_SHANI, test "x" = "y")
284  AM_CONDITIONAL(DARWIN, test "x" = "y")
285fi
286
287# Check for header files
288AC_CHECK_HEADERS([limits.h stdint.h stdlib.h string.h])
289
290# Checks for typedefs, structures, and compiler characteristics.
291AC_C_INLINE
292AC_TYPE_SIZE_T
293AC_TYPE_UINT16_T
294AC_TYPE_UINT32_T
295AC_TYPE_UINT64_T
296AC_TYPE_UINT8_T
297
298# Checks for library functions.
299AC_FUNC_MALLOC  # Used only in tests
300AC_CHECK_FUNCS([memmove memset])
301
302my_CFLAGS="\
303-Wall \
304-fPIC \
305-Wchar-subscripts \
306-Wformat-security \
307-Wnested-externs \
308-Wpointer-arith \
309-Wshadow \
310-Wstrict-prototypes \
311-Wtype-limits \
312-fstack-protector \
313-D_FORTIFY_SOURCE=2 \
314-DNO_COMPAT_ISAL_CRYPTO_API_2_24
315"
316AC_SUBST([my_CFLAGS])
317
318AC_CONFIG_FILES([\
319  Makefile\
320  libisal_crypto.pc
321])
322
323AC_OUTPUT
324AC_MSG_RESULT([
325        $PACKAGE $VERSION
326        =====
327
328        prefix:                 ${prefix}
329        sysconfdir:             ${sysconfdir}
330        libdir:                 ${libdir}
331        includedir:             ${includedir}
332
333        compiler:               ${CC}
334        cflags:                 ${CFLAGS}
335        ldflags:                ${LDFLAGS}
336
337        debug:                  ${enable_debug}
338        safe_data:              ${safe_data}
339        safe_param:             ${safe_param}
340        FIPS mode:              ${enable_fips_mode}
341])
342