Add -lpthread in addition to -pthread on Linux.
[platform/upstream/glog.git] / configure.ac
1 ## Process this file with autoconf to produce configure.
2 ## In general, the safest way to proceed is to run the following:
3 ##    % aclocal -I . -I `pwd`/../autoconf && autoheader && autoconf && automake
4
5 # make sure we're interpreted by some minimal autoconf
6 AC_PREREQ(2.57)
7
8 AC_INIT(glog, 0.1.2, opensource@google.com)
9 # The argument here is just something that should be in the current directory
10 # (for sanity checking)
11 AC_CONFIG_SRCDIR(README)
12 AM_INIT_AUTOMAKE
13 AM_CONFIG_HEADER(src/config.h)
14
15 # Checks for programs.
16 AC_PROG_CC
17 AC_PROG_CPP
18 AC_PROG_CXX
19 AM_CONDITIONAL(GCC, test "$GCC" = yes)   # let the Makefile know if we're gcc
20
21 AC_PROG_LIBTOOL
22 AC_SUBST(LIBTOOL_DEPS)
23
24 # Check whether some low-level functions/files are available
25 AC_HEADER_STDC
26
27 # These are tested for by AC_HEADER_STDC, but I check again to set the var
28 AC_CHECK_HEADER(stdint.h, ac_cv_have_stdint_h=1, ac_cv_have_stdint_h=0)
29 AC_CHECK_HEADER(sys/types.h, ac_cv_have_systypes_h=1, ac_cv_have_systypes_h=0)
30 AC_CHECK_HEADER(inttypes.h, ac_cv_have_inttypes_h=1, ac_cv_have_inttypes_h=0)
31 AC_CHECK_HEADERS(syscall.h)
32 AC_CHECK_HEADERS(sys/syscall.h)
33 # For backtrace with glibc.
34 AC_CHECK_HEADERS(execinfo.h)
35 # For backtrace with libunwind.
36 AC_CHECK_HEADERS(libunwind.h, ac_cv_have_libunwind_h=1, ac_cv_have_libunwind_h=0)
37 AC_CHECK_HEADERS(ucontext.h)
38
39 AC_CHECK_SIZEOF(void *)
40
41 # These are the types I need.  We look for them in either stdint.h,
42 # sys/types.h, or inttypes.h, all of which are part of the default-includes.
43 AC_CHECK_TYPE(uint16_t, ac_cv_have_uint16_t=1, ac_cv_have_uint16_t=0)
44 AC_CHECK_TYPE(u_int16_t, ac_cv_have_u_int16_t=1, ac_cv_have_u_int16_t=0)
45 AC_CHECK_TYPE(__uint16, ac_cv_have___uint16=1, ac_cv_have___uint16=0)
46
47 AC_CHECK_FUNC(sigaltstack,
48               AC_DEFINE(HAVE_SIGALTSTACK, 1,
49                         [Define if you have the `sigaltstack' function]))
50 AC_CHECK_FUNC(dladdr,
51               AC_DEFINE(HAVE_DLADDR, 1,
52                         [Define if you have the `dladdr' function]))
53
54 AX_C___ATTRIBUTE__
55 # We only care about these two attributes.
56 if test x"$ac_cv___attribute__" = x"yes"; then
57   ac_cv___attribute___noreturn="__attribute__ ((noreturn))"
58   ac_cv___attribute___printf_4_5="__attribute__((__format__ (__printf__, 4, 5)))"
59 else
60   ac_cv___attribute___noreturn=
61   ac_cv___attribute___printf_4_5=
62 fi
63
64 AX_C___BUILTIN_EXPECT
65 if test x"$ac_cv___builtin_expect" = x"yes"; then
66   ac_cv_have___builtin_expect=1
67 else
68   ac_cv_have___builtin_expect=0
69 fi
70
71 AX_C___SYNC_VAL_COMPARE_AND_SWAP
72
73 # On x86_64, instead of libunwind, we can choose to compile with frame-pointers
74 # (This isn't needed on i386, where -fno-omit-frame-pointer is the default).
75 AC_ARG_ENABLE(frame_pointers,
76               AS_HELP_STRING([--enable-frame-pointers],
77                              [On x86_64 systems, compile with -fno-omit-frame-pointer (see INSTALL)]),
78               enable_frame_pointers=no)
79 AC_COMPILE_IFELSE([AC_LANG_PROGRAM(, [return __x86_64__ == 1 ? 0 : 1])],
80                   [is_x86_64=yes], [is_x86_64=no])
81 AM_CONDITIONAL(ENABLE_FRAME_POINTERS, test "$enable_frame_pointers" = yes)
82 AM_CONDITIONAL(X86_64, test "$is_x86_64" = yes)
83
84 # Some of the code in this directory depends on pthreads
85 ACX_PTHREAD
86 # To make libglog depend on libpthread on Linux, we need to add
87 # -lpthread in addition to -pthread.
88 AC_CHECK_LIB(pthread, pthread_self)
89
90 # Check if there is google-gflags library installed.
91 AC_CHECK_LIB(gflags, main, ac_cv_have_libgflags=1, ac_cv_have_libgflags=0)
92 if test x"$ac_cv_have_libgflags" = x"1"; then
93   GFLAGS_LIBS=-lgflags
94   AC_DEFINE(HAVE_LIB_GFLAGS, 1, [define if you have google gflags library])
95 else
96   GFLAGS_LIBS=
97 fi
98
99 # We want to link in libunwind if it exists
100 UNWIND_LIBS=
101 # Unfortunately, we need to check the header file in addition to the
102 # lib file to check if libunwind is available since libunwind-0.98
103 # doesn't install all necessary header files.
104 if test x"$ac_cv_have_libunwind_h" = x"1"; then
105  AC_CHECK_LIB(unwind, backtrace, UNWIND_LIBS=-lunwind)
106 fi
107 AC_SUBST(UNWIND_LIBS)
108 if test x"$UNWIND_LIBS" != x""; then
109   AC_DEFINE(HAVE_LIB_UNWIND, 1, [define if you have libunwind])
110 fi
111
112 # We'd like to use read/write locks in several places in the code.
113 # See if our pthreads support extends to that.  Note: for linux, it
114 # does as long as you define _XOPEN_SOURCE appropriately.
115 AC_RWLOCK
116
117 # Find out what namespace 'normal' STL code lives in, and also what namespace
118 # the user wants our classes to be defined in
119 AC_CXX_STL_NAMESPACE
120 AC_DEFINE_GOOGLE_NAMESPACE(google)
121
122 AC_CXX_USING_OPERATOR
123
124 # We want to access the "PC" (Program Counter) register from a struct
125 # ucontext.  Every system has its own way of doing that.  We try all the
126 # possibilities we know about.  Note REG_PC should come first (REG_RIP
127 # is also defined on solaris, but does the wrong thing).
128 AC_MSG_CHECKING([how to access the program counter from a struct ucontext])
129 pc_fields="           uc_mcontext.gregs[[REG_PC]]"  # Solaris x86 (32 + 64 bit)
130 pc_fields="$pc_fields uc_mcontext.gregs[[REG_EIP]]" # Linux (i386)
131 pc_fields="$pc_fields uc_mcontext.gregs[[REG_RIP]]" # Linux (x86_64)
132 pc_fields="$pc_fields uc_mcontext.sc_ip"            # Linux (ia64)
133 pc_fields="$pc_fields uc_mcontext.uc_regs->gregs[[PT_NIP]]" # Linux (ppc)
134 pc_fields="$pc_fields uc_mcontext.gregs[[R15]]"     # Linux (arm old [untested])
135 pc_fields="$pc_fields uc_mcontext.arm_pc"           # Linux (arm new [untested])
136 pc_fields="$pc_fields uc_mcontext.mc_eip"           # FreeBSD (i386)
137 pc_fields="$pc_fields uc_mcontext.mc_rip"           # FreeBSD (x86_64 [untested])
138 pc_fields="$pc_fields uc_mcontext->ss.eip"          # OS X (i386, <=10.4)
139 pc_fields="$pc_fields uc_mcontext->__ss.__eip"      # OS X (i386, >=10.5)
140 pc_fields="$pc_fields uc_mcontext->ss.rip"          # OS X (x86_64)
141 pc_fields="$pc_fields uc_mcontext->__ss.__rip"      # OS X (>=10.5 [untested])
142 pc_fields="$pc_fields uc_mcontext->ss.srr0"         # OS X (ppc, ppc64 [untested])
143 pc_fields="$pc_fields uc_mcontext->__ss.__srr0"     # OS X (>=10.5 [untested])
144 pc_field_found=false
145 for pc_field in $pc_fields; do
146   if ! $pc_field_found; then
147     AC_TRY_COMPILE([#define _GNU_SOURCE 1
148                     #include <ucontext.h>],
149                    [ucontext_t u; return u.$pc_field == 0;],
150                    AC_DEFINE_UNQUOTED(PC_FROM_UCONTEXT, $pc_field,
151                                       How to access the PC from a struct ucontext)
152                    AC_MSG_RESULT([$pc_field])
153                  pc_field_found=true)
154   fi
155 done
156 if ! $pc_field_found; then
157   AC_MSG_WARN(Could not find the PC.  Will not output failed addresses...)
158 fi
159
160 # These are what's needed by logging.h.in and raw_logging.h.in
161 AC_SUBST(ac_google_start_namespace)
162 AC_SUBST(ac_google_end_namespace)
163 AC_SUBST(ac_google_namespace)
164 AC_SUBST(ac_cv_cxx_using_operator)
165 AC_SUBST(ac_cv___attribute___noreturn)
166 AC_SUBST(ac_cv___attribute___printf_4_5)
167 AC_SUBST(ac_cv_have___builtin_expect)
168 AC_SUBST(ac_cv_have_stdint_h)
169 AC_SUBST(ac_cv_have_systypes_h)
170 AC_SUBST(ac_cv_have_inttypes_h)
171 AC_SUBST(ac_cv_have_uint16_t)
172 AC_SUBST(ac_cv_have_u_int16_t)
173 AC_SUBST(ac_cv_have___uint16)
174 AC_SUBST(ac_cv_have_libgflags)
175 AC_SUBST(GFLAGS_LIBS)
176
177 # Write generated configuration file
178 AC_CONFIG_FILES([Makefile src/glog/logging.h src/glog/raw_logging.h src/glog/vlog_is_on.h src/glog/stl_logging.h])
179 AC_OUTPUT