CXXFLAGS support

Sorin Manole sorin.v.manole at gmail.com
Mon May 22 10:14:04 UTC 2017


Missed attachment.

2017-05-21 22:23 GMT+03:00 Sorin Manole <sorin.v.manole at gmail.com>:
> Hello,
>
> Would you be willing to accept a patch to support CXX and CXXFLAGS in
> the nginx build logic?
> This could be used to write C++ nginx module code.
> I attached a partial implementation. Please confirm if this is the
> correct approach.
>
> Thanks.
-------------- next part --------------
diff -r 2c4dbcd6f2e4 auto/cc/acc
--- a/auto/cc/acc	Mon Apr 24 14:17:13 2017 +0300
+++ b/auto/cc/acc	Sun May 21 17:05:40 2017 +0100
@@ -8,6 +8,7 @@
 # C89 mode
 
 CFLAGS="$CFLAGS -Ae"
+CXXFLAGS="$CXXFLAGS -Ae"
 CC_TEST_FLAGS="-Ae"
 
 PCRE_OPT="$PCRE_OPT -Ae"
diff -r 2c4dbcd6f2e4 auto/cc/bcc
--- a/auto/cc/bcc	Mon Apr 24 14:17:13 2017 +0300
+++ b/auto/cc/bcc	Sun May 21 17:05:40 2017 +0100
@@ -8,7 +8,7 @@
 # optimizations
 
 # maximize speed
-CFLAGS="$CFLAGS -O2"
+NGX_BCC_OPT="-O2"
 
 case $CPU in
     pentium)
@@ -27,17 +27,19 @@
 # __fastcall
 #CPU_OPT="$CPU_OPT -pr"
 
-CFLAGS="$CFLAGS $CPU_OPT"
+NGX_BCC_OPT="$NGX_BCC_OPT $CPU_OPT"
 
 # multithreaded
-CFLAGS="$CFLAGS -tWM"
+NGX_BCC_OPT="$NGX_BCC_OPT -tWM"
 
 # stop on warning
-CFLAGS="$CFLAGS -w!"
+NGX_BCC_OPT="$NGX_BCC_OPT -w!"
 
 # disable logo
-CFLAGS="$CFLAGS -q"
+NGX_BCC_OPT="$NGX_BCC_OPT -q"
 
+CFLAGS="$CFLAGS $NGX_BCC_OPT"
+CXXFLAGS="$CXXFLAGS $NGX_BCC_OPT"
 
 # precompiled headers
 CORE_DEPS="$CORE_DEPS $NGX_OBJS/ngx_config.csm"
diff -r 2c4dbcd6f2e4 auto/cc/ccc
--- a/auto/cc/ccc	Mon Apr 24 14:17:13 2017 +0300
+++ b/auto/cc/ccc	Sun May 21 17:05:40 2017 +0100
@@ -9,38 +9,41 @@
 
 # warnings
 
-CFLAGS="$CFLAGS -msg_enable level6 -msg_fatal level6"
+NGX_CCC_OPT="-msg_enable level6 -msg_fatal level6"
 
-CFLAGS="$CFLAGS -msg_disable unknownmacro"
-CFLAGS="$CFLAGS -msg_disable unusedincl"
-CFLAGS="$CFLAGS -msg_disable unnecincl"
-CFLAGS="$CFLAGS -msg_disable nestincl"
-CFLAGS="$CFLAGS -msg_disable strctpadding"
-CFLAGS="$CFLAGS -msg_disable ansialiascast"
-CFLAGS="$CFLAGS -msg_disable inlinestoclsmod"
-CFLAGS="$CFLAGS -msg_disable cxxkeyword"
-CFLAGS="$CFLAGS -msg_disable longlongsufx"
-CFLAGS="$CFLAGS -msg_disable valuepres"
+NGX_CCC_OPT="$NGX_CCC_OPT -msg_disable unknownmacro"
+NGX_CCC_OPT="$NGX_CCC_OPT -msg_disable unusedincl"
+NGX_CCC_OPT="$NGX_CCC_OPT -msg_disable unnecincl"
+NGX_CCC_OPT="$NGX_CCC_OPT -msg_disable nestincl"
+NGX_CCC_OPT="$NGX_CCC_OPT -msg_disable strctpadding"
+NGX_CCC_OPT="$NGX_CCC_OPT -msg_disable ansialiascast"
+NGX_CCC_OPT="$NGX_CCC_OPT -msg_disable inlinestoclsmod"
+NGX_CCC_OPT="$NGX_CCC_OPT -msg_disable cxxkeyword"
+NGX_CCC_OPT="$NGX_CCC_OPT -msg_disable longlongsufx"
+NGX_CCC_OPT="$NGX_CCC_OPT -msg_disable valuepres"
 
 # STUB
