I have elsewhere described my frustration in trying, during development, to set more stringent error-finding and warning-generating compilation options. But they seem to require the use of CXXFLAGS, which in at least the case of trying to set -std=c++14, causes libcody's compilation to fail, since it wants, specifically c++11.
So, I dove in and figured out how to implement CXXFLAGS_FOR_COBOL. This new flag applies only to compilations of c++ programs in the gcc/cobol source code tree. These changes were tested with a bootstrap build of --enable-languages=c,c++,fortran,cobol. Is this okay for trunk? Thanks. Bob Dubner >From ff295ac4ba9728fdd8d97fa73754cd17a21d0f18 Mon Sep 17 00:00:00 2001 From: Robert Dubner <rdub...@symas.com> Date: Mon, 7 Jul 2025 16:34:09 -0400 Subject: [PATCH] cobol: Implement CXXFLAGS_FOR_COBOL. It's useful during development to be able to specify compilation options that apply only to the COBOL front end. These changes provide the ability to set persistent flags at configure time: CXXFLAGS_FOR_COBOL=xxx ../configure .... while providing the ability to subsequently override them at build time make CXXFLAGS_FOR_COBOL=yyy ChangeLog: * configure.ac: Create output variable @CXXFLAGS_FOR_COBOL@. * Makefile.def: Include CXXFLAGS_FOR_COBOL in flags_to_pass. * Makefile.tpl: Include CXXFLAGS_FOR_COBOL in HOST_EXPORTS; incorporate @CXXFLAGS_FOR_COBOL@. * configure: Regenerated. * Makefile.in: Regenerated gcc/cobol/ChangeLog: * Make-lang.in: Use CXXFLAGS_FOR_COBOL in gcc/cobol compilations. --- Makefile.def | 1 + Makefile.in | 3 +++ Makefile.tpl | 2 ++ configure | 2 ++ configure.ac | 1 + gcc/cobol/Make-lang.in | 20 ++++++++++++++++++++ 6 files changed, 29 insertions(+) diff --git a/Makefile.def b/Makefile.def index fa60f6ea0b9..bd17c89b875 100644 --- a/Makefile.def +++ b/Makefile.def @@ -304,6 +304,7 @@ flags_to_pass = { flag= BOOT_CFLAGS ; }; flags_to_pass = { flag= BOOT_LDFLAGS ; }; flags_to_pass = { flag= CFLAGS ; }; flags_to_pass = { flag= CXXFLAGS ; }; +flags_to_pass = { flag= CXXFLAGS_FOR_COBOL ; }; flags_to_pass = { flag= LDFLAGS ; }; flags_to_pass = { flag= LIBCFLAGS ; }; flags_to_pass = { flag= LIBCXXFLAGS ; }; diff --git a/Makefile.in b/Makefile.in index 12d4395d8e2..1ab2efbc612 100644 --- a/Makefile.in +++ b/Makefile.in @@ -203,6 +203,7 @@ HOST_EXPORTS = \ CONFIG_SHELL="$(SHELL)"; export CONFIG_SHELL; \ CXX="$(CXX)"; export CXX; \ CXXFLAGS="$(CXXFLAGS)"; export CXXFLAGS; \ + CXXFLAGS_FOR_COBOL="$(CXXFLAGS_FOR_COBOL)"; export CXXFLAGS_FOR_COBOL; \ GFORTRAN="$(GFORTRAN)"; export GFORTRAN; \ GOC="$(GOC)"; export GOC; \ GDC="$(GDC)"; export GDC; \ @@ -451,6 +452,7 @@ CFLAGS = @CFLAGS@ LDFLAGS = @LDFLAGS@ LIBCFLAGS = $(CFLAGS) CXXFLAGS = @CXXFLAGS@ +CXXFLAGS_FOR_COBOL = @CXXFLAGS_FOR_COBOL@ LIBCXXFLAGS = $(CXXFLAGS) -fno-implicit-templates GOCFLAGS = $(CFLAGS) GDCFLAGS = @GDCFLAGS@ @@ -882,6 +884,7 @@ BASE_FLAGS_TO_PASS = \ "BOOT_LDFLAGS=$(BOOT_LDFLAGS)" \ "CFLAGS=$(CFLAGS)" \ "CXXFLAGS=$(CXXFLAGS)" \ + "CXXFLAGS_FOR_COBOL=$(CXXFLAGS_FOR_COBOL)" \ "LDFLAGS=$(LDFLAGS)" \ "LIBCFLAGS=$(LIBCFLAGS)" \ "LIBCXXFLAGS=$(LIBCXXFLAGS)" \ diff --git a/Makefile.tpl b/Makefile.tpl index ddcca558913..047845b7692 100644 --- a/Makefile.tpl +++ b/Makefile.tpl @@ -206,6 +206,7 @@ HOST_EXPORTS = \ CONFIG_SHELL="$(SHELL)"; export CONFIG_SHELL; \ CXX="$(CXX)"; export CXX; \ CXXFLAGS="$(CXXFLAGS)"; export CXXFLAGS; \ + CXXFLAGS_FOR_COBOL="$(CXXFLAGS_FOR_COBOL)"; export CXXFLAGS_FOR_COBOL; \ GFORTRAN="$(GFORTRAN)"; export GFORTRAN; \ GOC="$(GOC)"; export GOC; \ GDC="$(GDC)"; export GDC; \ @@ -454,6 +455,7 @@ CFLAGS = @CFLAGS@ LDFLAGS = @LDFLAGS@ LIBCFLAGS = $(CFLAGS) CXXFLAGS = @CXXFLAGS@ +CXXFLAGS_FOR_COBOL = @CXXFLAGS_FOR_COBOL@ LIBCXXFLAGS = $(CXXFLAGS) -fno-implicit-templates GOCFLAGS = $(CFLAGS) GDCFLAGS = @GDCFLAGS@ diff --git a/configure b/configure index ccec3f21cd8..c8e6d729f1b 100755 --- a/configure +++ b/configure @@ -624,6 +624,7 @@ RANLIB_PLUGIN_OPTION AR_PLUGIN_OPTION PKG_CONFIG_PATH GDCFLAGS +CXXFLAGS_FOR_COBOL READELF OTOOL OBJDUMP @@ -14218,6 +14219,7 @@ fi + GDCFLAGS=${GDCFLAGS-${CFLAGS}} diff --git a/configure.ac b/configure.ac index 55d10265958..6153b1d7957 100644 --- a/configure.ac +++ b/configure.ac @@ -4010,6 +4010,7 @@ AC_SUBST(CC) AC_SUBST(CXX) AC_SUBST(CFLAGS) AC_SUBST(CXXFLAGS) +AC_SUBST(CXXFLAGS_FOR_COBOL) AC_SUBST(GDC) AC_SUBST(GDCFLAGS) GDCFLAGS=${GDCFLAGS-${CFLAGS}} diff --git a/gcc/cobol/Make-lang.in b/gcc/cobol/Make-lang.in index 18eb3b0f1e5..1e60cea060e 100644 --- a/gcc/cobol/Make-lang.in +++ b/gcc/cobol/Make-lang.in @@ -384,3 +384,23 @@ cobol.stagefeedback: stagefeedback-start selftest-cobol: lang_checks += check-cobol + +# +# Front-end specific flags: Originally done for the COBOL front end, this +# scripting applies CXXFLAGS_FOR_COBOL only to compilations of source code in the +# gcc/cobol source code tree. Both forms can be used: +# +# CXXFLAGS_FOR_COBOL=xxx ../configure --enable-languages=.... +# and +# make <gcc> CXXFLAGS_FOR_COBOL=yyy +# +# The second form overrides the first. +# +# To apply this feature to other front ends, look for and clone lines +# containing "CXXFLAGS_FOR_COBOL" in configure.ac, Makefile.tbl, and Makefile.def. +# + +cobol/%.o: cobol/%.cc + @echo $(COMPILE) $(CXXFLAGS_FOR_COBOL) $< + $(COMPILE) $(CXXFLAGS_FOR_COBOL) $< + $(POSTCOMPILE) -- 2.34.1