summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjperkin <jperkin@pkgsrc.org>2022-07-05 17:32:24 +0000
committerjperkin <jperkin@pkgsrc.org>2022-07-05 17:32:24 +0000
commit5a3d1af2d7a6c0ed8ff87f491e85df1385cf7145 (patch)
tree67659afe759ecac8566507f844e5660245524cb4
parente2599434fcbef2e4a36803c8a1ed5464eaedf64e (diff)
downloadpkgsrc-5a3d1af2d7a6c0ed8ff87f491e85df1385cf7145.tar.gz
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.
-rw-r--r--mk/compiler.mk36
-rw-r--r--mk/compiler/clang.mk6
-rw-r--r--mk/compiler/gcc.mk16
3 files changed, 37 insertions, 21 deletions
diff --git a/mk/compiler.mk b/mk/compiler.mk
index 9f9c29af6d8..cf579f40251 100644
--- a/mk/compiler.mk
+++ b/mk/compiler.mk
@@ -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 @@ _SYS_VARS.compiler= CC_VERSION
# 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 @@ ${_var_}:= ${${_var_}:C/^/_asdf_/1:M_asdf_*:S/^_asdf_//:T} ${${_var_}:C/^/_asdf_
. 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.
-#
-# If and when the flags differ between compilers we can push this down into
-# the respective mk/compiler/*.mk files.
+# 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.
#
+_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 --git a/mk/compiler/clang.mk b/mk/compiler/clang.mk
index 66625977c30..7310a20533b 100644
--- a/mk/compiler/clang.mk
+++ b/mk/compiler/clang.mk
@@ -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 @@ _NOERROR_IMPLICIT_cmd= ${CCPATH} -\#\#\# -E -x c /dev/null 2>&1 \
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 --git a/mk/compiler/gcc.mk b/mk/compiler/gcc.mk
index d688db08a03..e039eaf8a61 100644
--- a/mk/compiler/gcc.mk
+++ b/mk/compiler/gcc.mk
@@ -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 @@ _DEF_VARS.gcc= \
_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 @@ _GCC_VERSION= 0
.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 @@ _LANGUAGES.gcc+= ${LANGUAGES.gcc:M${_lang_}}
_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