-CFLAGS="$CFLAGS -msg_disable truncintcast"
-CFLAGS="$CFLAGS -msg_disable trunclongcast"
+NGX_CCC_OPT="$NGX_CCC_OPT -msg_disable truncintcast"
+NGX_CCC_OPT="$NGX_CCC_OPT -msg_disable trunclongcast"
 
-CFLAGS="$CFLAGS -msg_disable truncintasn"
-CFLAGS="$CFLAGS -msg_disable trunclongint"
-CFLAGS="$CFLAGS -msg_disable intconcastsgn"
-CFLAGS="$CFLAGS -msg_disable intconstsign"
-CFLAGS="$CFLAGS -msg_disable switchlong"
-CFLAGS="$CFLAGS -msg_disable subscrbounds2"
+NGX_CCC_OPT="$NGX_CCC_OPT -msg_disable truncintasn"
+NGX_CCC_OPT="$NGX_CCC_OPT -msg_disable trunclongint"
+NGX_CCC_OPT="$NGX_CCC_OPT -msg_disable intconcastsgn"
+NGX_CCC_OPT="$NGX_CCC_OPT -msg_disable intconstsign"
+NGX_CCC_OPT="$NGX_CCC_OPT -msg_disable switchlong"
+NGX_CCC_OPT="$NGX_CCC_OPT -msg_disable subscrbounds2"
+
+NGX_CCC_OPT="$NGX_CCC_OPT -msg_disable hexoctunsign"
 
-CFLAGS="$CFLAGS -msg_disable hexoctunsign"
+NGX_CCC_OPT="$NGX_CCC_OPT -msg_disable ignorecallval"
+NGX_CCC_OPT="$NGX_CCC_OPT -msg_disable nonstandcast"
+NGX_CCC_OPT="$NGX_CCC_OPT -msg_disable embedcomment"
+NGX_CCC_OPT="$NGX_CCC_OPT -msg_disable unreachcode"
+NGX_CCC_OPT="$NGX_CCC_OPT -msg_disable questcompare2"
+NGX_CCC_OPT="$NGX_CCC_OPT -msg_disable unusedtop"
+NGX_CCC_OPT="$NGX_CCC_OPT -msg_disable unrefdecl"
 
-CFLAGS="$CFLAGS -msg_disable ignorecallval"
-CFLAGS="$CFLAGS -msg_disable nonstandcast"
-CFLAGS="$CFLAGS -msg_disable embedcomment"
-CFLAGS="$CFLAGS -msg_disable unreachcode"
-CFLAGS="$CFLAGS -msg_disable questcompare2"
-CFLAGS="$CFLAGS -msg_disable unusedtop"
-CFLAGS="$CFLAGS -msg_disable unrefdecl"
+NGX_CCC_OPT="$NGX_CCC_OPT -msg_disable bitnotint"
 
-CFLAGS="$CFLAGS -msg_disable bitnotint"
+CFLAGS="$CFLAGS $NGX_CCC_OPT"
+CXXFLAGS="$CXXFLAGS $NGX_CCC_OPT"
diff -r 2c4dbcd6f2e4 auto/cc/clang
--- a/auto/cc/clang	Mon Apr 24 14:17:13 2017 +0300
+++ b/auto/cc/clang	Sun May 21 17:05:40 2017 +0100
@@ -58,7 +58,7 @@
 CC_AUX_FLAGS="$CC_AUX_FLAGS $CPU_OPT"
 
 
-CFLAGS="$CFLAGS -pipe $CPU_OPT"
+NGX_CLANG_OPT="$NGX_CLANG_OPT -pipe $CPU_OPT"
 
 if [ ".$PCRE_OPT" = "." ]; then
     PCRE_OPT="-O2 -pipe $CPU_OPT"
