some tweaks
[mkp224o.git] / configure.ac
blob9c2ddacf2e9ac462858aca403f9b9d8286b0e6f5
1 AC_INIT(mkp224o)
2 # sanity check
3 AC_CONFIG_SRCDIR([main.c])
4 # C compiler
5 oldcflags="$CFLAGS"
6 AC_PROG_CC
8 # NOTE: this script intentionally doesn't check for small details like posix functions and hard dependencies (libsodium) so you may get errors at compilation
10 if test "x$oldcflags" != "x$CFLAGS"
11 then
12         oldcflags="-O3"
13         CFLAGS="-march=native"
14         AC_MSG_CHECKING([whether CC supports -march=native])
15         AC_COMPILE_IFELSE([AC_LANG_PROGRAM([])],
16                 [AC_MSG_RESULT([yes])]
17                 [oldcflags="$oldcflags -march=native"],
18                 [AC_MSG_RESULT([no])]
19         )
20         CFLAGS="-fomit-frame-pointer"
21         AC_MSG_CHECKING([whether CC supports -fomit-frame-pointer])
22         AC_COMPILE_IFELSE([AC_LANG_PROGRAM([])],
23                 [AC_MSG_RESULT([yes])]
24                 [oldcflags="$oldcflags -fomit-frame-pointer"],
25                 [AC_MSG_RESULT([no])]
26         )
27         CFLAGS="$oldcflags"
30 nopie=""
32 oldcflags="$CFLAGS"
33 CFLAGS="-nopie -Werror"
34 AC_MSG_CHECKING([whether CC supports -nopie])
35 AC_LINK_IFELSE([AC_LANG_PROGRAM([])],
36     [AC_MSG_RESULT([yes])]
37     [nopie="-nopie"],
38     [AC_MSG_RESULT([no])]
40 CFLAGS="$oldcflags"
42 if test "x$nopie" = "x"
43 then
44         oldcflags="$CFLAGS"
45         CFLAGS="-no-pie -Werror"
46         AC_MSG_CHECKING([whether CC supports -no-pie])
47         AC_LINK_IFELSE([AC_LANG_PROGRAM([])],
48                 [AC_MSG_RESULT([yes])]
49                 [nopie="-no-pie"],
50                 [AC_MSG_RESULT([no])]
51         )
52         CFLAGS="$oldcflags"
55 MYDEFS=""
56 MAINLIB=""
58 ed25519impl=""
59 AC_ARG_ENABLE([ref10],
60         [AS_HELP_STRING([--enable-ref10],
61                 [use SUPERCOP ref10 ed25519 implementation @<:@default=no@:>@])],
62         [
63                 AS_IF([test "x$ed25519impl" != "x" -a "$ed25519impl" != "ref10"],
64                         [AC_ERROR([only one ed25519 implementation can be defined])])
65                 ed25519impl="ref10"
66         ],
67         []
70 AC_ARG_ENABLE([amd64-51-30k],
71         [AS_HELP_STRING([--enable-amd64-51-30k],
72                 [use SUPERCOP amd64-51-30k ed25519 implementation @<:@default=no@:>@])],
73         [
74                 AS_IF([test "x$ed25519impl" != "x" -a "$ed25519impl" != "amd64_51_30k"],
75                         [AC_ERROR([only one ed25519 implementation can be defined])])
76                 ed25519impl="amd64_51_30k"
77         ],
78         []
81 AC_ARG_ENABLE([amd64-64-24k],
82         [AS_HELP_STRING([--enable-amd64-64-24k],
83                 [use SUPERCOP amd64-64-24k ed25519 implementation @<:@default=no@:>@])],
84         [
85                 AS_IF([test "x$ed25519impl" != "x" -a "$ed25519impl" != "amd64_64_24k"],
86                         [AC_ERROR([only one ed25519 implementation can be defined])])
87                 ed25519impl="amd64_64_24k"
88         ],
89         []
92 AC_ARG_ENABLE([donna],
93         [AS_HELP_STRING([--enable-donna],
94                 [use ed25519-donna implementation @<:@default=yes@:>@])],
95         [
96                 AS_IF([test "x$ed25519impl" != "x" -a "$ed25519impl" != "donna"],
97                         [AC_ERROR([only one ed25519 implementation can be defined])])
98                 ed25519impl="donna"
99         ],
100         []
103 AC_ARG_ENABLE([donna-sse2],
104         [AS_HELP_STRING([--enable-donna-sse2],
105                 [use ed25519-donna SSE2 implementation @<:@default=no@:>@])],
106         [
107                 AS_IF([test "x$ed25519impl" != "x" -a "$ed25519impl" != "donna-sse2"],
108                         [AC_ERROR([only one ed25519 implementation can be defined])])
109                 ed25519impl="donna-sse2"
110         ],
111         []
114 # default
115 AS_IF([test "x$ed25519impl" == "x"],[ed25519impl="donna"])
117 if test "$ed25519impl" = "donna-sse2"
118 then
119         ed25519impl="donna"
120         MYDEFS="$MYDEFS -DED25519_SSE2"
121         CFLAGS="$CFLAGS -msse2"
126 AC_ARG_ENABLE([intfilter],
127         [AS_HELP_STRING([--enable-intfilter@<:@=(32|64|128|native)@:>@],
128                 [use integers of specific size @<:@default=64@:>@ for filtering. faster but limits filter length to: 6 for 32-bit, 12 for 64-bit, 24 for 128-bit @<:@default=no@:>@])],
129         [], [enable_intfilter=no]
131 AC_ARG_ENABLE([intfilter32],
132         [AS_HELP_STRING([--enable-intfilter32], [deprecated. use --enable-intfilter=32 instead])],
133         [enable_intfilter=32]
134         [AC_MSG_WARN([--enable-intfilter32 option is deprecated. use --enable-intfilter=32 instead])],
135         []
137 case "$enable_intfilter" in
139         intfiltertype="u32"
140         ;;
141 64|yes)
142         intfiltertype="u64"
143         ;;
144 128)
145         intfiltertype="unsigned __int128"
146         ;;
147 native)
148         intfiltertype="size_t"
149         ;;
150 no|"")
151         intfiltertype=""
152         ;;
154         AC_MSG_WARN([unrecognised intfilter type: $enable_intfilter])
155         intfiltertype=""
156         ;;
157 esac
159 if test -n "$intfiltertype"
160 then
161         MYDEFS="$MYDEFS -DINTFILTER -DIFT='$intfiltertype'"
164 AC_ARG_ENABLE([batchnum],
165         [AS_HELP_STRING([--enable-batchnum=number],
166                 [number of elements to batch when using -B @<:@default=2048@:>@])],
167         [], []
169 if test -n "$enable_batchnum" -a x"$enable_batchnum" != x"no"
170 then
171         MYDEFS="$MYDEFS -DBATCHNUM=$enable_batchnum"
174 cstd=""
175 c99=""
176 oldcflags="$CFLAGS"
178 CFLAGS="-std=c99"
179 AC_MSG_CHECKING([whether CC supports -std=c99])
180 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([])],
181     [AC_MSG_RESULT([yes])]
182     [c99="yes"]
183     [cstd="-std=c99"],
184     [AC_MSG_RESULT([no])]
187 CFLAGS="$cstd -Wall"
188 AC_MSG_CHECKING([whether CC supports -Wall])
189 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([])],
190     [AC_MSG_RESULT([yes])]
191     [cstd="$cstd -Wall"],
192     [AC_MSG_RESULT([no])]
195 CFLAGS="$cstd -Wextra"
196 AC_MSG_CHECKING([whether CC supports -Wextra])
197 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([])],
198     [AC_MSG_RESULT([yes])]
199     [cstd="$cstd -Wextra"],
200     [AC_MSG_RESULT([no])]
203 # (negative) detection on clang fails without -Werror
204 CFLAGS="$cstd -Wno-maybe-uninitialized -Werror"
205 AC_MSG_CHECKING([whether CC supports -Wno-maybe-uninitialized])
206 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([])],
207     [AC_MSG_RESULT([yes])]
208     [cstd="$cstd -Wno-maybe-uninitialized"],
209     [AC_MSG_RESULT([no])]
212 if test "x$c99" = "xyes" -a "x$ed25519impl" != "xdonna" -a "x$enable_intfilter" != "x128"
213 then
214         CFLAGS="$cstd -pedantic"
215         AC_MSG_CHECKING([whether CC supports -pedantic])
216         AC_COMPILE_IFELSE([AC_LANG_PROGRAM([])],
217                 [AC_MSG_RESULT([yes])]
218                 [cstd="$cstd -pedantic"],
219                 [AC_MSG_RESULT([no])]
220         )
223 CFLAGS="$cstd -Wno-format -Wno-pedantic-ms-format -Werror"
224 AC_MSG_CHECKING([whether CC supports and needs -Wno-format -Wno-pedantic-ms-format])
225 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#ifndef _WIN32
226 #error wants windows
227 #endif]], [])],
228         [AC_MSG_RESULT([yes])]
229         [cstd="$cstd -Wno-format -Wno-pedantic-ms-format"],
230         [AC_MSG_RESULT([no])]
233 if test "x$ed25519impl" = "xdonna"
234 then
235         CFLAGS="$cstd -Wno-unused-function -Werror"
236         AC_MSG_CHECKING([whether CC supports -Wno-unused-function])
237         AC_COMPILE_IFELSE([AC_LANG_PROGRAM([])],
238                 [AC_MSG_RESULT([yes])]
239                 [cstd="$cstd -Wno-unused-function"],
240                 [AC_MSG_RESULT([no])]
241         )
244 CFLAGS="$cstd -Wmissing-prototypes -Werror"
245 AC_MSG_CHECKING([whether CC supports -Wmissing-prototypes])
246 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([])],
247     [AC_MSG_RESULT([yes])]
248     [cstd="$cstd -Wmissing-prototypes"],
249     [AC_MSG_RESULT([no])]
252 # XXX AC_LANG_PROGRAM produces unsuitable prototype so this check must be last one
253 CFLAGS="$cstd -Wstrict-prototypes -Werror"
254 AC_MSG_CHECKING([whether CC supports -Wstrict-prototypes])
255 AC_COMPILE_IFELSE([AC_LANG_SOURCE([[int main(void) { return 0; }]])],
256     [AC_MSG_RESULT([yes])]
257     [cstd="$cstd -Wstrict-prototypes"],
258     [AC_MSG_RESULT([no])]
261 CFLAGS="$oldcflags"
263 AC_ARG_ENABLE([binfilterlen],
264         [AS_HELP_STRING([--enable-binfilterlen=VAL],
265                 [set binary string filter length (if you don't use intfilter) @<:@default=32@:>@])],
266         [], [enable_binfilterlen=no]
268 if test "x$enable_binfilterlen" != "xyes" -a "x$enable_binfilterlen" != "xno"
269 then
270         MYDEFS="$MYDEFS -DBINFILTERLEN=$enable_binfilterlen"
273 AC_ARG_ENABLE([binsearch],
274         [AS_HELP_STRING([--enable-binsearch],
275                 [enable binary search algoritm; MUCH faster if there are a lot of filters @<:@default=no@:>@])],
276         [], [enable_binsearch=no]
278 if test "x$enable_binsearch" = "xyes"
279 then
280         MYDEFS="$MYDEFS -DBINSEARCH"
283 AC_ARG_ENABLE([besort],
284         [AS_HELP_STRING([--enable-besort],
285                 [force intfilter binsearch case to use big endian sorting and not omit masks from filters; useful if your filters aren't of same length @<:@default=no@:>@])],
286         [], [enable_besort=no]
288 if test "x$enable_besort" = "xyes"
289 then
290         MYDEFS="$MYDEFS -DBESORT"
293 AC_ARG_ENABLE([statistics],
294         [AS_HELP_STRING([--enable-statistics],
295                 [collect statistics @<:@default=yes@:>@])],
296         [], [enable_statistics=yes]
298 if test "x$enable_statistics" = "xyes"
299 then
300         MYDEFS="$MYDEFS -DSTATISTICS"
303 AC_ARG_WITH([pcre2],[AC_HELP_STRING([--with-pcre2],[pcre2-config executable @<:@default=pcre2-config@:>@])],[],[with_pcre2="pcre2-config"])
305 AC_ARG_ENABLE([regex],[AC_HELP_STRING([--enable-regex],[whether to enable regex engine. currently possible values are "pcre2" and "yes" which defaults to "pcre2" @<:@default=no@:>@])],[],[enable_regex=no])
306 case "$enable_regex" in
307 no|"")
308         ;;
309 yes|pcre2)
310         AC_MSG_CHECKING([pcre2])
311         V=""
312         if test "$with_pcre2" != "yes"
313         then
314                 V=`"$with_pcre2" --version 2>/dev/null`
315         fi
316         if test -n "$V"
317         then
318                 AC_MSG_RESULT([$V])
319                 MYDEFS="$MYDEFS -DPCRE2FILTER"
320                 CF=`"$with_pcre2" --cflags`
321                 if test -n "$CF"
322                 then
323                         CFLAGS="$CFLAGS $CF"
324                 fi
325                 LF=`"$with_pcre2" --libs8`
326                 if test -n "$LF"
327                 then
328                         MAINLIB="$MAINLIB $LF"
329                 fi
330         else
331                 AC_MSG_RESULT([not found])
332                 AC_ERROR([pcre2-config cannot be executed])
333         fi
334         ;;
336         AC_MSG_WARN([unrecognised regex engine type: $enable_regex])
337         ;;
338 esac
341 AC_MSG_CHECKING([whether ARGON2ID13 is supported by libsodium])
342 AC_COMPILE_IFELSE(
343         [AC_LANG_PROGRAM(
344                 [[#include <sodium/crypto_pwhash.h>]],
345                 [[int alg = crypto_pwhash_ALG_ARGON2ID13;(void) alg;]]
346         )],
347         [AC_MSG_RESULT([yes])]
348         [MYDEFS="$MYDEFS -DPASSPHRASE"],
349         [AC_MSG_RESULT([no])]
353 # recreate dir tree, because otherwise gcc will fuck up
354 (cd "$srcdir" && find ed25519 -type d) | xargs mkdir -p
356 AC_SUBST(CSTD,["$cstd"])
357 AC_SUBST(ED25519IMPL,["$ed25519impl"])
358 AC_SUBST(MYDEFS,["$MYDEFS"])
359 AC_SUBST(MAINLIB,["$MAINLIB"])
360 AC_SUBST(NOPIE,["$nopie"])
361 AC_SUBST(SRCDIR,["$srcdir"])
362 AC_OUTPUT(GNUmakefile)