pkgsrc-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[pkgsrc/trunk]: pkgsrc/mk mk: Add support for newer C standards.



details:   https://anonhg.NetBSD.org/pkgsrc/rev/9ae626e38d43
branches:  trunk
changeset: 381379:9ae626e38d43
user:      jperkin <jperkin%pkgsrc.org@localhost>
date:      Tue Jul 05 17:32:24 2022 +0000

description:
mk: Add support for newer C standards.

For now the GCC "c99 == gnu99" override is kept, but gnu99 is now supported as
a specific value for USE_LANGUAGES, so we may want to be specific where
required.

c11 and c17 (and the corresponding gnu11/gnu17 versions) are newly supported.

diffstat:

 mk/compiler.mk       |  36 ++++++++++++++++++++++--------------
 mk/compiler/clang.mk |   6 +++++-
 mk/compiler/gcc.mk   |  16 ++++++++++------
 3 files changed, 37 insertions(+), 21 deletions(-)

diffs (129 lines):

diff -r a6712852650c -r 9ae626e38d43 mk/compiler.mk
--- a/mk/compiler.mk    Tue Jul 05 16:28:33 2022 +0000
+++ b/mk/compiler.mk    Tue Jul 05 17:32:24 2022 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: compiler.mk,v 1.97 2022/04/10 19:54:02 riastradh Exp $
+# $NetBSD: compiler.mk,v 1.98 2022/07/05 17:32:24 jperkin Exp $
 #
 # This Makefile fragment implements handling for supported C/C++/Fortran
 # compilers.
@@ -48,9 +48,9 @@
 #      This is used to determine the correct compilers to make
 #      visible to the build environment, installing them if
 #      necessary.  Flags such as -std=c++99 are also added.
-#      Valid values are: c, c99, c++, c++03, gnu++03, c++0x, gnu++0x,
-#      c++11, gnu++11, c++14, gnu++14, c++17, gnu++17, c++20, gnu++20,
-#      fortran, fortran77, java, objc, obj-c++, and ada.
+#      Valid values are: c, c99, gnu99, c11, gnu11, c17, gnu17, c++, c++03,
+#      gnu++03, c++0x, gnu++0x, c++11, gnu++11, c++14, gnu++14, c++17,
+#      gnu++17, c++20, gnu++20, fortran, fortran77, java, objc, obj-c++, ada.
 #      The default is "c".
 #
 #       The above is partly aspirational.  As an example c++11 does
@@ -83,10 +83,12 @@
 # Since most packages need a C compiler, this is the default value.
 USE_LANGUAGES?=        c
 
-# Add c support if c99 is set
-.if !empty(USE_LANGUAGES:Mc99)
-USE_LANGUAGES+=        c
-.endif
+_C_STD_VERSIONS=       c99 gnu99 c11 gnu11 c17 gnu17
+.for _version_ in ${_C_STD_VERSIONS}
+.  if !empty(USE_LANGUAGES:M${_version_})
+USE_LANGUAGES+=                c
+.  endif
+.endfor
 
 _CXX_STD_VERSIONS=     gnu++20 c++20 gnu++17 c++17 gnu++14 c++14 gnu++11 c++11 gnu++0x c++0x gnu++03 c++03
 .for _version_ in ${_CXX_STD_VERSIONS}
@@ -178,13 +180,19 @@
 .  endif
 .endfor
 
-# Pass the compiler flag based on the most recent version of the C++ standard
-# required.  We currently assume that each standard is a superset of all that
-# come after it.
+# Pass the compiler flag based on the most recent version of the C or C++
+# standard required.  We currently assume that each standard is a superset of
+# all that come after it.
 #
