]> www.ginac.de Git - cln.git/blob - m4/c++-constructors.m4
* Fix typo.
[cln.git] / m4 / c++-constructors.m4
1 dnl Copyright (C) 1993-2002 Free Software Foundation, Inc.
2 dnl This file is free software, distributed under the terms of the GNU
3 dnl General Public License.  As a special exception to the GNU General
4 dnl Public License, this file may be distributed as part of a program
5 dnl that contains a configuration script generated by Autoconf, under
6 dnl the same distribution terms as the rest of that program.
7
8 dnl From Bruno Haible, Marcus Daniels.
9
10 AC_PREREQ(2.13)
11
12 AC_DEFUN([CL_GLOBAL_CONSTRUCTORS],
13 [AC_REQUIRE([CL_AS_UNDERSCORE])dnl
14 if test -n "$GCC"; then
15 AC_CACHE_CHECK(for the global constructors function prefix,
16 cl_cv_cplusplus_ctorprefix, [
17 cat > conftest.cc << EOF
18 struct foo { foo (); };
19 foo foobar;
20 EOF
21 # look for the assembly language name in the .s file
22 AC_TRY_COMMAND(${CXX-g++} $CXXFLAGS -S conftest.cc) >/dev/null 2>&1
23 if grep '_GLOBAL_\$I\$foobar' conftest.s >/dev/null ; then
24   cl_cv_cplusplus_ctorprefix='_GLOBAL_$I$'
25 else
26   if grep '_GLOBAL_\.I\.foobar' conftest.s >/dev/null ; then
27     cl_cv_cplusplus_ctorprefix='_GLOBAL_.I.'
28   else
29     if grep '_GLOBAL__I_foobar' conftest.s >/dev/null ; then
30       cl_cv_cplusplus_ctorprefix='_GLOBAL__I_'
31     else
32       cl_cv_cplusplus_ctorprefix=unknown
33     fi
34   fi
35 fi
36 rm -f conftest*
37 ])
38 if test "$cl_cv_cplusplus_ctorprefix" '!=' unknown; then
39   ac_value='"'"$cl_cv_cplusplus_ctorprefix"'"'
40   AC_DEFINE_UNQUOTED(CL_GLOBAL_CONSTRUCTOR_PREFIX,$ac_value)
41 AC_CACHE_CHECK(for the global destructors function prefix,
42 cl_cv_cplusplus_dtorprefix, [
43 cat > conftest.cc << EOF
44 struct foo { foo (); ~ foo (); };
45 foo foobar;
46 EOF
47 # look for the assembly language name in the .s file
48 AC_TRY_COMMAND(${CXX-g++} $CXXFLAGS -S conftest.cc) >/dev/null 2>&1
49 if grep '_GLOBAL_\$D\$foobar' conftest.s >/dev/null ; then
50   cl_cv_cplusplus_dtorprefix='_GLOBAL_$D$'
51 else
52   if grep '_GLOBAL_\.D\.foobar' conftest.s >/dev/null ; then
53     cl_cv_cplusplus_dtorprefix='_GLOBAL_.D.'
54   else
55     if grep '_GLOBAL__D_foobar' conftest.s >/dev/null ; then
56       cl_cv_cplusplus_dtorprefix='_GLOBAL__D_'
57     else
58       cl_cv_cplusplus_dtorprefix=none
59     fi
60   fi
61 fi
62 rm -f conftest*
63 ])
64   if test "$cl_cv_cplusplus_dtorprefix" '!=' none; then
65     ac_value='"'"$cl_cv_cplusplus_ctorprefix"'"'
66     AC_DEFINE_UNQUOTED(CL_GLOBAL_DESTRUCTOR_PREFIX,$ac_value)
67   fi
68 dnl Check whether the global constructors/destructors functions are file-scope
69 dnl only by default. This is the case in egcs-1.1.2 or newer.
70 AC_CACHE_CHECK(whether the global constructors function need to be exported,
71 cl_cv_cplusplus_ctorexport, [
72 cat > conftest1.cc << EOF
73 struct foo { foo (); };
74 foo foobar;
75 EOF
76 cat > conftest2.cc << EOF
77 #include "confdefs.h"
78 #ifdef ASM_UNDERSCORE
79 #define ASM_UNDERSCORE_PREFIX "_"
80 #else
81 #define ASM_UNDERSCORE_PREFIX ""
82 #endif
83 struct foo { foo (); };
84 foo::foo () {}
85 extern "C" void ctor (void) __asm__ (ASM_UNDERSCORE_PREFIX CL_GLOBAL_CONSTRUCTOR_PREFIX "foobar");
86 int main() { ctor(); return 0; }
87 EOF
88 if AC_TRY_COMMAND(${CXX-g++} -o conftest${ac_exeext} $CXXFLAGS $CPPFLAGS $LDFLAGS conftest1.cc conftest2.cc $LIBS 1>&5) >/dev/null 2>&1 && test -s conftest${ac_exeext}; then
89   cl_cv_cplusplus_ctorexport=no
90 else
91   cl_cv_cplusplus_ctorexport=yes
92 fi
93 rm -f conftest*
94 ])
95 if test "$cl_cv_cplusplus_ctorexport" = yes; then
96   AC_DEFINE(CL_NEED_GLOBALIZE_CTORDTOR)
97 fi
98 fi
99 fi
100 ])