1dnl ##
2dnl ##  OSSP ex - Exception Handling
3dnl ##  Copyright (c) 2002-2007 Ralf S. Engelschall <rse@engelschall.com>
4dnl ##  Copyright (c) 2002-2007 The OSSP Project <http://www.ossp.org/>
5dnl ##
6dnl ##  This file is part of OSSP ex, an exception handling library
7dnl ##  which can be found at http://www.ossp.org/pkg/lib/ex/.
8dnl ##
9dnl ##  Permission to use, copy, modify, and distribute this software for
10dnl ##  any purpose with or without fee is hereby granted, provided that
11dnl ##  the above copyright notice and this permission notice appear in all
12dnl ##  copies.
13dnl ##
14dnl ##  THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
15dnl ##  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
16dnl ##  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17dnl ##  IN NO EVENT SHALL THE AUTHORS AND COPYRIGHT HOLDERS AND THEIR
18dnl ##  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
19dnl ##  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
20dnl ##  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
21dnl ##  USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
22dnl ##  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
23dnl ##  OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
24dnl ##  OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25dnl ##  SUCH DAMAGE.
26dnl ##
27dnl ##  aclocal.m4: GNU Autoconf local macro definitions
28dnl ##
29
30dnl ##
31dnl ##  Check whether compiler option works
32dnl ##
33dnl ##  configure.in:
34dnl ##    AC_COMPILER_OPTION(<name>, <display>, <option>,
35dnl ##                       <action-success>, <action-failure>)
36dnl ##
37
38AC_DEFUN(AC_COMPILER_OPTION,[dnl
39AC_MSG_CHECKING(whether compiler option(s) $2 work)
40AC_CACHE_VAL(ac_cv_compiler_option_$1,[
41SAVE_CFLAGS="$CFLAGS"
42CFLAGS="$CFLAGS $3"
43AC_TRY_COMPILE([],[], ac_cv_compiler_option_$1=yes, ac_cv_compiler_option_$1=no)
44CFLAGS="$SAVE_CFLAGS"
45])dnl
46if test ".$ac_cv_compiler_option_$1" = .yes; then
47    ifelse([$4], , :, [$4])
48else
49    ifelse([$5], , :, [$5])
50fi
51AC_MSG_RESULT([$ac_cv_compiler_option_$1])
52])dnl
53
54dnl ##
55dnl ##  Debugging Support
56dnl ##
57dnl ##  configure.in:
58dnl ##    AC_CHECK_DEBUGGING
59dnl ##
60
61AC_DEFUN(AC_CHECK_DEBUGGING,[dnl
62AC_ARG_ENABLE(debug,dnl
63[  --enable-debug          build for debugging (default=no)],
64[dnl
65if test ".$ac_cv_prog_gcc" = ".yes"; then
66    case "$CFLAGS" in
67        *-O* ) ;;
68           * ) CFLAGS="$CFLAGS -O2" ;;
69    esac
70    case "$CFLAGS" in
71        *-g* ) ;;
72           * ) CFLAGS="$CFLAGS -g" ;;
73    esac
74    case "$CFLAGS" in
75        *-pipe* ) ;;
76              * ) AC_COMPILER_OPTION(pipe, -pipe, -pipe, CFLAGS="$CFLAGS -pipe") ;;
77    esac
78    AC_COMPILER_OPTION(defdbg, -DDEBUG, -DDEBUG, CFLAGS="$CFLAGS -DDEBUG")
79    AC_COMPILER_OPTION(ggdb3, -ggdb3, -ggdb3, CFLAGS="$CFLAGS -ggdb3")
80    CFLAGS="$CFLAGS -pedantic"
81    CFLAGS="$CFLAGS -Wall"
82    WMORE="-Wshadow -Wpointer-arith -Wcast-align -Winline"
83    WMORE="$WMORE -Wmissing-prototypes -Wmissing-declarations -Wnested-externs"
84    AC_COMPILER_OPTION(wmore, -W<xxx>, $WMORE, CFLAGS="$CFLAGS $WMORE")
85    AC_COMPILER_OPTION(wnolonglong, -Wno-long-long, -Wno-long-long, CFLAGS="$CFLAGS -Wno-long-long")
86else
87    case "$CFLAGS" in
88        *-g* ) ;;
89           * ) CFLAGS="$CFLAGS -g" ;;
90    esac
91fi
92msg="enabled"
93],[
94if test ".$ac_cv_prog_gcc" = ".yes"; then
95case "$CFLAGS" in
96    *-pipe* ) ;;
97          * ) AC_COMPILER_OPTION(pipe, -pipe, -pipe, CFLAGS="$CFLAGS -pipe") ;;
98esac
99fi
100case "$CFLAGS" in
101    *-g* ) CFLAGS=`echo "$CFLAGS" |\
102                   sed -e 's/ -g / /g' -e 's/ -g$//' -e 's/^-g //g' -e 's/^-g$//'` ;;
103esac
104case "$CXXFLAGS" in
105    *-g* ) CXXFLAGS=`echo "$CXXFLAGS" |\
106                     sed -e 's/ -g / /g' -e 's/ -g$//' -e 's/^-g //g' -e 's/^-g$//'` ;;
107esac
108msg=disabled
109])dnl
110AC_MSG_CHECKING(for compilation debug mode)
111AC_MSG_RESULT([$msg])
112if test ".$msg" = .enabled; then
113    enable_shared=no
114fi
115])
116
117dnl ##
118dnl ##  Check for C99 va_copy() implementation
119dnl ##  (and provide fallback implementation if neccessary)
120dnl ##
121dnl ##  configure.in:
122dnl ##    AC_CHECK_VA_COPY
123dnl ##  foo.c:
124dnl ##    #include "config.h"
125dnl ##    [...]
126dnl ##    va_copy(d,s)
127dnl ##
128dnl ##  This check is rather complex: first because we really have to
129dnl ##  try various possible implementations in sequence and second, we
130dnl ##  cannot define a macro in config.h with parameters directly.
131dnl ##
132
133dnl #   test program for va_copy() implementation
134changequote(<<,>>)
135m4_define(__va_copy_test, <<[
136#include <stdlib.h>
137#include <stdarg.h>
138#include <string.h>
139#define DO_VA_COPY(d, s) $1
140void test(char *str, ...)
141{
142    va_list ap, ap2;
143    int i;
144    va_start(ap, str);
145    DO_VA_COPY(ap2, ap);
146    for (i = 1; i <= 9; i++) {
147        int k = (int)va_arg(ap, int);
148        if (k != i)
149            abort();
150    }
151    DO_VA_COPY(ap, ap2);
152    for (i = 1; i <= 9; i++) {
153        int k = (int)va_arg(ap, int);
154        if (k != i)
155            abort();
156    }
157    va_end(ap);
158}
159int main(int argc, char *argv[])
160{
161    test("test", 1, 2, 3, 4, 5, 6, 7, 8, 9);
162    exit(0);
163}
164]>>)
165changequote([,])
166
167dnl #   test driver for va_copy() implementation
168m4_define(__va_copy_check, [
169    AH_VERBATIM($1,
170[/* Predefined possible va_copy() implementation (id: $1) */
171#define __VA_COPY_USE_$1(d, s) $2])
172    if test ".$ac_cv_va_copy" = .; then
173        AC_TRY_RUN(__va_copy_test($2), [ac_cv_va_copy="$1"])
174    fi
175])
176
177dnl #   Autoconf check for va_copy() implementation checking
178AC_DEFUN(AC_CHECK_VA_COPY,[
179  dnl #   provide Autoconf display check message
180  AC_MSG_CHECKING(for va_copy() function)
181  dnl #   check for various implementations in priorized sequence
182  AC_CACHE_VAL(ac_cv_va_copy, [
183    ac_cv_va_copy=""
184    dnl #   1. check for standardized C99 macro
185    __va_copy_check(C99, [va_copy((d), (s))])
186    dnl #   2. check for alternative/deprecated GCC macro
187    __va_copy_check(GCM, [VA_COPY((d), (s))])
188    dnl #   3. check for internal GCC macro (high-level define)
189    __va_copy_check(GCH, [__va_copy((d), (s))])
190    dnl #   4. check for internal GCC macro (built-in function)
191    __va_copy_check(GCB, [__builtin_va_copy((d), (s))])
192    dnl #   5. check for assignment approach (assuming va_list is a struct)
193    __va_copy_check(ASS, [do { (d) = (s); } while (0)])
194    dnl #   6. check for assignment approach (assuming va_list is a pointer)
195    __va_copy_check(ASP, [do { *(d) = *(s); } while (0)])
196    dnl #   7. check for memory copying approach (assuming va_list is a struct)
197    __va_copy_check(CPS, [memcpy((void *)&(d), (void *)&(s)), sizeof((s))])
198    dnl #   8. check for memory copying approach (assuming va_list is a pointer)
199    __va_copy_check(CPP, [memcpy((void *)(d), (void *)(s)), sizeof(*(s))])
200    if test ".$ac_cv_va_copy" = .; then
201        AC_ERROR([no working implementation found])
202    fi
203  ])
204  dnl #   optionally activate the fallback implementation
205  if test ".$ac_cv_va_copy" = ".C99"; then
206      AC_DEFINE(HAVE_VA_COPY, 1, [Define if va_copy() macro exists (and no fallback implementation is required)])
207  fi
208  dnl #   declare which fallback implementation to actually use
209  AC_DEFINE_UNQUOTED([__VA_COPY_USE], [__VA_COPY_USE_$ac_cv_va_copy],
210      [Define to id of used va_copy() implementation])
211  dnl #   provide activation hook for fallback implementation
212  AH_VERBATIM([__VA_COPY_ACTIVATION],
213[/* Optional va_copy() implementation activation */
214#ifndef HAVE_VA_COPY
215#define va_copy(d, s) __VA_COPY_USE(d, s)
216#endif
217])
218  dnl #   provide Autoconf display result message
219  if test ".$ac_cv_va_copy" = ".C99"; then
220      AC_MSG_RESULT([yes])
221  else
222      AC_MSG_RESULT([no (using fallback implementation)])
223  fi
224])
225
226