1#######################
2# type alignment test #
3#######################
4
5AC_DEFUN([AC_CHECK_ALIGNOF],
6	[changequote(<<, >>)dnl
7	dnl The name to #define.
8	define(<<AC_TYPE_NAME>>,
9		translit(orbit_alignof_$1, [a-z *], [A-Z_P]))dnl
10	dnl The cache variable name.
11	define(<<AC_CV_NAME>>,
12		translit(ac_cv_alignof_$1, [ *], [_p]))dnl
13	changequote([, ])dnl
14	AC_MSG_CHECKING(alignment of $1)
15	align_save_libs="$LIBS"
16	LIBS="$ORBIT_LIBS $LIBS"
17	AC_CACHE_VAL(AC_CV_NAME,
18		[AC_TRY_RUN(
19			[ #include <stdio.h>
20                          #include <stdlib.h>
21
22			#include "$srcdir/include/orbit/util/basic_types.h"
23			typedef struct {char s1;} CORBA_struct;
24			typedef void *CORBA_pointer;
25			struct test {char s1; $1 s2;};
26			main()
27			{
28			FILE *f=fopen("conftestval", "w");
29			if (!f) exit(1);
30			fprintf(f, "%d\n", &(((struct test*)0)->s2));
31			exit(0);
32			} ],
33			AC_CV_NAME=`cat conftestval`,
34			AC_CV_NAME=0, AC_CV_NAME=0)
35		])dnl
36	AC_MSG_RESULT($AC_CV_NAME)
37	if test "$AC_CV_NAME" = "0" ; then
38		AC_MSG_ERROR([Failed to find alignment. Check config.log for details.])
39	fi
40	LIBS="$align_save_libs"
41	AC_TYPE_NAME=$AC_CV_NAME
42	AC_SUBST(AC_TYPE_NAME)
43	undefine([AC_TYPE_NAME])dnl
44	undefine([AC_CV_NAME])dnl
45])
46
47
48dnl @synopsis AX_CFLAGS_GCC_OPTION (optionflag [,[shellvar][,[A][,[NA]]])
49dnl
50dnl AX_CFLAGS_GCC_OPTION(-fvomit-frame) would show a message as like
51dnl "checking CFLAGS for gcc -fvomit-frame ... yes" and adds
52dnl the optionflag to CFLAGS if it is understood. You can override
53dnl the shellvar-default of CFLAGS of course. The order of arguments
54dnl stems from the explicit macros like AX_CFLAGS_WARN_ALL.
55dnl
56dnl The cousin AX_CXXFLAGS_GCC_OPTION would check for an option to add
57dnl to CXXFLAGS - and it uses the autoconf setup for C++ instead of C
58dnl (since it is possible to use different compilers for C and C++).
59dnl
60dnl The macro is a lot simpler than any special AX_CFLAGS_* macro (or
61dnl ac_cxx_rtti.m4 macro) but allows to check for arbitrary options.
62dnl However, if you use this macro in a few places, it would be great
63dnl if you would make up a new function-macro and submit it to the
64dnl ac-archive.
65dnl
66dnl   - $1 option-to-check-for : required ("-option" as non-value)
67dnl   - $2 shell-variable-to-add-to : CFLAGS (or CXXFLAGS in the other case)
68dnl   - $3 action-if-found : add value to shellvariable
69dnl   - $4 action-if-not-found : nothing
70dnl
71dnl note: in earlier versions, $1-$2 were swapped. We try to detect the
72dnl situation and accept a $2=~/-/ as being the old option-to-check-for.
73dnl
74dnl also: there are other variants that emerged from the original macro
75dnl variant which did just test an option to be possibly added. However,
76dnl some compilers accept an option silently, or possibly for just
77dnl another option that was not intended. Therefore, we have to do a
78dnl generic test for a compiler family. For gcc we check "-pedantic"
79dnl being accepted which is also understood by compilers who just want
80dnl to be compatible with gcc even when not being made from gcc sources.
81dnl
82dnl see also:
83dnl       AX_CFLAGS_SUN_OPTION               AX_CFLAGS_HPUX_OPTION
84dnl       AX_CFLAGS_AIX_OPTION               AX_CFLAGS_IRIX_OPTION
85dnl
86dnl @, tested, experimental
87dnl @version $Id$
88dnl @author Guido Draheim <guidod@gmx.de>
89dnl
90AC_DEFUN([AX_CFLAGS_GCC_OPTION_OLD], [dnl
91AS_VAR_PUSHDEF([FLAGS],[CFLAGS])dnl
92AS_VAR_PUSHDEF([VAR],[ac_cv_cflags_gcc_option_$2])dnl
93AC_CACHE_CHECK([m4_ifval($1,$1,FLAGS) for gcc m4_ifval($2,$2,-option)],
94VAR,[VAR="no, unknown"
95 AC_LANG_SAVE
96 AC_LANG_C
97 ac_save_[]FLAGS="$[]FLAGS"
98for ac_arg dnl
99in "-pedantic  % m4_ifval($2,$2,-option)"  dnl   GCC
100   #
101do FLAGS="$ac_save_[]FLAGS "`echo $ac_arg | sed -e 's,%%.*,,' -e 's,%,,'`
102   AC_TRY_COMPILE([],[return 0;],
103   [VAR=`echo $ac_arg | sed -e 's,.*% *,,'` ; break])
104done
105 FLAGS="$ac_save_[]FLAGS"
106 AC_LANG_RESTORE
107])
108case ".$VAR" in
109     .ok|.ok,*) m4_ifvaln($3,$3) ;;
110   .|.no|.no,*) m4_ifvaln($4,$4) ;;
111   *) m4_ifvaln($3,$3,[
112   if echo " $[]m4_ifval($1,$1,FLAGS) " | grep " $VAR " 2>&1 >/dev/null
113   then AC_RUN_LOG([: m4_ifval($1,$1,FLAGS) does contain $VAR])
114   else AC_RUN_LOG([: m4_ifval($1,$1,FLAGS)="$m4_ifval($1,$1,FLAGS) $VAR"])
115                      m4_ifval($1,$1,FLAGS)="$m4_ifval($1,$1,FLAGS) $VAR"
116   fi ]) ;;
117esac
118AS_VAR_POPDEF([VAR])dnl
119AS_VAR_POPDEF([FLAGS])dnl
120])
121
122
123dnl the only difference - the LANG selection... and the default FLAGS
124
125AC_DEFUN([AX_CXXFLAGS_GCC_OPTION_OLD], [dnl
126AS_VAR_PUSHDEF([FLAGS],[CXXFLAGS])dnl
127AS_VAR_PUSHDEF([VAR],[ac_cv_cxxflags_gcc_option_$2])dnl
128AC_CACHE_CHECK([m4_ifval($1,$1,FLAGS) for gcc m4_ifval($2,$2,-option)],
129VAR,[VAR="no, unknown"
130 AC_LANG_SAVE
131 AC_LANG_CXX
132 ac_save_[]FLAGS="$[]FLAGS"
133for ac_arg dnl
134in "-pedantic  % m4_ifval($2,$2,-option)"  dnl   GCC
135   #
136do FLAGS="$ac_save_[]FLAGS "`echo $ac_arg | sed -e 's,%%.*,,' -e 's,%,,'`
137   AC_TRY_COMPILE([],[return 0;],
138   [VAR=`echo $ac_arg | sed -e 's,.*% *,,'` ; break])
139done
140 FLAGS="$ac_save_[]FLAGS"
141 AC_LANG_RESTORE
142])
143case ".$VAR" in
144     .ok|.ok,*) m4_ifvaln($3,$3) ;;
145   .|.no|.no,*) m4_ifvaln($4,$4) ;;
146   *) m4_ifvaln($3,$3,[
147   if echo " $[]m4_ifval($1,$1,FLAGS) " | grep " $VAR " 2>&1 >/dev/null
148   then AC_RUN_LOG([: m4_ifval($1,$1,FLAGS) does contain $VAR])
149   else AC_RUN_LOG([: m4_ifval($1,$1,FLAGS)="$m4_ifval($1,$1,FLAGS) $VAR"])
150                      m4_ifval($1,$1,FLAGS)="$m4_ifval($1,$1,FLAGS) $VAR"
151   fi ]) ;;
152esac
153AS_VAR_POPDEF([VAR])dnl
154AS_VAR_POPDEF([FLAGS])dnl
155])
156
157dnl -------------------------------------------------------------------------
158
159AC_DEFUN([AX_CFLAGS_GCC_OPTION_NEW], [dnl
160AS_VAR_PUSHDEF([FLAGS],[CFLAGS])dnl
161AS_VAR_PUSHDEF([VAR],[ac_cv_cflags_gcc_option_$1])dnl
162AC_CACHE_CHECK([m4_ifval($2,$2,FLAGS) for gcc m4_ifval($1,$1,-option)],
163VAR,[VAR="no, unknown"
164 AC_LANG_SAVE
165 AC_LANG_C
166 ac_save_[]FLAGS="$[]FLAGS"
167for ac_arg dnl
168in "-pedantic  % m4_ifval($1,$1,-option)"  dnl   GCC
169   #
170do FLAGS="$ac_save_[]FLAGS "`echo $ac_arg | sed -e 's,%%.*,,' -e 's,%,,'`
171   AC_TRY_COMPILE([],[return 0;],
172   [VAR=`echo $ac_arg | sed -e 's,.*% *,,'` ; break])
173done
174 FLAGS="$ac_save_[]FLAGS"
175 AC_LANG_RESTORE
176])
177case ".$VAR" in
178     .ok|.ok,*) m4_ifvaln($3,$3) ;;
179   .|.no|.no,*) m4_ifvaln($4,$4) ;;
180   *) m4_ifvaln($3,$3,[
181   if echo " $[]m4_ifval($2,$2,FLAGS) " | grep " $VAR " 2>&1 >/dev/null
182   then AC_RUN_LOG([: m4_ifval($2,$2,FLAGS) does contain $VAR])
183   else AC_RUN_LOG([: m4_ifval($2,$2,FLAGS)="$m4_ifval($2,$2,FLAGS) $VAR"])
184                      m4_ifval($2,$2,FLAGS)="$m4_ifval($2,$2,FLAGS) $VAR"
185   fi ]) ;;
186esac
187AS_VAR_POPDEF([VAR])dnl
188AS_VAR_POPDEF([FLAGS])dnl
189])
190
191
192dnl the only difference - the LANG selection... and the default FLAGS
193
194AC_DEFUN([AX_CXXFLAGS_GCC_OPTION_NEW], [dnl
195AS_VAR_PUSHDEF([FLAGS],[CXXFLAGS])dnl
196AS_VAR_PUSHDEF([VAR],[ac_cv_cxxflags_gcc_option_$1])dnl
197AC_CACHE_CHECK([m4_ifval($2,$2,FLAGS) for gcc m4_ifval($1,$1,-option)],
198VAR,[VAR="no, unknown"
199 AC_LANG_SAVE
200 AC_LANG_CXX
201 ac_save_[]FLAGS="$[]FLAGS"
202for ac_arg dnl
203in "-pedantic  % m4_ifval($1,$1,-option)"  dnl   GCC
204   #
205do FLAGS="$ac_save_[]FLAGS "`echo $ac_arg | sed -e 's,%%.*,,' -e 's,%,,'`
206   AC_TRY_COMPILE([],[return 0;],
207   [VAR=`echo $ac_arg | sed -e 's,.*% *,,'` ; break])
208done
209 FLAGS="$ac_save_[]FLAGS"
210 AC_LANG_RESTORE
211])
212case ".$VAR" in
213     .ok|.ok,*) m4_ifvaln($3,$3) ;;
214   .|.no|.no,*) m4_ifvaln($4,$4) ;;
215   *) m4_ifvaln($3,$3,[
216   if echo " $[]m4_ifval($2,$2,FLAGS) " | grep " $VAR " 2>&1 >/dev/null
217   then AC_RUN_LOG([: m4_ifval($2,$2,FLAGS) does contain $VAR])
218   else AC_RUN_LOG([: m4_ifval($2,$2,FLAGS)="$m4_ifval($2,$2,FLAGS) $VAR"])
219                      m4_ifval($2,$2,FLAGS)="$m4_ifval($2,$2,FLAGS) $VAR"
220   fi ]) ;;
221esac
222AS_VAR_POPDEF([VAR])dnl
223AS_VAR_POPDEF([FLAGS])dnl
224])
225
226AC_DEFUN([AX_CFLAGS_GCC_OPTION],[ifelse(m4_bregexp([$2],[-]),-1,
227[AX_CFLAGS_GCC_OPTION_NEW($@)],[AX_CFLAGS_GCC_OPTION_OLD($@)])])
228
229AC_DEFUN([AX_CXXFLAGS_GCC_OPTION],[ifelse(m4_bregexp([$2],[-]),-1,
230[AX_CXXFLAGS_GCC_OPTION_NEW($@)],[AX_CXXFLAGS_GCC_OPTION_OLD($@)])])
231