Hi there, I think this was mostly agreed on. The change since last time is that we pass -std=gnu++98 when testing C++ compiler existence, for correctness' sake. Thanks, Petr --- 8< ----------------------------------------------------------- - Detect C++ compiler in configure, add supporting infrastructure to eu.am. Signed-off-by: Petr Machata --- ChangeLog | 4 ++++ config/ChangeLog | 6 ++++++ config/eu.am | 21 ++++++++++++++++++++- configure.ac | 28 ++++++++++++++++++++++++++++ 4 files changed, 58 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 5c8e1c2..65c3ef5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2015-04-14 Petr Machata + + * configure.ac (HAVE_CXX): New conditional. + 2015-03-13 Mark Wielaard * configure.ac (ac_cv_c99): Add explicit return. diff --git a/config/ChangeLog b/config/ChangeLog index 586ebb0..936f62d 100644 --- a/config/ChangeLog +++ b/config/ChangeLog @@ -1,3 +1,9 @@ +2015-04-14 Petr Machata + + * eu.am (AM_CXXFLAGS, CXXCOMPILE.os): New variables. + (%.os: %.c %.o): Create dep-file subdirectory if necessary. + (%.os: %.cc %.o): New rule. + 2015-03-18 Petr Machata * known-dwarf.awk (comment): Drop all uses of this variable. diff --git a/config/eu.am b/config/eu.am index faf8add..f1d290b 100644 --- a/config/eu.am +++ b/config/eu.am @@ -1,6 +1,6 @@ ## Common automake fragments for elfutils subdirectory makefiles. ## -## Copyright (C) 2010, 2014 Red Hat, Inc. +## Copyright (C) 2010, 2014, 2015 Red Hat, Inc. ## ## This file is part of elfutils. ## @@ -35,11 +35,17 @@ AM_CFLAGS = -std=gnu99 -Wall -Wshadow -Wformat=2 \ $(if $($(*F)_no_Werror),,-Werror) \ $(if $($(*F)_no_Wunused),,-Wunused -Wextra) \ $($(*F)_CFLAGS) +AM_CXXFLAGS = -std=gnu++98 -Wall -Wshadow -Wformat=2 \ + $(if $($(*F)_no_Werror),,-Werror) \ + $(if $($(*F)_no_Wunused),,-Wunused -Wextra) \ + $($(*F)_CXXFLAGS) COMPILE.os = $(filter-out -fprofile-arcs -ftest-coverage, $(COMPILE)) +CXXCOMPILE.os = $(filter-out -fprofile-arcs -ftest-coverage, $(CXXCOMPILE)) %.os: %.c %.o if AMDEP + test -d $(DEPDIR)/$(*D) || mkdir $(DEPDIR)/$(*D) if $(COMPILE.os) -c -o $@ -fpic -DPIC -DSHARED -MT $@ -MD -MP \ -MF "$(DEPDIR)/$*.Tpo" `test -f '$<' || echo '$(srcdir)/'`$<; \ then cat "$(DEPDIR)/$*.Tpo" >> "$(DEPDIR)/$*.Po"; \ @@ -50,6 +56,19 @@ else $(COMPILE.os) -c -o $@ -fpic -DPIC -DSHARED $< endif +%.os: %.cc %.o +if AMDEP + test -d $(DEPDIR)/$(*D) || mkdir $(DEPDIR)/$(*D) + if $(CXXCOMPILE.os) -c -o $@ -fpic -DPIC -DSHARED -MT $@ -MD -MP \ + -MF "$(DEPDIR)/$*.Tpo" `test -f '$<' || echo '$(srcdir)/'`$<; \ + then cat "$(DEPDIR)/$*.Tpo" >> "$(DEPDIR)/$*.Po"; \ + rm -f "$(DEPDIR)/$*.Tpo"; \ + else rm -f "$(DEPDIR)/$*.Tpo"; exit 1; \ + fi +else + $(CXXCOMPILE.os) -c -o $@ -fpic -DPIC -DSHARED $< +endif + CLEANFILES = *.gcno *.gcda textrel_msg = echo "WARNING: TEXTREL found in '$@'" diff --git a/configure.ac b/configure.ac index c4b818d..6d1df60 100644 --- a/configure.ac +++ b/configure.ac @@ -71,6 +71,7 @@ AS_IF([test "$use_locks" = yes], AH_TEMPLATE([USE_LOCKS], [Defined if libraries should be thread-safe.]) AC_PROG_CC +AC_PROG_CXX AC_PROG_RANLIB AC_PROG_YACC AM_PROG_LEX @@ -89,6 +90,33 @@ CFLAGS="$old_CFLAGS"]) AS_IF([test "x$ac_cv_c99" != xyes], AC_MSG_ERROR([gcc with C99 support required])) +AC_LANG_PUSH([C++]) + +# Above, we check for C++ compiler. However even if none is available, +# CXX is set to a non-empty value. So we need to figure out whether a +# C++ compiler is actually available. + +# We in fact use -std=gnu++98. Check that the compiler supports this. +SAVE_CXXFLAGS="$CXXFLAGS" +CXXFLAGS="$CXXFLAGS -std=gnu++98" + +AC_CACHE_CHECK([for C++ compiler that supports -std=gnu++98], + ac_cv_cxx_works, +[AC_COMPILE_IFELSE([AC_LANG_SOURCE([dnl +struct foo { + int i; + explicit foo () : i (0) {} + virtual ~foo () {} +}; + +struct A { int i; int j; } a = {.i = 1, .j = 2}; +])], ac_cv_cxx_works=yes, ac_cv_cxx_works=no)]) + +CXXFLAGS="$SAVE_CXXFLAGS" +AC_LANG_POP() + +AM_CONDITIONAL(HAVE_CXX, test "$ac_cv_cxx_works" = yes) + AC_CACHE_CHECK([for __thread support], ac_cv_tls, [dnl # Use the same flags that we use for our DSOs, so the test is representative. # Some old compiler/linker/libc combinations fail some ways and not others. -- 2.1.0