Fix: configure.ac: check for possibly required libs for clock_gettime
[urcu.git] / configure.ac
1 AC_PREREQ(2.59)
2 AC_INIT([userspace-rcu],[0.9.0],[mathieu dot desnoyers at efficios dot com], [], [http://liburcu.org/])
3
4 # Following the numbering scheme proposed by libtool for the library version
5 # http://www.gnu.org/software/libtool/manual/html_node/Updating-version-info.html
6 AC_SUBST([URCU_LIBRARY_VERSION], [4:0:0])
7
8 AC_CONFIG_SRCDIR([urcu.h])
9 AC_CONFIG_HEADERS([config.h urcu/config.h])
10 AC_CONFIG_AUX_DIR([config])
11 AC_CONFIG_MACRO_DIR([m4])
12
13 AC_CANONICAL_TARGET
14 AC_CANONICAL_HOST
15
16 AM_INIT_AUTOMAKE([foreign dist-bzip2 no-dist-gzip])
17 AM_MAINTAINER_MODE([enable])
18
19 # Enable silent rules if available (Introduced in AM 1.11)
20 m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
21
22 AH_TEMPLATE([CONFIG_RCU_SMP], [Enable SMP support. With SMP support enabled, uniprocessors are also supported. With SMP support disabled, UP systems work fine, but the behavior of SMP systems is undefined.])
23 AH_TEMPLATE([CONFIG_RCU_HAVE_FENCE], [Defined when on a system that has memory fence instructions.])
24 AH_TEMPLATE([CONFIG_RCU_HAVE_FUTEX], [Defined when on a system with futex support.])
25 AH_TEMPLATE([CONFIG_RCU_COMPAT_ARCH], [Compatibility mode for i386 which lacks cmpxchg instruction.])
26 AH_TEMPLATE([CONFIG_RCU_ARM_HAVE_DMB], [Use the dmb instruction if available for use on ARM.])
27 AH_TEMPLATE([CONFIG_RCU_TLS], [TLS provided by the compiler.])
28
29 # Allow overriding storage used for TLS variables.
30 AC_ARG_ENABLE([compiler-tls],
31 AS_HELP_STRING([--disable-compiler-tls], [Use pthread_getspecific() to emulate Thread Local Storage (TLS) variables.]),
32 [def_compiler_tls=$enableval],
33 [def_compiler_tls="yes"])
34
35 # If not overridden, use ax_tls.m4 to check if TLS is available.
36 AS_IF([test "x$def_compiler_tls" = "xyes"],
37 [AX_TLS([def_tls_detect=$ac_cv_tls], [:])],
38 [:])
39
40 AS_IF([test "x$def_tls_detect" = "x"],
41 [:],
42 [AC_DEFINE_UNQUOTED([CONFIG_RCU_TLS], $def_tls_detect)])
43
44 # Checks for C compiler
45 AC_USE_SYSTEM_EXTENSIONS
46 AC_PROG_CC
47 AC_PROG_CC_STDC
48
49 # Checks for programs.
50 AC_PROG_AWK
51 AC_PROG_MAKE_SET
52 AC_CHECK_PROGS(NPROC, [nproc gnproc])
53 LT_INIT
54
55 # Checks for typedefs, structures, and compiler characteristics.
56 AC_C_INLINE
57 AC_TYPE_PID_T
58 AC_TYPE_SIZE_T
59 AC_TYPE_SSIZE_T
60 AC_TYPE_UINT16_T
61 AC_TYPE_INT32_T
62 AC_TYPE_UINT32_T
63 AC_TYPE_UINT64_T
64 AC_TYPE_UINT8_T
65
66 AX_C___ATTRIBUTE__
67 AS_IF([test "x$ax_cv___attribute__" = "xyes"],
68 [:],
69 [AC_MSG_ERROR([The compiler does not support __attribute__ extensions])])
70
71 AX_PTHREAD(,[AC_MSG_ERROR([Could not configure pthreads support])])
72 LIBS="$PTHREAD_LIBS $LIBS"
73 CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
74 CC="$PTHREAD_CC"
75
76 # Checks for library functions.
77 AC_FUNC_MALLOC
78 AC_FUNC_MMAP
79 AC_FUNC_FORK
80 AC_CHECK_FUNCS([ \
81 atexit \
82 getcpuid \
83 gettid \
84 gettimeofday \
85 memeset \
86 memset \
87 munmap \
88 sched_getcpu \
89 strerror \
90 strtoul \
91 sysconf \
92 ])
93
94 # Check for headers
95 AC_HEADER_STDBOOL
96 AC_CHECK_HEADERS([ \
97 limits.h \
98 stddef.h \
99 sys/param.h \
100 sys/time.h \
101 ])
102
103 # Find arch type
104 AS_CASE([$host_cpu],
105 [k1om], [ARCHTYPE="x86"],
106 [i386], [ARCHTYPE="x86" && SUBARCHTYPE="x86compat"],
107 [i486], [ARCHTYPE="x86"],
108 [i586], [ARCHTYPE="x86"],
109 [i686], [ARCHTYPE="x86"],
110 [amd64], [ARCHTYPE="x86"],
111 [x86_64], [ARCHTYPE="x86"],
112 [powerpc], [ARCHTYPE="ppc"],
113 [ppc64], [ARCHTYPE="ppc"],
114 [powerpc64], [ARCHTYPE="ppc"],
115 [powerpc64le], [ARCHTYPE="ppc"],
116 [ppc], [ARCHTYPE="ppc"],
117 [s390], [ARCHTYPE="s390"],
118 [s390x], [ARCHTYPE="s390"],
119 [sparc], [ARCHTYPE="sparc64"],
120 [sparc64], [ARCHTYPE="sparc64"],
121 [alpha*], [ARCHTYPE="alpha"],
122 [ia64], [ARCHTYPE="ia64"],
123 [arm*], [ARCHTYPE="arm"],
124 [aarch64], [ARCHTYPE="aarch64"],
125 [mips*], [ARCHTYPE="mips"],
126 [nios2*], [ARCHTYPE="nios2"],
127 [tile*], [ARCHTYPE="tile"],
128 [hppa*], [ARCHTYPE="hppa"],
129 [ARCHTYPE="unknown"]
130 )
131
132 AS_CASE([$host],[*-*-linux-androideabi],
133 [AM_CONDITIONAL(TARGET_IS_ANDROID, true)],
134 [AM_CONDITIONAL(TARGET_IS_ANDROID, false)]
135 )
136
137 AC_SUBST(ARCHTYPE)
138 AC_SUBST(SUBARCHTYPE)
139
140 UATOMICSRC=urcu/uatomic/$ARCHTYPE.h
141 ARCHSRC=urcu/arch/$ARCHTYPE.h
142
143 AS_IF([test "x$SUBARCHTYPE" = xx86compat],[
144 AC_DEFINE([CONFIG_RCU_COMPAT_ARCH], [1])
145 ])
146
147 AS_IF([test "$host_cpu" = "armv7l"],[
148 CFLAGS="$CFLAGS -mcpu=cortex-a9 -mtune=cortex-a9 -O1"
149 ])
150
151 # ARM-specific checks
152 AS_IF([test "x$ARCHTYPE" = "xarm"],[
153 AC_MSG_CHECKING([for dmb instruction])
154 AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
155 int main()
156 {
157 asm volatile("dmb":::"memory");
158 return 0;
159 }
160 ]])
161 ],[
162 AC_MSG_RESULT([yes])
163 AC_DEFINE([CONFIG_RCU_ARM_HAVE_DMB], [1])
164 ],[
165 AC_MSG_RESULT([no])
166 ])
167 ])
168
169 # Tile-specific checks
170 AS_IF([echo "$host_cpu" | grep "^tile"],[
171 AC_MSG_CHECKING([for Tile architecture type])
172 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
173 #ifndef __tilegx__
174 #error
175 #endif
176 ]])
177 ],[
178 AC_MSG_RESULT([ok])
179 ],[
180 AC_MSG_FAILURE([URCU has only been tested on the TileGx architecture. For other Tile* architectures, please run the tests first and report the results to the maintainer so that proper support can be added.])
181 ])
182 ])
183
184 # x86-specific checks
185 AS_IF([test "x$ARCHTYPE" = "xx86"],[
186 AC_MSG_CHECKING([if architecture really supports the mfence instruction])
187 #For now, using lock; addl compatibility mode even for i686, because the
188 #Pentium III is seen as a i686, but lacks mfence instruction.
189 #Only using fence for x86_64.
190 #
191 #k1om is the name for the Intel MIC family (Xeon Phi). It is an x86_64
192 #variant but lacks fence instructions.
193 AS_IF([test "x$host_cpu" != "xi386" -a "x$host_cpu" != "xi486" -a "x$host_cpu" != "xi586" -a "x$host_cpu" != "xi686" -a "x$host_vendor" != "xk1om" -a "x$host_cpu" != "xk1om"],[
194 AC_MSG_RESULT([yes])
195 AC_DEFINE([CONFIG_RCU_HAVE_FENCE], [1])
196 ],[
197 AC_MSG_RESULT([no])
198 ])
199 ])
200
201 # Check if sys_futex() is available
202 AC_MSG_CHECKING([for sys_futex()])
203 AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
204 #include <sys/syscall.h>
205 #ifndef __NR_futex
206 #error "futexes not available"
207 #endif
208 ]])
209 ],[
210 AC_MSG_RESULT([yes])
211 AC_DEFINE([CONFIG_RCU_HAVE_FUTEX], [1])
212 compat_futex_test=0
213 ],[
214 AC_MSG_RESULT([no])
215 compat_futex_test=1
216 ])
217
218 # Search for clock_gettime
219 AC_SEARCH_LIBS([clock_gettime], [rt], [],
220 [AC_MSG_ERROR([Cannot find clock_gettime function.])]
221 )
222
223 # Check for pthread
224 AC_CHECK_LIB([pthread], [pthread_create],
225 [AM_CONDITIONAL(LIBC_INCLUDES_PTHREAD, false)],
226 [AC_CHECK_LIB([c], [pthread_create],
227 [AM_CONDITIONAL(LIBC_INCLUDES_PTHREAD, true)],
228 [AC_MSG_ERROR([Cannot find libpthread. Use [LDFLAGS]=-Ldir to specify its location.])]
229 )]
230 )
231
232 AM_CONDITIONAL([COMPAT_FUTEX], [test "x$compat_futex_test" = "x1"])
233 AM_CONDITIONAL([COMPAT_ARCH], [test "x$SUBARCHTYPE" = "xx86compat"])
234 AM_CONDITIONAL([NO_SHARED], [test "x$enable_shared" = "xno"])
235
236 # smp-support configure option
237 AC_ARG_ENABLE([smp-support],
238 AS_HELP_STRING([--disable-smp-support], [Disable SMP support. Warning: only use this on uniprocessor systems. [default=enabled]]),
239 [def_smp_support=$enableval],
240 [def_smp_support="yes"])
241 AS_IF([test "x$def_smp_support" = "xyes"], [AC_DEFINE([CONFIG_RCU_SMP], [1])])
242
243
244 # From the sched_setaffinity(2)'s man page:
245 # ~~~~
246 # The CPU affinity system calls were introduced in Linux kernel 2.5.8.
247 # The library interfaces were introduced in glibc 2.3. Initially, the
248 # glibc interfaces included a cpusetsize argument. In glibc 2.3.3,
249 # the cpuset size argument was removed, but this argument was
250 # restored in glibc 2.3.4.
251 # ~~~~
252
253 # In addition to that, some vendors ported the system call to 2.4
254 # kernels.
255
256 # Furthermore, when the function first appeared, the MASK argument was
257 # an unsigned long pointer, while later it was made into a cpu_set_t
258 # pointer. Systems that have the cpu_set_t version also should have
259 # the CPU_ZERO, CPU_SET, etc. macros.
260
261 # All this mess means we have to cater for at least 3 different
262 # sched_setaffinity prototypes:
263
264 # ~~~~
265 # int sched_setaffinity (pid_t pid, unsigned int len, unsigned long *mask);
266 # int sched_setaffinity (pid_t __pid, size_t __cpusetsize, const cpu_set_t *__cpuset);
267 # int sched_setaffinity (pid_t __pid, const cpu_set_t *__mask);
268 # ~~~~
269
270 # Since we define _GNU_SOURCE in the sources, must do so too in the
271 # autoconf tests, as defining _GNU_SOURCE or not exposes
272 # sched_setaffinity bits differently.
273 saved_CFLAGS=$CFLAGS
274 CFLAGS="$CFLAGS -D_GNU_SOURCE"
275
276 AC_CHECK_TYPES([cpu_set_t],
277 [have_cpu_set_t="yes"],
278 [have_cpu_set_t="no"],
279 [#include <sched.h>])
280
281 # Confirm that we have CPU_ZERO, and it actually works.
282 AC_MSG_CHECKING([whether CPU_ZERO works])
283 AH_TEMPLATE([HAVE_CPU_ZERO], [Defined to 1 if we have CPU_ZERO and it works])
284 AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
285 #define _GNU_SOURCE
286 #include <sched.h>
287 int main()
288 {
289 cpu_set_t foo; CPU_ZERO(&foo);
290 return 0;
291 }
292 ]])
293 ],[
294 AC_DEFINE(HAVE_CPU_ZERO, 1)
295 AC_MSG_RESULT([yes])
296 ],[
297 AC_MSG_RESULT([no])
298 ])
299
300 # Confirm that we have CPU_SET, and it actually works.
301 AC_MSG_CHECKING([whether CPU_SET works])
302 AH_TEMPLATE([HAVE_CPU_SET], [Defined to 1 if we have CPU_SET and it works])
303 AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
304 #define _GNU_SOURCE
305 #include <sched.h>
306 int main()
307 {
308 cpu_set_t foo, mask; CPU_SET(0, &foo);
309 return 0;
310 }
311 ]])
312 ],[
313 AC_DEFINE(HAVE_CPU_SET, 1)
314 AC_MSG_RESULT([yes])
315 ],[
316 AC_MSG_RESULT([no])
317 ])
318
319 # First check if the function is available at all.
320 AC_CHECK_FUNCS([sched_setaffinity],[
321 # Okay, we have it. Check if also have cpu_set_t. If we don't,
322 # then we have the first version using unsigned long, and no
323 # CPU_ZERO, etc. macros. If we do have cpu_set_t, we may have the
324 # version with 2 or 3 arguments. In that case, CPU_ZERO, etc.,
325 # should also be present, but we confirm nonetheless.
326
327 AS_IF([test "x$have_cpu_set_t" = "xyes"], [
328 # We do have it.
329 # Check how many arguments does sched_setaffinity take.
330 # Should be 3 or 2.
331 AC_MSG_CHECKING([how many arguments sched_setaffinity takes])
332 AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
333 #include <sched.h>
334 int main()
335 {
336 cpu_set_t foo;
337 sched_setaffinity(0, sizeof (foo), &foo);
338 return 0;
339 }
340 ]])
341 ],
342 [sched_set_affinity_args=3],
343 [sched_set_affinity_args=2])
344 AC_DEFINE_UNQUOTED(SCHED_SETAFFINITY_ARGS,
345 $sched_set_affinity_args,
346 [Defined to sched_setaffinity's number of arguments.])
347 AC_MSG_RESULT([$sched_set_affinity_args])
348 ],[
349 # No cpu_set_t, always 3 args.
350 AC_DEFINE(SCHED_SETAFFINITY_ARGS, 3)
351 ])
352 ])
353
354 CFLAGS=$saved_CFLAGS
355
356 AC_CONFIG_LINKS([
357 urcu/arch.h:$ARCHSRC
358 urcu/uatomic.h:$UATOMICSRC
359 ])
360 AC_CONFIG_FILES([
361 Makefile
362 doc/Makefile
363 doc/examples/Makefile
364 tests/Makefile
365 tests/common/Makefile
366 tests/unit/Makefile
367 tests/benchmark/Makefile
368 tests/regression/Makefile
369 tests/regression/regression_tests
370 tests/utils/Makefile
371 liburcu.pc
372 liburcu-bp.pc
373 liburcu-cds.pc
374 liburcu-qsbr.pc
375 liburcu-mb.pc
376 liburcu-signal.pc
377 ])
378 AC_OUTPUT
379
380 # Report on selected configure options
381 AS_IF([test "x$def_smp_support" = "xyes"],[
382 AS_ECHO("SMP support enabled.")
383 ],[
384 AS_ECHO("SMP support disabled.")
385 ])
386
387 AS_IF([test "x$def_tls_detect" = "x"],[
388 AS_ECHO("Thread Local Storage (TLS): pthread_getspecific().")
389 ],[
390 AS_ECHO("Thread Local Storage (TLS): $def_tls_detect.")
391 ])
This page took 0.036878 seconds and 4 git commands to generate.