Whamcloud - gitweb
b=20339
[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         int main(void) {
180                 unsigned long long *data1;
181                 __u64 *data2;
182                 
183                 data1 = data2;
184                 return 0;
185         }
186 ],[
187         AC_MSG_RESULT([yes])
188         AC_DEFINE(HAVE_USER__U64_LONG_LONG, 1,
189                   [__u64 is long long type])
190 ],[
191         AC_MSG_RESULT([no])
192 ])
193 CFLAGS="$tmp_flags"
194 AC_MSG_CHECKING([kernel __u64 is long long type])
195 tmp_flags="$EXTRA_KCFLAGS"
196 EXTRA_KCFLAGS="$EXTRA_KCFLAGS -Werror"
197 LB_LINUX_TRY_COMPILE([
198         #include <linux/types.h>
199         #include <linux/stddef.h>
200 ],[
201         unsigned long long *data1;
202         __u64 *data2 = NULL;
203                 
204         data1 = data2;
205 ],[
206         AC_MSG_RESULT([yes])
207         AC_DEFINE(HAVE_KERN__U64_LONG_LONG, 1,
208                   [kernel __u64 is long long type])
209 ],[
210         AC_MSG_RESULT([no])
211 ])
212 EXTRA_KCFLAGS="$tmp_flags"
213 ])
214
215 # check if task_struct with rcu memeber
216 AC_DEFUN([LIBCFS_TASK_RCU],
217 [AC_MSG_CHECKING([if task_struct has a rcu field])
218 LB_LINUX_TRY_COMPILE([
219         #include <linux/sched.h>
220 ],[
221         struct task_struct tsk;
222
223         tsk.rcu.next = NULL;
224 ],[
225         AC_MSG_RESULT([yes])
226         AC_DEFINE(HAVE_TASK_RCU, 1,
227                   [task_struct has rcu field])
228 ],[
229         AC_MSG_RESULT([no])
230 ])
231 ])
232
233 # LIBCFS_TASKLIST_LOCK
234 # 2.6.18 remove tasklist_lock export
235 AC_DEFUN([LIBCFS_TASKLIST_LOCK],
236 [LB_CHECK_SYMBOL_EXPORT([tasklist_lock],
237 [kernel/fork.c],[
238 AC_DEFINE(HAVE_TASKLIST_LOCK, 1,
239          [tasklist_lock exported])
240 ],[
241 ])
242 ])
243
244 # 2.6.19 API changes
245 # kmem_cache_destroy(cachep) return void instead of
246 # int
247 AC_DEFUN([LIBCFS_KMEM_CACHE_DESTROY_INT],
248 [AC_MSG_CHECKING([kmem_cache_destroy(cachep) return int])
249 LB_LINUX_TRY_COMPILE([
250         #include <linux/slab.h>
251 ],[
252         int i = kmem_cache_destroy(NULL);
253 ],[
254         AC_MSG_RESULT(yes)
255         AC_DEFINE(HAVE_KMEM_CACHE_DESTROY_INT, 1,
256                 [kmem_cache_destroy(cachep) return int])
257 ],[
258         AC_MSG_RESULT(NO)
259 ])
260 ])
261
262 # 2.6.19 API change
263 #panic_notifier_list use atomic_notifier operations
264 #
265 AC_DEFUN([LIBCFS_ATOMIC_PANIC_NOTIFIER],
266 [AC_MSG_CHECKING([panic_notifier_list is atomic])
267 LB_LINUX_TRY_COMPILE([
268         #include <linux/notifier.h>
269         #include <linux/kernel.h>
270 ],[
271         struct atomic_notifier_head panic_notifier_list;
272 ],[
273         AC_MSG_RESULT(yes)
274         AC_DEFINE(HAVE_ATOMIC_PANIC_NOTIFIER, 1,
275                 [panic_notifier_list is atomic_notifier_head])
276 ],[
277         AC_MSG_RESULT(NO)
278 ])
279 ])
280
281 # 2.6.20 API change INIT_WORK use 2 args and not
282 # store data inside
283 AC_DEFUN([LIBCFS_3ARGS_INIT_WORK],
284 [AC_MSG_CHECKING([check INIT_WORK want 3 args])
285 LB_LINUX_TRY_COMPILE([
286         #include <linux/workqueue.h>
287 ],[
288         struct work_struct work;
289
290         INIT_WORK(&work, NULL, NULL);
291 ],[
292         AC_MSG_RESULT(yes)
293         AC_DEFINE(HAVE_3ARGS_INIT_WORK, 1,
294                   [INIT_WORK use 3 args and store data inside])
295 ],[
296         AC_MSG_RESULT(NO)
297 ])
298 ])
299
300 # 2.6.21 api change. 'register_sysctl_table' use only one argument,
301 # instead of more old which need two.
302 AC_DEFUN([LIBCFS_2ARGS_REGISTER_SYSCTL],
303 [AC_MSG_CHECKING([check register_sysctl_table want 2 args])
304 LB_LINUX_TRY_COMPILE([
305         #include <linux/sysctl.h>
306 ],[
307         return register_sysctl_table(NULL,0);
308 ],[
309         AC_MSG_RESULT(yes)
310         AC_DEFINE(HAVE_2ARGS_REGISTER_SYSCTL, 1,
311                   [register_sysctl_table want 2 args])
312 ],[
313         AC_MSG_RESULT(NO)
314 ])
315 ])
316
317 # 2.6.21 marks kmem_cache_t deprecated and uses struct kmem_cache
318 # instead
319 AC_DEFUN([LIBCFS_KMEM_CACHE],
320 [AC_MSG_CHECKING([check kernel has struct kmem_cache])
321 tmp_flags="$EXTRA_KCFLAGS"
322 EXTRA_KCFLAGS="-Werror"
323 LB_LINUX_TRY_COMPILE([
324         #include <linux/slab.h>
325         typedef struct kmem_cache cache_t;
326 ],[
327         cache_t *cachep = NULL;
328
329         kmem_cache_alloc(cachep, 0);
330 ],[
331         AC_MSG_RESULT(yes)
332         AC_DEFINE(HAVE_KMEM_CACHE, 1,
333                   [kernel has struct kmem_cache])
334 ],[
335         AC_MSG_RESULT(NO)
336 ])
337 EXTRA_KCFLAGS="$tmp_flags"
338 ])
339 # 2.6.23 lost dtor argument
340 AC_DEFUN([LIBCFS_KMEM_CACHE_CREATE_DTOR],
341 [AC_MSG_CHECKING([check kmem_cache_create has dtor argument])
342 LB_LINUX_TRY_COMPILE([
343         #include <linux/slab.h>
344 ],[
345         kmem_cache_create(NULL, 0, 0, 0, NULL, NULL);
346 ],[
347         AC_MSG_RESULT(yes)
348         AC_DEFINE(HAVE_KMEM_CACHE_CREATE_DTOR, 1,
349                   [kmem_cache_create has dtor argument])
350 ],[
351         AC_MSG_RESULT(NO)
352 ])
353 ])
354
355 # 2.6.24 request not use real numbers for ctl_name
356 AC_DEFUN([LN_SYSCTL_UNNUMBERED],
357 [AC_MSG_CHECKING([for CTL_UNNUMBERED])
358 LB_LINUX_TRY_COMPILE([
359         #include <linux/sysctl.h>
360 ],[
361         #ifndef CTL_UNNUMBERED
362         #error CTL_UNNUMBERED not exist in kernel
363         #endif
364 ],[
365         AC_MSG_RESULT(yes)
366         AC_DEFINE(HAVE_SYSCTL_UNNUMBERED, 1,
367                   [sysctl has CTL_UNNUMBERED])
368 ],[
369         AC_MSG_RESULT(NO)
370 ])
371 ])
372
373 # 2.6.24 lost scatterlist->page
374 AC_DEFUN([LN_SCATTERLIST_SETPAGE],
375 [AC_MSG_CHECKING([for exist sg_set_page])
376 LB_LINUX_TRY_COMPILE([
377         #include <linux/scatterlist.h>
378 ],[
379         sg_set_page(NULL,NULL,0,0);
380 ],[
381         AC_MSG_RESULT(yes)
382         AC_DEFINE(HAVE_SCATTERLIST_SETPAGE, 1,
383                   [struct scatterlist has page member])
384 ],[
385         AC_MSG_RESULT(NO)
386 ])
387 ])
388
389 # 2.6.26 use int instead of atomic for sem.count
390 AC_DEFUN([LN_SEM_COUNT],
391 [AC_MSG_CHECKING([atomic sem.count])
392 LB_LINUX_TRY_COMPILE([
393         #include <asm/semaphore.h>
394 ],[
395         struct semaphore s;
396         
397         atomic_read(&s.count);
398 ],[
399         AC_MSG_RESULT(yes)
400         AC_DEFINE(HAVE_SEM_COUNT_ATOMIC, 1,
401                   [semaphore counter is atomic])
402 ],[
403         AC_MSG_RESULT(NO)
404 ])
405 ])
406
407 #
408 # LIBCFS_PROG_LINUX
409 #
410 # LNet linux kernel checks
411 #
412 AC_DEFUN([LIBCFS_PROG_LINUX],
413 [
414 LIBCFS_FUNC_CPU_ONLINE
415 LIBCFS_TYPE_GFP_T
416 LIBCFS_TYPE_CPUMASK_T
417 LIBCFS_CONFIG_PANIC_DUMPLOG
418
419 LIBCFS_STRUCT_PAGE_LIST
420 LIBCFS_STRUCT_SIGHAND
421 LIBCFS_FUNC_SHOW_TASK
422 LIBCFS_U64_LONG_LONG
423 LIBCFS_TASK_RCU
424 # 2.6.18
425 LIBCFS_TASKLIST_LOCK
426 # 2.6.19
427 LIBCFS_KMEM_CACHE_DESTROY_INT
428 LIBCFS_ATOMIC_PANIC_NOTIFIER
429 # 2.6.20
430 LIBCFS_3ARGS_INIT_WORK
431 # 2.6.21
432 LIBCFS_2ARGS_REGISTER_SYSCTL
433 LIBCFS_KMEM_CACHE
434 # 2.6.23
435 LIBCFS_KMEM_CACHE_CREATE_DTOR
436 # 2.6.24
437 LN_SYSCTL_UNNUMBERED
438 LN_SCATTERLIST_SETPAGE
439 # 2.6.26
440 LN_SEM_COUNT
441 ])
442
443 #
444 # LIBCFS_PROG_DARWIN
445 #
446 # Darwin checks
447 #
448 AC_DEFUN([LIBCFS_PROG_DARWIN],
449 [LB_DARWIN_CHECK_FUNCS([get_preemption_level])
450 ])
451
452 #
453 # LIBCFS_PATH_DEFAULTS
454 #
455 # default paths for installed files
456 #
457 AC_DEFUN([LIBCFS_PATH_DEFAULTS],
458 [
459 ])
460
461 #
462 # LIBCFS_CONFIGURE
463 #
464 # other configure checks
465 #
466 AC_DEFUN([LIBCFS_CONFIGURE],
467 [# lnet/utils/portals.c
468 AC_CHECK_HEADERS([asm/types.h endian.h sys/ioctl.h])
469
470 # lnet/utils/debug.c
471 AC_CHECK_HEADERS([linux/version.h])
472
473 AC_CHECK_TYPE([spinlock_t],
474         [AC_DEFINE(HAVE_SPINLOCK_T, 1, [spinlock_t is defined])],
475         [],
476         [#include <linux/spinlock.h>])
477
478 # lnet/utils/wirecheck.c
479 AC_CHECK_FUNCS([strnlen])
480
481 AC_CHECK_TYPE([umode_t],
482         [AC_DEFINE(HAVE_UMODE_T, 1, [umode_t is defined])],
483         [],
484         [#include <asm/types.h>])
485
486 AC_CHECK_TYPE([__u64],
487         [AC_DEFINE(HAVE___U64, 1, [__u64 is defined])],
488         [],
489         [#include <asm/types.h>])
490
491 AC_CHECK_TYPE([__s64],
492         [AC_DEFINE(HAVE___S64, 1, [__s64 is defined])],
493         [],
494         [#include <asm/types.h>])
495
496 # --------  Check for required packages  --------------
497
498
499 AC_MSG_CHECKING([if efence debugging support is requested])
500 AC_ARG_ENABLE(efence,
501         AC_HELP_STRING([--enable-efence],
502                         [use efence library]),
503         [],[enable_efence='no'])
504 AC_MSG_RESULT([$enable_efence])
505 if test "$enable_efence" = "yes" ; then
506         LIBEFENCE="-lefence"
507         AC_DEFINE(HAVE_LIBEFENCE, 1, [libefence support is requested])
508 else
509         LIBEFENCE=""
510 fi
511 AC_SUBST(LIBEFENCE)
512
513
514 # -------- check for -lpthread support ----
515 AC_MSG_CHECKING([whether to use libpthread for libcfs library])
516 AC_ARG_ENABLE([libpthread],
517         AC_HELP_STRING([--disable-libpthread],
518                 [disable libpthread]),
519         [],[enable_libpthread=yes])
520 if test "$enable_libpthread" = "yes" ; then
521         AC_CHECK_LIB([pthread], [pthread_create],
522                 [ENABLE_LIBPTHREAD="yes"],
523                 [ENABLE_LIBPTHREAD="no"])
524         if test "$ENABLE_LIBPTHREAD" = "yes" ; then
525                 AC_MSG_RESULT([$ENABLE_LIBPTHREAD])
526                 PTHREAD_LIBS="-lpthread"
527                 AC_DEFINE([HAVE_LIBPTHREAD], 1, [use libpthread])
528         else
529                 PTHREAD_LIBS=""
530                 AC_MSG_RESULT([no libpthread is found])
531         fi
532         AC_SUBST(PTHREAD_LIBS)
533 else
534         AC_MSG_RESULT([no (disabled explicitly)])
535         ENABLE_LIBPTHREAD="no"
536 fi
537 AC_SUBST(ENABLE_LIBPTHREAD)
538
539
540 ])
541
542 #
543 # LIBCFS_CONDITIONALS
544 #
545 # AM_CONDITOINAL defines for lnet
546 #
547 AC_DEFUN([LIBCFS_CONDITIONALS],
548 [
549 ])
550
551 #
552 # LIBCFS_CONFIG_FILES
553 #
554 # files that should be generated with AC_OUTPUT
555 #
556 AC_DEFUN([LIBCFS_CONFIG_FILES],
557 [AC_CONFIG_FILES([
558 libcfs/Kernelenv
559 libcfs/Makefile
560 libcfs/autoMakefile
561 libcfs/autoconf/Makefile
562 libcfs/include/Makefile
563 libcfs/include/libcfs/Makefile
564 libcfs/include/libcfs/linux/Makefile
565 libcfs/include/libcfs/posix/Makefile
566 libcfs/include/libcfs/util/Makefile
567 libcfs/libcfs/Makefile
568 libcfs/libcfs/autoMakefile
569 libcfs/libcfs/linux/Makefile
570 libcfs/libcfs/ulinux/Makefile
571 libcfs/libcfs/posix/Makefile
572 libcfs/libcfs/util/Makefile
573 ])
574 case $lb_target_os in
575         darwin)
576                 AC_CONFIG_FILES([
577 libcfs/include/libcfs/darwin/Makefile
578 libcfs/libcfs/darwin/Makefile
579 ])
580                 ;;
581 esac
582 ])