diff --git a/scripts/libmakepkg/buildenv.sh.in b/scripts/libmakepkg/buildenv.sh.in index a5847777..ff7ea2a4 100644 --- a/scripts/libmakepkg/buildenv.sh.in +++ b/scripts/libmakepkg/buildenv.sh.in @@ -3,7 +3,7 @@ # buildenv.sh - functions for altering the build environment before # compilation # -# Copyright (c) 2015-2022 Pacman Development Team +# Copyright (c) 2015-2024 Pacman Development Team # # 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 @@ -24,8 +24,9 @@ LIBMAKEPKG_BUILDENV_SH=1 MAKEPKG_LIBRARY=${MAKEPKG_LIBRARY:-'@libmakepkgdir@'} -declare -a buildenv_functions build_options -buildenv_vars=('CPPFLAGS' 'CFLAGS' 'CXXFLAGS' 'LDFLAGS' 'MAKEFLAGS' 'CHOST') +declare -a buildenv_functions buildenv_vars build_options +buildenv_vars_exported=('LDFLAGS' 'MAKEFLAGS' 'CHOST') +build_options+=('buildflags') for lib in "$MAKEPKG_LIBRARY/buildenv/"*.sh; do source "$lib" @@ -33,14 +34,28 @@ done 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() { - # ensure this function runs first - buildenv_buildflags + if check_option "buildflags" "n"; then + unset ${buildenv_vars_exported[@]} + fi for func in ${buildenv_functions[@]}; do $func done # ensure all necessary build variables are exported - export ${buildenv_vars[@]} + export ${buildenv_vars_exported[@]} } diff --git a/scripts/libmakepkg/buildenv/debugflags.sh.in b/scripts/libmakepkg/buildenv/c.sh.in similarity index 54% rename from scripts/libmakepkg/buildenv/debugflags.sh.in rename to scripts/libmakepkg/buildenv/c.sh.in index 22a79281..46adc9a4 100644 --- a/scripts/libmakepkg/buildenv/debugflags.sh.in +++ b/scripts/libmakepkg/buildenv/c.sh.in @@ -1,9 +1,8 @@ #!/usr/bin/bash # -# debugflags.sh - Specify flags for building a package with debugging -# symbols +# c.sh - Specify flags for building a package with C # -# Copyright (c) 2012-2022 Pacman Development Team +# Copyright (c) 2024 Pacman Development Team # # 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 @@ -19,21 +18,18 @@ # along with this program. If not, see . # -[[ -n "$LIBMAKEPKG_BUILDENV_DEBUGFLAGS_SH" ]] && return -LIBMAKEPKG_BUILDENV_DEBUGFLAGS_SH=1 +[[ -n "$LIBMAKEPKG_BUILDENV_C_SH" ]] && return +LIBMAKEPKG_BUILDENV_C_SH=1 MAKEPKG_LIBRARY=${MAKEPKG_LIBRARY:-'@libmakepkgdir@'} source "$MAKEPKG_LIBRARY/util/option.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() { - if check_option "debug" "y" && ! check_option "buildflags" "n"; then - 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 +buildenv_c() { + check_append_debug_flags CFLAGS DEBUG_CFLAGS "-ffile-prefix-map=$srcdir=${DBGSRCDIR:-/usr/src/debug}/${pkgbase}" } diff --git a/scripts/libmakepkg/buildenv/buildflags.sh.in b/scripts/libmakepkg/buildenv/cpp.sh.in similarity index 67% rename from scripts/libmakepkg/buildenv/buildflags.sh.in rename to scripts/libmakepkg/buildenv/cpp.sh.in index 60774051..f9622f56 100644 --- a/scripts/libmakepkg/buildenv/buildflags.sh.in +++ b/scripts/libmakepkg/buildenv/cpp.sh.in @@ -1,8 +1,8 @@ #!/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 +# Copyright (c) 2024 Pacman Development Team # # 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 @@ -18,17 +18,13 @@ # along with this program. If not, see . # -[[ -n "$LIBMAKEPKG_BUILDENV_BUILDFLAGS_SH" ]] && return -LIBMAKEPKG_BUILDENV_BUILDFLAGS_SH=1 +[[ -n "$LIBMAKEPKG_BUILDENV_CPP_SH" ]] && return +LIBMAKEPKG_BUILDENV_CPP_SH=1 MAKEPKG_LIBRARY=${MAKEPKG_LIBRARY:-'@libmakepkgdir@'} source "$MAKEPKG_LIBRARY/util/option.sh" +source "$MAKEPKG_LIBRARY/util/util.sh" -build_options+=('buildflags') - -buildenv_buildflags() { - if check_option "buildflags" "n"; then - unset ${buildenv_vars[@]} - fi -} +buildenv_vars_exported+=('CPPFLAGS') +buildenv_functions+=('buildenv_rust') diff --git a/scripts/libmakepkg/buildenv/cxx.sh.in b/scripts/libmakepkg/buildenv/cxx.sh.in new file mode 100644 index 00000000..65974d1f --- /dev/null +++ b/scripts/libmakepkg/buildenv/cxx.sh.in @@ -0,0 +1,35 @@ +#!/usr/bin/bash +# +# cxx.sh - Specify flags for building a package with C++ +# +# Copyright (c) 2024 Pacman Development Team +# +# 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 . +# + +[[ -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}" +} diff --git a/scripts/libmakepkg/buildenv/meson.build b/scripts/libmakepkg/buildenv/meson.build index 4c289ac1..d782c33a 100644 --- a/scripts/libmakepkg/buildenv/meson.build +++ b/scripts/libmakepkg/buildenv/meson.build @@ -1,9 +1,10 @@ libmakepkg_module = 'buildenv' sources = [ - 'buildflags.sh.in', + 'c.sh.in', 'compiler.sh.in', - 'debugflags.sh.in', + 'cpp.sh.in', + 'cxx.sh.in', 'lto.sh.in', 'makeflags.sh.in', 'rust.sh.in', diff --git a/scripts/libmakepkg/buildenv/rust.sh.in b/scripts/libmakepkg/buildenv/rust.sh.in index 93114dcd..d3d90fef 100644 --- a/scripts/libmakepkg/buildenv/rust.sh.in +++ b/scripts/libmakepkg/buildenv/rust.sh.in @@ -2,7 +2,7 @@ # # rust.sh - Specify flags for building a package with rust # -# Copyright (c) 2022 Pacman Development Team +# Copyright (c) 2022-2024 Pacman Development Team # # 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 @@ -26,12 +26,10 @@ MAKEPKG_LIBRARY=${MAKEPKG_LIBRARY:-'@libmakepkgdir@'} source "$MAKEPKG_LIBRARY/util/option.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_rust() { - if check_option "debug" "y" && ! check_option "buildflags" "n"; then - append_once DEBUG_RUSTFLAGS "--remap-path-prefix=$srcdir=${DBGSRCDIR:-/usr/src/debug}/${pkgbase}" - append_once RUSTFLAGS "$DEBUG_RUSTFLAGS" - fi -} \ No newline at end of file + check_append_debug_flags RUSTFLAGS DEBUG_RUSTFLAGS "--remap-path-prefix=$srcdir=${DBGSRCDIR:-/usr/src/debug}/${pkgbase}" +} diff --git a/scripts/libmakepkg/lint_config/variable.sh.in b/scripts/libmakepkg/lint_config/variable.sh.in index 664230f9..db88618f 100644 --- a/scripts/libmakepkg/lint_config/variable.sh.in +++ b/scripts/libmakepkg/lint_config/variable.sh.in @@ -2,7 +2,7 @@ # # variable.sh - Check that variables are or are not arrays as appropriate # -# Copyright (c) 2018-2022 Pacman Development Team +# Copyright (c) 2018-2024 Pacman Development Team # # 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 @@ -24,6 +24,7 @@ LIBMAKEPKG_LINT_CONFIG_VARIABLE_SH=1 MAKEPKG_LIBRARY=${MAKEPKG_LIBRARY:-'@libmakepkgdir@'} source "$MAKEPKG_LIBRARY/util/message.sh" +source "$MAKEPKG_LIBRARY/buildenv.sh" lint_config_functions+=('lint_config_variables') @@ -32,10 +33,10 @@ lint_config_variables() { local array=(DLAGENTS VCSCLIENTS BUILDENV OPTIONS INTEGRITY_CHECK MAN_DIRS DOC_DIRS PURGE_TARGETS COMPRESSGZ COMPRESSBZ2 COMPRESSXZ COMPRESSLRZ COMPRESSLZO COMPRESSZ) - local string=(CARCH CHOST CPPFLAGS CFLAGS CXXFLAGS LDFLAGS LTOFLAGS DEBUG_CFLAGS - DEBUG_CXXFLAGS DISTCC_HOSTS BUILDDIR STRIP_BINARIES STRIP_SHARED - STRIP_STATIC PKGDEST SRCDEST SRCPKGDEST LOGDEST PACKAGER GPGKEY - PKGEXT SRCEXT) + local string=(CARCH CHOST LDFLAGS LTOFLAGS DISTCC_HOSTS BUILDDIR + STRIP_BINARIES STRIP_SHARED STRIP_STATIC PKGDEST SRCDEST + SRCPKGDEST LOGDEST PACKAGER GPGKEY PKGEXT SRCEXT + ${buildenv_vars[@]} ${buildenv_vars_exported[@]}) local i keys ret=0