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
This commit is contained in:
Baptiste Daroussin 2022-07-21 11:56:06 +02:00
parent 5f87249229
commit b26839acc2
4 changed files with 45 additions and 34 deletions

24
Mk/Features/debug.mk Normal file
View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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}
. 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
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
. 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