1
0

configure.ac 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398
  1. AC_INIT(mkp224o)
  2. # sanity check
  3. AC_CONFIG_SRCDIR([main.c])
  4. # C compiler
  5. oldcflags="$CFLAGS"
  6. AC_PROG_CC
  7. # determine version
  8. ver=""
  9. if test -r "$srcdir/version.txt"
  10. then
  11. ver=`cat "$srcdir/version.txt"`
  12. elif test -d "$srcdir/.git"
  13. then
  14. if git --version >/dev/null 2>&1
  15. then
  16. # try matching exact tag
  17. ver=`git -C "$srcdir" describe --tags --exact-match 2>/dev/null`
  18. if test -z "$ver"
  19. then
  20. # otherwise obtain full commit ID
  21. ver=`git -C "$srcdir" rev-parse HEAD 2>/dev/null`
  22. if test -n "$ver"
  23. then
  24. ver=git-$ver
  25. fi
  26. fi
  27. if test -n "$ver"
  28. then
  29. if ! git -C "$srcdir" diff --exit-code >/dev/null 2>&1
  30. then
  31. # add at the end to mark modified version
  32. ver="$ver"'*'
  33. fi
  34. fi
  35. fi
  36. fi
  37. if test -z "$ver"
  38. then
  39. ver=unknown
  40. fi
  41. # NOTE: this script intentionally doesn't check for small details like posix functions and hard dependencies (libsodium) so you may get errors at compilation
  42. if test x"$oldcflags" != x"$CFLAGS"
  43. then
  44. oldcflags="-O3"
  45. CFLAGS="-march=native"
  46. AC_MSG_CHECKING([whether CC supports -march=native])
  47. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([])],
  48. [AC_MSG_RESULT([yes])]
  49. [oldcflags="$oldcflags -march=native"],
  50. [AC_MSG_RESULT([no])]
  51. )
  52. CFLAGS="-fomit-frame-pointer"
  53. AC_MSG_CHECKING([whether CC supports -fomit-frame-pointer])
  54. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([])],
  55. [AC_MSG_RESULT([yes])]
  56. [oldcflags="$oldcflags -fomit-frame-pointer"],
  57. [AC_MSG_RESULT([no])]
  58. )
  59. CFLAGS="$oldcflags"
  60. fi
  61. pie=""
  62. oldcflags="$CFLAGS"
  63. CFLAGS="-fPIE -Werror"
  64. AC_MSG_CHECKING([whether CC supports -fPIE])
  65. AC_LINK_IFELSE([AC_LANG_PROGRAM([])],
  66. [AC_MSG_RESULT([yes])]
  67. [pie="-fPIE"],
  68. [AC_MSG_RESULT([no])]
  69. )
  70. CFLAGS="$oldcflags"
  71. MYDEFS=""
  72. MAINLIB=""
  73. ed25519impl=""
  74. AC_ARG_ENABLE([ref10],
  75. [AS_HELP_STRING([--enable-ref10],
  76. [use SUPERCOP ref10 ed25519 implementation @<:@default=no@:>@])],
  77. [
  78. AS_IF([test x"$ed25519impl" != x"" -a "$ed25519impl" != "ref10"],
  79. [AC_MSG_ERROR(only one ed25519 implementation can be defined)])
  80. ed25519impl="ref10"
  81. ],
  82. []
  83. )
  84. AC_ARG_ENABLE([amd64-51-30k],
  85. [AS_HELP_STRING([--enable-amd64-51-30k],
  86. [use SUPERCOP amd64-51-30k ed25519 implementation @<:@default=no@:>@])],
  87. [
  88. AS_IF([test x"$ed25519impl" != x"" -a "$ed25519impl" != "amd64_51_30k"],
  89. [AC_MSG_ERROR(only one ed25519 implementation can be defined)])
  90. ed25519impl="amd64_51_30k"
  91. ],
  92. []
  93. )
  94. AC_ARG_ENABLE([amd64-64-24k],
  95. [AS_HELP_STRING([--enable-amd64-64-24k],
  96. [use SUPERCOP amd64-64-24k ed25519 implementation @<:@default=no@:>@])],
  97. [
  98. AS_IF([test x"$ed25519impl" != x"" -a "$ed25519impl" != "amd64_64_24k"],
  99. [AC_MSG_ERROR(only one ed25519 implementation can be defined)])
  100. ed25519impl="amd64_64_24k"
  101. ],
  102. []
  103. )
  104. AC_ARG_ENABLE([donna],
  105. [AS_HELP_STRING([--enable-donna],
  106. [use ed25519-donna implementation @<:@default=yes@:>@])],
  107. [
  108. AS_IF([test x"$ed25519impl" != x"" -a "$ed25519impl" != "donna"],
  109. [AC_MSG_ERROR(only one ed25519 implementation can be defined)])
  110. ed25519impl="donna"
  111. ],
  112. []
  113. )
  114. AC_ARG_ENABLE([donna-sse2],
  115. [AS_HELP_STRING([--enable-donna-sse2],
  116. [use ed25519-donna SSE2 implementation @<:@default=no@:>@])],
  117. [
  118. AS_IF([test x"$ed25519impl" != x"" -a "$ed25519impl" != "donna-sse2"],
  119. [AC_MSG_ERROR(only one ed25519 implementation can be defined)])
  120. ed25519impl="donna-sse2"
  121. ],
  122. []
  123. )
  124. # default
  125. AS_IF([test x"$ed25519impl" = x""],[ed25519impl="donna"])
  126. if test "$ed25519impl" = "donna-sse2"
  127. then
  128. ed25519impl="donna"
  129. MYDEFS="$MYDEFS -DED25519_SSE2"
  130. CFLAGS="$CFLAGS -msse2"
  131. fi
  132. AC_ARG_ENABLE([intfilter],
  133. [AS_HELP_STRING([--enable-intfilter@<:@=(32|64|128|native)@:>@],
  134. [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@:>@])],
  135. [], [enable_intfilter=no]
  136. )
  137. AC_ARG_ENABLE([intfilter32],
  138. [AS_HELP_STRING([--enable-intfilter32], [deprecated. use --enable-intfilter=32 instead])],
  139. [enable_intfilter=32]
  140. [AC_MSG_WARN([--enable-intfilter32 option is deprecated. use --enable-intfilter=32 instead])],
  141. []
  142. )
  143. case "$enable_intfilter" in
  144. 32)
  145. intfiltertype="u32"
  146. ;;
  147. 64|yes)
  148. intfiltertype="u64"
  149. ;;
  150. 128)
  151. intfiltertype="unsigned __int128"
  152. ;;
  153. native)
  154. intfiltertype="size_t"
  155. ;;
  156. no|"")
  157. intfiltertype=""
  158. ;;
  159. *)
  160. AC_MSG_WARN([unrecognised intfilter type: $enable_intfilter])
  161. intfiltertype=""
  162. ;;
  163. esac
  164. if test -n "$intfiltertype"
  165. then
  166. MYDEFS="$MYDEFS -DINTFILTER -DIFT='$intfiltertype'"
  167. fi
  168. AC_ARG_ENABLE([batchnum],
  169. [AS_HELP_STRING([--enable-batchnum=number],
  170. [number of elements to batch when using -B @<:@default=2048@:>@])],
  171. [], []
  172. )
  173. if test -n "$enable_batchnum" -a x"$enable_batchnum" != x"no"
  174. then
  175. MYDEFS="$MYDEFS -DBATCHNUM=$enable_batchnum"
  176. fi
  177. cstd=""
  178. c99=""
  179. oldcflags="$CFLAGS"
  180. CFLAGS="-std=c99"
  181. AC_MSG_CHECKING([whether CC supports -std=c99])
  182. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([])],
  183. [AC_MSG_RESULT([yes])]
  184. [c99="yes"]
  185. [cstd="-std=c99"],
  186. [AC_MSG_RESULT([no])]
  187. )
  188. CFLAGS="$cstd -Wall"
  189. AC_MSG_CHECKING([whether CC supports -Wall])
  190. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([])],
  191. [AC_MSG_RESULT([yes])]
  192. [cstd="$cstd -Wall"],
  193. [AC_MSG_RESULT([no])]
  194. )
  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])]
  201. )
  202. # (negative) detection on clang fails without -Werror
  203. CFLAGS="$cstd -Wno-maybe-uninitialized -Werror"
  204. AC_MSG_CHECKING([whether CC supports -Wno-maybe-uninitialized])
  205. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([])],
  206. [AC_MSG_RESULT([yes])]
  207. [cstd="$cstd -Wno-maybe-uninitialized"],
  208. [AC_MSG_RESULT([no])]
  209. )
  210. if test x"$c99" = x"yes" -a x"$ed25519impl" != x"donna" -a x"$enable_intfilter" != x"128"
  211. then
  212. CFLAGS="$cstd -pedantic"
  213. AC_MSG_CHECKING([whether CC supports -pedantic])
  214. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([])],
  215. [AC_MSG_RESULT([yes])]
  216. [cstd="$cstd -pedantic"],
  217. [AC_MSG_RESULT([no])]
  218. )
  219. fi
  220. CFLAGS="$cstd -Wno-format -Wno-pedantic-ms-format -Werror"
  221. AC_MSG_CHECKING([whether CC supports and needs -Wno-format -Wno-pedantic-ms-format])
  222. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#ifndef _WIN32
  223. #error wants windows
  224. #endif]], [])],
  225. [AC_MSG_RESULT([yes])]
  226. [cstd="$cstd -Wno-format -Wno-pedantic-ms-format"],
  227. [AC_MSG_RESULT([no])]
  228. )
  229. if test x"$ed25519impl" = x"donna"
  230. then
  231. CFLAGS="$cstd -Wno-unused-function -Werror"
  232. AC_MSG_CHECKING([whether CC supports -Wno-unused-function])
  233. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([])],
  234. [AC_MSG_RESULT([yes])]
  235. [cstd="$cstd -Wno-unused-function"],
  236. [AC_MSG_RESULT([no])]
  237. )
  238. fi
  239. if test x"$ed25519impl" = x"amd64_64_24k"
  240. then
  241. CFLAGS="$cstd -Wno-unused-const-variable -Werror"
  242. AC_MSG_CHECKING([whether CC supports -Wno-unused-const-variable])
  243. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([])],
  244. [AC_MSG_RESULT([yes])]
  245. [cstd="$cstd -Wno-unused-const-variable"],
  246. [AC_MSG_RESULT([no])]
  247. )
  248. fi
  249. CFLAGS="$cstd -Wmissing-prototypes -Werror"
  250. AC_MSG_CHECKING([whether CC supports -Wmissing-prototypes])
  251. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([])],
  252. [AC_MSG_RESULT([yes])]
  253. [cstd="$cstd -Wmissing-prototypes"],
  254. [AC_MSG_RESULT([no])]
  255. )
  256. # XXX AC_LANG_PROGRAM produces unsuitable prototype so this check must be last one
  257. CFLAGS="$cstd -Wstrict-prototypes -Werror"
  258. AC_MSG_CHECKING([whether CC supports -Wstrict-prototypes])
  259. AC_COMPILE_IFELSE([AC_LANG_SOURCE([[int main(void) { return 0; }]])],
  260. [AC_MSG_RESULT([yes])]
  261. [cstd="$cstd -Wstrict-prototypes"],
  262. [AC_MSG_RESULT([no])]
  263. )
  264. CFLAGS="$oldcflags"
  265. AC_ARG_ENABLE([binfilterlen],
  266. [AS_HELP_STRING([--enable-binfilterlen=VAL],
  267. [set binary string filter length (if you don't use intfilter) @<:@default=32@:>@])],
  268. [], [enable_binfilterlen=no]
  269. )
  270. if test x"$enable_binfilterlen" != x"yes" -a x"$enable_binfilterlen" != x"no"
  271. then
  272. MYDEFS="$MYDEFS -DBINFILTERLEN=$enable_binfilterlen"
  273. fi
  274. AC_ARG_ENABLE([binsearch],
  275. [AS_HELP_STRING([--enable-binsearch],
  276. [enable binary search algoritm; MUCH faster if there are a lot of filters @<:@default=no@:>@])],
  277. [], [enable_binsearch=no]
  278. )
  279. if test x"$enable_binsearch" = x"yes"
  280. then
  281. MYDEFS="$MYDEFS -DBINSEARCH"
  282. fi
  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]
  287. )
  288. if test x"$enable_besort" = x"yes"
  289. then
  290. MYDEFS="$MYDEFS -DBESORT"
  291. fi
  292. AC_ARG_ENABLE([statistics],
  293. [AS_HELP_STRING([--enable-statistics],
  294. [collect statistics @<:@default=yes@:>@])],
  295. [], [enable_statistics=yes]
  296. )
  297. if test x"$enable_statistics" = x"yes"
  298. then
  299. MYDEFS="$MYDEFS -DSTATISTICS"
  300. fi
  301. AC_ARG_WITH([pcre2],[AS_HELP_STRING([--with-pcre2],[pcre2-config executable @<:@default=pcre2-config@:>@])],[],[with_pcre2="pcre2-config"])
  302. AC_ARG_ENABLE([regex],[AS_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])
  303. case "$enable_regex" in
  304. no|"")
  305. ;;
  306. yes|pcre2)
  307. AC_MSG_CHECKING([pcre2])
  308. V=""
  309. if test "$with_pcre2" != "yes"
  310. then
  311. V=`"$with_pcre2" --version 2>/dev/null`
  312. fi
  313. if test -n "$V"
  314. then
  315. AC_MSG_RESULT([$V])
  316. MYDEFS="$MYDEFS -DPCRE2FILTER"
  317. CF=`"$with_pcre2" --cflags`
  318. if test -n "$CF"
  319. then
  320. CFLAGS="$CFLAGS $CF"
  321. fi
  322. LF=`"$with_pcre2" --libs8`
  323. if test -n "$LF"
  324. then
  325. MAINLIB="$MAINLIB $LF"
  326. fi
  327. else
  328. AC_MSG_RESULT([not found])
  329. AC_MSG_ERROR(pcre2-config cannot be executed)
  330. fi
  331. ;;
  332. *)
  333. AC_MSG_WARN([unrecognised regex engine type: $enable_regex])
  334. ;;
  335. esac
  336. AC_MSG_CHECKING([whether ARGON2ID13 is supported by libsodium])
  337. AC_COMPILE_IFELSE(
  338. [AC_LANG_PROGRAM(
  339. [[#include <sodium/crypto_pwhash.h>]],
  340. [[int alg = crypto_pwhash_ALG_ARGON2ID13;(void) alg;]]
  341. )],
  342. [AC_MSG_RESULT([yes])]
  343. [MYDEFS="$MYDEFS -DPASSPHRASE"],
  344. [AC_MSG_RESULT([no])]
  345. )
  346. # recreate dir tree, because otherwise gcc will fuck up
  347. (cd "$srcdir" && find ed25519 -type d) | xargs mkdir -p
  348. AC_SUBST(CSTD,["$cstd"])
  349. AC_SUBST(ED25519IMPL,["$ed25519impl"])
  350. AC_SUBST(MYDEFS,["$MYDEFS"])
  351. AC_SUBST(MAINLIB,["$MAINLIB"])
  352. AC_SUBST(PIE,["$pie"])
  353. AC_SUBST(SRCDIR,["$srcdir"])
  354. AC_SUBST(VERSION,["$ver"])
  355. AC_CONFIG_FILES([GNUmakefile])
  356. AC_OUTPUT