Whamcloud - gitweb
Branch HEAD
[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 #
63 # LIBCFS_STRUCT_PAGE_LIST
64 #
65 # 2.6.4 no longer has page->list
66 #
67 AC_DEFUN([LIBCFS_STRUCT_PAGE_LIST],
68 [AC_MSG_CHECKING([if struct page has a list field])
69 LB_LINUX_TRY_COMPILE([
70         #include <linux/mm.h>
71 ],[
72         struct page page;
73         &page.list;
74 ],[
75         AC_MSG_RESULT([yes])
76         AC_DEFINE(HAVE_PAGE_LIST, 1, [struct page has a list field])
77 ],[
78         AC_MSG_RESULT([no])
79 ])
80 ])
81
82 #
83 # LIBCFS_STRUCT_SIGHAND
84 #
85 # red hat 2.4 adds sighand to struct task_struct
86 #
87 AC_DEFUN([LIBCFS_STRUCT_SIGHAND],
88 [AC_MSG_CHECKING([if task_struct has a sighand field])
89 LB_LINUX_TRY_COMPILE([
90         #include <linux/sched.h>
91 ],[
92         struct task_struct p;
93         p.sighand = NULL;
94 ],[
95         AC_DEFINE(CONFIG_RH_2_4_20, 1, [this kernel contains Red Hat 2.4.20 patches])
96         AC_MSG_RESULT([yes])
97 ],[
98         AC_MSG_RESULT([no])
99 ])
100 ])
101
102 #
103 # LIBCFS_FUNC_CPU_ONLINE
104 #
105 # cpu_online is different in rh 2.4, vanilla 2.4, and 2.6
106 #
107 AC_DEFUN([LIBCFS_FUNC_CPU_ONLINE],
108 [AC_MSG_CHECKING([if kernel defines cpu_online()])
109 LB_LINUX_TRY_COMPILE([
110         #include <linux/sched.h>
111 ],[
112         cpu_online(0);
113 ],[
114         AC_MSG_RESULT([yes])
115         AC_DEFINE(HAVE_CPU_ONLINE, 1, [cpu_online found])
116 ],[
117         AC_MSG_RESULT([no])
118 ])
119 ])
120
121 #
122 # LIBCFS_TYPE_GFP_T
123 #
124 # check if gfp_t is typedef-ed
125 #
126 AC_DEFUN([LIBCFS_TYPE_GFP_T],
127 [AC_MSG_CHECKING([if kernel defines gfp_t])
128 LB_LINUX_TRY_COMPILE([
129         #include <linux/gfp.h>
130 ],[
131         return sizeof(gfp_t);
132 ],[
133         AC_MSG_RESULT([yes])
134         AC_DEFINE(HAVE_GFP_T, 1, [gfp_t found])
135 ],[
136         AC_MSG_RESULT([no])
137 ])
138 ])
139
140 #
141 # LIBCFS_TYPE_CPUMASK_T
142 #
143 # same goes for cpumask_t
144 #
145 AC_DEFUN([LIBCFS_TYPE_CPUMASK_T],
146 [AC_MSG_CHECKING([if kernel defines cpumask_t])
147 LB_LINUX_TRY_COMPILE([
148         #include <linux/sched.h>
149 ],[
150         return sizeof (cpumask_t);
151 ],[
152         AC_MSG_RESULT([yes])
153         AC_DEFINE(HAVE_CPUMASK_T, 1, [cpumask_t found])
154 ],[
155         AC_MSG_RESULT([no])
156 ])
157 ])
158
159 #
160 # LIBCFS_FUNC_SHOW_TASK
161 #
162 # we export show_task(), but not all kernels have it (yet)
163 #
164 AC_DEFUN([LIBCFS_FUNC_SHOW_TASK],
165 [LB_CHECK_SYMBOL_EXPORT([show_task],
166 [kernel/ksyms.c kernel/sched.c],[
167 AC_DEFINE(HAVE_SHOW_TASK, 1, [show_task is exported])
168 ],[
169 ])
170 ])
171
172 # check userland & kernel __u64 type
173 AC_DEFUN([LIBCFS_U64_LONG_LONG],
174 [AC_MSG_CHECKING([u64 is long long type])
175 tmp_flags="$CFLAGS"
176 CFLAGS="$CFLAGS -Werror"
177 AC_COMPILE_IFELSE([
178         #include <linux/types.h>
179         #include <linux/stddef.h>
180         int main(void) {
181                 unsigned long long *data1;
182                 __u64 *data2 = NULL;
183
184                 data1 = data2;
185                 return 0;
186         }
187 ],[
188         AC_MSG_RESULT([yes])
189         AC_DEFINE(HAVE_USER__U64_LONG_LONG, 1,
190                   [__u64 is long long type])
191 ],[
192         AC_MSG_RESULT([no])
193 ])
194 CFLAGS="$tmp_flags"
195 AC_MSG_CHECKING([kernel __u64 is long long type])
196 tmp_flags="$EXTRA_KCFLAGS"
197 EXTRA_KCFLAGS="$EXTRA_KCFLAGS -Werror"
198 LB_LINUX_TRY_COMPILE([
199         #include <linux/types.h>
200         #include <linux/stddef.h>
201 ],[
202         unsigned long long *data1;
203         __u64 *data2 = NULL;
204
205         data1 = data2;
206 ],[
207         AC_MSG_RESULT([yes])
208         AC_DEFINE(HAVE_KERN__U64_LONG_LONG, 1,
209                   [kernel __u64 is long long type])
210 ],[
211         AC_MSG_RESULT([no])
212 ])
213 EXTRA_KCFLAGS="$tmp_flags"
214 ])
215
216 # check userland size_t type
217 AC_DEFUN([LIBCFS_SIZE_T_LONG],
218 [AC_MSG_CHECKING([size_t is unsigned long type])
219 tmp_flags="$CFLAGS"
220 CFLAGS="$CFLAGS -Werror"
221 AC_COMPILE_IFELSE([
222         #include <linux/types.h>
223         #include <linux/stddef.h>
224         int main(void) {
225                 unsigned long *data1;
226                 size_t *data2 = NULL;
227
228                 data1 = data2;
229                 return 0;
230         }
231 ],[
232         AC_MSG_RESULT([yes])
233         AC_DEFINE(HAVE_SIZE_T_LONG, 1,
234                   [size_t is long type])
235 ],[
236         AC_MSG_RESULT([no])
237 ])
238 CFLAGS="$tmp_flags"
239 ])
240
241 AC_DEFUN([LIBCFS_SSIZE_T_LONG],
242 [AC_MSG_CHECKING([ssize_t is signed long type])
243 tmp_flags="$CFLAGS"
244 CFLAGS="$CFLAGS -Werror"
245 AC_COMPILE_IFELSE([
246         #include <linux/types.h>
247         #include <linux/stddef.h>
248         int main(void) {
249                 long *data1;
250                 ssize_t *data2 = NULL;
251
252                 data1 = data2;
253                 return 0;
254         }
255 ],[
256         AC_MSG_RESULT([yes])
257         AC_DEFINE(HAVE_SSIZE_T_LONG, 1,
258                   [ssize_t is long type])
259 ],[
260         AC_MSG_RESULT([no])
261 ])
262 CFLAGS="$tmp_flags"
263 ])
264
265
266 # check if task_struct with rcu memeber
267 AC_DEFUN([LIBCFS_TASK_RCU],
268 [AC_MSG_CHECKING([if task_struct has a rcu field])
269 LB_LINUX_TRY_COMPILE([
270         #include <linux/sched.h>
271 ],[
272         struct task_struct tsk;
273
274         tsk.rcu.next = NULL;
275 ],[
276         AC_MSG_RESULT([yes])
277         AC_DEFINE(HAVE_TASK_RCU, 1,
278                   [task_struct has rcu field])
279 ],[
280         AC_MSG_RESULT([no])
281 ])
282 ])
283
284 # LIBCFS_TASKLIST_LOCK
285 # 2.6.18 remove tasklist_lock export
286 AC_DEFUN([LIBCFS_TASKLIST_LOCK],
287 [LB_CHECK_SYMBOL_EXPORT([tasklist_lock],
288 [kernel/fork.c],[
289 AC_DEFINE(HAVE_TASKLIST_LOCK, 1,
290          [tasklist_lock exported])
291 ],[
292 ])
293 ])
294
295 # 2.6.19 API changes
296 # kmem_cache_destroy(cachep) return void instead of
297 # int
298 AC_DEFUN([LIBCFS_KMEM_CACHE_DESTROY_INT],
299 [AC_MSG_CHECKING([kmem_cache_destroy(cachep) return int])
300 LB_LINUX_TRY_COMPILE([
301         #include <linux/slab.h>
302 ],[
303         int i = kmem_cache_destroy(NULL);
304 ],[
305         AC_MSG_RESULT(yes)
306         AC_DEFINE(HAVE_KMEM_CACHE_DESTROY_INT, 1,
307                 [kmem_cache_destroy(cachep) return int])
308 ],[
309         AC_MSG_RESULT(NO)
310 ])
311 ])
312
313 # 2.6.19 API change
314 #panic_notifier_list use atomic_notifier operations
315 #
316 AC_DEFUN([LIBCFS_ATOMIC_PANIC_NOTIFIER],
317 [AC_MSG_CHECKING([panic_notifier_list is atomic])
318 LB_LINUX_TRY_COMPILE([
319         #include <linux/notifier.h>
320         #include <linux/kernel.h>
321 ],[
322         struct atomic_notifier_head panic_notifier_list;
323 ],[
324         AC_MSG_RESULT(yes)
325         AC_DEFINE(HAVE_ATOMIC_PANIC_NOTIFIER, 1,
326                 [panic_notifier_list is atomic_notifier_head])
327 ],[
328         AC_MSG_RESULT(NO)
329 ])
330 ])
331
332 # 2.6.20 API change INIT_WORK use 2 args and not
333 # store data inside
334 AC_DEFUN([LIBCFS_3ARGS_INIT_WORK],
335 [AC_MSG_CHECKING([check INIT_WORK want 3 args])
336 LB_LINUX_TRY_COMPILE([
337         #include <linux/workqueue.h>
338 ],[
339         struct work_struct work;
340
341         INIT_WORK(&work, NULL, NULL);
342 ],[
343         AC_MSG_RESULT(yes)
344         AC_DEFINE(HAVE_3ARGS_INIT_WORK, 1,
345                   [INIT_WORK use 3 args and store data inside])
346 ],[
347         AC_MSG_RESULT(NO)
348 ])
349 ])
350
351 # 2.6.21 api change. 'register_sysctl_table' use only one argument,
352 # instead of more old which need two.
353 AC_DEFUN([LIBCFS_2ARGS_REGISTER_SYSCTL],
354 [AC_MSG_CHECKING([check register_sysctl_table want 2 args])
355 LB_LINUX_TRY_COMPILE([
356         #include <linux/sysctl.h>
357 ],[
358         return register_sysctl_table(NULL,0);
359 ],[
360         AC_MSG_RESULT(yes)
361         AC_DEFINE(HAVE_2ARGS_REGISTER_SYSCTL, 1,
362                   [register_sysctl_table want 2 args])
363 ],[
364         AC_MSG_RESULT(NO)
365 ])
366 ])
367
368 # 2.6.21 marks kmem_cache_t deprecated and uses struct kmem_cache
369 # instead
370 AC_DEFUN([LIBCFS_KMEM_CACHE],
371 [AC_MSG_CHECKING([check kernel has struct kmem_cache])
372 tmp_flags="$EXTRA_KCFLAGS"
373 EXTRA_KCFLAGS="-Werror"
374 LB_LINUX_TRY_COMPILE([
375         #include <linux/slab.h>
376         typedef struct kmem_cache cache_t;
377 ],[
378         cache_t *cachep = NULL;
379
380         kmem_cache_alloc(cachep, 0);
381 ],[
382         AC_MSG_RESULT(yes)
383         AC_DEFINE(HAVE_KMEM_CACHE, 1,
384                   [kernel has struct kmem_cache])
385 ],[
386         AC_MSG_RESULT(NO)
387 ])
388 EXTRA_KCFLAGS="$tmp_flags"
389 ])
390 # 2.6.23 lost dtor argument
391 AC_DEFUN([LIBCFS_KMEM_CACHE_CREATE_DTOR],
392 [AC_MSG_CHECKING([check kmem_cache_create has dtor argument])
393 LB_LINUX_TRY_COMPILE([
394         #include <linux/slab.h>
395 ],[
396         kmem_cache_create(NULL, 0, 0, 0, NULL, NULL);
397 ],[
398         AC_MSG_RESULT(yes)
399         AC_DEFINE(HAVE_KMEM_CACHE_CREATE_DTOR, 1,
400                   [kmem_cache_create has dtor argument])
401 ],[
402         AC_MSG_RESULT(NO)
403 ])
404 ])
405
406 # 2.6.24 request not use real numbers for ctl_name
407 AC_DEFUN([LN_SYSCTL_UNNUMBERED],
408 [AC_MSG_CHECKING([for CTL_UNNUMBERED])
409 LB_LINUX_TRY_COMPILE([
410         #include <linux/sysctl.h>
411 ],[
412         #ifndef CTL_UNNUMBERED
413         #error CTL_UNNUMBERED not exist in kernel
414         #endif
415 ],[
416         AC_MSG_RESULT(yes)
417         AC_DEFINE(HAVE_SYSCTL_UNNUMBERED, 1,
418                   [sysctl has CTL_UNNUMBERED])
419 ],[
420         AC_MSG_RESULT(NO)
421 ])
422 ])
423
424 # 2.6.24 lost scatterlist->page
425 AC_DEFUN([LN_SCATTERLIST_SETPAGE],
426 [AC_MSG_CHECKING([for exist sg_set_page])
427 LB_LINUX_TRY_COMPILE([
428         #include <linux/scatterlist.h>
429 ],[
430         sg_set_page(NULL,NULL,0,0);
431 ],[
432         AC_MSG_RESULT(yes)
433         AC_DEFINE(HAVE_SCATTERLIST_SETPAGE, 1,
434                   [struct scatterlist has page member])
435 ],[
436         AC_MSG_RESULT(NO)
437 ])
438 ])
439
440 # 2.6.26 use int instead of atomic for sem.count
441 AC_DEFUN([LN_SEM_COUNT],
442 [AC_MSG_CHECKING([atomic sem.count])
443 LB_LINUX_TRY_COMPILE([
444         #include <asm/semaphore.h>
445 ],[
446         struct semaphore s;
447         
448         atomic_read(&s.count);
449 ],[
450         AC_MSG_RESULT(yes)
451         AC_DEFINE(HAVE_SEM_COUNT_ATOMIC, 1,
452                   [semaphore counter is atomic])
453 ],[
454         AC_MSG_RESULT(NO)
455 ])
456 ])
457
458 #
459 # LIBCFS_PROG_LINUX
460 #
461 # LNet linux kernel checks
462 #
463 AC_DEFUN([LIBCFS_PROG_LINUX],
464 [
465 LIBCFS_FUNC_CPU_ONLINE
466 LIBCFS_TYPE_GFP_T
467 LIBCFS_TYPE_CPUMASK_T
468 LIBCFS_CONFIG_PANIC_DUMPLOG
469
470 LIBCFS_STRUCT_PAGE_LIST
471 LIBCFS_STRUCT_SIGHAND
472 LIBCFS_FUNC_SHOW_TASK
473 LIBCFS_U64_LONG_LONG
474 LIBCFS_SSIZE_T_LONG
475 LIBCFS_SIZE_T_LONG
476 LIBCFS_TASK_RCU
477 # 2.6.18
478 LIBCFS_TASKLIST_LOCK
479 # 2.6.19
480 LIBCFS_KMEM_CACHE_DESTROY_INT
481 LIBCFS_ATOMIC_PANIC_NOTIFIER
482 # 2.6.20
483 LIBCFS_3ARGS_INIT_WORK
484 # 2.6.21
485 LIBCFS_2ARGS_REGISTER_SYSCTL
486 LIBCFS_KMEM_CACHE
487 # 2.6.23
488 LIBCFS_KMEM_CACHE_CREATE_DTOR
489 # 2.6.24
490 LN_SYSCTL_UNNUMBERED
491 LN_SCATTERLIST_SETPAGE
492 # 2.6.26
493 LN_SEM_COUNT
494 ])
495
496 #
497 # LIBCFS_PROG_DARWIN
498 #
499 # Darwin checks
500 #
501 AC_DEFUN([LIBCFS_PROG_DARWIN],
502 [LB_DARWIN_CHECK_FUNCS([get_preemption_level])
503 ])
504
505 #
506 # LIBCFS_PATH_DEFAULTS
507 #
508 # default paths for installed files
509 #
510 AC_DEFUN([LIBCFS_PATH_DEFAULTS],
511 [
512 ])
513
514 #
515 # LIBCFS_CONFIGURE
516 #
517 # other configure checks
518 #
519 AC_DEFUN([LIBCFS_CONFIGURE],
520 [# lnet/utils/portals.c
521 AC_CHECK_HEADERS([asm/types.h endian.h sys/ioctl.h])
522
523 # lnet/utils/debug.c
524 AC_CHECK_HEADERS([linux/version.h])
525
526 AC_CHECK_TYPE([spinlock_t],
527         [AC_DEFINE(HAVE_SPINLOCK_T, 1, [spinlock_t is defined])],
528         [],
529         [#include <linux/spinlock.h>])
530
531 # lnet/utils/wirecheck.c
532 AC_CHECK_FUNCS([strnlen])
533
534 AC_CHECK_TYPE([umode_t],
535         [AC_DEFINE(HAVE_UMODE_T, 1, [umode_t is defined])],
536         [],
537         [#include <asm/types.h>])
538
539 AC_CHECK_TYPE([__u64],
540         [AC_DEFINE(HAVE___U64, 1, [__u64 is defined])],
541         [],
542         [#include <asm/types.h>])
543
544 AC_CHECK_TYPE([__s64],
545         [AC_DEFINE(HAVE___S64, 1, [__s64 is defined])],
546         [],
547         [#include <asm/types.h>])
548
549 # --------  Check for required packages  --------------
550
551
552 AC_MSG_CHECKING([if efence debugging support is requested])
553 AC_ARG_ENABLE(efence,
554         AC_HELP_STRING([--enable-efence],
555                         [use efence library]),
556         [],[enable_efence='no'])
557 AC_MSG_RESULT([$enable_efence])
558 if test "$enable_efence" = "yes" ; then
559         LIBEFENCE="-lefence"
560         AC_DEFINE(HAVE_LIBEFENCE, 1, [libefence support is requested])
561 else
562         LIBEFENCE=""
563 fi
564 AC_SUBST(LIBEFENCE)
565
566
567 # -------- check for -lpthread support ----
568 AC_MSG_CHECKING([whether to use libpthread for libcfs library])
569 AC_ARG_ENABLE([libpthread],
570         AC_HELP_STRING([--disable-libpthread],
571                 [disable libpthread]),
572         [],[enable_libpthread=yes])
573 if test "$enable_libpthread" = "yes" ; then
574         AC_CHECK_LIB([pthread], [pthread_create],
575                 [ENABLE_LIBPTHREAD="yes"],
576                 [ENABLE_LIBPTHREAD="no"])
577         if test "$ENABLE_LIBPTHREAD" = "yes" ; then
578                 AC_MSG_RESULT([$ENABLE_LIBPTHREAD])
579                 PTHREAD_LIBS="-lpthread"
580                 AC_DEFINE([HAVE_LIBPTHREAD], 1, [use libpthread])
581         else
582                 PTHREAD_LIBS=""
583                 AC_MSG_RESULT([no libpthread is found])
584         fi
585         AC_SUBST(PTHREAD_LIBS)
586 else
587         AC_MSG_RESULT([no (disabled explicitly)])
588         ENABLE_LIBPTHREAD="no"
589 fi
590 AC_SUBST(ENABLE_LIBPTHREAD)
591
592
593 ])
594
595 #
596 # LIBCFS_CONDITIONALS
597 #
598 # AM_CONDITOINAL defines for lnet
599 #
600 AC_DEFUN([LIBCFS_CONDITIONALS],
601 [
602 ])
603
604 #
605 # LIBCFS_CONFIG_FILES
606 #
607 # files that should be generated with AC_OUTPUT
608 #
609 AC_DEFUN([LIBCFS_CONFIG_FILES],
610 [AC_CONFIG_FILES([
611 libcfs/Kernelenv
612 libcfs/Makefile
613 libcfs/autoMakefile
614 libcfs/autoconf/Makefile
615 libcfs/include/Makefile
616 libcfs/include/libcfs/Makefile
617 libcfs/include/libcfs/linux/Makefile
618 libcfs/include/libcfs/posix/Makefile
619 libcfs/include/libcfs/util/Makefile
620 libcfs/libcfs/Makefile
621 libcfs/libcfs/autoMakefile
622 libcfs/libcfs/linux/Makefile
623 libcfs/libcfs/ulinux/Makefile
624 libcfs/libcfs/posix/Makefile
625 libcfs/libcfs/util/Makefile
626 ])
627 case $lb_target_os in
628         darwin)
629                 AC_CONFIG_FILES([
630 libcfs/include/libcfs/darwin/Makefile
631 libcfs/libcfs/darwin/Makefile
632 ])
633                 ;;
634 esac
635 ])