1AC_INIT(m4ri,20200125)
2
3AC_CANONICAL_HOST
4
5AC_CONFIG_SRCDIR(m4ri/brilliantrussian.c)
6
7AM_INIT_AUTOMAKE
8
9dnl Include maintainer mode targets.
10AM_MAINTAINER_MODE
11
12dnl Needed when reconfiguring with 'autoreconf -i -s'
13AC_CONFIG_MACRO_DIR([m4])
14
15dnl Compiling with per-target flags (test_elimination.c) requires AM_PROG_CC_C_O.
16AM_PROG_CC_C_O
17
18LT_INIT
19
20AC_PROG_INSTALL
21
22AC_CONFIG_HEADERS(m4ri/config.h)
23
24AC_PROG_CC_C99()
25if test "$ac_cv_prog_cc_c99" = "no"; then
26  AC_MSG_ERROR([C99 support is required but not found.])
27fi
28
29# Find and set LIBM on the platform.
30LT_LIB_M
31AC_SUBST(LIBM)
32
33# SSE2 support
34AC_ARG_ENABLE([sse2],
35        AS_HELP_STRING([--disable-sse2], [don't use SSE2 instruction set.]),
36	, [if test "$m4ri_wrapword" = "yes"; then enable_sse2="no"; else enable_sse2="yes"; fi])
37
38AS_IF([test "x$enable_sse2" != "xno"], [
39   if test "$m4ri_wrapword" = "yes"; then
40      AC_MSG_ERROR([SSE2 cannot be supported when wrapping word in a C++ class.])
41   fi
42   case $host_cpu in i[[3456]]86*|x86_64*)
43          AX_EXT()
44   esac
45])
46if test x"$ax_cv_have_sse2_ext" = x"yes"; then
47  M4RI_HAVE_SSE2=1
48else
49  M4RI_HAVE_SSE2=0
50fi
51AC_SUBST(M4RI_HAVE_SSE2)
52
53
54AC_ARG_WITH(papi,
55    AS_HELP_STRING([--with-papi@<:@=PATH@:>@], [The PAPI install prefix, if configure can't find it.]),
56    [m4ri_config_papi=$withval])
57
58AC_ARG_WITH(cachesize,
59        AS_HELP_STRING([--with-cachesize@<:@=VALUE@:>@], [L1,L2 and L3 cache sizes in bytes, separated by a colon. Overrides cache tuning.]),[m4ri_config_cachesize=$withval])
60
61AC_CHECK_HEADER([mm_malloc.h],AC_DEFINE(HAVE_MM_MALLOC,,[Support aligned allocations]),)
62if test "$ac_cv_header_mm_malloc_h" = "yes"; then
63  M4RI_HAVE_MM_MALLOC=1
64else
65  M4RI_HAVE_MM_MALLOC=0
66fi
67AC_SUBST(M4RI_HAVE_MM_MALLOC)
68
69# Correctly working posix_memalign
70AX_FUNC_POSIX_MEMALIGN
71if test "$ax_cv_func_posix_memalign_works" = "yes"; then
72  M4RI_HAVE_POSIX_MEMALIGN=1
73else
74  M4RI_HAVE_POSIX_MEMALIGN=0
75fi
76AC_SUBST(M4RI_HAVE_POSIX_MEMALIGN)
77
78# OpenMP support
79AC_ARG_ENABLE([openmp],
80        AS_HELP_STRING( [--enable-openmp],[add support for OpenMP multicore support.]))
81
82AS_IF([test "x$enable_openmp" = "xyes"], [
83   AX_OPENMP()
84])
85AC_SUBST(OPENMP_CFLAGS)
86if test -n "$OPENMP_CFLAGS"; then
87  M4RI_HAVE_OPENMP=1
88else
89  M4RI_HAVE_OPENMP=0
90fi
91AC_SUBST(M4RI_HAVE_OPENMP)
92
93
94# Thread-Safety
95M4RI_ENABLE_MZD_CACHE=1
96M4RI_ENABLE_MMC=1
97
98AC_ARG_ENABLE([thread-safe],
99	AS_HELP_STRING([--enable-thread-safe], [make library thread safe.]))
100
101if test "x$enable_thread_safe" = "xyes"; then
102  M4RI_ENABLE_MMC=0
103  M4RI_ENABLE_MZD_CACHE=0
104fi
105
106if test $M4RI_HAVE_OPENMP = 1; then
107  M4RI_ENABLE_MZD_CACHE=0
108fi
109
110AC_SUBST(M4RI_ENABLE_MZD_CACHE)
111AC_SUBST(M4RI_ENABLE_MMC)
112
113# Debugging support
114AC_ARG_ENABLE([debug],
115	AS_HELP_STRING([--enable-debug], [enable assert() statements for debugging.]))
116
117AC_ARG_ENABLE([debug-dump],
118        AS_HELP_STRING([--enable-debug-dump], [dump output at exit of every function.]))
119
120if test "x$enable_debug_dump" = "xyes"; then
121  M4RI_DEBUG_DUMP=1
122else
123  M4RI_DEBUG_DUMP=0
124fi
125AC_SUBST(M4RI_DEBUG_DUMP)
126
127AC_ARG_ENABLE([debug-mzd],
128        AS_HELP_STRING([--enable-debug-mzd], [add consistency checks on matrix structures.]))
129
130if test "x$enable_debug_mzd" = "xyes"; then
131  M4RI_DEBUG_MZD=1
132else
133  M4RI_DEBUG_MZD=0
134fi
135AC_SUBST(M4RI_DEBUG_MZD)
136
137if test "x$enable_debug" = x"yes"; then
138  DEBUG_FLAGS="-g"
139  AC_SUBST(DEBUG_FLAGS)
140else
141  if test "x$enable_debug_mzd" != "xyes"; then
142    AC_DEFINE(NDEBUG,1,[define whether debugging is enabled])
143  fi
144fi
145
146# For tests. Detect if PAPI is installed. See http://icl.cs.utk.edu/papi/ .
147
148if test -z "$m4ri_config_papi"; then
149   AC_CHECK_LIB(papi, PAPI_start_counters,
150   [
151    AX_GUESS_PATH_LIB(papi)
152    AX_GUESS_PATH_HEADER(papi.h)
153    if test -n "$LIBPAPI_PATH"; then
154       PAPI_LDFLAGS="-Wl,-rpath,$LIBPAPI_PATH"
155       PAPI_LIBS="-L$LIBPAPI_PATH -lpapi"
156    else
157        PAPI_LIBS="-lpapi"
158        if ! test -e "/usr/lib/libpapi.so"; then
159           AC_MSG_WARN([Could not find libpapi.so. Use --with-papi=<install_prefix> or set LD_LIBRARY_PATH correctly before running benchmark applications.])
160        fi
161    fi
162    if test -n "$PAPI_H_PATH"; then
163       PAPI_CFLAGS="-I$PAPI_H_PATH"
164       AC_DEFINE_UNQUOTED([HAVE_LIBPAPI], 1, [Define when libpapi is available.])
165    else
166      AC_MSG_WARN([Could not find papi.h; Use --with-papi=<install_prefix> or add -I<install_prefix>/include to either CPPFLAGS
167                    or CFLAGS, or turn off papi all together by configuring with --without-papi.])
168    fi
169])
170fi
171
172if test x"$m4ri_config_papi" != x"no" && test -n "$m4ri_config_papi"; then
173    LIBPAPI_PATH="`realpath -s $m4ri_config_papi/lib`"
174    PAPI_H_PATH="`realpath -s $m4ri_config_papi/include`"
175    PAPI_CFLAGS="-I$PAPI_H_PATH"
176    PAPI_LDFLAGS="-Wl,-rpath,$LIBPAPI_PATH"
177    PAPI_LIBS="-L$LIBPAPI_PATH -lpapi"
178    AC_DEFINE_UNQUOTED([HAVE_LIBPAPI], 1, [Define when libpapi is available.])
179fi
180
181AC_SUBST(PAPI_LIBS)
182AC_SUBST(PAPI_LDFLAGS)
183AC_SUBST(PAPI_CFLAGS)
184
185AC_ARG_ENABLE([cachetune],
186     AS_HELP_STRING([--enable-cachetune],[calculate cache size from timing information (deprecated).]))
187
188# Cache Sizes
189if test -z $m4ri_config_cachesize; then
190   AX_CACHE_SIZE()
191   AS_IF([test "x$enable_cachetune" = "xyes"], [AC_MSG_WARN(--enable-cachetune is deprecated since it usually does not provide optimal parameters.) AX_CACHE_SIZE_TUNE()])
192else
193  AS_IF([test "x$enable_cachetune" = "xyes"], [AC_MSG_WARN(Ignoring cache tuning since --with-cachesize was given.)])
194
195  ax_l1_size=`echo $m4ri_config_cachesize | cut -d ":" -f 1`
196  ax_l2_size=`echo $m4ri_config_cachesize | cut -d ":" -f 2`
197  ax_l3_size=`echo $m4ri_config_cachesize | cut -d ":" -f 3`
198
199  M4RI_CPU_L1_CACHE=${ax_l1_size}
200  M4RI_CPU_L2_CACHE=${ax_l2_size}
201  M4RI_CPU_L3_CACHE=${ax_l3_size}
202  AC_SUBST(M4RI_CPU_L1_CACHE)
203  AC_SUBST(M4RI_CPU_L2_CACHE)
204  AC_SUBST(M4RI_CPU_L3_CACHE)
205
206fi
207
208# PNG
209
210have_libpng="no"
211AC_ARG_ENABLE([png],
212   [AC_HELP_STRING([--disable-png], [disable PNG support @<:@default=enabled@:>@])],
213   [
214    if test "x${enableval}" = "xyes" ; then
215       want_png="yes"
216    else
217       want_png="no"
218    fi
219   ],
220   [want_png="yes"])
221
222AC_MSG_CHECKING([whether to build with PNG support])
223AC_MSG_RESULT([${want_png}])
224
225if test "x${want_png}" = "xyes" ; then
226   PKG_CHECK_MODULES([PNG], [libpng],
227      [have_libpng="yes";
228       LIBPNG_LIBADD=${PNG_LIBS};
229       M4RI_USE_PNG_PC=libpng],
230      [have_libpng="no"])
231   if ! test "x${have_libpng}" = "xyes" ; then
232      AC_CHECK_LIB([png],
233         [png_create_write_struct],
234         [have_libpng="yes"; LIBPNG_LIBADD="-lpng"],
235         [AC_CHECK_LIB([png14],
236            [png_create_write_struct],
237            [have_libpng="yes"; LIBPNG_LIBADD="-lpng14"],
238            [AC_CHECK_LIB([png12],
239               [png_create_write_struct],
240               [have_libpng="yes"; LIBPNG_LIBADD="-lpng12"],
241               [AC_CHECK_LIB([png10],
242                  [png_create_write_struct],
243                  [have_libpng="yes"; LIBPNG_LIBADD="-lpng10"],
244                  [have_libpng="no"])
245               ])
246            ])
247        ])
248       RAW_LIBPNG=${LIBPNG_LIBADD}
249   fi
250   if test "x${have_libpng}" = "xno" ; then
251      AC_MSG_WARN([Can not find a usuable PNG library. Make sure that CPPFLAGS and LDFLAGS are correctly set.])
252   fi
253fi
254
255if test "x${have_libpng}" = "xyes" ; then
256   M4RI_HAVE_LIBPNG=1
257   AC_SUBST(M4RI_HAVE_LIBPNG)
258   AC_SUBST(LIBPNG_LIBADD)
259   AC_SUBST(M4RI_USE_PNG_PC)
260   AC_SUBST(RAW_LIBPNG)
261else
262   M4RI_HAVE_LIBPNG=0
263   AC_SUBST(M4RI_HAVE_LIBPNG)
264fi
265
266M4RI_BUILDING_M4RI=1
267AC_DEFINE([M4RI_BUILDING_M4RI], [1], [Define to indicate that m4ri is being built instead of being used])
268
269RELEASE="AC_PACKAGE_VERSION"
270AC_SUBST(RELEASE)
271
272AC_PROG_MAKE_SET
273
274AC_CONFIG_FILES([Makefile tests/Makefile bench/Makefile m4ri/m4ri_config.h m4ri.pc])
275AC_OUTPUT
276
277