21209d99f19c50c8ae9274f1722e69621748370a
[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(unistd.h, ac_cv_have_unistd_h=1, ac_cv_have_unistd_h=0)
32 AC_CHECK_HEADERS(syscall.h)
33 AC_CHECK_HEADERS(sys/syscall.h)
34 # For backtrace with glibc.
35 AC_CHECK_HEADERS(execinfo.h)
36 # For backtrace with libunwind.
37 AC_CHECK_HEADERS(libunwind.h)
38 AC_CHECK_HEADERS(ucontext.h)
39 AC_CHECK_HEADERS(sys/utsname.h)
40 AC_CHECK_HEADERS(pwd.h)
41 AC_CHECK_HEADERS(syslog.h)
42 AC_CHECK_HEADERS(sys/time.h)
43 AC_CHECK_HEADERS(glob.h)
44
45 AC_CHECK_SIZEOF(void *)
46
47 # These are the types I need.  We look for them in either stdint.h,
48 # sys/types.h, or inttypes.h, all of which are part of the default-includes.
49 AC_CHECK_TYPE(uint16_t, ac_cv_have_uint16_t=1, ac_cv_have_uint16_t=0)
50 AC_CHECK_TYPE(u_int16_t, ac_cv_have_u_int16_t=1, ac_cv_have_u_int16_t=0)
51 AC_CHECK_TYPE(__uint16, ac_cv_have___uint16=1, ac_cv_have___uint16=0)
52
53 AC_CHECK_FUNC(sigaltstack,
54               AC_DEFINE(HAVE_SIGALTSTACK, 1,
55                         [Define if you have the `sigaltstack' function]))
56 AC_CHECK_FUNC(dladdr,
57               AC_DEFINE(HAVE_DLADDR, 1,
58                         [Define if you have the `dladdr' function]))
59 AC_CHECK_FUNC(fcntl,
60               AC_DEFINE(HAVE_FCNTL, 1,
61                         [Define if you have the `fcntl' function]))
62
63 AX_C___ATTRIBUTE__
64 # We only care about these two attributes.
65 if test x"$ac_cv___attribute__" = x"yes"; then
66   ac_cv___attribute___noreturn="__attribute__ ((noreturn))"
67   ac_cv___attribute___printf_4_5="__attribute__((__format__ (__printf__, 4, 5)))"
68 else
69   ac_cv___attribute___noreturn=
70   ac_cv___attribute___printf_4_5=
71 fi
72
73 AX_C___BUILTIN_EXPECT
74 if test x"$ac_cv___builtin_expect" = x"yes"; then
75   ac_cv_have___builtin_expect=1
76 else
77   ac_cv_have___builtin_expect=0
78 fi
79
80 AX_C___SYNC_VAL_COMPARE_AND_SWAP
81
82 # On x86_64, instead of libunwind, we can choose to compile with frame-pointers
83 # (This isn't needed on i386, where -fno-omit-frame-pointer is the default).
84 AC_ARG_ENABLE(frame_pointers,
85               AS_HELP_STRING([--enable-frame-pointers],
86                              [On x86_64 systems, compile with -fno-omit-frame-pointer (see INSTALL)]),
87               enable_frame_pointers=no)
88 AC_COMPILE_IFELSE([AC_LANG_PROGRAM(, [return __x86_64__ == 1 ? 0 : 1])],
89                   [is_x86_64=yes], [is_x86_64=no])
90 AM_CONDITIONAL(ENABLE_FRAME_POINTERS, test "$enable_frame_pointers" = yes)
91 AM_CONDITIONAL(X86_64, test "$is_x86_64" = yes)
92
93 # Some of the code in this directory depends on pthreads
94 ACX_PTHREAD
95 # To make libglog depend on libpthread on Linux, we need to add
96 # -lpthread in addition to -pthread.
97 AC_CHECK_LIB(pthread, pthread_self)
98
99 # Check if there is google-gflags library installed.
100 AC_CHECK_LIB(gflags, main, ac_cv_have_libgflags=1, ac_cv_have_libgflags=0)
101 if test x"$ac_cv_have_libgflags" = x"1"; then
102   GFLAGS_LIBS=-lgflags
103   AC_DEFINE(HAVE_LIB_GFLAGS, 1, [define if you have google gflags library])
104 else
105   GFLAGS_LIBS=
106 fi
107
108 # TODO(hamaji): Use official m4 macros provided by testing libraries
109 #               once the m4 macro of Google Mocking becomes ready.
110 # Check if there is Google Test library installed.
111 AC_CHECK_PROG(GTEST_CONFIG, gtest-config, "yes")
112 if test x"$GTEST_CONFIG" = "xyes"; then
113   GTEST_CFLAGS=`gtest-config --cppflags --cxxflags`
114   GTEST_LIBS=`gtest-config --ldflags --libs`
115   AC_DEFINE(HAVE_LIB_GTEST, 1, [define if you have google gtest library])
116
117   # Check if there is Google Mocking library installed.
118   AC_CHECK_PROG(GMOCK_CONFIG, gmock-config, "yes")
119   if test x"$GMOCK_CONFIG" = "xyes"; then
120     GMOCK_CFLAGS=`gmock-config --cppflags --cxxflags`
121     GMOCK_LIBS=`gmock-config --ldflags --libs`
122     AC_DEFINE(HAVE_LIB_GMOCK, 1, [define if you have google gmock library])
123   else
124     # We don't run test cases which use Google Mocking framework.
125     GMOCK_CFLAGS=
126     GMOCK_LIBS=
127   fi
128 else
129   # We'll use src/googletest.h for our unittests.
130   GTEST_CFLAGS=
131   GTEST_LIBS=
132 fi
133 AM_CONDITIONAL(HAVE_GMOCK, test x"$GMOCK_CONFIG" = "xyes")
134
135 # We want to link in libunwind if it exists
136 UNWIND_LIBS=
137 # Unfortunately, we need to check the header file in addition to the
138 # lib file to check if libunwind is available since libunwind-0.98
139 # doesn't install all necessary header files.
140 if test x"$ac_cv_have_libunwind_h" = x"1"; then
141  AC_CHECK_LIB(unwind, backtrace, UNWIND_LIBS=-lunwind)
142 fi
143 AC_SUBST(UNWIND_LIBS)
144 if test x"$UNWIND_LIBS" != x""; then
145   AC_DEFINE(HAVE_LIB_UNWIND, 1, [define if you have libunwind])
146 fi
147
148 # We'd like to use read/write locks in several places in the code.
149 # See if our pthreads support extends to that.  Note: for linux, it
150 # does as long as you define _XOPEN_SOURCE appropriately.
151 AC_RWLOCK
152
153 # Find out what namespace 'normal' STL code lives in, and also what namespace
154 # the user wants our classes to be defined in
155 AC_CXX_STL_NAMESPACE
156 AC_DEFINE_GOOGLE_NAMESPACE(google)
157
158 AC_CXX_USING_OPERATOR
159
160 # We want to access the "PC" (Program Counter) register from a struct
161 # ucontext.  Every system has its own way of doing that.  We try all the
162 # possibilities we know about.  Note REG_PC should come first (REG_RIP
163 # is also defined on solaris, but does the wrong thing).
164 AC_MSG_CHECKING([how to access the program counter from a struct ucontext])
165 pc_fields="           uc_mcontext.gregs[[REG_PC]]"  # Solaris x86 (32 + 64 bit)
166 pc_fields="$pc_fields uc_mcontext.gregs[[REG_EIP]]" # Linux (i386)
167 pc_fields="$pc_fields uc_mcontext.gregs[[REG_RIP]]" # Linux (x86_64)
168 pc_fields="$pc_fields uc_mcontext.sc_ip"            # Linux (ia64)
169 pc_fields="$pc_fields uc_mcontext.uc_regs->gregs[[PT_NIP]]" # Linux (ppc)
170 pc_fields="$pc_fields uc_mcontext.gregs[[R15]]"     # Linux (arm old [untested])
171 pc_fields="$pc_fields uc_mcontext.arm_pc"           # Linux (arm new [untested])
172 pc_fields="$pc_fields uc_mcontext.mc_eip"           # FreeBSD (i386)
173 pc_fields="$pc_fields uc_mcontext.mc_rip"           # FreeBSD (x86_64 [untested])
174 pc_fields="$pc_fields uc_mcontext->ss.eip"          # OS X (i386, <=10.4)
175 pc_fields="$pc_fields uc_mcontext->__ss.__eip"      # OS X (i386, >=10.5)
176 pc_fields="$pc_fields uc_mcontext->ss.rip"          # OS X (x86_64)
177 pc_fields="$pc_fields uc_mcontext->__ss.__rip"      # OS X (>=10.5 [untested])
178 pc_fields="$pc_fields uc_mcontext->ss.srr0"         # OS X (ppc, ppc64 [untested])
179 pc_fields="$pc_fields uc_mcontext->__ss.__srr0"     # OS X (>=10.5 [untested])
180 pc_field_found=false
181 for pc_field in $pc_fields; do
182   if ! $pc_field_found; then
183     AC_TRY_COMPILE([#define _GNU_SOURCE 1
184                     #include <ucontext.h>],
185                    [ucontext_t u; return u.$pc_field == 0;],
186                    AC_DEFINE_UNQUOTED(PC_FROM_UCONTEXT, $pc_field,
187                                       How to access the PC from a struct ucontext)
188                    AC_MSG_RESULT([$pc_field])
189                  pc_field_found=true)
190   fi
191 done
192 if ! $pc_field_found; then
193   AC_MSG_WARN(Could not find the PC.  Will not output failed addresses...)
194 fi
195
196 # These are what's needed by logging.h.in and raw_logging.h.in
197 AC_SUBST(ac_google_start_namespace)
198 AC_SUBST(ac_google_end_namespace)
199 AC_SUBST(ac_google_namespace)
200 AC_SUBST(ac_cv_cxx_using_operator)
201 AC_SUBST(ac_cv___attribute___noreturn)
202 AC_SUBST(ac_cv___attribute___printf_4_5)
203 AC_SUBST(ac_cv_have___builtin_expect)
204 AC_SUBST(ac_cv_have_stdint_h)
205 AC_SUBST(ac_cv_have_systypes_h)
206 AC_SUBST(ac_cv_have_inttypes_h)
207 AC_SUBST(ac_cv_have_unistd_h)
208 AC_SUBST(ac_cv_have_uint16_t)
209 AC_SUBST(ac_cv_have_u_int16_t)
210 AC_SUBST(ac_cv_have___uint16)
211 AC_SUBST(ac_cv_have_libgflags)
212 AC_SUBST(GFLAGS_LIBS)
213 AC_SUBST(GTEST_CFLAGS)
214 AC_SUBST(GMOCK_CFLAGS)
215 AC_SUBST(GTEST_LIBS)
216 AC_SUBST(GMOCK_LIBS)
217
218 # Write generated configuration file
219 AC_CONFIG_FILES([Makefile src/glog/logging.h src/glog/raw_logging.h src/glog/vlog_is_on.h src/glog/stl_logging.h])
220 AC_OUTPUT