@@ -75,23 +75,25 @@
 
 # warnings
 
-CFLAGS="$CFLAGS $NGX_CLANG_OPT -Wall -Wextra -Wpointer-arith"
-CFLAGS="$CFLAGS -Wconditional-uninitialized"
-#CFLAGS="$CFLAGS -Wmissing-prototypes"
+NGX_CLANG_OPT="$NGX_CLANG_OPT -Wall -Wextra -Wpointer-arith"
+NGX_CLANG_OPT="$NGX_CLANG_OPT -Wconditional-uninitialized"
+#NGX_CLANG_OPT="$NGX_CLANG_OPT -Wmissing-prototypes"
 
 # we have a lot of unused function arguments
-CFLAGS="$CFLAGS -Wno-unused-parameter"
+NGX_CLANG_OPT="$NGX_CLANG_OPT -Wno-unused-parameter"
 
 # deprecated system OpenSSL library on OS X
 if [ "$NGX_SYSTEM" = "Darwin" ]; then
-    CFLAGS="$CFLAGS -Wno-deprecated-declarations"
+    NGX_CLANG_OPT="$NGX_CLANG_OPT -Wno-deprecated-declarations"
 fi
 
 # stop on warning
-CFLAGS="$CFLAGS -Werror"
+NGX_CLANG_OPT="$NGX_CLANG_OPT -Werror"
 
 # debug
-CFLAGS="$CFLAGS -g"
+NGX_CLANG_OPT="$NGX_CLANG_OPT -g"
+
+CFLAGS="$CFLAGS $NGX_CLANG_OPT"
 
 if [ ".$CPP" = "." ]; then
     CPP="$CC -E"
diff -r 2c4dbcd6f2e4 auto/cc/conf
--- a/auto/cc/conf	Mon Apr 24 14:17:13 2017 +0300
+++ b/auto/cc/conf	Sun May 21 17:05:40 2017 +0100
@@ -142,6 +142,7 @@
 fi
 
 CFLAGS="$CFLAGS $NGX_CC_OPT"
+CXXFLAGS="$CXXFLAGS $NGX_CXX_OPT"
 NGX_TEST_LD_OPT="$NGX_LD_OPT"
 
 if [ "$NGX_PLATFORM" != win32 ]; then
diff -r 2c4dbcd6f2e4 auto/cc/gcc
--- a/auto/cc/gcc	Mon Apr 24 14:17:13 2017 +0300
+++ b/auto/cc/gcc	Sun May 21 17:05:40 2017 +0100
@@ -40,7 +40,7 @@
 
     sun4u | sun4v | sparc | sparc64 )
         # "-mcpu=v9" enables the "casa" assembler instruction
-        CFLAGS="$CFLAGS -mcpu=v9"
+        NGX_GCC_OPT="-mcpu=v9"
     ;;
 
 esac
@@ -48,11 +48,11 @@
 
 # optimizations
 
-#NGX_GCC_OPT="-O2"
-#NGX_GCC_OPT="-Os"
-NGX_GCC_OPT="-O"
+#NGX_GCC_OPTIM="$NGX_GCC_OPTIM -O2"
+#NGX_GCC_OPTIM="$NGX_GCC_OPTIM -Os"
+NGX_GCC_OPTIM="$NGX_GCC_OPTIM -O"
 
-#CFLAGS="$CFLAGS -fomit-frame-pointer"
+#NGX_GCC_OPT="$NGX_GCC_OPT -fomit-frame-pointer"
 
 case $CPU in
     pentium)
@@ -120,7 +120,7 @@
 esac
 
 
-CFLAGS="$CFLAGS $PIPE $CPU_OPT"
+NGX_GCC_OPT="$NGX_GCC_OPT $PIPE $CPU_OPT"
 
 if [ ".$PCRE_OPT" = "." ]; then
     PCRE_OPT="-O2 -fomit-frame-pointer $PIPE $CPU_OPT"
@@ -138,41 +138,41 @@
 # warnings
 
 # -W requires at least -O
-CFLAGS="$CFLAGS ${NGX_GCC_OPT:--O} -W"
+NGX_GCC_OPT="$NGX_GCC_OPT ${NGX_GCC_OPTIM:--O} -W"
 
