[PATCH] Provide support for CXXFLAGS for c++ modules

Maxim Dounin mdounin at mdounin.ru
Mon Nov 16 15:29:47 UTC 2015


Hello!

On Mon, Nov 16, 2015 at 09:38:41AM +1100, Vasily Chekalkin wrote:

> # HG changeset patch
> # User Vasily Chekalkin <bacek at bacek.com>
> # Date 1447626235 -39600
> #      Mon Nov 16 09:23:55 2015 +1100
> # Node ID 07ad1f9b4307940ecd0b952badba80fab7caba4b
> # Parent  ec6b07be88a5108d5b48386e06abe1d1bf975ab3
> Provide support for CXXFLAGS for c++ modules.
> 
> When you want to implement module in modern C++ (e.g. c++11, etc) you have to
> specify --std=c++11 in compiler command line. In this case GCC will complain
> about using this flag for non-c++ sources. To avoid unnecessary clutter we
> separate CFLAGS and CXXFLAGS.
> 
> diff -r ec6b07be88a5 -r 07ad1f9b4307 auto/make
> --- a/auto/make Fri Nov 13 20:10:50 2015 +0300
> +++ b/auto/make Mon Nov 16 09:23:55 2015 +1100
> @@ -22,6 +22,7 @@
> 
>  CC =   $CC
>  CFLAGS = $CFLAGS
> +CXXFLAGS = $CXXFLAGS
>  CPP =  $CPP
>  LINK = $LINK
> 
> @@ -410,10 +411,16 @@
> 
>          ngx_src=`echo $ngx_src | sed -e "s/\//$ngx_regex_dirsep/g"`
> 
> +        # Append CXXFLAGS iff source is c++
> +        ngx_cpp=`echo $ngx_src \
> +            | sed -e "s#^.*\.cpp\\$# \\$(CXXFLAGS)#" \
> +                  -e "s#^.*\.cc\\$# \\$(CXXFLAGS)#" \
> +                  -e "s#^$ngx_src\\$##g"`
> +
>          cat << END                                            >> $NGX_MAKEFILE
> 
>  $ngx_obj:      \$(ADDON_DEPS)$ngx_cont$ngx_src
> -       $ngx_cc$ngx_tab$ngx_objout$ngx_obj$ngx_tab$ngx_src$NGX_AUX
> +       $ngx_cc$ngx_cpp$ngx_tab$ngx_objout$ngx_obj$ngx_tab$ngx_src$NGX_AUX

This way CFLAGS and CXXFLAGS are not separated, but rather 
CXXFLAGS is expected to complement CFLAGS.  This is not how 
CXXFLAGS are expected to work.

While CXXFLAGS are not specified by any standard, AFAIK, at least 
GNU catalogue of built-in rules says,
https://www.gnu.org/software/make/manual/html_node/Catalogue-of-Rules.html#Catalogue-of-Rules:

: Compiling C programs
: n.o is made automatically from n.c with a recipe of the form 
: ‘$(CC) $(CPPFLAGS) $(CFLAGS) -c’.

: Compiling C++ programs
: n.o is made automatically from n.cc, n.cpp, or n.C
: with a recipe of the form ‘$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c’. We 
: encourage you to use the suffix ‘.cc’ for C++ source files instead 
: of ‘.C’.

That is, CXXFLAGS is expected to be a replacement of CFLAGS, not 
an addition to CFLAGS.

As far as I understand, correct support for CXXFLAGS will require 
much more changes, and I'm not sure it worth the effort.

-- 
Maxim Dounin
http://nginx.org/



More information about the nginx-devel mailing list