4 # whether to enable various libcfs debugs (CDEBUG, ENTRY/EXIT, LASSERT, etc.)
6 AC_DEFUN([LN_CONFIG_CDEBUG],
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])
17 AC_DEFINE(CDEBUG_ENABLED, 0, [disable libcfs CDEBUG, CWARN])
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])
29 AC_DEFINE(CDEBUG_ENTRY_EXIT, 0, [disable libcfs ENTRY/EXIT])
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])
44 # LIBCFS_CONFIG_PANIC_DUMPLOG
46 # check if tunable panic_dumplog is wanted
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)])
63 # LIBCFS_STRUCT_PAGE_LIST
65 # 2.6.4 no longer has page->list
67 AC_DEFUN([LIBCFS_STRUCT_PAGE_LIST],
68 [AC_MSG_CHECKING([if struct page has a list field])
69 LB_LINUX_TRY_COMPILE([
76 AC_DEFINE(HAVE_PAGE_LIST, 1, [struct page has a list field])
83 # LIBCFS_STRUCT_SIGHAND
85 # red hat 2.4 adds sighand to struct task_struct
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>
95 AC_DEFINE(CONFIG_RH_2_4_20, 1, [this kernel contains Red Hat 2.4.20 patches])
103 # LIBCFS_FUNC_CPU_ONLINE
105 # cpu_online is different in rh 2.4, vanilla 2.4, and 2.6
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>
115 AC_DEFINE(HAVE_CPU_ONLINE, 1, [cpu_online found])
124 # check if gfp_t is typedef-ed
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>
131 return sizeof(gfp_t);
134 AC_DEFINE(HAVE_GFP_T, 1, [gfp_t found])
141 # LIBCFS_TYPE_CPUMASK_T
143 # same goes for cpumask_t
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>
150 return sizeof (cpumask_t);
153 AC_DEFINE(HAVE_CPUMASK_T, 1, [cpumask_t found])
160 # LIBCFS_FUNC_SHOW_TASK
162 # we export show_task(), but not all kernels have it (yet)
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])
172 # check userland & kernel __u64 type
173 AC_DEFUN([LIBCFS_U64_LONG_LONG],
174 [AC_MSG_CHECKING([u64 is long long type])
176 CFLAGS="$CFLAGS -Werror"
178 #include <linux/types.h>
179 #include <linux/stddef.h>
181 unsigned long long *data1;
189 AC_DEFINE(HAVE_USER__U64_LONG_LONG, 1,
190 [__u64 is long long type])
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>
202 unsigned long long *data1;
208 AC_DEFINE(HAVE_KERN__U64_LONG_LONG, 1,
209 [kernel __u64 is long long type])
213 EXTRA_KCFLAGS="$tmp_flags"
216 # check if task_struct with rcu memeber
217 AC_DEFUN([LIBCFS_TASK_RCU],
218 [AC_MSG_CHECKING([if task_struct has a rcu field])
219 LB_LINUX_TRY_COMPILE([
220 #include <linux/sched.h>
222 struct task_struct tsk;
227 AC_DEFINE(HAVE_TASK_RCU, 1,
228 [task_struct has rcu field])
234 # LIBCFS_TASKLIST_LOCK
235 # 2.6.18 remove tasklist_lock export
236 AC_DEFUN([LIBCFS_TASKLIST_LOCK],
237 [LB_CHECK_SYMBOL_EXPORT([tasklist_lock],
239 AC_DEFINE(HAVE_TASKLIST_LOCK, 1,
240 [tasklist_lock exported])
246 # kmem_cache_destroy(cachep) return void instead of
248 AC_DEFUN([LIBCFS_KMEM_CACHE_DESTROY_INT],
249 [AC_MSG_CHECKING([kmem_cache_destroy(cachep) return int])
250 LB_LINUX_TRY_COMPILE([
251 #include <linux/slab.h>
253 int i = kmem_cache_destroy(NULL);
256 AC_DEFINE(HAVE_KMEM_CACHE_DESTROY_INT, 1,
257 [kmem_cache_destroy(cachep) return int])
264 #panic_notifier_list use atomic_notifier operations
266 AC_DEFUN([LIBCFS_ATOMIC_PANIC_NOTIFIER],
267 [AC_MSG_CHECKING([panic_notifier_list is atomic])
268 LB_LINUX_TRY_COMPILE([
269 #include <linux/notifier.h>
270 #include <linux/kernel.h>
272 struct atomic_notifier_head panic_notifier_list;
275 AC_DEFINE(HAVE_ATOMIC_PANIC_NOTIFIER, 1,
276 [panic_notifier_list is atomic_notifier_head])
282 # since 2.6.19 nlmsg_multicast() needs 5 argument.
283 AC_DEFUN([LIBCFS_NLMSG_MULTICAST],
284 [AC_MSG_CHECKING([nlmsg_multicast needs 5 argument])
285 LB_LINUX_TRY_COMPILE([
286 #include <net/netlink.h>
288 nlmsg_multicast(NULL, NULL, 0, 0, 0);
291 AC_DEFINE(HAVE_NLMSG_MULTICAST_5ARGS, 1,
292 [nlmsg_multicast needs 5 argument])
301 # If we have netlink.h, and nlmsg_new takes 2 args (2.6.19)
303 AC_DEFUN([LIBCFS_NETLINK],
304 [AC_MSG_CHECKING([if netlink.h can be compiled])
305 LB_LINUX_TRY_COMPILE([
306 #include <net/netlink.h>
309 AC_DEFINE(HAVE_NETLINK, 1, [net/netlink.h found])
311 AC_MSG_CHECKING([if nlmsg_new takes a 2nd argument])
312 LB_LINUX_TRY_COMPILE([
313 #include <net/netlink.h>
315 nlmsg_new(100, GFP_KERNEL);
318 AC_DEFINE(HAVE_NETLINK_NL2, 1, [nlmsg_new takes 2 args])
327 # 2.6.20 API change INIT_WORK use 2 args and not
329 AC_DEFUN([LIBCFS_3ARGS_INIT_WORK],
330 [AC_MSG_CHECKING([check INIT_WORK want 3 args])
331 LB_LINUX_TRY_COMPILE([
332 #include <linux/workqueue.h>
334 struct work_struct work;
336 INIT_WORK(&work, NULL, NULL);
339 AC_DEFINE(HAVE_3ARGS_INIT_WORK, 1,
340 [INIT_WORK use 3 args and store data inside])
346 # 2.6.21 api change. 'register_sysctl_table' use only one argument,
347 # instead of more old which need two.
348 AC_DEFUN([LIBCFS_2ARGS_REGISTER_SYSCTL],
349 [AC_MSG_CHECKING([check register_sysctl_table want 2 args])
350 LB_LINUX_TRY_COMPILE([
351 #include <linux/sysctl.h>
353 return register_sysctl_table(NULL,0);
356 AC_DEFINE(HAVE_2ARGS_REGISTER_SYSCTL, 1,
357 [register_sysctl_table want 2 args])
363 # 2.6.21 marks kmem_cache_t deprecated and uses struct kmem_cache
365 AC_DEFUN([LIBCFS_KMEM_CACHE],
366 [AC_MSG_CHECKING([check kernel has struct kmem_cache])
367 tmp_flags="$EXTRA_KCFLAGS"
368 EXTRA_KCFLAGS="-Werror"
369 LB_LINUX_TRY_COMPILE([
370 #include <linux/slab.h>
371 typedef struct kmem_cache cache_t;
373 cache_t *cachep = NULL;
375 kmem_cache_alloc(cachep, 0);
378 AC_DEFINE(HAVE_KMEM_CACHE, 1,
379 [kernel has struct kmem_cache])
383 EXTRA_KCFLAGS="$tmp_flags"
386 # 2.6.23 lost dtor argument
387 AC_DEFUN([LIBCFS_KMEM_CACHE_CREATE_DTOR],
388 [AC_MSG_CHECKING([check kmem_cache_create has dtor argument])
389 LB_LINUX_TRY_COMPILE([
390 #include <linux/slab.h>
392 kmem_cache_create(NULL, 0, 0, 0, NULL, NULL);
395 AC_DEFINE(HAVE_KMEM_CACHE_CREATE_DTOR, 1,
396 [kmem_cache_create has dtor argument])
403 AC_DEFUN([LIBCFS_NETLINK_CBMUTEX],
404 [AC_MSG_CHECKING([for mutex in netlink_kernel_create])
405 LB_LINUX_TRY_COMPILE([
406 #include <linux/netlink.h>
408 struct mutex *lock = NULL;
410 netlink_kernel_create(0, 0, NULL, lock, NULL);
413 AC_DEFINE(HAVE_NETLINK_CBMUTEX, 1,
414 [netlink_kernel_create want mutex for callback])
420 # 2.6.24 request not use real numbers for ctl_name
421 AC_DEFUN([LIBCFS_SYSCTL_UNNUMBERED],
422 [AC_MSG_CHECKING([for CTL_UNNUMBERED])
423 LB_LINUX_TRY_COMPILE([
424 #include <linux/sysctl.h>
426 #ifndef CTL_UNNUMBERED
427 #error CTL_UNNUMBERED not exist in kernel
431 AC_DEFINE(HAVE_SYSCTL_UNNUMBERED, 1,
432 [sysctl has CTL_UNNUMBERED])
438 # 2.6.24 lost scatterlist->page
439 AC_DEFUN([LIBCFS_SCATTERLIST_SETPAGE],
440 [AC_MSG_CHECKING([for exist sg_set_page])
441 LB_LINUX_TRY_COMPILE([
442 #include <asm/types.h>
443 #include <linux/scatterlist.h>
445 sg_set_page(NULL,NULL,0,0);
448 AC_DEFINE(HAVE_SCATTERLIST_SETPAGE, 1,
449 [struct scatterlist has page member])
455 # from 2.6.24 please use sg_init_table
456 AC_DEFUN([LIBCFS_SCATTERLIST_INITTABLE],
457 [AC_MSG_CHECKING([if sg_init_table is defined])
458 LB_LINUX_TRY_COMPILE([
459 #include <linux/scatterlist.h>
461 sg_init_table(NULL,0);
464 AC_DEFINE(HAVE_SCATTERLIST_INITTABLE, 1,
465 [sg_init_table is defined])
472 AC_DEFUN([LIBCFS_NETWORK_NAMESPACE],
473 [AC_MSG_CHECKING([for network stack has namespaces])
474 LB_LINUX_TRY_COMPILE([
475 #include <net/net_namespace.h>
477 struct net *net = &init_net;
480 AC_DEFINE(HAVE_INIT_NET, 1,
481 [kernel is support network namespaces ])
489 AC_DEFUN([LIBCFS_NETLINK_NETNS],
490 [AC_MSG_CHECKING([for netlink support net ns])
491 LB_LINUX_TRY_COMPILE([
492 #include <linux/netlink.h>
494 struct net *net = NULL;
495 struct mutex *lock = NULL;
497 netlink_kernel_create(net, 0, 0, NULL,
502 AC_DEFINE(HAVE_NETLINK_NS, 1,
503 [netlink is support network namespace])
505 # for now - if kernel have netlink ns - he uses cbmutex
506 AC_DEFINE(HAVE_NETLINK_CBMUTEX, 1,
507 [netlink_kernel_create want mutex for callback])
515 AC_DEFUN([LIBCFS_NL_BROADCAST_GFP],
516 [AC_MSG_CHECKING([for netlink_broadcast is want to have gfp parameter])
517 LB_LINUX_TRY_COMPILE([
518 #include <linux/netlink.h>
520 gfp_t gfp = GFP_KERNEL;
522 netlink_broadcast(NULL, NULL, 0, 0, gfp);
525 AC_DEFINE(HAVE_NL_BROADCAST_GFP, 1,
526 [netlink brouacast is want to have gfp paramter])
533 # LIBCFS_FUNC_DUMP_TRACE
535 # 2.6.23 exports dump_trace() so we can dump_stack() on any task
536 # 2.6.24 has stacktrace_ops.address with "reliable" parameter
538 AC_DEFUN([LIBCFS_FUNC_DUMP_TRACE],
539 [LB_CHECK_SYMBOL_EXPORT([dump_trace],
540 [kernel/ksyms.c arch/${LINUX_ARCH%_64}/kernel/traps_64.c],[
541 tmp_flags="$EXTRA_KCFLAGS"
542 EXTRA_KCFLAGS="-Werror"
543 AC_MSG_CHECKING([whether we can really use dump_trace])
544 LB_LINUX_TRY_COMPILE([
547 #include <asm/stacktrace.h>
551 AC_DEFINE(HAVE_DUMP_TRACE, 1, [dump_trace is exported])
556 AC_MSG_CHECKING([whether print_trace_address has reliable argument])
557 LB_LINUX_TRY_COMPILE([
560 void print_addr(void *data, unsigned long addr, int reliable);
561 #include <asm/stacktrace.h>
563 struct stacktrace_ops ops;
565 ops.address = print_addr;
568 AC_DEFINE(HAVE_TRACE_ADDRESS_RELIABLE, 1,
569 [print_trace_address has reliable argument])
574 EXTRA_KCFLAGS="$tmp_flags"
579 # 2.6.26 use int instead of atomic for sem.count
580 AC_DEFUN([LIBCFS_SEM_COUNT],
581 [AC_MSG_CHECKING([atomic sem.count])
582 LB_LINUX_TRY_COMPILE([
583 #include <asm/semaphore.h>
587 atomic_read(&s.count);
590 AC_DEFINE(HAVE_SEM_COUNT_ATOMIC, 1,
591 [semaphore counter is atomic])
597 # 2.6.27 have second argument to sock_map_fd
598 AC_DEFUN([LIBCFS_SOCK_MAP_FD_2ARG],
599 [AC_MSG_CHECKING([sock_map_fd have second argument])
600 LB_LINUX_TRY_COMPILE([
601 #include <linux/net.h>
603 sock_map_fd(NULL, 0);
606 AC_DEFINE(HAVE_SOCK_MAP_FD_2ARG, 1,
607 [sock_map_fd have second argument])
613 # LIBCFS_CRED_WRAPPERS
615 # wrappers for task's credentials are in sles11
617 AC_DEFUN([LIBCFS_CRED_WRAPPERS],
618 [AC_MSG_CHECKING([if kernel has wrappers for task's credentials])
619 LB_LINUX_TRY_COMPILE([
620 #include <linux/sched.h>
627 AC_DEFINE(HAVE_CRED_WRAPPERS, 1, [task's cred wrappers found])
634 # LN_STRUCT_CRED_IN_TASK
636 # struct cred was introduced in 2.6.29 to streamline credentials in task struct
638 AC_DEFUN([LIBCFS_STRUCT_CRED_IN_TASK],
639 [AC_MSG_CHECKING([if kernel has struct cred])
640 LB_LINUX_TRY_COMPILE([
641 #include <linux/sched.h>
643 struct task_struct *tsk = NULL;
644 tsk->real_cred = NULL;
647 AC_DEFINE(HAVE_STRUCT_CRED, 1, [struct cred found])
654 # LIBCFS_FUNC_UNSHARE_FS_STRUCT
656 # unshare_fs_struct was introduced in 2.6.30 to prevent others to directly
657 # mess with copy_fs_struct
659 AC_DEFUN([LIBCFS_FUNC_UNSHARE_FS_STRUCT],
660 [AC_MSG_CHECKING([if kernel defines unshare_fs_struct()])
661 tmp_flags="$EXTRA_KCFLAGS"
662 EXTRA_KCFLAGS="-Werror"
663 LB_LINUX_TRY_COMPILE([
664 #include <linux/sched.h>
665 #include <linux/fs_struct.h>
670 AC_DEFINE(HAVE_UNSHARE_FS_STRUCT, 1, [unshare_fs_struct found])
674 EXTRA_KCFLAGS="$tmp_flags"
678 # LIBCFS_HAVE_IS_COMPAT_TASK
680 # Added in 2.6.17, it wasn't until 2.6.29 that all
681 # Linux architectures have is_compat_task()
683 AC_DEFUN([LIBCFS_HAVE_IS_COMPAT_TASK],
684 [AC_MSG_CHECKING([if is_compat_task() is declared])
685 LB_LINUX_TRY_COMPILE([
686 #include <linux/compat.h>
688 int i = is_compat_task();
691 AC_DEFINE(HAVE_IS_COMPAT_TASK, 1, [is_compat_task() is available])
700 # LNet linux kernel checks
702 AC_DEFUN([LIBCFS_PROG_LINUX],
704 LIBCFS_FUNC_CPU_ONLINE
706 LIBCFS_TYPE_CPUMASK_T
707 LIBCFS_CONFIG_PANIC_DUMPLOG
709 LIBCFS_STRUCT_PAGE_LIST
710 LIBCFS_STRUCT_SIGHAND
711 LIBCFS_FUNC_SHOW_TASK
716 LIBCFS_HAVE_IS_COMPAT_TASK
719 LIBCFS_NLMSG_MULTICAST
720 LIBCFS_KMEM_CACHE_DESTROY_INT
721 LIBCFS_ATOMIC_PANIC_NOTIFIER
723 LIBCFS_3ARGS_INIT_WORK
725 LIBCFS_2ARGS_REGISTER_SYSCTL
728 LIBCFS_KMEM_CACHE_CREATE_DTOR
729 LIBCFS_NETLINK_CBMUTEX
731 LIBCFS_SYSCTL_UNNUMBERED
732 LIBCFS_SCATTERLIST_SETPAGE
733 LIBCFS_SCATTERLIST_INITTABLE
734 LIBCFS_NL_BROADCAST_GFP
735 LIBCFS_NETWORK_NAMESPACE
737 LIBCFS_FUNC_DUMP_TRACE
743 LIBCFS_STRUCT_CRED_IN_TASK
745 LIBCFS_FUNC_UNSHARE_FS_STRUCT
746 LIBCFS_SOCK_MAP_FD_2ARG
754 AC_DEFUN([LIBCFS_PROG_DARWIN],
755 [LB_DARWIN_CHECK_FUNCS([get_preemption_level])
759 # LIBCFS_PATH_DEFAULTS
761 # default paths for installed files
763 AC_DEFUN([LIBCFS_PATH_DEFAULTS],
770 # other configure checks
772 AC_DEFUN([LIBCFS_CONFIGURE],
773 [# lnet/utils/portals.c
774 AC_CHECK_HEADERS([asm/types.h endian.h sys/ioctl.h])
777 AC_CHECK_HEADERS([linux/version.h])
779 AC_CHECK_TYPE([spinlock_t],
780 [AC_DEFINE(HAVE_SPINLOCK_T, 1, [spinlock_t is defined])],
782 [#include <linux/spinlock.h>])
784 # lnet/utils/wirecheck.c
785 AC_CHECK_FUNCS([strnlen])
787 AC_CHECK_TYPE([umode_t],
788 [AC_DEFINE(HAVE_UMODE_T, 1, [umode_t is defined])],
790 [#include <asm/types.h>])
792 AC_CHECK_TYPE([__s8],
793 [AC_DEFINE(HAVE___S8, 1, [__s8 is defined])],
795 [#include <asm/types.h>])
797 AC_CHECK_TYPE([__u8],
798 [AC_DEFINE(HAVE___U8, 1, [__u8 is defined])],
800 [#include <asm/types.h>])
802 AC_CHECK_TYPE([__s16],
803 [AC_DEFINE(HAVE___S16, 1, [__s16 is defined])],
805 [#include <asm/types.h>])
807 AC_CHECK_TYPE([__u16],
808 [AC_DEFINE(HAVE___U16, 1, [__u16 is defined])],
810 [#include <asm/types.h>])
812 AC_CHECK_TYPE([__s32],
813 [AC_DEFINE(HAVE___S32, 1, [__s32 is defined])],
815 [#include <asm/types.h>])
817 AC_CHECK_TYPE([__u32],
818 [AC_DEFINE(HAVE___U32, 1, [__u32 is defined])],
820 [#include <asm/types.h>])
822 AC_CHECK_TYPE([__u64],
823 [AC_DEFINE(HAVE___U64, 1, [__u64 is defined])],
825 [#include <asm/types.h>])
827 AC_CHECK_TYPE([__s64],
828 [AC_DEFINE(HAVE___S64, 1, [__s64 is defined])],
830 [#include <asm/types.h>])
832 # -------- Check for required packages --------------
835 AC_MSG_CHECKING([if efence debugging support is requested])
836 AC_ARG_ENABLE(efence,
837 AC_HELP_STRING([--enable-efence],
838 [use efence library]),
839 [],[enable_efence='no'])
840 AC_MSG_RESULT([$enable_efence])
841 if test "$enable_efence" = "yes" ; then
843 AC_DEFINE(HAVE_LIBEFENCE, 1, [libefence support is requested])
849 # ===========================================================================
850 # http://www.gnu.org/software/autoconf-archive/ax_pthread.html
851 # ===========================================================================
855 # AX_PTHREAD([ACTION-IF-FOUND[, ACTION-IF-NOT-FOUND]])
859 # This macro figures out how to build C programs using POSIX threads. It
860 # sets the PTHREAD_LIBS output variable to the threads library and linker
861 # flags, and the PTHREAD_CFLAGS output variable to any special C compiler
862 # flags that are needed. (The user can also force certain compiler
863 # flags/libs to be tested by setting these environment variables.)
865 # Also sets PTHREAD_CC to any special C compiler that is needed for
866 # multi-threaded programs (defaults to the value of CC otherwise). (This
867 # is necessary on AIX to use the special cc_r compiler alias.)
869 # NOTE: You are assumed to not only compile your program with these flags,
870 # but also link it with them as well. e.g. you should link with
871 # $PTHREAD_CC $CFLAGS $PTHREAD_CFLAGS $LDFLAGS ... $PTHREAD_LIBS $LIBS
873 # If you are only building threads programs, you may wish to use these
874 # variables in your default LIBS, CFLAGS, and CC:
876 # LIBS="$PTHREAD_LIBS $LIBS"
877 # CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
880 # In addition, if the PTHREAD_CREATE_JOINABLE thread-attribute constant
881 # has a nonstandard name, defines PTHREAD_CREATE_JOINABLE to that name
882 # (e.g. PTHREAD_CREATE_UNDETACHED on AIX).
884 # ACTION-IF-FOUND is a list of shell commands to run if a threads library
885 # is found, and ACTION-IF-NOT-FOUND is a list of commands to run it if it
886 # is not found. If ACTION-IF-FOUND is not specified, the default action
887 # will define HAVE_PTHREAD.
889 # Please let the authors know if this macro fails on any platform, or if
890 # you have any other suggestions or comments. This macro was based on work
891 # by SGJ on autoconf scripts for FFTW (http://www.fftw.org/) (with help
892 # from M. Frigo), as well as ac_pthread and hb_pthread macros posted by
893 # Alejandro Forero Cuervo to the autoconf macro repository. We are also
894 # grateful for the helpful feedback of numerous users.
898 # Copyright (c) 2008 Steven G. Johnson <stevenj@alum.mit.edu>
900 # This program is free software: you can redistribute it and/or modify it
901 # under the terms of the GNU General Public License as published by the
902 # Free Software Foundation, either version 3 of the License, or (at your
903 # option) any later version.
905 # This program is distributed in the hope that it will be useful, but
906 # WITHOUT ANY WARRANTY; without even the implied warranty of
907 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
908 # Public License for more details.
910 # You should have received a copy of the GNU General Public License along
911 # with this program. If not, see <http://www.gnu.org/licenses/>.
913 # As a special exception, the respective Autoconf Macro's copyright owner
914 # gives unlimited permission to copy, distribute and modify the configure
915 # scripts that are the output of Autoconf when processing the Macro. You
916 # need not follow the terms of the GNU General Public License when using
917 # or distributing such scripts, even though portions of the text of the
918 # Macro appear in them. The GNU General Public License (GPL) does govern
919 # all other use of the material that constitutes the Autoconf Macro.
921 # This special exception to the GPL applies to versions of the Autoconf
922 # Macro released by the Autoconf Archive. When you make and distribute a
923 # modified version of the Autoconf Macro, you may extend this special
924 # exception to the GPL to apply to your modified version as well.
928 AU_ALIAS([ACX_PTHREAD], [AX_PTHREAD])
929 AC_DEFUN([AX_PTHREAD], [
930 AC_REQUIRE([AC_CANONICAL_HOST])
935 # We used to check for pthread.h first, but this fails if pthread.h
936 # requires special compiler flags (e.g. on True64 or Sequent).
937 # It gets checked for in the link test anyway.
939 # First of all, check if the user has set any of the PTHREAD_LIBS,
940 # etcetera environment variables, and if threads linking works using
942 if test x"$PTHREAD_LIBS$PTHREAD_CFLAGS" != x; then
943 save_CFLAGS="$CFLAGS"
944 CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
946 LIBS="$PTHREAD_LIBS $LIBS"
947 AC_MSG_CHECKING([for pthread_join in LIBS=$PTHREAD_LIBS with CFLAGS=$PTHREAD_CFLAGS])
948 AC_TRY_LINK_FUNC(pthread_join, ax_pthread_ok=yes)
949 AC_MSG_RESULT($ax_pthread_ok)
950 if test x"$ax_pthread_ok" = xno; then
955 CFLAGS="$save_CFLAGS"
958 # We must check for the threads library under a number of different
959 # names; the ordering is very important because some systems
960 # (e.g. DEC) have both -lpthread and -lpthreads, where one of the
961 # libraries is broken (non-POSIX).
963 # Create a list of thread flags to try. Items starting with a "-" are
964 # C compiler flags, and other items are library names, except for "none"
965 # which indicates that we try without any flags at all, and "pthread-config"
966 # which is a program returning the flags for the Pth emulation library.
968 ax_pthread_flags="pthreads none -Kthread -kthread lthread -pthread -pthreads -mthreads pthread --thread-safe -mt pthread-config"
970 # The ordering *is* (sometimes) important. Some notes on the
971 # individual items follow:
973 # pthreads: AIX (must check this before -lpthread)
974 # none: in case threads are in libc; should be tried before -Kthread and
975 # other compiler flags to prevent continual compiler warnings
976 # -Kthread: Sequent (threads in libc, but -Kthread needed for pthread.h)
977 # -kthread: FreeBSD kernel threads (preferred to -pthread since SMP-able)
978 # lthread: LinuxThreads port on FreeBSD (also preferred to -pthread)
979 # -pthread: Linux/gcc (kernel threads), BSD/gcc (userland threads)
980 # -pthreads: Solaris/gcc
981 # -mthreads: Mingw32/gcc, Lynx/gcc
982 # -mt: Sun Workshop C (may only link SunOS threads [-lthread], but it
983 # doesn't hurt to check since this sometimes defines pthreads too;
984 # also defines -D_REENTRANT)
985 # ... -mt is also the pthreads flag for HP/aCC
986 # pthread: Linux, etcetera
987 # --thread-safe: KAI C++
988 # pthread-config: use pthread-config program (for GNU Pth library)
990 case "${host_cpu}-${host_os}" in
993 # On Solaris (at least, for some versions), libc contains stubbed
994 # (non-functional) versions of the pthreads routines, so link-based
995 # tests will erroneously succeed. (We need to link with -pthreads/-mt/
996 # -lpthread.) (The stubs are missing pthread_cleanup_push, or rather
997 # a function called by this macro, so we could check for that, but
998 # who knows whether they'll stub that too in a future libc.) So,
999 # we'll just look for -pthreads and -lpthread first:
1001 ax_pthread_flags="-pthreads pthread -mt -pthread $ax_pthread_flags"
1005 ax_pthread_flags="-pthread $ax_pthread_flags"
1009 if test x"$ax_pthread_ok" = xno; then
1010 for flag in $ax_pthread_flags; do
1014 AC_MSG_CHECKING([whether pthreads work without any flags])
1018 AC_MSG_CHECKING([whether pthreads work with $flag])
1019 PTHREAD_CFLAGS="$flag"
1023 AC_CHECK_PROG(ax_pthread_config, pthread-config, yes, no)
1024 if test x"$ax_pthread_config" = xno; then continue; fi
1025 PTHREAD_CFLAGS="`pthread-config --cflags`"
1026 PTHREAD_LIBS="`pthread-config --ldflags` `pthread-config --libs`"
1030 AC_MSG_CHECKING([for the pthreads library -l$flag])
1031 PTHREAD_LIBS="-l$flag"
1036 save_CFLAGS="$CFLAGS"
1037 LIBS="$PTHREAD_LIBS $LIBS"
1038 CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
1040 # Check for various functions. We must include pthread.h,
1041 # since some functions may be macros. (On the Sequent, we
1042 # need a special flag -Kthread to make this header compile.)
1043 # We check for pthread_join because it is in -lpthread on IRIX
1044 # while pthread_create is in libc. We check for pthread_attr_init
1045 # due to DEC craziness with -lpthreads. We check for
1046 # pthread_cleanup_push because it is one of the few pthread
1047 # functions on Solaris that doesn't have a non-functional libc stub.
1048 # We try pthread_create on general principles.
1049 AC_TRY_LINK([#include <pthread.h>
1050 static void routine(void* a) {a=0;}
1051 static void* start_routine(void* a) {return a;}],
1052 [pthread_t th; pthread_attr_t attr;
1053 pthread_join(th, 0);
1054 pthread_attr_init(&attr);
1055 pthread_cleanup_push(routine, 0);
1056 pthread_create(&th,0,start_routine,0);
1057 pthread_cleanup_pop(0); ],
1058 [ax_pthread_ok=yes])
1061 CFLAGS="$save_CFLAGS"
1063 AC_MSG_RESULT($ax_pthread_ok)
1064 if test "x$ax_pthread_ok" = xyes; then
1073 # Various other checks:
1074 if test "x$ax_pthread_ok" = xyes; then
1076 LIBS="$PTHREAD_LIBS $LIBS"
1077 save_CFLAGS="$CFLAGS"
1078 CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
1080 # Detect AIX lossage: JOINABLE attribute is called UNDETACHED.
1081 AC_MSG_CHECKING([for joinable pthread attribute])
1083 for attr in PTHREAD_CREATE_JOINABLE PTHREAD_CREATE_UNDETACHED; do
1084 AC_TRY_LINK([#include <pthread.h>], [int attr=$attr; return attr;],
1085 [attr_name=$attr; break])
1087 AC_MSG_RESULT($attr_name)
1088 if test "$attr_name" != PTHREAD_CREATE_JOINABLE; then
1089 AC_DEFINE_UNQUOTED(PTHREAD_CREATE_JOINABLE, $attr_name,
1090 [Define to necessary symbol if this constant
1091 uses a non-standard name on your system.])
1094 AC_MSG_CHECKING([if more special flags are required for pthreads])
1096 case "${host_cpu}-${host_os}" in
1097 *-aix* | *-freebsd* | *-darwin*) flag="-D_THREAD_SAFE";;
1098 *solaris* | *-osf* | *-hpux*) flag="-D_REENTRANT";;
1100 AC_MSG_RESULT(${flag})
1101 if test "x$flag" != xno; then
1102 PTHREAD_CFLAGS="$flag $PTHREAD_CFLAGS"
1106 CFLAGS="$save_CFLAGS"
1108 # More AIX lossage: must compile with xlc_r or cc_r
1109 if test x"$GCC" != xyes; then
1110 AC_CHECK_PROGS(PTHREAD_CC, xlc_r cc_r, ${CC})
1118 AC_SUBST(PTHREAD_LIBS)
1119 AC_SUBST(PTHREAD_CFLAGS)
1120 AC_SUBST(PTHREAD_CC)
1122 # Finally, execute ACTION-IF-FOUND/ACTION-IF-NOT-FOUND:
1123 if test x"$ax_pthread_ok" = xyes; then
1124 ifelse([$1],,AC_DEFINE(HAVE_PTHREAD,1,[Define if you have POSIX threads libraries and header files.]),[$1])
1139 # LIBCFS_CONDITIONALS
1141 # AM_CONDITOINAL defines for lnet
1143 AC_DEFUN([LIBCFS_CONDITIONALS],
1148 # LIBCFS_CONFIG_FILES
1150 # files that should be generated with AC_OUTPUT
1152 AC_DEFUN([LIBCFS_CONFIG_FILES],
1157 libcfs/autoconf/Makefile
1158 libcfs/include/Makefile
1159 libcfs/include/libcfs/Makefile
1160 libcfs/include/libcfs/linux/Makefile
1161 libcfs/include/libcfs/posix/Makefile
1162 libcfs/include/libcfs/util/Makefile
1163 libcfs/libcfs/Makefile
1164 libcfs/libcfs/autoMakefile
1165 libcfs/libcfs/linux/Makefile
1166 libcfs/libcfs/posix/Makefile
1167 libcfs/libcfs/util/Makefile
1168 libcfs/include/libcfs/darwin/Makefile
1169 libcfs/libcfs/darwin/Makefile