- Detect C++ compiler in configure, add supporting infrastructure to
  eu.am.

Signed-off-by: Petr Machata <[email protected]>
---
 ChangeLog        |  4 ++++
 config/ChangeLog |  6 ++++++
 config/eu.am     | 21 ++++++++++++++++++++-
 configure.ac     | 15 +++++++++++++++
 4 files changed, 45 insertions(+), 1 deletion(-)

diff --git a/ChangeLog b/ChangeLog
index 5c8e1c2..6c6f216 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2015-03-18  Petr Machata  <[email protected]>
+
+       * configure.ac (HAVE_CXX): New conditional.
+
 2015-03-13  Mark Wielaard  <[email protected]>
 
        * configure.ac (ac_cv_c99): Add explicit return.
diff --git a/config/ChangeLog b/config/ChangeLog
index 586ebb0..32f3c93 100644
--- a/config/ChangeLog
+++ b/config/ChangeLog
@@ -1,3 +1,9 @@
+2015-04-02  Petr Machata  <[email protected]>
+
+       * 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  <[email protected]>
 
        * 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..bc40bff 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,20 @@ CFLAGS="$old_CFLAGS"])
 AS_IF([test "x$ac_cv_c99" != xyes],
       AC_MSG_ERROR([gcc with C99 support required]))
 
+# 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.
+AC_CACHE_CHECK([for working C++ compiler], ac_cv_cxx_works,
+[AC_LANG_PUSH([C++])
+ AC_COMPILE_IFELSE([AC_LANG_SOURCE([dnl
+struct foo {
+  int i;
+  explicit foo () : i (0) {}
+  virtual ~foo () {}
+};])], ac_cv_cxx_works=yes, ac_cv_cxx_works=no)
+ 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

Reply via email to