Merged trunk.
[awesomized/libmemcached] / m4 / pandora_canonical.m4
1 dnl Copyright (C) 2009 Sun Microsystems
2 dnl This file is free software; Sun Microsystems
3 dnl gives unlimited permission to copy and/or distribute it,
4 dnl with or without modifications, as long as this notice is preserved.
5
6 dnl Which version of the canonical setup we're using
7 AC_DEFUN([PANDORA_CANONICAL_VERSION],[0.79])
8
9 AC_DEFUN([PANDORA_FORCE_DEPEND_TRACKING],[
10 dnl Force dependency tracking on for Sun Studio builds
11 AS_IF([test "x${enable_dependency_tracking}" = "x"],[
12 enable_dependency_tracking=yes
13 ])
14 ])
15
16 dnl The standard setup for how we build Pandora projects
17 AC_DEFUN([PANDORA_CANONICAL_TARGET],[
18 AC_REQUIRE([PANDORA_FORCE_DEPEND_TRACKING])
19 ifdef([m4_define],,[define([m4_define], defn([define]))])
20 ifdef([m4_undefine],,[define([m4_undefine], defn([undefine]))])
21 m4_define([PCT_ALL_ARGS],[$*])
22 m4_define([PCT_USE_GNULIB],[no])
23 m4_define([PCT_REQUIRE_CXX],[no])
24 m4_define([PCT_IGNORE_SHARED_PTR],[no])
25 m4_define([PCT_FORCE_GCC42],[no])
26 m4_define([PCT_SRC_IN_SRC],[no])
27 m4_define([PCT_VERSION_FROM_VC],[no])
28 m4_define([PCT_USE_VISIBILITY],[yes])
29 m4_foreach([pct_arg],[$*],[
30 m4_case(pct_arg,
31 [use-gnulib], [
32 m4_undefine([PCT_USE_GNULIB])
33 m4_define([PCT_USE_GNULIB],[yes])
34 ],
35 [require-cxx], [
36 m4_undefine([PCT_REQUIRE_CXX])
37 m4_define([PCT_REQUIRE_CXX],[yes])
38 ],
39 [ignore-shared-ptr], [
40 m4_undefine([PCT_IGNORE_SHARED_PTR])
41 m4_define([PCT_IGNORE_SHARED_PTR],[yes])
42 ],
43 [force-gcc42], [
44 m4_undefine([PCT_FORCE_GCC42])
45 m4_define([PCT_FORCE_GCC42],[yes])
46 ],
47 [skip-visibility], [
48 m4_undefine([PCT_USE_VISIBILITY])
49 m4_define([PCT_USE_VISIBILITY],[no])
50 ],
51 [src-in-src], [
52 m4_undefine([PCT_SRC_IN_SRC])
53 m4_define([PCT_SRC_IN_SRC],[yes])
54 ],
55 [version-from-vc], [
56 m4_undefine([PCT_VERSION_FROM_VC])
57 m4_define([PCT_VERSION_FROM_VC],[yes])
58 ])
59 ])
60
61 # We need to prevent canonical target
62 # from injecting -O2 into CFLAGS - but we won't modify anything if we have
63 # set CFLAGS on the command line, since that should take ultimate precedence
64 AS_IF([test "x${ac_cv_env_CFLAGS_set}" = "x"],
65 [CFLAGS=""])
66 AS_IF([test "x${ac_cv_env_CXXFLAGS_set}" = "x"],
67 [CXXFLAGS=""])
68
69 AC_CANONICAL_TARGET
70
71 AM_INIT_AUTOMAKE(-Wall -Werror nostdinc subdir-objects foreign)
72 m4_ifdef([AM_SILENT_RULES],[AM_SILENT_RULES([yes])])
73
74 m4_if(PCT_USE_GNULIB,yes,[ gl_EARLY ])
75
76 AC_REQUIRE([AC_PROG_CC])
77 AC_REQUIRE([PANDORA_MAC_GCC42])
78 AC_REQUIRE([PANDORA_64BIT])
79
80 m4_if(PCT_VERSION_FROM_VC,yes,[
81 PANDORA_VC_VERSION
82 ])
83 PANDORA_VERSION
84
85 dnl Once we can use a modern autoconf, we can use this
86 dnl AC_PROG_CC_C99
87 AC_REQUIRE([AC_PROG_CXX])
88 PANDORA_EXTENSIONS
89 AM_PROG_CC_C_O
90
91
92 m4_if(PCT_FORCE_GCC42, [yes], [
93 AS_IF([test "$GCC" = "yes"], PANDORA_ENSURE_GCC_VERSION)
94 ])
95
96 PANDORA_PLATFORM
97
98 PANDORA_LIBTOOL
99
100 AS_IF([test "$lt_cv_prog_gnu_ld" = "yes"],[
101 AM_LDFLAGS="${AM_LDFLAGS} -Wl,--default-symver"
102 ])
103
104 dnl autoconf doesn't automatically provide a fail-if-no-C++ macro
105 dnl so we check c++98 features and fail if we don't have them, mainly
106 dnl for that reason
107 PANDORA_CHECK_CXX_STANDARD
108 m4_if(PCT_REQUIRE_CXX, [yes], [
109 AS_IF([test "$ac_cv_cxx_stdcxx_98" = "no"],[
110 AC_MSG_ERROR([No working C++ Compiler has been found. ${PACKAGE} requires a C++ compiler that can handle C++98])
111 ])
112
113 ])
114
115 PANDORA_SHARED_PTR
116 m4_if(PCT_IGNORE_SHARED_PTR, [no], [
117 AS_IF([test "$ac_cv_shared_ptr_namespace" = "missing"],[
118 AC_MSG_WARN([a usable shared_ptr implementation was not found. Let someone know what your platform is.])
119 ])
120 ])
121
122 m4_if(PCT_USE_GNULIB, [yes], [
123 gl_INIT
124 AC_CONFIG_LIBOBJ_DIR([gnulib])
125 ])
126
127 PANDORA_CHECK_C_VERSION
128 PANDORA_CHECK_CXX_VERSION
129
130 AC_C_BIGENDIAN
131 AC_C_CONST
132 AC_C_INLINE
133 AC_C_VOLATILE
134 AC_C_RESTRICT
135
136 AC_HEADER_TIME
137 AC_TYPE_SIZE_T
138 AC_SYS_LARGEFILE
139
140 # off_t is not a builtin type
141 AC_CHECK_SIZEOF(off_t, 4)
142 AS_IF([test "$ac_cv_sizeof_off_t" -eq 0],[
143 AC_MSG_ERROR("${PACKAGE} needs an off_t type.")
144 ])
145
146 AC_CHECK_SIZEOF(size_t)
147 AS_IF([test "$ac_cv_sizeof_size_t" -eq 0],[
148 AC_MSG_ERROR("${PACKAGE} needs an size_t type.")
149 ])
150
151 AC_DEFINE_UNQUOTED([SIZEOF_SIZE_T],[$ac_cv_sizeof_size_t],[Size of size_t as computed by sizeof()])
152 AC_CHECK_SIZEOF(long long)
153 AC_DEFINE_UNQUOTED([SIZEOF_LONG_LONG],[$ac_cv_sizeof_long_long],[Size of long long as computed by sizeof()])
154 AC_CACHE_CHECK([if time_t is unsigned], [ac_cv_time_t_unsigned],[
155 AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
156 [[
157 #include <time.h>
158 ]],
159 [[
160 int array[(((time_t)-1) > 0) ? 1 : -1];
161 ]])
162 ],[
163 ac_cv_time_t_unsigned=yes
164 ],[
165 ac_cv_time_t_unsigned=no
166 ])
167 ])
168 AS_IF([test "$ac_cv_time_t_unsigned" = "yes"],[
169 AC_DEFINE([TIME_T_UNSIGNED], 1, [Define to 1 if time_t is unsigned])
170 ])
171
172 dnl AC_FUNC_ALLOCA would test for stack direction if we didn't have a working
173 dnl alloca - but we need to know it anyway for check_stack_overrun.
174 PANDORA_STACK_DIRECTION
175
176 save_LIBS="${LIBS}"
177 LIBS=""
178 AC_CHECK_LIB(m, floor, [], AC_CHECK_LIB(m, __infinity))
179 LIBM="${LIBS}"
180 LIBS="${save_LIBS}"
181 AC_SUBST([LIBM])
182
183 AC_CHECK_FUNC(setsockopt, [], [AC_CHECK_LIB(socket, setsockopt)])
184 AC_CHECK_FUNC(bind, [], [AC_CHECK_LIB(bind, bind)])
185
186
187
188 PANDORA_OPTIMIZE
189
190 AC_LANG_PUSH(C++)
191 # Test whether madvise() is declared in C++ code -- it is not on some
192 # systems, such as Solaris
193 AC_CHECK_DECLS([madvise], [], [], [AC_INCLUDES_DEFAULT[
194 #if HAVE_SYS_MMAN_H
195 #include <sys/types.h>
196 #include <sys/mman.h>
197 #endif
198 ]])
199 AC_LANG_POP()
200
201 PANDORA_HAVE_GCC_ATOMICS
202
203 m4_if(PCT_USE_VISIBILITY,[yes],[
204 dnl We need to inject error into the cflags to test if visibility works or not
205 save_CFLAGS="${CFLAGS}"
206 CFLAGS="${CFLAGS} -Werror"
207 gl_VISIBILITY
208 CFLAGS="${save_CFLAGS}"
209 ])
210
211 PANDORA_HEADER_ASSERT
212
213 PANDORA_WARNINGS(PCT_ALL_ARGS)
214
215 PANDORA_ENABLE_DTRACE
216
217 AC_LIB_PREFIX
218 PANDORA_HAVE_BETTER_MALLOC
219
220 AC_CHECK_PROGS([DOXYGEN], [doxygen])
221 AC_CHECK_PROGS([PERL], [perl])
222
223 AS_IF([test "x${gl_LIBOBJS}" != "x"],[
224 AS_IF([test "$GCC" = "yes"],[
225 AM_CPPFLAGS="-isystem \$(top_srcdir)/gnulib -isystem \$(top_builddir)/gnulib ${AM_CPPFLAGS}"
226 ],[
227 AM_CPPFLAGS="-I\$(top_srcdir)/gnulib -I\$(top_builddir)/gnulib ${AM_CPPFLAGS}"
228 ])
229 ])
230 AS_IF([test "PCT_SRC_IN_SRC" = "yes"],[
231 AM_CPPFLAGS="-I\$(top_srcdir)/src -I\$(top_builddir)/src ${AM_CPPFLAGS}"
232 ])
233
234 PANDORA_USE_PIPE
235
236
237 AM_CPPFLAGS="-I\${top_srcdir} -I\${top_builddir} ${AM_CPPFLAGS}"
238 AM_CFLAGS="${AM_CFLAGS} ${CC_WARNINGS} ${CC_PROFILING} ${CC_COVERAGE}"
239 AM_CXXFLAGS="${AM_CXXFLAGS} ${CXX_WARNINGS} ${CC_PROFILING} ${CC_COVERAGE}"
240
241 AC_SUBST([AM_CFLAGS])
242 AC_SUBST([AM_CXXFLAGS])
243 AC_SUBST([AM_CPPFLAGS])
244 AC_SUBST([AM_LDFLAGS])
245
246 ])