-CFLAGS="$CFLAGS -Wall -Wpointer-arith"
-#CFLAGS="$CFLAGS -Wconversion"
-#CFLAGS="$CFLAGS -Winline"
-#CFLAGS="$CFLAGS -Wmissing-prototypes"
+NGX_GCC_OPT="$NGX_GCC_OPT -Wall -Wpointer-arith"
+#NGX_GCC_OPT="$NGX_GCC_OPT -Wconversion"
+#NGX_GCC_OPT="$NGX_GCC_OPT -Winline"
+#NGX_GCC_OPT="$NGX_GCC_OPT -Wmissing-prototypes"
 
 case "$NGX_GCC_VER" in
     2.*)
         # we have a lot of the unused function arguments
-        CFLAGS="$CFLAGS -Wno-unused"
+        NGX_GCC_OPT="$NGX_GCC_OPT -Wno-unused"
     ;;
 
     *)
         # we have a lot of the unused function arguments
-        CFLAGS="$CFLAGS -Wno-unused-parameter"
+        NGX_GCC_OPT="$NGX_GCC_OPT -Wno-unused-parameter"
         # 4.2.1 shows the warning in wrong places
-        #CFLAGS="$CFLAGS -Wunreachable-code"
+        #NGX_GCC_OPT="$NGX_GCC_OPT -Wunreachable-code"
 
         # deprecated system OpenSSL library on OS X
         if [ "$NGX_SYSTEM" = "Darwin" ]; then
-            CFLAGS="$CFLAGS -Wno-deprecated-declarations"
+            NGX_GCC_OPT="$NGX_GCC_OPT -Wno-deprecated-declarations"
         fi
     ;;
 esac
 
 
 # stop on warning
-CFLAGS="$CFLAGS -Werror"
+NGX_GCC_OPT="$NGX_GCC_OPT -Werror"
 
 # debug
-CFLAGS="$CFLAGS -g"
+NGX_GCC_OPT="$NGX_GCC_OPT -g"
 
 # DragonFly's gcc3 generates DWARF
-#CFLAGS="$CFLAGS -g -gstabs"
+#NGX_GCC_OPT="$NGX_GCC_OPT -g -gstabs"
 
 if [ ".$CPP" = "." ]; then
     CPP="$CC -E"
diff -r 2c4dbcd6f2e4 auto/cc/icc
--- a/auto/cc/icc	Mon Apr 24 14:17:13 2017 +0300
+++ b/auto/cc/icc	Sun May 21 17:05:40 2017 +0100
@@ -15,7 +15,7 @@
 
 # optimizations
 
-CFLAGS="$CFLAGS -O"
+NGX_ICC_OPT="-O"
 
 CORE_LINK="$CORE_LINK -opt_report_file=$NGX_OBJS/opt_report_file"
 
@@ -37,7 +37,7 @@
     ;;
 esac
 
-CFLAGS="$CFLAGS $CPU_OPT"
+NGX_ICC_OPT="$NGX_ICC_OPT $CPU_OPT"
 
 if [ ".$PCRE_OPT" = "." ]; then
     PCRE_OPT="-O $CPU_OPT"
@@ -50,60 +50,60 @@
 
 # warnings
 
-CFLAGS="$CFLAGS -w2"
+NGX_ICC_OPT="$NGX_ICC_OPT -w2"
 
 # disable some warnings
 
 # invalid type conversion: "int" to "char *"
-CFLAGS="$CFLAGS -wd171"
+NGX_ICC_OPT="$NGX_ICC_OPT -wd171"
 # argument is incompatible with corresponding format string conversion
-CFLAGS="$CFLAGS -wd181"
+NGX_ICC_OPT="$NGX_ICC_OPT -wd181"
 # zero used for undefined preprocessing identifier
-CFLAGS="$CFLAGS -wd193"
+NGX_ICC_OPT="$NGX_ICC_OPT -wd193"
 # the format string ends before this argument
-CFLAGS="$CFLAGS -wd268"
+NGX_ICC_OPT="$NGX_ICC_OPT -wd268"
 # invalid format string conversion
-CFLAGS="$CFLAGS -wd269"
+NGX_ICC_OPT="$NGX_ICC_OPT -wd269"
 # conversion from "long long" to "size_t" may lose significant bits
