Whamcloud - gitweb
840bff7c14328de5ccef93c9b3848a5948742d13
[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 [LB_CHECK_SYMBOL_EXPORT([sock_alloc_file], [net/socket.c],[
247         LB_LINUX_TRY_COMPILE([
248                 #include <linux/net.h>
249         ],[
250                 sock_alloc_file(NULL, 0, NULL);
251         ],[
252                 AC_DEFINE(HAVE_SOCK_ALLOC_FILE_3ARGS, 1,
253                         [sock_alloc_file takes 3 arguments])
254         ],[
255                 AC_DEFINE(HAVE_SOCK_ALLOC_FILE, 1,
256                         [sock_alloc_file is exported])
257         ])
258 ],[
259 ])
260 ])
261
262 AC_DEFUN([LIBCFS_HAVE_CRC32],
263 [LB_LINUX_CONFIG_IM([CRC32],
264         [have_crc32=true],[have_crc32=false])
265 if test x$have_crc32 = xtrue; then
266         AC_DEFINE(HAVE_CRC32, 1, [kernel compiled with CRC32 functions])
267 fi
268 ])
269
270 AC_DEFUN([LIBCFS_ENABLE_CRC32_ACCEL],
271 [LB_LINUX_CONFIG_IM([CRYPTO_CRC32_PCLMUL],
272         [enable_crc32_crypto=false],[enable_crc32_crypto=true])
273 if test x$have_crc32 = xtrue -a x$enable_crc32_crypto = xtrue; then
274         AC_DEFINE(NEED_CRC32_ACCEL, 1, [need pclmulqdq based crc32])
275         AC_MSG_WARN([
276
277 No crc32 pclmulqdq crypto api found, enable internal pclmulqdq based crc32
278 ])
279 fi
280 ])
281
282 AC_DEFUN([LIBCFS_ENABLE_CRC32C_ACCEL],
283 [LB_LINUX_CONFIG_IM([CRYPTO_CRC32C_INTEL],
284         [enable_crc32c_crypto=false],[enable_crc32c_crypto=true])
285 if test x$enable_crc32c_crypto = xtrue; then
286         AC_DEFINE(NEED_CRC32C_ACCEL, 1, [need pclmulqdq based crc32c])
287         AC_MSG_WARN([
288
289 No crc32c pclmulqdq crypto api found, enable internal pclmulqdq based crc32c
290 ])
291 fi
292 ])
293
294 #
295 # LIBCFS_PROG_LINUX
296 #
297 # LNet linux kernel checks
298 #
299 AC_DEFUN([LIBCFS_PROG_LINUX],
300 [
301 LIBCFS_CONFIG_PANIC_DUMPLOG
302
303 LIBCFS_U64_LONG_LONG_LINUX
304 # 2.6.32
305 LIBCFS_STACKTRACE_OPS_HAVE_WALK_STACK
306 LC_SHRINKER_WANT_SHRINK_PTR
307 # 2.6.33
308 LIBCFS_SYSCTL_CTLNAME
309 # 2.6.34
310 LIBCFS_ADD_WAIT_QUEUE_EXCLUSIVE
311 # 2.6.35
312 LC_SK_SLEEP
313 # 2.6.39
314 LIBCFS_DUMP_TRACE_ADDRESS
315 # 2.6.40 fc15
316 LC_SHRINK_CONTROL
317 # 3.0
318 LIBCFS_STACKTRACE_WARNING
319 # 3.7
320 LIBCFS_SOCK_ALLOC_FILE
321 # 3.8
322 LIBCFS_HAVE_CRC32
323 LIBCFS_ENABLE_CRC32_ACCEL
324 # 3.10
325 LIBCFS_ENABLE_CRC32C_ACCEL
326 ])
327
328 #
329 # LIBCFS_PROG_DARWIN
330 #
331 # Darwin checks
332 #
333 AC_DEFUN([LIBCFS_PROG_DARWIN],
334 [LB_DARWIN_CHECK_FUNCS([get_preemption_level])
335 ])
336
337 #
338 # LIBCFS_PATH_DEFAULTS
339 #
340 # default paths for installed files
341 #
342 AC_DEFUN([LIBCFS_PATH_DEFAULTS],
343 [
344 ])
345
346 #
347 # LIBCFS_CONFIGURE
348 #
349 # other configure checks
350 #
351 AC_DEFUN([LIBCFS_CONFIGURE],
352 [# lnet/utils/portals.c
353 AC_CHECK_HEADERS([asm/types.h endian.h sys/ioctl.h])
354
355 # lnet/utils/debug.c
356 AC_CHECK_HEADERS([linux/version.h])
357
358 AC_CHECK_TYPE([spinlock_t],
359         [AC_DEFINE(HAVE_SPINLOCK_T, 1, [spinlock_t is defined])],
360         [],
361         [#include <linux/spinlock.h>])
362
363 # lnet/utils/wirecheck.c
364 AC_CHECK_FUNCS([strnlen])
365
366 # lnet/libcfs/user-prim.c, missing for RHEL5 and earlier userspace
367 AC_CHECK_FUNCS([strlcpy])
368
369 # libcfs/libcfs/user-prim.c, missing for RHEL5 and earlier userspace
370 AC_CHECK_FUNCS([strlcat])
371
372 AC_CHECK_TYPE([umode_t],
373         [AC_DEFINE(HAVE_UMODE_T, 1, [umode_t is defined])],
374         [],
375         [#include <asm/types.h>])
376
377 AC_CHECK_TYPE([__s8],
378         [AC_DEFINE(HAVE___S8, 1, [__s8 is defined])],
379         [],
380         [#include <asm/types.h>])
381
382 AC_CHECK_TYPE([__u8],
383         [AC_DEFINE(HAVE___U8, 1, [__u8 is defined])],
384         [],
385         [#include <asm/types.h>])
386
387 AC_CHECK_TYPE([__s16],
388         [AC_DEFINE(HAVE___S16, 1, [__s16 is defined])],
389         [],
390         [#include <asm/types.h>])
391
392 AC_CHECK_TYPE([__u16],
393         [AC_DEFINE(HAVE___U16, 1, [__u16 is defined])],
394         [],
395         [#include <asm/types.h>])
396
397 AC_CHECK_TYPE([__s32],
398         [AC_DEFINE(HAVE___S32, 1, [__s32 is defined])],
399         [],
400         [#include <asm/types.h>])
401
402 AC_CHECK_TYPE([__u32],
403         [AC_DEFINE(HAVE___U32, 1, [__u32 is defined])],
404         [],
405         [#include <asm/types.h>])
406
407 AC_CHECK_TYPE([__u64],
408         [AC_DEFINE(HAVE___U64, 1, [__u64 is defined])],
409         [],
410         [#include <asm/types.h>])
411
412 AC_CHECK_TYPE([__s64],
413         [AC_DEFINE(HAVE___S64, 1, [__s64 is defined])],
414         [],
415         [#include <asm/types.h>])
416
417 # check userland __u64 type
418 AC_MSG_CHECKING([userspace __u64 is long long type])
419 tmp_flags="$CFLAGS"
420 CFLAGS="$CFLAGS -Werror"
421 AC_COMPILE_IFELSE([
422         #include <stdio.h>
423         #include <linux/types.h>
424         #include <linux/stddef.h>
425         int main(void) {
426                 unsigned long long *data1;
427                 __u64 *data2 = NULL;
428
429                 data1 = data2;
430                 data2 = data1;
431                 return 0;
432         }
433 ],[
434         AC_MSG_RESULT([yes])
435         AC_DEFINE(HAVE_USER__U64_LONG_LONG, 1,
436                   [__u64 is long long type])
437 ],[
438         AC_MSG_RESULT([no])
439 ])
440 CFLAGS="$tmp_flags"
441
442 # --------  Check for required packages  --------------
443
444
445 AC_MSG_CHECKING([if efence debugging support is requested])
446 AC_ARG_ENABLE(efence,
447         AC_HELP_STRING([--enable-efence],
448                         [use efence library]),
449         [],[enable_efence='no'])
450 AC_MSG_RESULT([$enable_efence])
451 if test "$enable_efence" = "yes" ; then
452         LIBEFENCE="-lefence"
453         AC_DEFINE(HAVE_LIBEFENCE, 1, [libefence support is requested])
454 else
455         LIBEFENCE=""
456 fi
457 AC_SUBST(LIBEFENCE)
458
459
460 # -------- check for -lpthread support ----
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         AC_MSG_CHECKING([whether to use libpthread for libcfs library])
470         AC_MSG_RESULT([$ENABLE_LIBPTHREAD])
471         if test "$ENABLE_LIBPTHREAD" = "yes" ; then
472                 PTHREAD_LIBS="-lpthread"
473                 AC_DEFINE([HAVE_LIBPTHREAD], 1, [use libpthread])
474         else
475                 PTHREAD_LIBS=""
476         fi
477         AC_SUBST(PTHREAD_LIBS)
478 else
479         AC_MSG_WARN([Using libpthread for libcfs library is disabled explicitly])
480         ENABLE_LIBPTHREAD="no"
481 fi
482 AC_SUBST(ENABLE_LIBPTHREAD)
483 ])
484
485 #
486 # LIBCFS_CONDITIONALS
487 #
488 # AM_CONDITOINAL defines for lnet
489 #
490 AC_DEFUN([LIBCFS_CONDITIONALS],
491 [
492 AM_CONDITIONAL(HAVE_CRC32, test x$have_crc32 = xtrue)
493 AM_CONDITIONAL(NEED_PCLMULQDQ_CRC32,  test x$have_crc32 = xtrue -a x$enable_crc32_crypto = xtrue)
494 AM_CONDITIONAL(NEED_PCLMULQDQ_CRC32C, test x$enable_crc32c_crypto = xtrue)
495 ])
496
497 #
498 # LIBCFS_CONFIG_FILES
499 #
500 # files that should be generated with AC_OUTPUT
501 #
502 AC_DEFUN([LIBCFS_CONFIG_FILES],
503 [AC_CONFIG_FILES([
504 libcfs/Kernelenv
505 libcfs/Makefile
506 libcfs/autoMakefile
507 libcfs/autoconf/Makefile
508 libcfs/include/Makefile
509 libcfs/include/libcfs/Makefile
510 libcfs/include/libcfs/linux/Makefile
511 libcfs/include/libcfs/posix/Makefile
512 libcfs/include/libcfs/util/Makefile
513 libcfs/libcfs/Makefile
514 libcfs/libcfs/autoMakefile
515 libcfs/libcfs/linux/Makefile
516 libcfs/libcfs/posix/Makefile
517 libcfs/libcfs/util/Makefile
518 libcfs/include/libcfs/darwin/Makefile
519 libcfs/libcfs/darwin/Makefile
520 ])
521 ])