File: xstd_cpp_checks.ac

package info (click to toggle)
libecap 1.0.1-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,728 kB
  • sloc: sh: 10,170; cpp: 740; makefile: 91
file content (108 lines) | stat: -rw-r--r-- 2,268 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
dnl generally useful C++ checks 

AC_LANG([C++])

dnl save pre-set values (if any) for variables that are
dnl created by autoconf
PRESET_CXXFLAGS="$CXXFLAGS"
PRESET_LDFLAGS="$LDFLAGS"

dnl check for programs
AC_PROG_CXX

# change default extention for source files
ac_ext=cc

dnl check for optional features
AC_SUBST(std_include)
AC_ARG_ENABLE(std-include,
	[ --enable-std-include=DIR Where to find standard C++ headers ],
	[
		std_include=`echo -I$enableval | sed 's/:/ -I/g'`
		CPPFLAGS="$CPPFLAGS $std_include"
	],
	[ std_include='' ]
)


dnl check if alleged C++ compiler understands C++
AC_MSG_CHECKING(whether the C++ compiler ($CXX) is a C++ compiler)
AC_TRY_COMPILE([
	#define Concat(a,b) a ## b
	struct T { 
		virtual ~T();
		virtual int m() const = 0;
		mutable bool a;
	};

	template <class P>
	struct C: public P {
		C(int): c(0) {}
		int m() const;
		int c;
	};

	template <class P>
	int C<P>::m() const { Concat(re,turn) c; }

	inline int test_inline() { return 0; }
],[
	// this is main()'s body
	static C<T> ct(1);
	return 0;
],[
	AC_MSG_RESULT(yes)
],[
	AC_MSG_RESULT(no)
	AC_MSG_ERROR(the compiler ($CXX) failed to pass a simple C++ test; check config.log for details)
])


dnl adjust program options

OLD_CXXFLAGS=$CXXFLAGS
if test -z "$PRESET_CXXFLAGS"
then
	if test "x$GXX" = xyes
	then [
		# reset to preferred options
		# replace -O? with -O3
		CXXFLAGS=`echo $CXXFLAGS | sed 's/-O[0-9]*/-O3/'`;
		# enable useful warnings
		CXXFLAGS="$CXXFLAGS -Wall -Wwrite-strings -Woverloaded-virtual"
		# avoid disk I/O
		CXXFLAGS="$CXXFLAGS -pipe"

		# custom host-dependent tuning
		case "$host" in
		alpha-dec-osf4.*)
			# we get random coredumps with g++ -O
			echo deleting -On on $host
			CXXFLAGS=`echo $CXXFLAGS | sed -e 's/-O[0-9]* *//'`
			;;
		*-linux-*)
			# -O2,3 seems to produce coredumps on RH and MDK linux
			echo enforcing -O1 on $host
			CXXFLAGS=`echo $CXXFLAGS | sed -e 's/-O[0-9]* */-O1 /'`
			;;
		esac
	] fi
fi

if test "x$PRESET_CXXFLAGS" != "x$CXXFLAGS"
then
	AC_MSG_CHECKING(whether custom $CXX flags work)
	AC_TRY_COMPILE(
		[
		],[
			return 0;
		],[
			AC_MSG_RESULT(probably)
			echo "changing $CXX flags to $CXXFLAGS"
		],[
			AC_MSG_RESULT(no)
			CXXFLAGS=$OLD_CXXFLAGS
			echo "leaving  $CXX flags at $CXXFLAGS"
		]
	)
fi