Whamcloud - gitweb
LU-3963 libcfs: convert md[d/t]/mg[c/s] to linux atomic primitives
[fs/lustre-release.git] / libcfs / autoconf / lustre-libcfs.m4
1 #
2 # LN_CONFIG_CDEBUG
3 #
4 # whether to enable various libcfs debugs (CDEBUG, ENTRY/EXIT, LASSERT, etc.)
5 #
6 AC_DEFUN([LN_CONFIG_CDEBUG],
7 [
8 AC_MSG_CHECKING([whether to enable CDEBUG, CWARN])
9 AC_ARG_ENABLE([libcfs_cdebug],
10         AC_HELP_STRING([--disable-libcfs-cdebug],
11                         [disable libcfs CDEBUG, CWARN]),
12         [],[enable_libcfs_cdebug='yes'])
13 AC_MSG_RESULT([$enable_libcfs_cdebug])
14 if test x$enable_libcfs_cdebug = xyes; then
15    AC_DEFINE(CDEBUG_ENABLED, 1, [enable libcfs CDEBUG, CWARN])
16 else
17    AC_DEFINE(CDEBUG_ENABLED, 0, [disable libcfs CDEBUG, CWARN])
18 fi
19
20 AC_MSG_CHECKING([whether to enable ENTRY/EXIT])
21 AC_ARG_ENABLE([libcfs_trace],
22         AC_HELP_STRING([--disable-libcfs-trace],
23                         [disable libcfs ENTRY/EXIT]),
24         [],[enable_libcfs_trace='yes'])
25 AC_MSG_RESULT([$enable_libcfs_trace])
26 if test x$enable_libcfs_trace = xyes; then
27    AC_DEFINE(CDEBUG_ENTRY_EXIT, 1, [enable libcfs ENTRY/EXIT])
28 else
29    AC_DEFINE(CDEBUG_ENTRY_EXIT, 0, [disable libcfs ENTRY/EXIT])
30 fi
31
32 AC_MSG_CHECKING([whether to enable LASSERT, LASSERTF])
33 AC_ARG_ENABLE([libcfs_assert],
34         AC_HELP_STRING([--disable-libcfs-assert],
35                         [disable libcfs LASSERT, LASSERTF]),
36         [],[enable_libcfs_assert='yes'])
37 AC_MSG_RESULT([$enable_libcfs_assert])
38 if test x$enable_libcfs_assert = xyes; then
39    AC_DEFINE(LIBCFS_DEBUG, 1, [enable libcfs LASSERT, LASSERTF])
40 fi
41 ])
42
43 #
44 # LIBCFS_CONFIG_PANIC_DUMPLOG
45 #
46 # check if tunable panic_dumplog is wanted
47 #
48 AC_DEFUN([LIBCFS_CONFIG_PANIC_DUMPLOG],
49 [AC_MSG_CHECKING([for tunable panic_dumplog support])
50 AC_ARG_ENABLE([panic_dumplog],
51        AC_HELP_STRING([--enable-panic_dumplog],
52                       [enable panic_dumplog]),
53        [],[enable_panic_dumplog='no'])
54 if test x$enable_panic_dumplog = xyes ; then
55        AC_DEFINE(LNET_DUMP_ON_PANIC, 1, [use dumplog on panic])
56        AC_MSG_RESULT([yes (by request)])
57 else
58        AC_MSG_RESULT([no])
59 fi
60 ])
61
62 # check kernel __u64 type
63 AC_DEFUN([LIBCFS_U64_LONG_LONG_LINUX],
64 [
65 AC_MSG_CHECKING([kernel __u64 is long long type])
66 tmp_flags="$EXTRA_KCFLAGS"
67 EXTRA_KCFLAGS="$EXTRA_KCFLAGS -Werror"
68 LB_LINUX_TRY_COMPILE([
69         #include <linux/types.h>
70         #include <linux/stddef.h>
71 ],[
72         unsigned long long *data;
73
74         data = (__u64*)sizeof(data);
75 ],[
76         AC_MSG_RESULT([yes])
77         AC_DEFINE(HAVE_KERN__U64_LONG_LONG, 1,
78                   [kernel __u64 is long long type])
79 ],[
80         AC_MSG_RESULT([no])
81 ])
82 EXTRA_KCFLAGS="$tmp_flags"
83 ])
84
85 #
86 # LIBCFS_STACKTRACE_OPS_HAVE_WALK_STACK
87 #
88 # 2.6.32-30.el6 adds a new 'walk_stack' field in 'struct stacktrace_ops'
89 #
90 AC_DEFUN([LIBCFS_STACKTRACE_OPS_HAVE_WALK_STACK],
91 [AC_MSG_CHECKING([if 'struct stacktrace_ops' has 'walk_stack' field])
92 LB_LINUX_TRY_COMPILE([
93         #include <asm/stacktrace.h>
94 ],[
95         ((struct stacktrace_ops *)0)->walk_stack(NULL, NULL, 0, NULL, NULL, NULL, NULL);
96 ],[
97         AC_MSG_RESULT([yes])
98         AC_DEFINE(STACKTRACE_OPS_HAVE_WALK_STACK, 1, ['struct stacktrace_ops' has 'walk_stack' field])
99 ],[
100         AC_MSG_RESULT([no])
101 ])
102 ])
103
104 #
105 # RHEL6/2.6.32 want to have pointer to shrinker self pointer in handler function
106 #
107 AC_DEFUN([LC_SHRINKER_WANT_SHRINK_PTR],
108 [AC_MSG_CHECKING([shrinker want self pointer in handler])
109 LB_LINUX_TRY_COMPILE([
110         #include <linux/mm.h>
111 ],[
112         struct shrinker *tmp = NULL;
113         tmp->shrink(tmp, 0, 0);
114 ],[
115         AC_MSG_RESULT(yes)
116         AC_DEFINE(HAVE_SHRINKER_WANT_SHRINK_PTR, 1,
117                   [shrinker want self pointer in handler])
118 ],[
119         AC_MSG_RESULT(no)
120 ])
121 ])
122
123 #
124 # 2.6.33 no longer has ctl_name & strategy field in struct ctl_table.
125 #
126 AC_DEFUN([LIBCFS_SYSCTL_CTLNAME],
127 [AC_MSG_CHECKING([if ctl_table has a ctl_name field])
128 LB_LINUX_TRY_COMPILE([
129         #include <linux/sysctl.h>
130 ],[
131         struct ctl_table ct;
132         ct.ctl_name = sizeof(ct);
133 ],[
134         AC_MSG_RESULT(yes)
135         AC_DEFINE(HAVE_SYSCTL_CTLNAME, 1,
136                   [ctl_table has ctl_name field])
137 ],[
138         AC_MSG_RESULT(no)
139 ])
140 ])
141
142 #
143 # LIBCFS_ADD_WAIT_QUEUE_EXCLUSIVE
144 #
145 # 2.6.34 adds __add_wait_queue_exclusive
146 #
147 AC_DEFUN([LIBCFS_ADD_WAIT_QUEUE_EXCLUSIVE],
148 [AC_MSG_CHECKING([if __add_wait_queue_exclusive exists])
149 LB_LINUX_TRY_COMPILE([
150         #include <linux/wait.h>
151 ],[
152         wait_queue_head_t queue;
153         wait_queue_t      wait;
154
155         __add_wait_queue_exclusive(&queue, &wait);
156 ],[
157         AC_MSG_RESULT(yes)
158         AC_DEFINE(HAVE___ADD_WAIT_QUEUE_EXCLUSIVE, 1,
159                   [__add_wait_queue_exclusive exists])
160 ],[
161         AC_MSG_RESULT(no)
162 ])
163 ])
164
165 #
166 # 2.6.35 kernel has sk_sleep function
167 #
168 AC_DEFUN([LC_SK_SLEEP],
169 [AC_MSG_CHECKING([if kernel has sk_sleep])
170 LB_LINUX_TRY_COMPILE([
171         #include <net/sock.h>
172 ],[
173         sk_sleep(NULL);
174 ],[
175         AC_MSG_RESULT(yes)
176         AC_DEFINE(HAVE_SK_SLEEP, 1, [kernel has sk_sleep])
177 ],[
178         AC_MSG_RESULT(no)
179 ],[
180 ])
181 ])
182
183 # 2.6.39 adds a base pointer address argument to dump_trace
184 AC_DEFUN([LIBCFS_DUMP_TRACE_ADDRESS],
185 [AC_MSG_CHECKING([dump_trace want address])
186 LB_LINUX_TRY_COMPILE([
187         struct task_struct;
188         struct pt_regs;
189         #include <asm/stacktrace.h>
190 ],[
191         dump_trace(NULL, NULL, NULL, 0, NULL, NULL);
192 ],[
193         AC_MSG_RESULT(yes)
194         AC_DEFINE(HAVE_DUMP_TRACE_ADDRESS, 1,
195                 [dump_trace want address argument])
196 ],[
197         AC_MSG_RESULT(no)
198 ],[
199 ])
200 ])
201
202 #
203 # FC15 2.6.40-5 backported the "shrink_control" parameter to the memory
204 # pressure shrinker from Linux 3.0
205 #
206 AC_DEFUN([LC_SHRINK_CONTROL],
207 [AC_MSG_CHECKING([shrink_control is present])
208 LB_LINUX_TRY_COMPILE([
209         #include <linux/mm.h>
210 ],[
211         struct shrink_control tmp = {0};
212         tmp.nr_to_scan = sizeof(tmp);
213 ],[
214         AC_MSG_RESULT(yes)
215         AC_DEFINE(HAVE_SHRINK_CONTROL, 1,
216                   [shrink_control is present])
217 ],[
218         AC_MSG_RESULT(no)
219 ])
220 ])
221
222 # 3.0 removes stacktrace_ops warning* functions
223 AC_DEFUN([LIBCFS_STACKTRACE_WARNING],
224 [AC_MSG_CHECKING([whether stacktrace_ops.warning is exist])
225 LB_LINUX_TRY_COMPILE([
226         struct task_struct;
227         struct pt_regs;
228         #include <asm/stacktrace.h>
229 ],[
230         ((struct stacktrace_ops *)0)->warning(NULL, NULL);
231 ],[
232         AC_MSG_RESULT(yes)
233         AC_DEFINE(HAVE_STACKTRACE_WARNING, 1, [stacktrace_ops.warning is exist])
234 ],[
235         AC_MSG_RESULT(no)
236 ],[
237 ])
238 ])
239
240 #
241 # FC18 3.7.2-201 unexport sock_map_fd() change to
242 # use sock_alloc_file().
243 # upstream commit 56b31d1c9f1e6a3ad92e7bfe252721e05d92b285
244 #
245 AC_DEFUN([LIBCFS_SOCK_ALLOC_FILE],
246 [AC_MSG_CHECKING([sock_alloc_file is exported])
247 LB_CHECK_SYMBOL_EXPORT([sock_alloc_file], [net/socket.c],[
248         LB_LINUX_TRY_COMPILE([
249                 #include <linux/net.h>
250         ],[
251                 sock_alloc_file(NULL, 0, NULL);
252         ],[
253                 AC_MSG_RESULT(yes)
254                 AC_DEFINE(HAVE_SOCK_ALLOC_FILE_3ARGS, 1,
255                         [sock_alloc_file takes 3 arguments])
256         ],[
257                 AC_MSG_RESULT(yes)
258                 AC_DEFINE(HAVE_SOCK_ALLOC_FILE, 1,
259                         [sock_alloc_file is exported])
260         ])
261 ],[
262 ])
263 ])
264
265 AC_DEFUN([LIBCFS_HAVE_CRC32],
266 [LB_LINUX_CONFIG_IM([CRC32],
267         [have_crc32=true],[have_crc32=false])
268 if test x$have_crc32 = xtrue; then
269         AC_DEFINE(HAVE_CRC32, 1, [kernel compiled with CRC32 functions])
270 fi
271 ])
272
273 AC_DEFUN([LIBCFS_ENABLE_CRC32_ACCEL],
274 [LB_LINUX_CONFIG_IM([CRYPTO_CRC32_PCLMUL],
275         [enable_crc32_crypto=false],[enable_crc32_crypto=true])
276 if test x$have_crc32 = xtrue -a x$enable_crc32_crypto = xtrue; then
277         AC_DEFINE(NEED_CRC32_ACCEL, 1, [need pclmulqdq based crc32])
278         AC_MSG_WARN([No crc32 pclmulqdq crypto api found,
279                     enable internal pclmulqdq based crc32])
280 fi
281 ])
282
283 AC_DEFUN([LIBCFS_ENABLE_CRC32C_ACCEL],
284 [LB_LINUX_CONFIG_IM([CRYPTO_CRC32C_INTEL],
285         [enable_crc32c_crypto=false],[enable_crc32c_crypto=true])
286 if test x$enable_crc32c_crypto = xtrue; then
287         AC_DEFINE(NEED_CRC32C_ACCEL, 1, [need pclmulqdq based crc32c])
288         AC_MSG_WARN([No crc32c pclmulqdq crypto api found,
289                     enable internal pclmulqdq based crc32c])
290 fi
291 ])
292
293 #
294 # LIBCFS_PROG_LINUX
295 #
296 # LNet linux kernel checks
297 #
298 AC_DEFUN([LIBCFS_PROG_LINUX],
299 [
300 LIBCFS_CONFIG_PANIC_DUMPLOG
301
302 LIBCFS_U64_LONG_LONG_LINUX
303 # 2.6.32
304 LIBCFS_STACKTRACE_OPS_HAVE_WALK_STACK
305 LC_SHRINKER_WANT_SHRINK_PTR
306 # 2.6.33
307 LIBCFS_SYSCTL_CTLNAME
308 # 2.6.34
309 LIBCFS_ADD_WAIT_QUEUE_EXCLUSIVE
310 # 2.6.35
311 LC_SK_SLEEP
312 # 2.6.39
313 LIBCFS_DUMP_TRACE_ADDRESS
314 # 2.6.40 fc15
315 LC_SHRINK_CONTROL
316 # 3.0
317 LIBCFS_STACKTRACE_WARNING
318 # 3.7
319 LIBCFS_SOCK_ALLOC_FILE
320 # 3.8
321 LIBCFS_HAVE_CRC32
322 LIBCFS_ENABLE_CRC32_ACCEL
323 # 3.10
324 LIBCFS_ENABLE_CRC32C_ACCEL
325 ])
326
327 #
328 # LIBCFS_PROG_DARWIN
329 #
330 # Darwin checks
331 #
332 AC_DEFUN([LIBCFS_PROG_DARWIN],
333 [LB_DARWIN_CHECK_FUNCS([get_preemption_level])
334 ])
335
336 #
337 # LIBCFS_PATH_DEFAULTS
338 #
339 # default paths for installed files
340 #
341 AC_DEFUN([LIBCFS_PATH_DEFAULTS],
342 [
343 ])
344
345 #
346 # LIBCFS_CONFIGURE
347 #
348 # other configure checks
349 #
350 AC_DEFUN([LIBCFS_CONFIGURE],
351 [# lnet/utils/portals.c
352 AC_CHECK_HEADERS([asm/types.h endian.h sys/ioctl.h])
353
354 # lnet/utils/debug.c
355 AC_CHECK_HEADERS([linux/version.h])
356
357 AC_CHECK_TYPE([spinlock_t],
358         [AC_DEFINE(HAVE_SPINLOCK_T, 1, [spinlock_t is defined])],
359         [],
360         [#include <linux/spinlock.h>])
361
362 # lnet/utils/wirecheck.c
363 AC_CHECK_FUNCS([strnlen])
364
365 # lnet/libcfs/user-prim.c, missing for RHEL5 and earlier userspace
366 AC_CHECK_FUNCS([strlcpy])
367
368 # libcfs/libcfs/user-prim.c, missing for RHEL5 and earlier userspace
369 AC_CHECK_FUNCS([strlcat])
370
371 AC_CHECK_TYPE([umode_t],
372         [AC_DEFINE(HAVE_UMODE_T, 1, [umode_t is defined])],
373         [],
374         [#include <asm/types.h>])
375
376 AC_CHECK_TYPE([__s8],
377         [AC_DEFINE(HAVE___S8, 1, [__s8 is defined])],
378         [],
379         [#include <asm/types.h>])
380
381 AC_CHECK_TYPE([__u8],
382         [AC_DEFINE(HAVE___U8, 1, [__u8 is defined])],
383         [],
384         [#include <asm/types.h>])
385
386 AC_CHECK_TYPE([__s16],
387         [AC_DEFINE(HAVE___S16, 1, [__s16 is defined])],
388         [],
389         [#include <asm/types.h>])
390
391 AC_CHECK_TYPE([__u16],
392         [AC_DEFINE(HAVE___U16, 1, [__u16 is defined])],
393         [],
394         [#include <asm/types.h>])
395
396 AC_CHECK_TYPE([__s32],
397         [AC_DEFINE(HAVE___S32, 1, [__s32 is defined])],
398         [],
399         [#include <asm/types.h>])
400
401 AC_CHECK_TYPE([__u32],
402         [AC_DEFINE(HAVE___U32, 1, [__u32 is defined])],
403         [],
404         [#include <asm/types.h>])
405
406 AC_CHECK_TYPE([__u64],
407         [AC_DEFINE(HAVE___U64, 1, [__u64 is defined])],
408         [],
409         [#include <asm/types.h>])
410
411 AC_CHECK_TYPE([__s64],
412         [AC_DEFINE(HAVE___S64, 1, [__s64 is defined])],
413         [],
414         [#include <asm/types.h>])
415
416 # check userland __u64 type
417 AC_MSG_CHECKING([userspace __u64 is long long type])
418 tmp_flags="$CFLAGS"
419 CFLAGS="$CFLAGS -Werror"
420 AC_COMPILE_IFELSE([
421         #include <stdio.h>
422         #include <linux/types.h>
423         #include <linux/stddef.h>
424         int main(void) {
425                 unsigned long long *data1;
426                 __u64 *data2 = NULL;
427
428                 data1 = data2;
429                 data2 = data1;
430                 return 0;
431         }
432 ],[
433         AC_MSG_RESULT([yes])
434         AC_DEFINE(HAVE_USER__U64_LONG_LONG, 1,
435                   [__u64 is long long type])
436 ],[
437         AC_MSG_RESULT([no])
438 ])
439 CFLAGS="$tmp_flags"
440
441 # --------  Check for required packages  --------------
442
443
444 AC_MSG_CHECKING([if efence debugging support is requested])
445 AC_ARG_ENABLE(efence,
446         AC_HELP_STRING([--enable-efence],
447                         [use efence library]),
448         [],[enable_efence='no'])
449 AC_MSG_RESULT([$enable_efence])
450 if test "$enable_efence" = "yes" ; then
451         LIBEFENCE="-lefence"
452         AC_DEFINE(HAVE_LIBEFENCE, 1, [libefence support is requested])
453 else
454         LIBEFENCE=""
455 fi
456 AC_SUBST(LIBEFENCE)
457
458
459 # -------- check for -lpthread support ----
460 AC_MSG_CHECKING([whether to use libpthread for libcfs library])
461 AC_ARG_ENABLE([libpthread],
462         AC_HELP_STRING([--disable-libpthread],
463                 [disable libpthread]),
464         [],[enable_libpthread=yes])
465 if test "$enable_libpthread" = "yes" ; then
466         AC_CHECK_LIB([pthread], [pthread_create],
467                 [ENABLE_LIBPTHREAD="yes"],
468                 [ENABLE_LIBPTHREAD="no"])
469         if test "$ENABLE_LIBPTHREAD" = "yes" ; then
470                 AC_MSG_RESULT([$ENABLE_LIBPTHREAD])
471                 PTHREAD_LIBS="-lpthread"
472                 AC_DEFINE([HAVE_LIBPTHREAD], 1, [use libpthread])
473         else
474                 PTHREAD_LIBS=""
475                 AC_MSG_RESULT([no libpthread is found])
476         fi
477         AC_SUBST(PTHREAD_LIBS)
478 else
479         AC_MSG_RESULT([no (disabled explicitly)])
480         ENABLE_LIBPTHREAD="no"
481 fi
482 AC_SUBST(ENABLE_LIBPTHREAD)
483
484
485 ])
486
487 #
488 # LIBCFS_CONDITIONALS
489 #
490 # AM_CONDITOINAL defines for lnet
491 #
492 AC_DEFUN([LIBCFS_CONDITIONALS],
493 [
494 AM_CONDITIONAL(HAVE_CRC32, test x$have_crc32 = xtrue)
495 AM_CONDITIONAL(NEED_PCLMULQDQ_CRC32,  test x$have_crc32 = xtrue -a x$enable_crc32_crypto = xtrue)
496 AM_CONDITIONAL(NEED_PCLMULQDQ_CRC32C, test x$enable_crc32c_crypto = xtrue)
497 ])
498
499 #
500 # LIBCFS_CONFIG_FILES
501 #
502 # files that should be generated with AC_OUTPUT
503 #
504 AC_DEFUN([LIBCFS_CONFIG_FILES],
505 [AC_CONFIG_FILES([
506 libcfs/Kernelenv
507 libcfs/Makefile
508 libcfs/autoMakefile
509 libcfs/autoconf/Makefile
510 libcfs/include/Makefile
511 libcfs/include/libcfs/Makefile
512 libcfs/include/libcfs/linux/Makefile
513 libcfs/include/libcfs/posix/Makefile
514 libcfs/include/libcfs/util/Makefile
515 libcfs/libcfs/Makefile
516 libcfs/libcfs/autoMakefile
517 libcfs/libcfs/linux/Makefile
518 libcfs/libcfs/posix/Makefile
519 libcfs/libcfs/util/Makefile
520 libcfs/include/libcfs/darwin/Makefile
521 libcfs/libcfs/darwin/Makefile
522 ])
523 ])