-# If and when the flags differ between compilers we can push this down into
-# the respective mk/compiler/*.mk files.
-#
+_C_VERSION_REQD=
+.for _version_ in ${_C_STD_VERSIONS}
+.  if empty(_C_VERSION_REQD) && !empty(USE_LANGUAGES:M${_version_})
+_C_VERSION_REQD=       ${_version_}
+_WRAP_EXTRA_ARGS.CC+=  ${_C_STD_FLAG.${_C_VERSION_REQD}}
+CWRAPPERS_PREPEND.cc+= ${_C_STD_FLAG.${_C_VERSION_REQD}}
+.  endif
+.endfor
+
 _CXX_VERSION_REQD=
 .for _version_ in ${_CXX_STD_VERSIONS}
 .  if empty(_CXX_VERSION_REQD) && !empty(USE_LANGUAGES:M${_version_})
diff -r a6712852650c -r 9ae626e38d43 mk/compiler/clang.mk
--- a/mk/compiler/clang.mk      Tue Jul 05 16:28:33 2022 +0000
+++ b/mk/compiler/clang.mk      Tue Jul 05 17:32:24 2022 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: clang.mk,v 1.35 2022/03/13 06:26:57 nia Exp $
+# $NetBSD: clang.mk,v 1.36 2022/07/05 17:32:24 jperkin Exp $
 #
 # This is the compiler definition for the clang compiler.
 #
@@ -121,6 +121,10 @@
 CWRAPPERS_PREPEND.cc+= ${_NOERROR_IMPLICIT_cmd:sh}
 .endif
 
+.for _version_ in ${_C_STD_VERSIONS}
+_C_STD_FLAG.${_version_}?=     -std=${_version_}
+.endfor
+
 .for _version_ in ${_CXX_STD_VERSIONS}
 _CXX_STD_FLAG.${_version_}?=   -std=${_version_}
 .endfor
diff -r a6712852650c -r 9ae626e38d43 mk/compiler/gcc.mk
--- a/mk/compiler/gcc.mk        Tue Jul 05 16:28:33 2022 +0000
+++ b/mk/compiler/gcc.mk        Tue Jul 05 17:32:24 2022 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: gcc.mk,v 1.243 2022/06/16 15:46:22 adam Exp $
+# $NetBSD: gcc.mk,v 1.244 2022/07/05 17:32:24 jperkin Exp $
 #
 # This is the compiler definition for the GNU Compiler Collection.
 #
@@ -101,6 +101,8 @@
        _USE_GCC_SHLIB _USE_PKGSRC_GCC \
        _WRAP_EXTRA_ARGS.CC \
        _EXTRA_CC_DIRS \
+       _C_STD_VERSIONS \
+       ${_C_STD_VERSIONS:@std@_C_STD_FLAG.${std}@} \
        _CXX_STD_VERSIONS \
        ${_CXX_STD_VERSIONS:@std@_CXX_STD_FLAG.${std}@} \
        _MKPIE_CFLAGS.gcc _MKPIE_LDFLAGS \
@@ -221,6 +223,13 @@
 .endif
 _GCC_PKG=      gcc-${_GCC_VERSION:C/-.*$//}
 
+.for _version_ in ${_C_STD_VERSIONS}
+_C_STD_FLAG.${_version_}?=     -std=${_version_}
+.endfor
+# XXX: pkgsrc historically hardcoded c99=gnu99 so we retain that for now, but
+# we should look at removing this and be explicit in packages where required.
+_C_STD_FLAG.c99=       -std=gnu99
+
 .for _version_ in ${_CXX_STD_VERSIONS}
 _CXX_STD_FLAG.${_version_}?=   -std=${_version_}
 .  if !empty(_GCC_VERSION:M[34].[1234].*)
@@ -384,11 +393,6 @@
 _WRAP_EXTRA_ARGS.cc+=  -fcommon
 CWRAPPERS_PREPEND.cc+= -fcommon
 
-.if !empty(USE_LANGUAGES:Mc99)
-_WRAP_EXTRA_ARGS.CC+=  -std=gnu99
-CWRAPPERS_APPEND.cc+=  -std=gnu99
-.endif
-
 .if ${_PKGSRC_MKPIE} == "yes"
 _MKPIE_CFLAGS.gcc=     -fPIC
 _MKPIE_FCFLAGS.gcc=    -fPIC



Home | Main Index | Thread Index | Old Index