-CFLAGS="$CFLAGS -wd810"
+NGX_ICC_OPT="$NGX_ICC_OPT -wd810"
 # parameter was never referenced
-CFLAGS="$CFLAGS -wd869"
+NGX_ICC_OPT="$NGX_ICC_OPT -wd869"
 # attribute "unused" is only allowed in a function definition, warning on pTHX_
-CFLAGS="$CFLAGS -wd1301"
+NGX_ICC_OPT="$NGX_ICC_OPT -wd1301"
 
 # STUB
 # enumerated type mixed with another type
-CFLAGS="$CFLAGS -wd188"
+NGX_ICC_OPT="$NGX_ICC_OPT -wd188"
 # controlling expression is constant
-CFLAGS="$CFLAGS -wd279"
+NGX_ICC_OPT="$NGX_ICC_OPT -wd279"
 # operands are evaluated in unspecified order
-CFLAGS="$CFLAGS -wd981"
+NGX_ICC_OPT="$NGX_ICC_OPT -wd981"
 # external definition with no prior declaration
-CFLAGS="$CFLAGS -wd1418"
+NGX_ICC_OPT="$NGX_ICC_OPT -wd1418"
 # external declaration in primary source file
-CFLAGS="$CFLAGS -wd1419"
+NGX_ICC_OPT="$NGX_ICC_OPT -wd1419"
 
 case "$NGX_ICC_VER" in
     9.*)
         # "cc" clobber ignored, warnings for Linux's htonl()/htons()
-        CFLAGS="$CFLAGS -wd1469"
+        NGX_ICC_OPT="$NGX_ICC_OPT -wd1469"
         # explicit conversion of a 64-bit integral type to a smaller
         # integral type
-        CFLAGS="$CFLAGS -wd1683"
+        NGX_ICC_OPT="$NGX_ICC_OPT -wd1683"
         # conversion from pointer to same-sized integral type,
         # warning on offsetof()
-        CFLAGS="$CFLAGS -wd1684"
+        NGX_ICC_OPT="$NGX_ICC_OPT -wd1684"
         # floating-point equality and inequality comparisons are unreliable,
         # warning on SvTRUE()
-        CFLAGS="$CFLAGS -wd1572"
+        NGX_ICC_OPT="$NGX_ICC_OPT -wd1572"
     ;;
 
     8.*)
         # "cc" clobber ignored, warnings for Linux's htonl()/htons()
-        CFLAGS="$CFLAGS -wd1469"
+        NGX_ICC_OPT="$NGX_ICC_OPT -wd1469"
         # floating-point equality and inequality comparisons are unreliable,
         # warning on SvTRUE()
-        CFLAGS="$CFLAGS -wd1572"
+        NGX_ICC_OPT="$NGX_ICC_OPT -wd1572"
     ;;
 
     *)
@@ -111,7 +111,10 @@
 esac
 
 # stop on warning
-CFLAGS="$CFLAGS -Werror"
+NGX_ICC_OPT="$NGX_ICC_OPT -Werror"
 
 # debug
-CFLAGS="$CFLAGS -g"
+NGX_ICC_OPT="$NGX_ICC_OPT -g"
+
+CFLAGS="$CFLAGS $NGX_ICC_OPT"
+CXXFLAGS="$CXXFLAGS $NGX_ICC_OPT"
diff -r 2c4dbcd6f2e4 auto/make
--- a/auto/make	Mon Apr 24 14:17:13 2017 +0300
+++ b/auto/make	Sun May 21 17:05:40 2017 +0100
@@ -21,9 +21,11 @@
 cat << END                                                     > $NGX_MAKEFILE
 
 CC =	$CC
+CXX =	$CXX
 CFLAGS = $CFLAGS
-CPP =	$CPP
-LINK =	$LINK
+CXXFLAGS = $CXXFLAGS
+CPP =   $CPP
+LINK =  $LINK
 
 END
 
@@ -384,8 +386,9 @@
 
     ngx_cc="\$(CC) $ngx_compile_opt \$(CFLAGS) $ngx_use_pch \$(ALL_INCS)"
 
-    for ngx_src in $MISC_SRCS
+    for ngx_src in $NGX_MISC_SRCS
     do
