xref: /isa-l/configure.ac (revision 28305ade9e07213a2c602697a6a3a1e1eed2acca)
1#                                               -*- Autoconf -*-
2# Process this file with autoconf to produce a configure script.
3
4AC_PREREQ(2.69)
5AC_INIT([libisal],
6        [2.31.1],
7        [https://github.com/intel/isa-l/issues],
8        [isa-l])
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  [powerpc64le], [CPU="ppc64le"],
33  [ppc64le], [CPU="ppc64le"],
34)
35AM_CONDITIONAL([CPU_X86_64], [test "$CPU" = "x86_64"])
36AM_CONDITIONAL([CPU_X86_32], [test "$CPU" = "x86_32"])
37AM_CONDITIONAL([CPU_AARCH64], [test "$CPU" = "aarch64"])
38AM_CONDITIONAL([CPU_PPC64LE], [test "$CPU" = "ppc64le"])
39AM_CONDITIONAL([CPU_UNDEFINED], [test "x$CPU" = "x"])
40
41if test "$CPU" = "x86_64"; then
42   is_x86=yes
43else
44   if test "$CPU" = "x86_32"; then
45      is_x86=yes
46   else
47      is_x86=no
48   fi
49fi
50
51# Check for programs
52AC_PROG_CC_STDC
53AC_USE_SYSTEM_EXTENSIONS
54AM_SILENT_RULES([yes])
55LT_INIT
56AC_PREFIX_DEFAULT([/usr])
57AC_PROG_SED
58AC_PROG_MKDIR_P
59
60# Options
61AC_ARG_ENABLE([debug],
62        AS_HELP_STRING([--enable-debug], [enable debug messages @<:@default=disabled@:>@]),
63        [], [enable_debug=no])
64AS_IF([test "x$enable_debug" = "xyes"], [
65        AC_DEFINE(ENABLE_DEBUG, [1], [Debug messages.])
66])
67
68# If this build is for x86, look for yasm and nasm
69if test x"$is_x86" = x"yes"; then
70  AC_MSG_CHECKING([whether Intel CET is enabled])
71  AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[
72#ifndef __CET__
73# error CET is not enabled
74#endif]])],[AC_MSG_RESULT([yes])
75		   intel_cet_enabled=yes],[AC_MSG_RESULT([no])
76		   intel_cet_enabled=no])
77AS_IF([test "x$intel_cet_enabled" = "xyes"], [
78        AC_DEFINE(INTEL_CET_ENABLED, [1], [Intel CET enabled.])
79])
80
81# check if LD -z options are supported
82LDFLAGS="\
83-Wl,-z,noexecstack \
84-Wl,-z,relro \
85-Wl,-z,now \
86"
87AC_MSG_CHECKING([if $LD supports $LDFLAGS])
88AC_LINK_IFELSE([AC_LANG_PROGRAM([[]], [[
89int main(int argc, char **argv)
90{
91	return 0;
92}]])],
93	[AC_MSG_RESULT([yes])],
94	[AC_MSG_RESULT([no])
95		LDFLAGS=""]
96)
97
98  # Pick an assembler yasm or nasm
99  if test x"$AS" = x""; then
100    # Check for yasm and yasm features
101    yasm_feature_level=0
102    AC_CHECK_PROG(HAVE_YASM, yasm, yes, no)
103    if test "$HAVE_YASM" = "yes"; then
104       yasm_feature_level=1
105    else
106       AC_MSG_RESULT([no yasm])
107    fi
108    if test x"$yasm_feature_level" = x"1"; then
109       AC_MSG_CHECKING([for modern yasm])
110       AC_LANG_CONFTEST([AC_LANG_SOURCE([[vmovdqa %xmm0, %xmm1;]])])
111       if yasm -f elf64 -p gas conftest.c ; then
112         AC_MSG_RESULT([yes])
113         yasm_feature_level=4
114       else
115         AC_MSG_RESULT([no])
116       fi
117    fi
118    if test x"$yasm_feature_level" = x"4"; then
119       AC_MSG_CHECKING([for optional yasm AVX512 support])
120       AC_LANG_CONFTEST([AC_LANG_SOURCE([[vpshufb %zmm0, %zmm1, %zmm2;]])])
121       if yasm -f elf64 -p gas conftest.c 2> /dev/null; then
122         AC_MSG_RESULT([yes])
123         yasm_feature_level=6
124       else
125         AC_MSG_RESULT([no])
126       fi
127    fi
128    if test x"$yasm_feature_level" = x"6"; then
129      AC_MSG_CHECKING([for additional yasm AVX512 support])
130      AC_LANG_CONFTEST([AC_LANG_SOURCE([[vpcompressb zmm0, k1, zmm1;]])])
131      sed -i -e '/vpcompressb/!d' conftest.c
132      if yasm -f elf64  conftest.c 2> /dev/null; then
133        AC_MSG_RESULT([yes])
134        yasm_feature_level=10
135      else
136        AC_MSG_RESULT([no])
137      fi
138    fi
139
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    if test $nasm_feature_level -ge $yasm_feature_level ; then
184      AS=nasm
185      as_feature_level=$nasm_feature_level
186    else
187      AS=yasm
188      as_feature_level=$yasm_feature_level
189    fi
190
191  else
192    # Check for $AS supported features
193    as_feature_level=0
194    AC_CHECK_PROG(HAVE_AS, $AS, yes, no)
195    if test "$HAVE_AS" = "yes"; then
196       as_feature_level=1
197    else
198       AC_MSG_ERROR([no $AS])
199    fi
200
201    if test x"$as_feature_level" = x"1"; then
202      AC_MSG_CHECKING([for modern $AS])
203      AC_LANG_CONFTEST([AC_LANG_SOURCE([[pblendvb xmm2, xmm1;]])])
204      sed -i -e '/pblendvb/!d' conftest.c
205      if $AS -f elf64 conftest.c 2> /dev/null; then
206        AC_MSG_RESULT([yes])
207        as_feature_level=4
208      else
209        AC_MSG_RESULT([no])
210      fi
211    fi
212    if test x"$as_feature_level" = x"4"; then
213      AC_MSG_CHECKING([for optional as AVX512 support])
214      AC_LANG_CONFTEST([AC_LANG_SOURCE([[vinserti32x8 zmm0, ymm1, 1;]])])
215      sed -i -e '/vinsert/!d' conftest.c
216      if $AS -f elf64  conftest.c 2> /dev/null; then
217        AC_MSG_RESULT([yes])
218        as_feature_level=6
219      else
220        AC_MSG_RESULT([no])
221      fi
222    fi
223    if test x"$as_feature_level" = x"6"; then
224      AC_MSG_CHECKING([for additional as AVX512 support])
225      AC_LANG_CONFTEST([AC_LANG_SOURCE([[vpcompressb zmm0, k1, zmm1;]])])
226      sed -i -e '/vpcompressb/!d' conftest.c
227      if $AS -f elf64  conftest.c 2> /dev/null; then
228        AC_MSG_RESULT([yes])
229        as_feature_level=10
230      else
231        AC_MSG_RESULT([no])
232      fi
233    fi
234  fi
235
236  if test $as_feature_level -lt 2 ; then
237    AC_MSG_ERROR([No modern nasm or yasm found as required. Nasm should be v2.11.01 or later (v2.13 for AVX512) and yasm should be 1.2.0 or later.])
238  fi
239
240  case $host_os in
241       *linux*)  arch=linux   yasm_args="-f elf64";;
242       *darwin*) arch=darwin  yasm_args="-f macho64 --prefix=_ ";;
243       *netbsd*) arch=netbsd  yasm_args="-f elf64";;
244       *mingw*)  arch=mingw   yasm_args="-f win64";;
245       *)        arch=unknown yasm_args="-f elf64";;
246  esac
247
248  # Fix for nasm missing windows features
249  if test x"$arch" = x"mingw"; then
250    AS=yasm
251    as_feature_level=$yasm_feature_level
252    if test $as_feature_level -lt 2 ; then
253      AC_MSG_ERROR([Mingw build requires Yasm 1.2.0 or later.])
254    fi
255  fi
256
257  AC_DEFINE_UNQUOTED(AS_FEATURE_LEVEL, [$as_feature_level], [Assembler feature level.])
258  if test $as_feature_level -ge 6 ; then
259    AC_DEFINE(HAVE_AS_KNOWS_AVX512, [1], [Assembler can do AVX512.])
260    have_as_knows_avx512=yes
261  else
262    AC_MSG_RESULT([Assembler does not understand AVX512 opcodes.  Consider upgrading for best performance.])
263  fi
264
265  AM_CONDITIONAL(USE_YASM, test x"$AS" = x"yasm")
266  AM_CONDITIONAL(USE_NASM, test x"$AS" = x"nasm")
267  AM_CONDITIONAL(WITH_AVX512, test x"$have_as_knows_avx512" = x"yes")
268  AC_SUBST([yasm_args])
269  AM_CONDITIONAL(DARWIN, test x"$arch" = x"darwin")
270  AC_MSG_RESULT([Using $AS args target "$arch" "$yasm_args"])
271else
272  # Disable below conditionals if not x86
273  AM_CONDITIONAL(USE_YASM, test "x" = "y")
274  AM_CONDITIONAL(USE_NASM, test "x" = "y")
275  AM_CONDITIONAL(WITH_AVX512, test "x" = "y")
276  AM_CONDITIONAL(DARWIN, test "x" = "y")
277fi
278
279# Check for header files
280AC_CHECK_HEADERS([limits.h stdint.h stdlib.h string.h])
281
282# Checks for typedefs, structures, and compiler characteristics.
283AC_C_INLINE
284AC_TYPE_SIZE_T
285AC_TYPE_UINT16_T
286AC_TYPE_UINT32_T
287AC_TYPE_UINT64_T
288AC_TYPE_UINT8_T
289
290# Checks for library functions.
291AC_FUNC_MALLOC  # Used only in tests
292AC_CHECK_FUNCS([memmove memset getopt])
293
294my_CFLAGS="\
295-Wall \
296-Wchar-subscripts \
297-Wformat-security \
298-Wnested-externs \
299-Wpointer-arith \
300-Wshadow \
301-Wstrict-prototypes \
302-Wtype-limits \
303-fstack-protector \
304-D_FORTIFY_SOURCE=2 \
305"
306AC_SUBST([my_CFLAGS])
307
308AC_CONFIG_FILES([\
309	Makefile\
310	libisal.pc
311])
312
313AC_OUTPUT
314AC_MSG_RESULT([
315        $PACKAGE $VERSION
316        =====
317
318        prefix:                 ${prefix}
319        sysconfdir:             ${sysconfdir}
320        libdir:                 ${libdir}
321        includedir:             ${includedir}
322
323        compiler:               ${CC}
324        cflags:                 ${CFLAGS}
325        ldflags:                ${LDFLAGS}
326
327        debug:                  ${enable_debug}
328])
329