From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 22088 invoked by alias); 28 Oct 2016 09:03:27 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 22078 invoked by uid 89); 28 Oct 2016 09:03:26 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.5 required=5.0 tests=BAYES_00,KAM_ASCII_DIVIDERS,RP_MATCHES_RCVD,SPF_HELO_PASS autolearn=ham version=3.3.2 spammy= X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 28 Oct 2016 09:03:16 +0000 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 21FA83F20D; Fri, 28 Oct 2016 09:03:15 +0000 (UTC) Received: from [127.0.0.1] (ovpn01.gateway.prod.ext.ams2.redhat.com [10.39.146.11]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u9S93DYO022138; Fri, 28 Oct 2016 05:03:14 -0400 Subject: Re: [PATCH 2/2] gdb: Require C++11 To: Philipp Rudo References: <1477596094-3244-1-git-send-email-palves@redhat.com> <1477596094-3244-3-git-send-email-palves@redhat.com> <20161028104718.540c10ed@ThinkPad> Cc: gdb-patches@sourceware.org From: Pedro Alves Message-ID: <62202286-b8c3-df2f-0744-fc4d6ebc4b45@redhat.com> Date: Fri, 28 Oct 2016 09:03:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.2.0 MIME-Version: 1.0 In-Reply-To: <20161028104718.540c10ed@ThinkPad> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit X-SW-Source: 2016-10/txt/msg00782.txt.bz2 On 10/28/2016 09:47 AM, Philipp Rudo wrote: > Without knowing much about autoconf. But you are repeating those > exact 280 lines a total of 6 times in this patch. Isn't there a nicer > way? Like moving it to a function? It would make the path significantly > shorter. Oh, you're looking at "configure", but that's a generated file that autoconf spits out. The source for that repeated code is ax_cxx_compile_stdcxx.m4 (the file added by patch #1), and that one does contain a single copy of that code. autoconf decides to expand the same code more than once because the ax_cxx_compile_stdcxx.m4 file has support for testing c++14 too, and that inlines the C++11 standards tests too: dnl Test body for checking C++11 support m4_define([_AX_CXX_COMPILE_STDCXX_testbody_11], _AX_CXX_COMPILE_STDCXX_testbody_new_in_11 ) dnl Test body for checking C++14 support m4_define([_AX_CXX_COMPILE_STDCXX_testbody_14], _AX_CXX_COMPILE_STDCXX_testbody_new_in_11 _AX_CXX_COMPILE_STDCXX_testbody_new_in_14 ) Becasily, those AX_CXX_COMPILE_STDCXX_foo calls mean "inline body of test code" here. So the duplicated code is already factored out and maintained in a single place. (I didn't strip out the support for C++14 from that script, to minimize changes compared to the upstream copy.) Below's the same patch but without the autogenerated bits. >From ffb94ceac7fc12d6147bc3280bd8cd7d30dda4e1 Mon Sep 17 00:00:00 2001 From: Pedro Alves Date: Thu, 13 Oct 2016 00:27:45 +0100 Subject: [PATCH] gdb: Require C++11 Use AX_CXX_COMPILE_STDCXX to detect if the compiler supports C++11, and if -std=xxx switches are necessary to enable C++11. We need to tweak AX_CXX_COMPILE_STDCXX a bit though. Pristine upstream AX_CXX_COMPILE_STDCXX appends -std=gnu++11 to CXX directly. That doesn't work for us, because the top level Makefile passes CXX down to subdirs, and that overrides whatever gdb/Makefile may set CXX to. The result would be that a make invocation from the build/gdb/ directory would use "g++ -std=gnu++11" as expected, while a make invocation at the top level would not. So instead of having AX_CXX_COMPILE_STDCXX set CXX directly, tweak it to AC_SUBST a separate variable -- CXX_DIALECT -- and use '$(CXX) (CXX_DIALECT)' to compile/link. Confirmed that this enables C++11 starting with gcc 4.8, the first gcc release with full C++11 support. Also confirmed that configure errors out gracefully with older GCC releases: checking whether /opt/gcc-4.7/bin/g++ supports C++11 features by default... no checking whether /opt/gcc-4.7/bin/g++ supports C++11 features with -std=gnu++11... no checking whether /opt/gcc-4.7/bin/g++ supports C++11 features with -std=gnu++0x... no checking whether /opt/gcc-4.7/bin/g++ supports C++11 features with -std=c++11... no checking whether /opt/gcc-4.7/bin/g++ supports C++11 features with -std=c++0x... no checking whether /opt/gcc-4.7/bin/g++ supports C++11 features with +std=c++11... no checking whether /opt/gcc-4.7/bin/g++ supports C++11 features with -h std=c++11... no configure: error: *** A compiler with support for C++11 language features is required. Makefile:9451: recipe for target 'configure-gdb' failed make[1]: *** [configure-gdb] Error 1 make[1]: Leaving directory '/home/pedro/brno/pedro/gdb/mygit/cxx-convertion/build-gcc-4.7' If we need to revert back to making C++03 optional, all that's necessary is to change the "mandatory" to "optional" in configure.ac and regenerate configure (both gdb and gdbserver). gdb/ChangeLog: yyyy-mm-dd Pedro Alves * Makefile.in (CXX_DIALECT): Get from configure. (COMPILE.pre, CC_LD): Append $(CXX_DIALECT). (FLAGS_TO_PASS): Pass CXX_DIALECT. * acinclude.m4: Include ax_cxx_compile_stdcxx.m4. * ax_cxx_compile_stdcxx.m4: Add FSF copyright header. Set and AC_SUBST CXX_DIALECT instead of changing CXX/CXXCPP. * configure.ac: Call AX_CXX_COMPILE_STDCXX. * config.in: Regenerate. * configure: Regenerate. gdb/gdbserver/ChangeLog: yyyy-mm-dd Pedro Alves * Makefile.in (CXX_DIALECT): Get from configure. (COMPILE.pre, CC_LD): Append $(CXX_DIALECT). * acinclude.m4: Include ../ax_cxx_compile_stdcxx.m4. * configure.ac: Call AX_CXX_COMPILE_STDCXX. * config.in: Regenerate. * configure: Regenerate. --- gdb/Makefile.in | 6 +- gdb/acinclude.m4 | 2 + gdb/ax_cxx_compile_stdcxx.m4 | 21 +- gdb/config.in | 3 + gdb/configure | 981 ++++++++++++++++++++++++++++++++++++++++++- gdb/configure.ac | 4 + gdb/gdbserver/Makefile.in | 5 +- gdb/gdbserver/acinclude.m4 | 2 + gdb/gdbserver/config.in | 3 + gdb/gdbserver/configure | 981 ++++++++++++++++++++++++++++++++++++++++++- gdb/gdbserver/configure.ac | 4 + 11 files changed, 1998 insertions(+), 14 deletions(-) diff --git a/gdb/Makefile.in b/gdb/Makefile.in index 2c88434..d035d8e 100644 --- a/gdb/Makefile.in +++ b/gdb/Makefile.in @@ -86,6 +86,7 @@ CATALOGS = @CATALOGS@ # distribution will fix your include files up. CC=@CC@ CXX=@CXX@ +CXX_DIALECT= @CXX_DIALECT@ # Dependency tracking information. DEPMODE = @CCDEPMODE@ @@ -94,7 +95,7 @@ depcomp = $(SHELL) $(srcdir)/../depcomp # Note that these are overridden by GNU make-specific code below if # GNU make is used. The overrides implement dependency tracking. -COMPILE.pre = $(CXX) +COMPILE.pre = $(CXX) $(CXX_DIALECT) COMPILE.post = -c -o $@ COMPILE = $(COMPILE.pre) $(INTERNAL_CFLAGS) $(COMPILE.post) POSTCOMPILE = @true @@ -125,7 +126,7 @@ MAKEHTMLFLAGS = # Set this up with gcc if you have gnu ld and the loader will print out # line numbers for undefined references. #CC_LD=g++ -static -CC_LD=$(CXX) +CC_LD=$(CXX) $(CXX_DIALECT) # Where is our "include" directory? Typically $(srcdir)/../include. # This is essentially the header file directory for the library @@ -742,6 +743,7 @@ FLAGS_TO_PASS = \ "CC=$(CC)" \ "CFLAGS=$(CFLAGS)" \ "CXX=$(CXX)" \ + "CXX_DIALECT=$(CXX_DIALECT)" \ "CXXFLAGS=$(CXXFLAGS)" \ "DLLTOOL=$(DLLTOOL)" \ "LDFLAGS=$(LDFLAGS)" \ diff --git a/gdb/acinclude.m4 b/gdb/acinclude.m4 index 4b3f7fc..daf4a91 100644 --- a/gdb/acinclude.m4 +++ b/gdb/acinclude.m4 @@ -68,6 +68,8 @@ m4_include(libiberty.m4) dnl For GDB_AC_PTRACE. m4_include(ptrace.m4) +m4_include(ax_cxx_compile_stdcxx.m4) + ## ----------------------------------------- ## ## ANSIfy the C compiler whenever possible. ## ## From Franc,ois Pinard ## diff --git a/gdb/ax_cxx_compile_stdcxx.m4 b/gdb/ax_cxx_compile_stdcxx.m4 index 2c18e49..ffaeb6e 100644 --- a/gdb/ax_cxx_compile_stdcxx.m4 +++ b/gdb/ax_cxx_compile_stdcxx.m4 @@ -1,3 +1,12 @@ +# Copyright (c) 2016 Free Software Foundation, Inc. +# +# Originally based on the AX_CXX_COMPILE_STDCXX macro found at the url +# below. +# +# Local GDB customizations: +# +# - AC_SUBST CXX_DIALECT instead of changing CXX/CXXCPP. +# # =========================================================================== # http://www.gnu.org/software/autoconf-archive/ax_cxx_compile_stdcxx.html # =========================================================================== @@ -58,6 +67,7 @@ AC_DEFUN([AX_CXX_COMPILE_STDCXX], [dnl [$3], [optional], [ax_cxx_compile_cxx$1_required=false], [m4_fatal([invalid third argument `$3' to AX_CXX_COMPILE_STDCXX])]) AC_LANG_PUSH([C++])dnl + CXX_DIALECT="" ac_success=no AC_CACHE_CHECK(whether $CXX supports C++$1 features by default, ax_cv_cxx_compile_cxx$1, @@ -81,10 +91,7 @@ AC_DEFUN([AX_CXX_COMPILE_STDCXX], [dnl [eval $cachevar=no]) CXX="$ac_save_CXX"]) if eval test x\$$cachevar = xyes; then - CXX="$CXX $switch" - if test -n "$CXXCPP" ; then - CXXCPP="$CXXCPP $switch" - fi + CXX_DIALECT="$switch" ac_success=yes break fi @@ -107,10 +114,7 @@ AC_DEFUN([AX_CXX_COMPILE_STDCXX], [dnl [eval $cachevar=no]) CXX="$ac_save_CXX"]) if eval test x\$$cachevar = xyes; then - CXX="$CXX $switch" - if test -n "$CXXCPP" ; then - CXXCPP="$CXXCPP $switch" - fi + CXX_DIALECT="$switch" ac_success=yes break fi @@ -131,6 +135,7 @@ AC_DEFUN([AX_CXX_COMPILE_STDCXX], [dnl [define if the compiler supports basic C++$1 syntax]) fi AC_SUBST(HAVE_CXX$1) + AC_SUBST(CXX_DIALECT) ]) diff --git a/gdb/configure.ac b/gdb/configure.ac index e451e60..83c2707 100644 --- a/gdb/configure.ac +++ b/gdb/configure.ac @@ -38,6 +38,10 @@ AC_CONFIG_AUX_DIR(..) AC_CANONICAL_SYSTEM AC_ARG_PROGRAM +# We require a C++11 compiler. Check if one is available, and if +# necessary, set CXX_DIALECT to some -std=xxx switch. +AX_CXX_COMPILE_STDCXX(11, , mandatory) + # Dependency checking. ZW_CREATE_DEPDIR ZW_PROG_COMPILER_DEPENDENCIES([CC]) diff --git a/gdb/gdbserver/Makefile.in b/gdb/gdbserver/Makefile.in index 0db5287..5ba559c 100644 --- a/gdb/gdbserver/Makefile.in +++ b/gdb/gdbserver/Makefile.in @@ -51,6 +51,7 @@ RANLIB = @RANLIB@ CC = @CC@ CXX = @CXX@ +CXX_DIALECT= @CXX_DIALECT@ AR = @AR@ AR_FLAGS = rc @@ -61,7 +62,7 @@ depcomp = $(SHELL) $(srcdir)/../depcomp # Note that these are overridden by GNU make-specific code below if # GNU make is used. The overrides implement dependency tracking. -COMPILE.pre = $(CXX) +COMPILE.pre = $(CXX) $(CXX_DIALECT) COMPILE.post = -c -o $@ COMPILE = $(COMPILE.pre) $(INTERNAL_CFLAGS) $(COMPILE.post) POSTCOMPILE = @true @@ -80,7 +81,7 @@ VPATH = @srcdir@ # Set this up with gcc if you have gnu ld and the loader will print out # line numbers for undefinded refs. #CC_LD=g++ -static -CC_LD=$(CXX) +CC_LD=$(CXX) $(CXX_DIALECT) # Where is the "include" directory? Traditionally ../include or ./include INCLUDE_DIR = ${srcdir}/../../include diff --git a/gdb/gdbserver/acinclude.m4 b/gdb/gdbserver/acinclude.m4 index 8ec9188..c75d783 100644 --- a/gdb/gdbserver/acinclude.m4 +++ b/gdb/gdbserver/acinclude.m4 @@ -29,6 +29,8 @@ m4_include(../libiberty.m4) dnl For GDB_AC_PTRACE. m4_include(../ptrace.m4) +m4_include(../ax_cxx_compile_stdcxx.m4) + dnl Check for existence of a type $1 in libthread_db.h dnl Based on BFD_HAVE_SYS_PROCFS_TYPE in bfd/bfd.m4. diff --git a/gdb/gdbserver/configure.ac b/gdb/gdbserver/configure.ac index 6d5907b..11d8c79 100644 --- a/gdb/gdbserver/configure.ac +++ b/gdb/gdbserver/configure.ac @@ -38,6 +38,10 @@ AC_PROG_RANLIB AC_ARG_PROGRAM +# We require a C++11 compiler. Check if one is available, and if +# necessary, set CXX_DIALECT to some -std=xxx switch. +AX_CXX_COMPILE_STDCXX(11, , mandatory) + AC_HEADER_STDC # Set the 'development' global. -- 2.5.5