+        ngx_src_is_cpp=`echo $ngx_src | grep -E "\.cpp$" | wc -l`
         ngx_src=`echo $ngx_src | sed -e "s/\//$ngx_regex_dirsep/g"`
         ngx_obj=`echo $ngx_src \
             | sed -e "s#^\(.*\.\)cpp\\$#$ngx_objs_dir\1$ngx_objext#g" \
@@ -393,6 +396,12 @@
                   -e "s#^\(.*\.\)c\\$#$ngx_objs_dir\1$ngx_objext#g" \
                   -e "s#^\(.*\.\)S\\$#$ngx_objs_dir\1$ngx_objext#g"`
 
+        if [ "$ngx_src_is_cpp" -eq '1' ]; then
+            ngx_cc="\$(CXX) $ngx_compile_opt \$(CXXFLAGS) $ngx_use_pch \$(ALL_INCS)"
+        else
+            ngx_cc="\$(CC) $ngx_compile_opt \$(CFLAGS) $ngx_use_pch \$(ALL_INCS)"
+        fi;
+
         cat << END                                            >> $NGX_MAKEFILE
 
 $ngx_obj:	\$(CORE_DEPS) $ngx_cont$ngx_src
@@ -408,10 +417,10 @@
 
 if test -n "$NGX_ADDON_SRCS"; then
 
-    ngx_cc="\$(CC) $ngx_compile_opt \$(CFLAGS) $ngx_use_pch \$(ALL_INCS)"
-
     for ngx_src in $NGX_ADDON_SRCS
     do
+        ngx_src_is_cpp=`echo $ngx_src | grep -E "\.cpp$" | wc -l`
+
         ngx_obj="addon/`basename \`dirname $ngx_src\``"
 
         ngx_obj=`echo $ngx_obj/\`basename $ngx_src\` \
@@ -424,6 +433,12 @@
                   -e "s#^\(.*\.\)S\\$#$ngx_objs_dir\1$ngx_objext#g"`
 
         ngx_src=`echo $ngx_src | sed -e "s/\//$ngx_regex_dirsep/g"`
+        if [ "$ngx_src_is_cpp" -eq '1' ]; then
+            ngx_cc="\$(CXX) $ngx_compile_opt \$(CXXFLAGS) $ngx_use_pch \$(ALL_INCS)"
+        else
+            ngx_cc="\$(CC) $ngx_compile_opt \$(CFLAGS) $ngx_use_pch \$(ALL_INCS)"
+        fi;
+
 
         cat << END                                            >> $NGX_MAKEFILE
 
diff -r 2c4dbcd6f2e4 auto/options
--- a/auto/options	Mon Apr 24 14:17:13 2017 +0300
+++ b/auto/options	Sun May 21 17:05:40 2017 +0100
@@ -23,6 +23,7 @@
 
 NGX_DEBUG=NO
 NGX_CC_OPT=
+NGX_CXX_OPT=
 NGX_LD_OPT=
 CPU=NO
 
@@ -333,8 +334,10 @@
         --with-compat)                   NGX_COMPAT=YES             ;;
 
         --with-cc=*)                     CC="$value"                ;;
+        --with-cxx=*)                    CXX="$value"               ;;
         --with-cpp=*)                    CPP="$value"               ;;
         --with-cc-opt=*)                 NGX_CC_OPT="$value"        ;;
+        --with-cxx-opt=*)                NGX_CXX_OPT="$value"       ;;
         --with-ld-opt=*)                 NGX_LD_OPT="$value"        ;;
         --with-cpu-opt=*)                CPU="$value"               ;;
         --with-debug)                    NGX_DEBUG=YES              ;;
@@ -541,8 +544,10 @@
   --with-compat                      dynamic modules compatibility
 
   --with-cc=PATH                     set C compiler pathname
+  --with-cxx=PATH                    set C++ compiler pathname
   --with-cpp=PATH                    set C preprocessor pathname
   --with-cc-opt=OPTIONS              set additional C compiler options
+  --with-cxx-opt=OPTIONS             set additional C++ compiler options
   --with-ld-opt=OPTIONS              set additional linker options
   --with-cpu-opt=CPU                 build for the specified CPU, valid values:
                                      pentium, pentiumpro, pentium3, pentium4,


More information about the nginx-devel mailing list