aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBaptiste Daroussin <bapt@FreeBSD.org>2022-07-21 09:56:06 +0000
committerBaptiste Daroussin <bapt@FreeBSD.org>2022-07-27 13:21:32 +0000
commitb26839acc225c7007ebb8910e7136703667effda (patch)
tree7f11302d37acf7521128fae2e8d6c02e93d201c9
parent5f87249229d34dcdad7b60433fd423db35203efb (diff)
downloadports-b26839acc225c7007ebb8910e7136703667effda.tar.gz
ports-b26839acc225c7007ebb8910e7136703667effda.zip
framework: generalize WITH_ code
Make the definition of WITH_ variable (end user actionable) a define via a generic code Move the WITH_DEBUG code into its own file Features/debug.mk Replace USE_LTO into WITH_LTO and move it into Features/lto.mk Move WITH_SSP into its own Features/ssp.mk Add a variable to defined which one are activated by default (here SSP) Reviewed by: portmgr (tcberner) Differential Revision: https://reviews.freebsd.org/D35873
-rw-r--r--Mk/Features/debug.mk24
-rw-r--r--Mk/Features/lto.mk (renamed from Mk/bsd.lto.mk)8
-rw-r--r--Mk/Features/ssp.mk (renamed from Mk/bsd.ssp.mk)5
-rw-r--r--Mk/bsd.port.mk42
4 files changed, 45 insertions, 34 deletions
diff --git a/Mk/Features/debug.mk b/Mk/Features/debug.mk
new file mode 100644
index 000000000000..6e67a2315223
--- /dev/null
+++ b/Mk/Features/debug.mk
@@ -0,0 +1,24 @@
+# DEBUG Support
+#
+# Add WITH_DEBUG into make.conf:
+# - If set, debugging flags are added to CFLAGS and the binaries don't get
+# stripped by INSTALL_PROGRAM or INSTALL_LIB. Besides, individual ports might
+# add their specific to produce binaries for debugging purposes. You can
+# override the debug flags that are passed to the compiler by setting
+# DEBUG_FLAGS. It is set to "-g" at default.
+
+.if !defined(_DEBUG_MK_INCLUDED)
+_DEBUG_MK_INCLUDED= yes
+DEBUG_Include_MAINTAINER= portmgr@FreeBSD.org
+
+. if !defined(INSTALL_STRIPPED)
+STRIP= #none
+MAKE_ENV+= DONTSTRIP=yes
+STRIP_CMD= ${TRUE}
+. endif
+DEBUG_FLAGS?= -g
+CFLAGS:= ${CFLAGS:N-O*:N-fno-strict*} ${DEBUG_FLAGS}
+. if defined(INSTALL_TARGET)
+INSTALL_TARGET:= ${INSTALL_TARGET:S/^install-strip$/install/g}
+. endif
+.endif
diff --git a/Mk/bsd.lto.mk b/Mk/Features/lto.mk
index 196f686f9a7c..9d38448f312c 100644
--- a/Mk/bsd.lto.mk
+++ b/Mk/Features/lto.mk
@@ -1,13 +1,17 @@
# LTO Support
+#
# This file enforces Link Time Optimization for ports.
-# In order to use it, add USE_LTO=yes to your /etc/make.conf.
+# In order to use it, add WITH_LTO=yes to your /etc/make.conf.
+.if !defined(_LTO_MK_INCLUDED)
+_LTO_MK_INCLUDED= yes
LTO_Include_MAINTAINER= pkubaj@FreeBSD.org
-.if !defined(LTO_UNSAFE)
+. if !defined(LTO_UNSAFE)
# Overridable as a user may want to use -flto
LTO_FLAGS?= -flto=thin
CFLAGS+= ${LTO_FLAGS}
CXXFLAGS+= ${LTO_FLAGS}
LDFLAGS+= ${LTO_FLAGS}
+. endif
.endif
diff --git a/Mk/bsd.ssp.mk b/Mk/Features/ssp.mk
index f85b4e5c58a8..4213e6d668a6 100644
--- a/Mk/bsd.ssp.mk
+++ b/Mk/Features/ssp.mk
@@ -1,11 +1,14 @@
# SSP Support
+.if !defined(_SSP_MK_INCLUDED)
+_SSP_MK_INCLUDED= yes
SSP_Include_MAINTAINER= portmgr@FreeBSD.org
-.if !defined(SSP_UNSAFE) && \
+. if !defined(SSP_UNSAFE) && \
(! ${ARCH:Mmips*})
# Overridable as a user may want to use -fstack-protector-all
SSP_CFLAGS?= -fstack-protector-strong
CFLAGS+= ${SSP_CFLAGS}
LDFLAGS+= ${SSP_CFLAGS}
+. endif
.endif
diff --git a/Mk/bsd.port.mk b/Mk/bsd.port.mk
index bcffecf2ab93..cc4de5aff0c4 100644
--- a/Mk/bsd.port.mk
+++ b/Mk/bsd.port.mk
@@ -325,17 +325,6 @@ FreeBSD_MAINTAINER= portmgr@FreeBSD.org
# usage inside the ports framework, and the latter are reserved for user-
# settable options. (Setting USE_* in /etc/make.conf is always wrong).
#
-# WITH_DEBUG - If set, debugging flags are added to CFLAGS and the
-# binaries don't get stripped by INSTALL_PROGRAM or
-# INSTALL_LIB. Besides, individual ports might
-# add their specific to produce binaries for debugging
-# purposes. You can override the debug flags that are
-# passed to the compiler by setting DEBUG_FLAGS. It is
-# set to "-g" at default.
-#
-# NOTE: to override a globally defined WITH_DEBUG at a
-# later time ".undef WITH_DEBUG" can be used
-#
# WITH_DEBUG_PORTS - A list of origins for which WITH_DEBUG will be set
#
# WITHOUT_SSP - Disable SSP.
@@ -1019,6 +1008,8 @@ LC_ALL= C
# These need to be absolute since we don't know how deep in the ports
# tree we are and thus can't go relative. They can, of course, be overridden
# by individual Makefiles or local system make configuration.
+_LIST_OF_WITH_FEATURES= debug lto ssp
+_DEFAULT_WITH_FEATURES= ssp
PORTSDIR?= /usr/ports
LOCALBASE?= /usr/local
LINUXBASE?= /compat/linux
@@ -1312,6 +1303,11 @@ WITH_DEBUG= yes
. endif
. endif
+. if defined(USE_LTO)
+WITH_LTO= ${USE_LTO}
+WARNING+= USE_LTO is precrecated in favor of WITH_LTO
+. endif
+
.include "${PORTSDIR}/Mk/bsd.default-versions.mk"
.include "${PORTSDIR}/Mk/bsd.options.mk"
@@ -1766,27 +1762,11 @@ CFLAGS:= ${CFLAGS:C/${_CPUCFLAGS}//}
. endif
. endif
-# Reset value from bsd.own.mk.
-. if defined(WITH_DEBUG)
-. if !defined(INSTALL_STRIPPED)
-STRIP= #none
-MAKE_ENV+= DONTSTRIP=yes
-STRIP_CMD= ${TRUE}
-. endif
-DEBUG_FLAGS?= -g
-CFLAGS:= ${CFLAGS:N-O*:N-fno-strict*} ${DEBUG_FLAGS}
-. if defined(INSTALL_TARGET)
-INSTALL_TARGET:= ${INSTALL_TARGET:S/^install-strip$/install/g}
+. for f in ${_LIST_OF_WITH_FEATURES}
+. if defined(WITH_${f:tu}) || ( ${_DEFAULT_WITH_FEATURES:M${f}} && !defined(WITHOUT_${f:tu}) )
+.include "${PORTSDIR}/Mk/Features/$f.mk"
. endif
-. endif
-
-. if defined(USE_LTO)
-.include "${PORTSDIR}/Mk/bsd.lto.mk"
-. endif
-
-. if !defined(WITHOUT_SSP)
-.include "${PORTSDIR}/Mk/bsd.ssp.mk"
-. endif
+. endfor
# XXX PIE support to be added here
MAKE_ENV+= NO_PIE=yes