configure.ac 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. # configure.ac - process this file with autoconf to produce a configure script
  2. # Copyright (C) 2015-2021 Alex Vong <alexvong1995 AT protonmail DOT com>
  3. #
  4. # This program is free software; you can redistribute it and/or
  5. # modify it under the terms of the GNU General Public License
  6. # as published by the Free Software Foundation; either version 2
  7. # of the License, or (at your option) any later version.
  8. #
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. # GNU General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU General Public License
  15. # along with this program; if not, write to the Free Software Foundation,
  16. # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  17. # prelude
  18. AC_PREREQ([2.69])
  19. AC_INIT([Mlucas],
  20. [20.1.1],
  21. [ewmayer AT aol DOT com],
  22. [mlucas],
  23. [https://www.mersenneforum.org/mayer/README.html])
  24. AC_CONFIG_SRCDIR([upstream/src/Mlucas.c])
  25. AC_CONFIG_AUX_DIR([build-aux])
  26. AC_CONFIG_MACRO_DIR([m4])
  27. AM_INIT_AUTOMAKE([-Wall -Werror foreign subdir-objects serial-tests])
  28. # find tools
  29. AC_PROG_SED
  30. AC_CHECK_PROGS([CHMOD], [chmod])
  31. AS_IF([test x"$CHMOD" != 'xchmod'], [AC_MSG_ERROR([cannot find program chmod])])
  32. AC_CHECK_PROGS([CP], [cp])
  33. AS_IF([test x"$CP" != 'xcp'], [AC_MSG_ERROR([cannot find program cp])])
  34. # find c compiler
  35. : "${CC:="$PTHREAD_CC"}"
  36. : "${CFLAGS:=""}"
  37. AC_PROG_CC
  38. # detect thread support
  39. AC_ARG_ENABLE([threads],
  40. [AS_HELP_STRING([--disable-threads],
  41. [disable thread support detection])])
  42. AS_IF([test "x$enable_threads" != 'xno'],
  43. [AX_PTHREAD([CC="$PTHREAD_CC"
  44. AC_DEFINE([USE_THREADS], [1])])])
  45. AM_CONDITIONAL([USE_THREADS], [test "x$ax_pthread_ok" = 'xyes'])
  46. # check for libraries
  47. AC_CHECK_HEADERS([math.h], [], AC_MSG_ERROR([cannot find header math.h]))
  48. AC_SEARCH_LIBS([cos], [m], [], AC_MSG_ERROR([cannot link with library libm]))
  49. AC_CHECK_HEADERS([gmp.h], [], AC_MSG_ERROR([cannot find header gmp.h]))
  50. AC_SEARCH_LIBS([__gmpz_init],
  51. [gmp],
  52. [],
  53. AC_MSG_ERROR([cannot link with library libgmp]))
  54. # enable Large File Support (useful on 32-bit systems)
  55. AC_SYS_LARGEFILE
  56. # allow user to set MLUCAS_DEFAULT_PATH to "$HOME/.mlucas.d/"
  57. AC_ARG_ENABLE([mlucas-default-path],
  58. [AS_HELP_STRING([--enable-mlucas-default-path],
  59. [set MLUCAS_DEFAULT_PATH (unset by default) to
  60. "$HOME/.mlucas.d/"])])
  61. AS_IF([test "x$enable_mlucas_default_path" = 'xyes'],
  62. [AC_DEFINE([MLUCAS_DEFAULT_PATH], ["$HOME/.mlucas.d/"])])
  63. # detect compiler features
  64. AC_ARG_ENABLE([compiler-features],
  65. [AS_HELP_STRING([[--enable-compiler-features[=feature[,...]]]],
  66. [list of compiler features to be detected
  67. (default to optimization,debugging,hardening
  68. if none is given)])])
  69. AC_ARG_ENABLE([compiler-features],
  70. [AS_HELP_STRING([--disable-compiler-features],
  71. [disable compiler features detection])])
  72. # check for optimization features
  73. # FIXME: workaround the following self-test error by disabling
  74. # link-time optimization for now despite the performance penalty
  75. # --8<---------------cut here---------------start------------->8---
  76. # ERROR: at line 457 of file upstream/src/mi64.c
  77. # Assertion failed: Nonzero carryout of nonoverlapping vector add!
  78. # --8<---------------cut here---------------end--------------->8---
  79. AS_IF([expr ",$enable_compiler_features," : '.*,optimization,' \
  80. '|' "x$enable_compiler_features" : 'xyes$' \
  81. '|' "x$enable_compiler_features" : 'x$' >/dev/null],
  82. [AX_APPEND_COMPILE_FLAGS([m4_normalize([-pipe
  83. -O2 -O3 -Ofast
  84. -ftree-vectorize
  85. -floop-nest-optimize
  86. -fomit-frame-pointer])],
  87. [OPTCFLAGS])])
  88. # check for debugging features
  89. AS_IF([expr ",$enable_compiler_features," : '.*,debugging,' \
  90. '|' "x$enable_compiler_features" : 'xyes$' \
  91. '|' "x$enable_compiler_features" : 'x$' >/dev/null],
  92. [AX_APPEND_COMPILE_FLAGS([-g -g3], [DEBUGCFLAGS])])
  93. # check for hardening features
  94. AS_IF([expr ",$enable_compiler_features," : '.*,hardening,' \
  95. '|' "x$enable_compiler_features" : 'xyes$' \
  96. '|' "x$enable_compiler_features" : 'x$' >/dev/null],
  97. [AC_DEFINE([_FORTIFY_SOURCE], [2])
  98. AX_APPEND_COMPILE_FLAGS([m4_normalize([-fstack-protector-strong
  99. -fstack-clash-protection
  100. -fwrapv])],
  101. [HARDENCFLAGS])
  102. AX_APPEND_LINK_FLAGS([-Wl,-z,relro -Wl,-z,now -Wl,--as-needed],
  103. [HARDENLDFLAGS])])
  104. # allow user to specify build variants
  105. AC_ARG_ENABLE([builds],
  106. [AS_HELP_STRING([[--enable-builds[=build[,...]]]],
  107. [list of build variants to be enabled
  108. (default to generic-c,sse2 for x86 host,
  109. generic-c,sse2,avx,avx2,avx512 for x86_64 host,
  110. generic-c,arm-v8-simd for aarch64 host
  111. if none is given)])])
  112. # detect host
  113. AC_CANONICAL_HOST
  114. AS_CASE(["$host_cpu"],
  115. [i?86],
  116. [AC_DEFINE([CPU_IS_X86], [1])
  117. AX_APPEND_COMPILE_FLAGS([-m32], [ARCHCFLAGS])],
  118. [x86_64],
  119. [AX_APPEND_COMPILE_FLAGS([-m64], [ARCHCFLAGS])],
  120. [aarch64],
  121. [AX_APPEND_COMPILE_FLAGS([-march=armv8-a], [ARCHCFLAGS])])
  122. # build variants
  123. AM_CONDITIONAL([BUILD_GENERIC_C],
  124. [expr ",$enable_builds," : '.*,generic-c,' \
  125. '|' "x$enable_builds" : 'xyes$' \
  126. '|' "x$enable_builds" : 'x$' >/dev/null])
  127. AM_CONDITIONAL([BUILD_SSE2],
  128. [expr ",$enable_builds," : '.*,sse2,' \
  129. '|' '(' '(' "x$host_cpu" : 'xi.86$' \
  130. '|' "x$host_cpu" : 'xx86_64$' ')' \
  131. '&' '(' "x$enable_builds" : 'xyes$' \
  132. '|' "x$enable_builds" : 'x$' ')' ')' \
  133. >/dev/null])
  134. AM_CONDITIONAL([BUILD_AVX],
  135. [expr ",$enable_builds," : '.*,avx,' \
  136. '|' '(' "x$host_cpu" : 'xx86_64$' \
  137. '&' '(' "x$enable_builds" : 'xyes$' \
  138. '|' "x$enable_builds" : 'x$' ')' ')' \
  139. >/dev/null])
  140. AM_CONDITIONAL([BUILD_AVX2],
  141. [expr ",$enable_builds," : '.*,avx2,' \
  142. '|' '(' "x$host_cpu" : 'xx86_64$' \
  143. '&' '(' "x$enable_builds" : 'xyes$' \
  144. '|' "x$enable_builds" : 'x$' ')' ')' \
  145. >/dev/null])
  146. AM_CONDITIONAL([BUILD_AVX512],
  147. [expr ",$enable_builds," : '.*,avx512,' \
  148. '|' '(' "x$host_cpu" : 'xx86_64$' \
  149. '&' '(' "x$enable_builds" : 'xyes$' \
  150. '|' "x$enable_builds" : 'x$' ')' ')' \
  151. >/dev/null])
  152. AM_CONDITIONAL([BUILD_ARM_V8_SIMD],
  153. [expr ",$enable_builds," : '.*,arm-v8-simd,' \
  154. '|' '(' "x$host_cpu" : 'xaarch64$' \
  155. '&' '(' "x$enable_builds" : 'xyes$' \
  156. '|' "x$enable_builds" : 'x$' ')' ')' \
  157. >/dev/null])
  158. # flags used by Makefile.am
  159. AC_SUBST([EXTRACFLAGS],
  160. ["$PTHREAD_CFLAGS $OPTCFLAGS $DEBUGCFLAGS $HARDENCFLAGS $ARCHCFLAGS"])
  161. AC_SUBST([EXTRALDFLAGS], ["$HARDENLDFLAGS"])
  162. AC_SUBST([EXTRALIBS], ["$PTHREAD_LIBS"])
  163. # deprecated options
  164. AC_ARG_ENABLE([verbose-compiler],
  165. [AS_HELP_STRING([--enable-verbose-compiler],
  166. [ignored and will be removed in the future])])
  167. AS_CASE(["$enable_verbose_compiler"],
  168. [?*],
  169. [AC_MSG_WARN([m4_normalize([--enable-verbose-compiler is ignored and
  170. will be removed in the future])])])
  171. AC_ARG_ENABLE([instruction],
  172. [AS_HELP_STRING([--enable-instruction],
  173. [ignored and will be removed in the future])])
  174. AS_CASE(["$enable_instruction"],
  175. [?*],
  176. [AC_MSG_WARN([m4_normalize([--enable-instruction is ignored and will be
  177. removed in the future])])])
  178. AC_ARG_ENABLE([MLUCAS-DEFAULT-PATH],
  179. [AS_HELP_STRING([--enable-MLUCAS-DEFAULT-PATH],
  180. [ignored and will be removed in the future])])
  181. AS_CASE(["$enable_MLUCAS_DEFAULT_PATH"],
  182. [?*],
  183. [AC_MSG_WARN([m4_normalize([--enable-MLUCAS-DEFAULT-PATH is ignored and
  184. will be removed in the future])])])
  185. # postlude
  186. AC_CONFIG_FILES([Makefile])
  187. AC_OUTPUT