pkgsrc-Changes archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
CVS commit: pkgsrc/mk
Module Name: pkgsrc
Committed By: nia
Date: Sat Jul 29 17:55:47 UTC 2023
Modified Files:
pkgsrc/mk: compiler.mk
pkgsrc/mk/compiler: clang.mk gcc.mk
Added Files:
pkgsrc/mk/compiler: gcc-style-args.mk
Log Message:
mk: Begin to refactor common support for GCC/Clang into a single file.
They share lots of command line argument features and it doesn't make
sense to duplicate our work.
To generate a diff of this commit:
cvs rdiff -u -r1.102 -r1.103 pkgsrc/mk/compiler.mk
cvs rdiff -u -r1.40 -r1.41 pkgsrc/mk/compiler/clang.mk
cvs rdiff -u -r0 -r1.1 pkgsrc/mk/compiler/gcc-style-args.mk
cvs rdiff -u -r1.257 -r1.258 pkgsrc/mk/compiler/gcc.mk
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: pkgsrc/mk/compiler.mk
diff -u pkgsrc/mk/compiler.mk:1.102 pkgsrc/mk/compiler.mk:1.103
--- pkgsrc/mk/compiler.mk:1.102 Sat Jul 22 12:20:37 2023
+++ pkgsrc/mk/compiler.mk Sat Jul 29 17:55:47 2023
@@ -1,4 +1,4 @@
-# $NetBSD: compiler.mk,v 1.102 2023/07/22 12:20:37 nia Exp $
+# $NetBSD: compiler.mk,v 1.103 2023/07/29 17:55:47 nia Exp $
#
# This Makefile fragment implements handling for supported C/C++/Fortran
# compilers.
@@ -249,6 +249,48 @@ CWRAPPERS_APPEND.cxx+= ${_SSP_CFLAGS}
CWRAPPERS_APPEND.f77+= ${_SSP_CFLAGS}
.endif
+# Enable FORTIFY_SOURCE if the user has chosen to and the compiler
+# supports it.
+#
+.if ${_PKGSRC_USE_FORTIFY} != "no" && defined(_FORTIFY_CFLAGS)
+_WRAP_EXTRA_ARGS.CC+= ${_FORTIFY_CFLAGS}
+_WRAP_EXTRA_ARGS.CXX+= ${_FORTIFY_CFLAGS}
+CWRAPPERS_PREPEND.cc+= ${_FORTIFY_CFLAGS}
+CWRAPPERS_PREPEND.cxx+= ${_FORTIFY_CFLAGS}
+.endif
+
+# Enable reproducible executables if the user has chosen to and the
+# compiler supports it.
+#
+.if ${_PKGSRC_MKREPRO} != "no" && defined(_MKREPRO_CFLAGS)
+_WRAP_EXTRA_ARGS.CC+= ${_MKREPRO_CFLAGS}
+_WRAP_EXTRA_ARGS.CXX+= ${_MKREPRO_CFLAGS}
+CWRAPPERS_PREPEND.cc+= ${_MKREPRO_CFLAGS}
+CWRAPPERS_PREPEND.cxx+= ${_MKREPRO_CFLAGS}
+.endif
+
+# Enable relocation read-only if the user has chosen to and the compiler
+# supports it.
+#
+.if defined(_RELRO_LDFLAGS)
+LDFLAGS+= ${_RELRO_LDFLAGS}
+_WRAP_EXTRA_ARGS.CC+= ${_RELRO_LDFLAGS}
+_WRAP_EXTRA_ARGS.CXX+= ${_RELRO_LDFLAGS}
+CWRAPPERS_PREPEND.cc+= ${_RELRO_LDFLAGS}
+CWRAPPERS_PREPEND.cxx+= ${_RELRO_LDFLAGS}
+.endif
+
+# Enable position-independent executables if the user has chosen to and
+# the compiler supports it.
+#
+.if ${_PKGSRC_MKPIE} == "yes" && ${PKGSRC_OVERRIDE_MKPIE:tl} == "no"
+_WRAP_EXTRA_ARGS.CC+= ${_MKPIE_CFLAGS}
+_WRAP_EXTRA_ARGS.CXX+= ${_MKPIE_CFLAGS}
+CWRAPPERS_PREPEND.cc+= ${_MKPIE_CFLAGS}
+CWRAPPERS_PREPEND.cxx+= ${_MKPIE_CFLAGS}
+CWRAPPERS_PREPEND.f77+= ${_MKPIE_FCFLAGS}
+.endif
+
# Add debug flags if the user has requested CTF and the compiler supports it.
#
.if ${_PKGSRC_USE_CTF} == "yes" && defined(_CTF_CFLAGS)
Index: pkgsrc/mk/compiler/clang.mk
diff -u pkgsrc/mk/compiler/clang.mk:1.40 pkgsrc/mk/compiler/clang.mk:1.41
--- pkgsrc/mk/compiler/clang.mk:1.40 Tue Jun 27 10:27:21 2023
+++ pkgsrc/mk/compiler/clang.mk Sat Jul 29 17:55:47 2023
@@ -1,4 +1,4 @@
-# $NetBSD: clang.mk,v 1.40 2023/06/27 10:27:21 riastradh Exp $
+# $NetBSD: clang.mk,v 1.41 2023/07/29 17:55:47 nia Exp $
#
# This is the compiler definition for the clang compiler.
#
@@ -49,45 +49,8 @@ CC_VERSION?= clang
_COMPILER_ABI_FLAG.32= -m32
_COMPILER_ABI_FLAG.64= -m64
-_COMPILER_LD_FLAG= -Wl,
-_LINKER_RPATH_FLAG= -R
-_COMPILER_RPATH_FLAG= ${_COMPILER_LD_FLAG}${_LINKER_RPATH_FLAG}
-
-_CTF_CFLAGS= -gdwarf-2
-
-# The user or package can choose the level of RELRO.
-.if ${PKGSRC_USE_RELRO} != "partial" && \
- ${RELRO_SUPPORTED:Uyes:tl} != "partial"
-_RELRO_LDFLAGS= -Wl,-zrelro -Wl,-znow
-.else
-_RELRO_LDFLAGS= -Wl,-zrelro
-.endif
-
-# The user can choose the level of stack smashing protection.
-.if ${PKGSRC_USE_SSP} == "all"
-_SSP_CFLAGS= -fstack-protector-all
-.elif ${PKGSRC_USE_SSP} == "strong"
-_SSP_CFLAGS= -fstack-protector-strong
-.else
-_SSP_CFLAGS= -fstack-protector
-.endif
-.if ${_PKGSRC_USE_RELRO} == "yes"
-_CLANG_LDFLAGS+= ${_RELRO_LDFLAGS}
-CWRAPPERS_PREPEND.cc+= ${_RELRO_LDFLAGS}
-CWRAPPERS_PREPEND.cxx+= ${_RELRO_LDFLAGS}
-.endif
-
-.if ${_PKGSRC_MKPIE} == "yes"
-_MKPIE_CFLAGS.clang= -fPIC
-_MKPIE_LDFLAGS= -pie
-
-. if ${PKGSRC_OVERRIDE_MKPIE:tl} == "no"
-CFLAGS+= ${_MKPIE_CFLAGS.clang}
-CWRAPPERS_APPEND.cc+= ${_MKPIE_CFLAGS.clang}
-CWRAPPERS_APPEND.cxx+= ${_MKPIE_CFLAGS.clang}
-. endif
-.endif
+.include "gcc-style-args.mk"
LDFLAGS+= ${_CLANG_LDFLAGS}
@@ -105,9 +68,9 @@ PKGSRC_FORTRAN?=gfortran
. include "../../mk/compiler/${PKGSRC_FORTRAN}.mk"
.endif
-_WRAP_EXTRA_ARGS.CC+= -Qunused-arguments -fcommon
+_WRAP_EXTRA_ARGS.CC+= -Qunused-arguments
CWRAPPERS_APPEND.cc+= -Qunused-arguments
-CWRAPPERS_PREPEND.cc+= -Qunused-arguments -fcommon
+CWRAPPERS_PREPEND.cc+= -Qunused-arguments
_WRAP_EXTRA_ARGS.CXX+= -Qunused-arguments
CWRAPPERS_APPEND.cxx+= -Qunused-arguments
Index: pkgsrc/mk/compiler/gcc.mk
diff -u pkgsrc/mk/compiler/gcc.mk:1.257 pkgsrc/mk/compiler/gcc.mk:1.258
--- pkgsrc/mk/compiler/gcc.mk:1.257 Sat Jul 22 12:20:37 2023
+++ pkgsrc/mk/compiler/gcc.mk Sat Jul 29 17:55:47 2023
@@ -1,4 +1,4 @@
-# $NetBSD: gcc.mk,v 1.257 2023/07/22 12:20:37 nia Exp $
+# $NetBSD: gcc.mk,v 1.258 2023/07/29 17:55:47 nia Exp $
#
# This is the compiler definition for the GNU Compiler Collection.
#
@@ -150,6 +150,8 @@ GCC_REQD+= 2.8.0
. endif
.endif
+.include "gcc-style-args.mk"
+
#
# Most of the time, GCC adds support for features of new C and C++
# standards incrementally, so USE_CXX_FEATURES= c++XX is for
@@ -515,59 +517,6 @@ _LANGUAGES.gcc= # empty
_LANGUAGES.gcc+= ${LANGUAGES.gcc:M${_lang_}}
.endfor
-_WRAP_EXTRA_ARGS.cc+= -fcommon
-CWRAPPERS_PREPEND.cc+= -fcommon
-
-.if ${_PKGSRC_MKPIE} == "yes"
-_MKPIE_CFLAGS.gcc= -fPIC
-_MKPIE_FCFLAGS.gcc= -fPIC
-# for libraries a sink wrapper around gcc is required and used instead
-_MKPIE_LDFLAGS= -pie
-
-. if ${PKGSRC_OVERRIDE_MKPIE:tl} == "no"
-_GCC_CFLAGS+= ${_MKPIE_CFLAGS.gcc}
-_GCC_FCFLAGS+= ${_MKPIE_FCFLAGS.gcc}
-CWRAPPERS_APPEND.cc+= ${_MKPIE_CFLAGS.gcc}
-CWRAPPERS_APPEND.cxx+= ${_MKPIE_CFLAGS.gcc}
-CWRAPPERS_APPEND.f77+= ${_MKPIE_FCFLAGS.gcc}
-. endif
-.endif
-
-.if ${_PKGSRC_MKREPRO} == "yes"
-.export WRKDIR
-# XXX the dollar sign should not be expanded by the shell
-_GCC_CFLAGS+= -fdebug-prefix-map=$$$$WRKDIR/=
-.endif
-
-.if ${_PKGSRC_MKREPRO} == "yes"
-_GCC_CFLAGS+= ${_MKREPRO_CFLAGS.gcc}
-CWRAPPERS_APPEND.cc+= ${_MKREPRO_CFLAGS.gcc}
-.endif
-
-# The user can choose the level of FORTIFY.
-.if ${PKGSRC_USE_FORTIFY} == "weak"
-_FORTIFY_CFLAGS= -D_FORTIFY_SOURCE=1
-.else
-_FORTIFY_CFLAGS= -D_FORTIFY_SOURCE=2
-.endif
-
-.if ${_PKGSRC_USE_FORTIFY} == "yes"
-_GCC_CFLAGS+= ${_FORTIFY_CFLAGS}
-CWRAPPERS_APPEND.cc+= ${_FORTIFY_CFLAGS}
-.endif
-
-# The user or package can choose the level of RELRO.
-.if ${PKGSRC_USE_RELRO} != "partial" && \
- ${RELRO_SUPPORTED:Uyes:tl} != "partial"
-_RELRO_LDFLAGS= -Wl,-zrelro -Wl,-znow
-.else
-_RELRO_LDFLAGS= -Wl,-zrelro
-.endif
-
-.if !empty(_RELRO_LDFLAGS) && !empty(MACHINE_PLATFORM:MNetBSD-*-*mips*)
-_RELRO_LDFLAGS+= -Wl,-z,common-page-size=0x10000
-.endif
-
.if ${_PKGSRC_USE_STACK_CHECK} == "yes"
_STACK_CHECK_CFLAGS= -fstack-check
_GCC_CFLAGS+= ${_STACK_CHECK_CFLAGS}
@@ -576,8 +525,6 @@ _STACK_CHECK_CFLAGS= -fstack-clash-prote
_GCC_CFLAGS+= ${_STACK_CHECK_CFLAGS}
.endif
-_CTF_CFLAGS= -gdwarf-2
-
# GCC has this annoying behaviour where it advocates in a multi-line
# banner the use of "#include" over "#import" when including headers.
# This generates a huge number of warnings when building practically all
@@ -819,12 +766,6 @@ _NEED_NEWER_GCC!= \
PKG_FAIL_REASON+= "Unable to satisfy dependency: ${_GCC_DEPENDS}"
.endif
-# GNU ld option used to set the rpath
-_LINKER_RPATH_FLAG= -R
-
-# GCC passes rpath directives to the linker using "-Wl,-R".
-_COMPILER_RPATH_FLAG= -Wl,${_LINKER_RPATH_FLAG}
-
.if !empty(_USE_PKGSRC_GCC:M[yY][eE][sS])
#
# Ensure that the correct rpath is passed to the linker if we need to
@@ -869,12 +810,6 @@ _GCC_LDFLAGS+= -L${_dir_} ${COMPILER_RPA
. endfor
.endif
-.if ${_PKGSRC_USE_RELRO} == "yes"
-_GCC_LDFLAGS+= ${_RELRO_LDFLAGS}
-CWRAPPERS_PREPEND.cc+= ${_RELRO_LDFLAGS}
-CWRAPPERS_PREPEND.cxx+= ${_RELRO_LDFLAGS}
-.endif
-
LDFLAGS+= ${_GCC_LDFLAGS}
# Point the variables that specify the compiler to the installed
@@ -1026,17 +961,6 @@ CC_VERSION_STRING= ${CC_VERSION}
CC_VERSION= ${_GCC_PKG}
.endif
-# The user can choose the level of stack smashing protection.
-.if empty(CC_VERSION:Mgcc-[1-3].*)
-. if ${PKGSRC_USE_SSP} == "all"
-_SSP_CFLAGS= -fstack-protector-all
-. elif ${PKGSRC_USE_SSP} == "strong"
-_SSP_CFLAGS= -fstack-protector-strong
-. else
-_SSP_CFLAGS= -fstack-protector
-. endif
-.endif
-
# Prepend the path to the compiler to the PATH.
.if !empty(_LANGUAGES.gcc)
PREPEND_PATH+= ${_GCC_DIR}/bin
Added files:
Index: pkgsrc/mk/compiler/gcc-style-args.mk
diff -u /dev/null pkgsrc/mk/compiler/gcc-style-args.mk:1.1
--- /dev/null Sat Jul 29 17:55:48 2023
+++ pkgsrc/mk/compiler/gcc-style-args.mk Sat Jul 29 17:55:47 2023
@@ -0,0 +1,65 @@
+# $NetBSD: gcc-style-args.mk,v 1.1 2023/07/29 17:55:47 nia Exp $
+
+#
+# Some compilers (e.g. clang) share command line argument formats with GCC.
+#
+
+_COMPILER_LD_FLAG= -Wl,
+_LINKER_RPATH_FLAG= -R
+_COMPILER_RPATH_FLAG= ${_COMPILER_LD_FLAG}${_LINKER_RPATH_FLAG}
+
+_CTF_CFLAGS= -gdwarf-2
+
+# Newer compiler versions default to -fno-common, which causes lots of
+# problems when compiling older code. Force -fno-common off until we're
+# ready.
+_WRAP_EXTRA_ARGS.cc+= -fcommon
+CWRAPPERS_PREPEND.cc+= -fcommon
+
+#
+# Hardening features
+#
+
+# The user or package can choose the level of RELRO.
+.if ${PKGSRC_USE_RELRO} != "partial" && \
+ ${RELRO_SUPPORTED:Uyes:tl} != "partial"
+_RELRO_LDFLAGS= -Wl,-zrelro -Wl,-znow
+.else
+_RELRO_LDFLAGS= -Wl,-zrelro
+.endif
+
+.if !empty(_RELRO_LDFLAGS) && !empty(MACHINE_PLATFORM:MNetBSD-*-*mips*)
+_RELRO_LDFLAGS+= -Wl,-z,common-page-size=0x10000
+.endif
+
+# The user can choose the level of stack smashing protection.
+.if empty(CC_VERSION:Mgcc-[1-3].*)
+. if ${PKGSRC_USE_SSP} == "all"
+_SSP_CFLAGS= -fstack-protector-all
+. elif ${PKGSRC_USE_SSP} == "strong"
+_SSP_CFLAGS= -fstack-protector-strong
+. else
+_SSP_CFLAGS= -fstack-protector
+. endif
+.endif
+
+# The user can choose the level of FORTIFY.
+.if ${_PKGSRC_USE_FORTIFY} != "no"
+. if ${_PKGSRC_USE_FORTIFY} == "weak"
+_FORTIFY_CFLAGS= -D_FORTIFY_SOURCE=1
+. else
+_FORTIFY_CFLAGS= -D_FORTIFY_SOURCE=2
+. endif
+.endif
+
+.if ${_PKGSRC_MKREPRO} == "yes"
+.export WRKDIR
+# XXX the dollar sign should not be expanded by the shell
+_MKREPRO_CFLAGS+= -fdebug-prefix-map=$$$$WRKDIR/=
+.endif
+
+.if ${_PKGSRC_MKPIE} == "yes"
+_MKPIE_CFLAGS= -fPIC
+# for libraries a sink wrapper around gcc is required and used instead
+_MKPIE_LDFLAGS= -pie
+.endif
Home |
Main Index |
Thread Index |
Old Index