Bernhard Rosenkraenzer | 84c1139 | 2012-09-27 01:39:09 +0159 | [diff] [blame^] | 1 | # configure.ac -- Backtrace configure script. |
| 2 | # Copyright (C) 2012 Free Software Foundation, Inc. |
| 3 | |
| 4 | # Redistribution and use in source and binary forms, with or without |
| 5 | # modification, are permitted provided that the following conditions are |
| 6 | # met: |
| 7 | |
| 8 | # (1) Redistributions of source code must retain the above copyright |
| 9 | # notice, this list of conditions and the following disclaimer. |
| 10 | |
| 11 | # (2) Redistributions in binary form must reproduce the above copyright |
| 12 | # notice, this list of conditions and the following disclaimer in |
| 13 | # the documentation and/or other materials provided with the |
| 14 | # distribution. |
| 15 | |
| 16 | # (3) The name of the author may not be used to |
| 17 | # endorse or promote products derived from this software without |
| 18 | # specific prior written permission. |
| 19 | |
| 20 | # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
| 21 | # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 22 | # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 23 | # DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, |
| 24 | # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 25 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
| 26 | # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 27 | # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
| 28 | # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING |
| 29 | # IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 30 | # POSSIBILITY OF SUCH DAMAGE. |
| 31 | |
| 32 | AC_PREREQ(2.64) |
| 33 | AC_INIT(package-unused, version-unused,, libbacktrace) |
| 34 | AC_CONFIG_SRCDIR(backtrace.h) |
| 35 | AC_CONFIG_HEADER(config.h) |
| 36 | |
| 37 | AC_CANONICAL_SYSTEM |
| 38 | target_alias=${target_alias-$host_alias} |
| 39 | |
| 40 | AC_USE_SYSTEM_EXTENSIONS |
| 41 | |
| 42 | libtool_VERSION=1:0:0 |
| 43 | AC_SUBST(libtool_VERSION) |
| 44 | |
| 45 | AM_INIT_AUTOMAKE([1.11.1 foreign no-dist no-define -Wall -Wno-portability]) |
| 46 | |
| 47 | AM_MAINTAINER_MODE |
| 48 | |
| 49 | AC_ARG_WITH(target-subdir, |
| 50 | [ --with-target-subdir=SUBDIR Configuring in a subdirectory for target]) |
| 51 | |
| 52 | # We must force CC to /not/ be precious variables; otherwise |
| 53 | # the wrong, non-multilib-adjusted value will be used in multilibs. |
| 54 | # As a side effect, we have to subst CFLAGS ourselves. |
| 55 | m4_rename([_AC_ARG_VAR_PRECIOUS],[backtrace_PRECIOUS]) |
| 56 | m4_define([_AC_ARG_VAR_PRECIOUS],[]) |
| 57 | AC_PROG_CC |
| 58 | m4_rename_force([backtrace_PRECIOUS],[_AC_ARG_VAR_PRECIOUS]) |
| 59 | |
| 60 | AC_SUBST(CFLAGS) |
| 61 | |
| 62 | AC_PROG_RANLIB |
| 63 | |
| 64 | AC_PROG_AWK |
| 65 | case "$AWK" in |
| 66 | "") AC_MSG_ERROR([can't build without awk]) ;; |
| 67 | esac |
| 68 | |
| 69 | LT_INIT([disable-shared]) |
| 70 | AM_PROG_LIBTOOL |
| 71 | |
| 72 | backtrace_supported=yes |
| 73 | |
| 74 | if test -n "${with_target_subdir}"; then |
| 75 | # We are compiling a GCC library. We can assume that the unwind |
| 76 | # library exists. |
| 77 | AM_ENABLE_MULTILIB(, ..) |
| 78 | BACKTRACE_FILE="backtrace.lo simple.lo" |
| 79 | else |
| 80 | AC_CHECK_HEADER([unwind.h], |
| 81 | [AC_CHECK_FUNC([_Unwind_Backtrace], |
| 82 | [BACKTRACE_FILE="backtrace.lo simple.lo"], |
| 83 | [BACKTRACE_FILE="nounwind.lo" |
| 84 | backtrace_supported=no])], |
| 85 | [BACKTRACE_FILE="nounwind.lo" |
| 86 | backtrace_supported=no]) |
| 87 | fi |
| 88 | AC_SUBST(BACKTRACE_FILE) |
| 89 | |
| 90 | ACX_PROG_CC_WARNING_OPTS([-W -Wall -Wwrite-strings -Wstrict-prototypes \ |
| 91 | -Wmissing-prototypes -Wold-style-definition \ |
| 92 | -Wmissing-format-attribute -Wcast-qual], |
| 93 | [WARN_FLAGS]) |
| 94 | |
| 95 | if test "x$GCC" = "xyes"; then |
| 96 | WARN_FLAGS="$WARN_FLAGS -Werror" |
| 97 | fi |
| 98 | |
| 99 | AC_SUBST(WARN_FLAGS) |
| 100 | |
| 101 | if test -n "${with_target_subdir}"; then |
| 102 | GCC_CHECK_UNWIND_GETIPINFO |
| 103 | else |
| 104 | AC_CHECK_FUNC(_Unwind_GetIPInfo, [have_unwind_getipinfo=yes], |
| 105 | [have_unwind_getipinfo=no]) |
| 106 | if test "$have_unwind_getipinfo" = "yes"; then |
| 107 | AC_DEFINE(HAVE_GETIPINFO, 1, [Define if _Unwind_GetIPInfo is available.]) |
| 108 | fi |
| 109 | fi |
| 110 | |
| 111 | # When building as a target library, shared libraries may want to link |
| 112 | # this in. We don't want to provide another shared library to |
| 113 | # complicate dependencies. Instead, we just compile with -fPIC. |
| 114 | PIC_FLAG= |
| 115 | if test -n "${with_target_subdir}"; then |
| 116 | PIC_FLAG=-fPIC |
| 117 | fi |
| 118 | AC_SUBST(PIC_FLAG) |
| 119 | |
| 120 | # Test for __sync support. |
| 121 | AC_CACHE_CHECK([__sync extensions], |
| 122 | [libbacktrace_cv_sys_sync], |
| 123 | [if test -n "${with_target_subdir}"; then |
| 124 | libbacktrace_cv_sys_sync=yes |
| 125 | else |
| 126 | AC_LINK_IFELSE( |
| 127 | [AC_LANG_PROGRAM([int i;], |
| 128 | [__sync_bool_compare_and_swap (&i, i, i); |
| 129 | __sync_lock_test_and_set (&i, 1); |
| 130 | __sync_lock_release (&i);])], |
| 131 | [libbacktrace_cv_sys_sync=yes], |
| 132 | [libbacktrace_cv_sys_sync=no]) |
| 133 | fi]) |
| 134 | BACKTRACE_SUPPORTS_THREADS=0 |
| 135 | if test "$libbacktrace_cv_sys_sync" = "yes"; then |
| 136 | BACKTRACE_SUPPORTS_THREADS=1 |
| 137 | AC_DEFINE([HAVE_SYNC_FUNCTIONS], 1, |
| 138 | [Define to 1 if you have the __sync functions]) |
| 139 | fi |
| 140 | AC_SUBST(BACKTRACE_SUPPORTS_THREADS) |
| 141 | |
| 142 | # The library needs to be able to read the executable itself. Compile |
| 143 | # a file to determine the executable format. The awk script |
| 144 | # filetype.awk prints out the file type. |
| 145 | AC_CACHE_CHECK([output filetype], |
| 146 | [libbacktrace_cv_sys_filetype], |
| 147 | [filetype= |
| 148 | AC_COMPILE_IFELSE( |
| 149 | [AC_LANG_PROGRAM([int i;], [int j;])], |
| 150 | [filetype=`${AWK} -f $srcdir/filetype.awk conftest.$ac_objext`], |
| 151 | [AC_MSG_FAILURE([compiler failed])]) |
| 152 | libbacktrace_cv_sys_filetype=$filetype]) |
| 153 | |
| 154 | # Match the file type to decide what files to compile. |
| 155 | FORMAT_FILE= |
| 156 | case "$libbacktrace_cv_sys_filetype" in |
| 157 | elf*) FORMAT_FILE="elf.lo" ;; |
| 158 | *) AC_MSG_WARN([could not determine output file type]) |
| 159 | FORMAT_FILE="unknown.lo" |
| 160 | backtrace_supported=no |
| 161 | ;; |
| 162 | esac |
| 163 | AC_SUBST(FORMAT_FILE) |
| 164 | |
| 165 | # ELF defines. |
| 166 | elfsize= |
| 167 | case "$libbacktrace_cv_sys_filetype" in |
| 168 | elf32) elfsize=32 ;; |
| 169 | elf64) elfsize=64 ;; |
| 170 | esac |
| 171 | AC_DEFINE_UNQUOTED([BACKTRACE_ELF_SIZE], [$elfsize], [ELF size: 32 or 64]) |
| 172 | |
| 173 | BACKTRACE_SUPPORTED=0 |
| 174 | if test "$backtrace_supported" = "yes"; then |
| 175 | BACKTRACE_SUPPORTED=1 |
| 176 | fi |
| 177 | AC_SUBST(BACKTRACE_SUPPORTED) |
| 178 | |
| 179 | GCC_HEADER_STDINT(gstdint.h) |
| 180 | |
| 181 | AC_CHECK_HEADERS(sys/mman.h) |
| 182 | if test "$ac_cv_header_sys_mman_h" = "no"; then |
| 183 | have_mmap=no |
| 184 | else |
| 185 | if test -n "${with_target_subdir}"; then |
| 186 | # When built as a GCC target library, we can't do a link test. We |
| 187 | # simply assume that if we have mman.h, we have mmap. |
| 188 | have_mmap=yes |
| 189 | else |
| 190 | AC_CHECK_FUNC(mmap, [have_mmap=yes], [have_mmap=no]) |
| 191 | fi |
| 192 | fi |
| 193 | if test "$have_mmap" = "no"; then |
| 194 | VIEW_FILE=read.lo |
| 195 | ALLOC_FILE=alloc.lo |
| 196 | else |
| 197 | VIEW_FILE=mmapio.lo |
| 198 | AC_PREPROC_IFELSE([ |
| 199 | #include <sys/mman.h> |
| 200 | #if !defined(MAP_ANONYMOUS) && !defined(MAP_ANON) |
| 201 | #error no MAP_ANONYMOUS |
| 202 | #endif |
| 203 | ], [ALLOC_FILE=mmap.lo], [ALLOC_FILE=alloc.lo]) |
| 204 | fi |
| 205 | AC_SUBST(VIEW_FILE) |
| 206 | AC_SUBST(ALLOC_FILE) |
| 207 | |
| 208 | BACKTRACE_USES_MALLOC=0 |
| 209 | if test "$ALLOC_FILE" = "alloc.lo"; then |
| 210 | BACKTRACE_USES_MALLOC=1 |
| 211 | fi |
| 212 | AC_SUBST(BACKTRACE_USES_MALLOC) |
| 213 | |
| 214 | # Check for the fcntl function. |
| 215 | if test -n "${with_target_subdir}"; then |
| 216 | case "${host}" in |
| 217 | *-*-mingw*) have_fcntl=no ;; |
| 218 | *) have_fcntl=yes ;; |
| 219 | esac |
| 220 | else |
| 221 | AC_CHECK_FUNC(fcntl, [have_fcntl=yes], [have_fcntl=no]) |
| 222 | fi |
| 223 | if test "$have_fcntl" = "yes"; then |
| 224 | AC_DEFINE([HAVE_FCNTL], 1, |
| 225 | [Define to 1 if you have the fcntl function]) |
| 226 | fi |
| 227 | |
| 228 | AC_CHECK_DECLS(strnlen) |
| 229 | |
| 230 | AC_CACHE_CHECK([whether tests can run], |
| 231 | [libbacktrace_cv_sys_native], |
| 232 | [AC_RUN_IFELSE([AC_LANG_PROGRAM([], [return 0;])], |
| 233 | [libbacktrace_cv_sys_native=yes], |
| 234 | [libbacktrace_cv_sys_native=no], |
| 235 | [libbacktrace_cv_sys_native=no])]) |
| 236 | AM_CONDITIONAL(NATIVE, test "$libbacktrace_cv_sys_native" = "yes") |
| 237 | |
| 238 | if test "${multilib}" = "yes"; then |
| 239 | multilib_arg="--enable-multilib" |
| 240 | else |
| 241 | multilib_arg= |
| 242 | fi |
| 243 | |
| 244 | AC_CONFIG_FILES(Makefile backtrace-supported.h) |
| 245 | |
| 246 | # We need multilib support, but only if configuring for the target. |
| 247 | AC_CONFIG_COMMANDS([default], |
| 248 | [if test -n "$CONFIG_FILES"; then |
| 249 | if test -n "${with_target_subdir}"; then |
| 250 | # Multilibs need MULTISUBDIR defined correctly in certain makefiles so |
| 251 | # that multilib installs will end up installed in the correct place. |
| 252 | # The testsuite needs it for multilib-aware ABI baseline files. |
| 253 | # To work around this not being passed down from config-ml.in -> |
| 254 | # srcdir/Makefile.am -> srcdir/{src,libsupc++,...}/Makefile.am, manually |
| 255 | # append it here. Only modify Makefiles that have just been created. |
| 256 | # |
| 257 | # Also, get rid of this simulated-VPATH thing that automake does. |
| 258 | cat > vpsed << \_EOF |
| 259 | s!`test -f '$<' || echo '$(srcdir)/'`!! |
| 260 | _EOF |
| 261 | for i in $SUBDIRS; do |
| 262 | case $CONFIG_FILES in |
| 263 | *${i}/Makefile*) |
| 264 | #echo "Adding MULTISUBDIR to $i/Makefile" |
| 265 | sed -f vpsed $i/Makefile > tmp |
| 266 | grep '^MULTISUBDIR =' Makefile >> tmp |
| 267 | mv tmp $i/Makefile |
| 268 | ;; |
| 269 | esac |
| 270 | done |
| 271 | rm vpsed |
| 272 | fi |
| 273 | fi |
| 274 | ], |
| 275 | [ |
| 276 | # Variables needed in config.status (file generation) which aren't already |
| 277 | # passed by autoconf. |
| 278 | SUBDIRS="$SUBDIRS" |
| 279 | ]) |
| 280 | |
| 281 | AC_OUTPUT |