Merge branch 'build_flags_WIP' into 'master'

Draft: Build flags

See merge request pacman/pacman!116
This commit is contained in:
loqs 2024-02-20 19:51:27 +00:00
commit 283ac6e5da
7 changed files with 86 additions and 44 deletions

View file

@ -3,7 +3,7 @@
# buildenv.sh - functions for altering the build environment before # buildenv.sh - functions for altering the build environment before
# compilation # compilation
# #
# Copyright (c) 2015-2022 Pacman Development Team <pacman-dev@lists.archlinux.org> # Copyright (c) 2015-2024 Pacman Development Team <pacman-dev@lists.archlinux.org>
# #
# This program is free software; you can redistribute it and/or modify # This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by # it under the terms of the GNU General Public License as published by
@ -24,8 +24,9 @@ LIBMAKEPKG_BUILDENV_SH=1
MAKEPKG_LIBRARY=${MAKEPKG_LIBRARY:-'@libmakepkgdir@'} MAKEPKG_LIBRARY=${MAKEPKG_LIBRARY:-'@libmakepkgdir@'}
declare -a buildenv_functions build_options declare -a buildenv_functions buildenv_vars build_options
buildenv_vars=('CPPFLAGS' 'CFLAGS' 'CXXFLAGS' 'LDFLAGS' 'MAKEFLAGS' 'CHOST') buildenv_vars_exported=('LDFLAGS' 'MAKEFLAGS' 'CHOST')
build_options+=('buildflags')
for lib in "$MAKEPKG_LIBRARY/buildenv/"*.sh; do for lib in "$MAKEPKG_LIBRARY/buildenv/"*.sh; do
source "$lib" source "$lib"
@ -33,14 +34,28 @@ done
readonly -a buildenv_functions buildenv_vars build_options readonly -a buildenv_functions buildenv_vars build_options
check_append_debug_flags() {
local -n flag=$1
local -n debug_flag=$2
if check_option "debug" "y" && ! check_option "buildflags" "n"; then
if [[ $# -gt 1 ]]; then
local debug_extra=$3
append_once debug_flag "$debug_extra"
fi
append_once flag "$debug_flag"
fi
}
prepare_buildenv() { prepare_buildenv() {
# ensure this function runs first if check_option "buildflags" "n"; then
buildenv_buildflags unset ${buildenv_vars_exported[@]}
fi
for func in ${buildenv_functions[@]}; do for func in ${buildenv_functions[@]}; do
$func $func
done done
# ensure all necessary build variables are exported # ensure all necessary build variables are exported
export ${buildenv_vars[@]} export ${buildenv_vars_exported[@]}
} }

View file

@ -1,9 +1,8 @@
#!/usr/bin/bash #!/usr/bin/bash
# #
# debugflags.sh - Specify flags for building a package with debugging # c.sh - Specify flags for building a package with C
# symbols
# #
# Copyright (c) 2012-2022 Pacman Development Team <pacman-dev@lists.archlinux.org> # Copyright (c) 2024 Pacman Development Team <pacman-dev@lists.archlinux.org>
# #
# This program is free software; you can redistribute it and/or modify # This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by # it under the terms of the GNU General Public License as published by
@ -19,21 +18,18 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
# #
[[ -n "$LIBMAKEPKG_BUILDENV_DEBUGFLAGS_SH" ]] && return [[ -n "$LIBMAKEPKG_BUILDENV_C_SH" ]] && return
LIBMAKEPKG_BUILDENV_DEBUGFLAGS_SH=1 LIBMAKEPKG_BUILDENV_C_SH=1
MAKEPKG_LIBRARY=${MAKEPKG_LIBRARY:-'@libmakepkgdir@'} MAKEPKG_LIBRARY=${MAKEPKG_LIBRARY:-'@libmakepkgdir@'}
source "$MAKEPKG_LIBRARY/util/option.sh" source "$MAKEPKG_LIBRARY/util/option.sh"
source "$MAKEPKG_LIBRARY/util/util.sh" source "$MAKEPKG_LIBRARY/util/util.sh"
buildenv_functions+=('buildenv_debugflags') buildenv_vars+=('DEBUG_CFLAGS')
buildenv_vars_exported+=('CFLAGS')
buildenv_functions+=('buildenv_c')
buildenv_debugflags() { buildenv_c() {
if check_option "debug" "y" && ! check_option "buildflags" "n"; then check_append_debug_flags CFLAGS DEBUG_CFLAGS "-ffile-prefix-map=$srcdir=${DBGSRCDIR:-/usr/src/debug}/${pkgbase}"
append_once DEBUG_CFLAGS "-ffile-prefix-map=$srcdir=${DBGSRCDIR:-/usr/src/debug}/${pkgbase}"
append_once DEBUG_CXXFLAGS "-ffile-prefix-map=$srcdir=${DBGSRCDIR:-/usr/src/debug}/${pkgbase}"
append_once CFLAGS "$DEBUG_CFLAGS"
append_once CXXFLAGS "$DEBUG_CXXFLAGS"
fi
} }

View file

@ -1,8 +1,8 @@
#!/usr/bin/bash #!/usr/bin/bash
# #
# buildflags.sh - Clear user-specified buildflags if requested # rust.sh - Specify flags for building a package with rust
# #
# Copyright (c) 2011-2022 Pacman Development Team <pacman-dev@lists.archlinux.org> # Copyright (c) 2024 Pacman Development Team <pacman-dev@lists.archlinux.org>
# #
# This program is free software; you can redistribute it and/or modify # This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by # it under the terms of the GNU General Public License as published by
@ -18,17 +18,13 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
# #
[[ -n "$LIBMAKEPKG_BUILDENV_BUILDFLAGS_SH" ]] && return [[ -n "$LIBMAKEPKG_BUILDENV_CPP_SH" ]] && return
LIBMAKEPKG_BUILDENV_BUILDFLAGS_SH=1 LIBMAKEPKG_BUILDENV_CPP_SH=1
MAKEPKG_LIBRARY=${MAKEPKG_LIBRARY:-'@libmakepkgdir@'} MAKEPKG_LIBRARY=${MAKEPKG_LIBRARY:-'@libmakepkgdir@'}
source "$MAKEPKG_LIBRARY/util/option.sh" source "$MAKEPKG_LIBRARY/util/option.sh"
source "$MAKEPKG_LIBRARY/util/util.sh"
build_options+=('buildflags') buildenv_vars_exported+=('CPPFLAGS')
buildenv_functions+=('buildenv_rust')
buildenv_buildflags() {
if check_option "buildflags" "n"; then
unset ${buildenv_vars[@]}
fi
}

View file

@ -0,0 +1,35 @@
#!/usr/bin/bash
#
# cxx.sh - Specify flags for building a package with C++
#
# Copyright (c) 2024 Pacman Development Team <pacman-dev@lists.archlinux.org>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
[[ -n "$LIBMAKEPKG_BUILDENV_CXX_SH" ]] && return
LIBMAKEPKG_BUILDENV_CXX_SH=1
MAKEPKG_LIBRARY=${MAKEPKG_LIBRARY:-'@libmakepkgdir@'}
source "$MAKEPKG_LIBRARY/util/option.sh"
source "$MAKEPKG_LIBRARY/util/util.sh"
buildenv_vars+=('DEBUG_CXXFLAGS')
buildenv_vars_exported+=('CXXFLAGS')
buildenv_functions+=('buildenv_cxx')
buildenv_cxx() {
check_append_debug_flags CXXFLAGS DEBUG_CXXFLAGS "-ffile-prefix-map=$srcdir=${DBGSRCDIR:-/usr/src/debug}/${pkgbase}"
}

View file

@ -1,9 +1,10 @@
libmakepkg_module = 'buildenv' libmakepkg_module = 'buildenv'
sources = [ sources = [
'buildflags.sh.in', 'c.sh.in',
'compiler.sh.in', 'compiler.sh.in',
'debugflags.sh.in', 'cpp.sh.in',
'cxx.sh.in',
'lto.sh.in', 'lto.sh.in',
'makeflags.sh.in', 'makeflags.sh.in',
'rust.sh.in', 'rust.sh.in',

View file

@ -2,7 +2,7 @@
# #
# rust.sh - Specify flags for building a package with rust # rust.sh - Specify flags for building a package with rust
# #
# Copyright (c) 2022 Pacman Development Team <pacman-dev@lists.archlinux.org> # Copyright (c) 2022-2024 Pacman Development Team <pacman-dev@lists.archlinux.org>
# #
# This program is free software; you can redistribute it and/or modify # This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by # it under the terms of the GNU General Public License as published by
@ -26,12 +26,10 @@ MAKEPKG_LIBRARY=${MAKEPKG_LIBRARY:-'@libmakepkgdir@'}
source "$MAKEPKG_LIBRARY/util/option.sh" source "$MAKEPKG_LIBRARY/util/option.sh"
source "$MAKEPKG_LIBRARY/util/util.sh" source "$MAKEPKG_LIBRARY/util/util.sh"
buildenv_vars+=('RUSTFLAGS' 'DEBUG_RUSTFLAGS') buildenv_vars+=('DEBUG_RUSTFLAGS')
buildenv_vars_exported+=('RUSTFLAGS')
buildenv_functions+=('buildenv_rust') buildenv_functions+=('buildenv_rust')
buildenv_rust() { buildenv_rust() {
if check_option "debug" "y" && ! check_option "buildflags" "n"; then check_append_debug_flags RUSTFLAGS DEBUG_RUSTFLAGS "--remap-path-prefix=$srcdir=${DBGSRCDIR:-/usr/src/debug}/${pkgbase}"
append_once DEBUG_RUSTFLAGS "--remap-path-prefix=$srcdir=${DBGSRCDIR:-/usr/src/debug}/${pkgbase}"
append_once RUSTFLAGS "$DEBUG_RUSTFLAGS"
fi
} }

View file

@ -2,7 +2,7 @@
# #
# variable.sh - Check that variables are or are not arrays as appropriate # variable.sh - Check that variables are or are not arrays as appropriate
# #
# Copyright (c) 2018-2022 Pacman Development Team <pacman-dev@lists.archlinux.org> # Copyright (c) 2018-2024 Pacman Development Team <pacman-dev@lists.archlinux.org>
# #
# This program is free software; you can redistribute it and/or modify # This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by # it under the terms of the GNU General Public License as published by
@ -24,6 +24,7 @@ LIBMAKEPKG_LINT_CONFIG_VARIABLE_SH=1
MAKEPKG_LIBRARY=${MAKEPKG_LIBRARY:-'@libmakepkgdir@'} MAKEPKG_LIBRARY=${MAKEPKG_LIBRARY:-'@libmakepkgdir@'}
source "$MAKEPKG_LIBRARY/util/message.sh" source "$MAKEPKG_LIBRARY/util/message.sh"
source "$MAKEPKG_LIBRARY/buildenv.sh"
lint_config_functions+=('lint_config_variables') lint_config_functions+=('lint_config_variables')
@ -32,10 +33,10 @@ lint_config_variables() {
local array=(DLAGENTS VCSCLIENTS BUILDENV OPTIONS INTEGRITY_CHECK MAN_DIRS local array=(DLAGENTS VCSCLIENTS BUILDENV OPTIONS INTEGRITY_CHECK MAN_DIRS
DOC_DIRS PURGE_TARGETS COMPRESSGZ COMPRESSBZ2 COMPRESSXZ DOC_DIRS PURGE_TARGETS COMPRESSGZ COMPRESSBZ2 COMPRESSXZ
COMPRESSLRZ COMPRESSLZO COMPRESSZ) COMPRESSLRZ COMPRESSLZO COMPRESSZ)
local string=(CARCH CHOST CPPFLAGS CFLAGS CXXFLAGS LDFLAGS LTOFLAGS DEBUG_CFLAGS local string=(CARCH CHOST LDFLAGS LTOFLAGS DISTCC_HOSTS BUILDDIR
DEBUG_CXXFLAGS DISTCC_HOSTS BUILDDIR STRIP_BINARIES STRIP_SHARED STRIP_BINARIES STRIP_SHARED STRIP_STATIC PKGDEST SRCDEST
STRIP_STATIC PKGDEST SRCDEST SRCPKGDEST LOGDEST PACKAGER GPGKEY SRCPKGDEST LOGDEST PACKAGER GPGKEY PKGEXT SRCEXT
PKGEXT SRCEXT) ${buildenv_vars[@]} ${buildenv_vars_exported[@]})
local i keys ret=0 local i keys ret=0