tech-pkg archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
FORCE_C_STD and FORCE_CXX_STD
This patch is designed to replace several common patterns in pkgsrc:
- A package uses a feature from a newer language standard without
declaring so, effectively assuming the compiler defaults to
a newer standard. This replaces the pattern:
# "error: 'for' loop initial declarations are only allowed in C99 mode"
USE_LANGUAGES= c99
with
# "error: 'for' loop initial declarations are only allowed in C99 mode"
FORCE_C_STD= c99
- A package is old and uses deprecated language features without
setting std, failing with compilers that default to a newer standard.
This replaces the pattern:
USE_LANGUAGES= c c++03
with
USE_LANGUAGES= c c++
# fails with C++14 default
FORCE_CXX_STD= c++03
- A package uses standard library features that depend on non-standard
compiler extensions without realizing.
This replaces the pattern:
# Also needed for alloca(), c99 creeps in and overrides otherwise...
BUILDLINK_TRANSFORM+= opt:-std=c99:-std=gnu99
with
# Also needed for alloca(), c99 creeps in and overrides otherwise...
FORCE_C_STD= gnu99
Index: doc/guide/files/fixes.xml
===================================================================
RCS file: /cvsroot/pkgsrc/doc/guide/files/fixes.xml,v
retrieving revision 1.190
diff -u -p -u -r1.190 fixes.xml
--- doc/guide/files/fixes.xml 26 Jul 2023 22:41:02 -0000 1.190
+++ doc/guide/files/fixes.xml 29 Jul 2023 21:30:07 -0000
@@ -1433,19 +1433,12 @@ MESON_ARGS+= -Dx11=false
the <varname>USE_LANGUAGES</varname> variable. Allowed values
currently are:
<programlisting>
-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.
+c, c++, fortran, fortran77, java, objc, obj-c++, and ada.
</programlisting>
(and any combination). The default is
<quote>c</quote>. Packages using GNU configure scripts, even if
written in C++, usually need a C compiler for the configure
phase.
- Language variants like <literal>c++11</literal>
- can be specified if the package does not explicitly set
- <literal>-std=...</literal> when compiling (i.e. the package
- assumes the compiler defaults to C++11 or some other standard).
- This is a common bug in upstream build systems.</para>
<para>To declare which features a package requies from the
compiler, set either <varname>USE_CC_FEATURES</varname>
@@ -1462,6 +1455,28 @@ charconv, parallelism_ts, unique_ptr, pu
is_trivially_copy_constructible
</programlisting>
</para>
+
+ <para>Language variants like <literal>gnu99</literal> and
+ <literal>c++11</literal> can be specified in <varname>FORCE_C_STD</varname>
+ and <varname>FORCE_CXX_STD</varname> if the package does not explicitly set
+ <literal>-std=...</literal> when compiling (i.e. the package
+ assumes the compiler defaults to C++11 or some other standard).
+ This is a common bug in upstream build systems.</para>
+
+ <para>Allowed values for <varname>FORCE_C_STD</varname> are
+ currently:
+<programlisting>
+c90, c99, c11, gnu90, gnu99, gnu11
+</programlisting></para>
+ </para>
+
+ <para>Allowed values for <varname>USE_CXX_FEATURES</varname> are
+ currently:
+<programlisting>
+c++03, c++11, c++14, c++17, c++20,
+gnu++03, gnu++11, gnu++14, gnu++17, gnu++20
+</programlisting></para>
+ </para>
</sect2>
<sect2 id="java-programming-language">
Index: mk/compiler.mk
===================================================================
RCS file: /cvsroot/pkgsrc/mk/compiler.mk,v
retrieving revision 1.104
diff -u -p -u -r1.104 compiler.mk
--- mk/compiler.mk 29 Jul 2023 18:09:39 -0000 1.104
+++ mk/compiler.mk 29 Jul 2023 21:30:07 -0000
@@ -84,6 +84,29 @@
# regex, filesystem, unique_ptr, charconv, parallelism_ts,
# put_time, is_trivially_copy_constructible.
#
+# FORCE_C_STD
+#
+# Overrides the compiler's default C dialect to ensure that a
+# specific language variant is used. This is useful if a package
+# uses features from a later or earlier C standard but doesn't set
+# -std=cXX, since the default dialect choice of different compiler
+# versions is not consistent. It is also useful if a package
+# wants to use GNU language extensions without setting -std=gnuXX.
+#
+# Valid values are: c90, c99, c11, gnu90, gnu99, gnu11
+#
+# FORCE_CXX_STD
+#
+# Overrides the compiler's default C++ dialect to ensure that a
+# specific language variant is used. This is useful if a package
+# uses features from a later or earlier C++ standard but doesn't set
+# -std=c++XX, since the default dialect choice of different compiler
+# versions is not consistent. It is also useful if a package
+# wants to use GNU language extensions without setting -std=gnu++XX.
+#
+# Valid values are: c++03, c++11, c++14, c++17, c++20, gnu++03,
+# gnu++11, gnu++17, gnu++20
+#
# The following variables are defined, and available for testing in
# package Makefiles:
#
Index: mk/compiler/gcc-style-args.mk
===================================================================
RCS file: /cvsroot/pkgsrc/mk/compiler/gcc-style-args.mk,v
retrieving revision 1.1
diff -u -p -u -r1.1 gcc-style-args.mk
--- mk/compiler/gcc-style-args.mk 29 Jul 2023 17:55:47 -0000 1.1
+++ mk/compiler/gcc-style-args.mk 29 Jul 2023 21:30:07 -0000
@@ -17,6 +17,34 @@ _WRAP_EXTRA_ARGS.cc+= -fcommon
CWRAPPERS_PREPEND.cc+= -fcommon
#
+# Language dialects
+#
+
+_GCC_C_DIALECTS= c90 c99 c11
+
+_GCC_C_DIALECTS+= gnu90 gnu99 gnu11
+
+_GCC_CXX_DIALECTS= c++03 c++11 c++14 c++17 c++20
+
+_GCC_CXX_DIALECTS+= gnu++03 gnu++11 gnu++14 gnu++17 gnu++20
+
+.if !empty(FORCE_C_STD)
+. for std in ${_GCC_C_DIALECTS}
+. if !empty(FORCE_C_STD:M${std})
+CWRAPPERS_APPEND.cc+= -std=${std}
+. endif
+. endfor
+.endif
+
+.if !empty(FORCE_CXX_STD)
+. for std in ${_GCC_CXX_DIALECTS}
+. if !empty(FORCE_CXX_STD:M${std})
+CWRAPPERS_APPEND.cxx+= -std=${std}
+. endif
+. endfor
+.endif
+
+#
# Hardening features
#
Home |
Main Index |
Thread Index |
Old Index