refactor,fix,rewrite parts,tweak
[mkp224o.git] / configure.ac
blob21509fe691e59f714821871b5a9a551923a350e4
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"
34 AC_MSG_CHECKING([whether CC supports -nopie])
35 AC_COMPILE_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"
46         AC_MSG_CHECKING([whether CC supports -no-pie])
47         AC_COMPILE_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=yes@:>@])],
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=no@:>@])],
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 AS_IF([test "x$ed25519impl" == "x"],[ed25519impl=ref10])
116 if test "$ed25519impl" = "donna-sse2"
117 then
118         ed25519impl="donna"
119         MYDEFS="$MYDEFS -DED25519_SSE2"
120         CFLAGS="$CFLAGS -msse2"
123 AC_ARG_ENABLE([intfilter],
124         [AS_HELP_STRING([--enable-intfilter@<:@=(32|64|128|native)@:>@],
125                 [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@:>@])],
126         [], [enable_intfilter=no]
128 AC_ARG_ENABLE([intfilter32],
129         [AS_HELP_STRING([--enable-intfilter32], [deprecated. use --enable-intfilter=32 instead])],
130         [enable_intfilter=32]
131         [AC_MSG_WARN([--enable-intfilter32 option is deprecated. use --enable-intfilter=32 instead])],
132         []
134 case "$enable_intfilter" in
136         intfiltertype="u32"
137         ;;
138 64|yes)
139         intfiltertype="u64"
140         ;;
141 128)
142         intfiltertype="unsigned __int128"
143         ;;
144 native)
145         intfiltertype="size_t"
146         ;;
147 no|"")
148         intfiltertype=""
149         ;;
151         AC_MSG_WARN([unrecognised intfilter type: $enable_intfilter])
152         intfiltertype=""
153         ;;
154 esac
156 if test -n "$intfiltertype"
157 then
158         MYDEFS="$MYDEFS -DINTFILTER -DIFT='$intfiltertype'"
161 cstd=""
162 c99=""
163 oldcflags="$CFLAGS"
164 CFLAGS="-std=c99"
165 AC_MSG_CHECKING([whether CC supports -std=c99])
166 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([])],
167     [AC_MSG_RESULT([yes])]
168     [c99="yes"]
169     [cstd="-std=c99"],
170     [AC_MSG_RESULT([no])]
172 CFLAGS="$cstd -Wall"
173 AC_MSG_CHECKING([whether CC supports -Wall])
174 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([])],
175     [AC_MSG_RESULT([yes])]
176     [cstd="$cstd -Wall"],
177     [AC_MSG_RESULT([no])]
179 if test "x$c99" = "xyes" -a "x$ed25519impl" != "xdonna" -a "x$enable_intfilter" != "x128"
180 then
181         CFLAGS="$cstd -pedantic"
182         AC_MSG_CHECKING([whether CC supports -pedantic])
183         AC_COMPILE_IFELSE([AC_LANG_PROGRAM([])],
184                 [AC_MSG_RESULT([yes])]
185                 [cstd="$cstd -pedantic"],
186                 [AC_MSG_RESULT([no])]
187         )
189 if test "x$ed25519impl" = "xdonna"
190 then
191         CFLAGS="$cstd -Wno-unused-function"
192         AC_MSG_CHECKING([whether CC supports -Wno-unused-function])
193         AC_COMPILE_IFELSE([AC_LANG_PROGRAM([])],
194                 [AC_MSG_RESULT([yes])]
195                 [cstd="$cstd -Wno-unused-function"],
196                 [AC_MSG_RESULT([no])]
197         )
199 CFLAGS="$oldcflags"
201 AC_ARG_ENABLE([binfilterlen],
202         [AS_HELP_STRING([--enable-binfilterlen=VAL],
203                 [set binary string filter length (if you don't use intfilter) @<:@default=32@:>@])],
204         [], [enable_binfilterlen=no]
206 if test "x$enable_binfilterlen" != "xyes" -a "x$enable_binfilterlen" != "xno"
207 then
208         MYDEFS="$MYDEFS -DBINFILTERLEN=$enable_binfilterlen"
211 AC_ARG_ENABLE([binsearch],
212         [AS_HELP_STRING([--enable-binsearch],
213                 [enable binary search algoritm; MUCH faster if there are a lot of filters @<:@default=no@:>@])],
214         [], [enable_binsearch=no]
216 if test "x$enable_binsearch" = "xyes"
217 then
218         MYDEFS="$MYDEFS -DBINSEARCH"
221 AC_ARG_ENABLE([besort],
222         [AS_HELP_STRING([--enable-besort],
223                 [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@:>@])],
224         [], [enable_besort=no]
226 if test "x$enable_besort" = "xyes"
227 then
228         MYDEFS="$MYDEFS -DBESORT"
231 AC_ARG_ENABLE([statistics],
232         [AS_HELP_STRING([--enable-statistics],
233                 [collect statistics @<:@default=yes@:>@])],
234         [], [enable_statistics=yes]
236 if test "x$enable_statistics" = "xyes"
237 then
238         MYDEFS="$MYDEFS -DSTATISTICS"
241 AC_ARG_WITH([pcre2],[AC_HELP_STRING([--with-pcre2],[pcre2-config executable @<:@default=pcre2-config@:>@])],[],[with_pcre2="pcre2-config"])
243 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])
244 case "$enable_regex" in
245 no|"")
246         ;;
247 yes|pcre2)
248         AC_MSG_CHECKING([pcre2])
249         V=""
250         if test "$with_pcre2" != "yes"
251         then
252                 V=`"$with_pcre2" --version 2>/dev/null`
253         fi
254         if test -n "$V"
255         then
256                 AC_MSG_RESULT([$V])
257                 MYDEFS="$MYDEFS -DPCRE2FILTER"
258                 CF=`"$with_pcre2" --cflags`
259                 if test -n "$CF"
260                 then
261                         CFLAGS="$CFLAGS $CF"
262                 fi
263                 LF=`"$with_pcre2" --libs8`
264                 if test -n "$LF"
265                 then
266                         MAINLIB="$MAINLIB $LF"
267                 fi
268         else
269                 AC_MSG_RESULT([not found])
270                 AC_ERROR([pcre2-config cannot be executed])
271         fi
272         ;;
274         AC_MSG_WARN([unrecognised regex engine type: $enable_regex])
275         ;;
276 esac
278 AC_SUBST(CSTD,["$cstd"])
279 AC_SUBST(ED25519IMPL,["$ed25519impl"])
280 AC_SUBST(MYDEFS,["$MYDEFS"])
281 AC_SUBST(MAINLIB,["$MAINLIB"])
282 AC_SUBST(NOPIE,["$nopie"])
283 AC_OUTPUT(Makefile)