Skip to content

Commit

Permalink
meson.eclass: add _meson_move_flags function
Browse files Browse the repository at this point in the history
This is used to move flags from CC to CFLAGS, typically during a
multilib build.
  • Loading branch information
floppym committed May 24, 2018
1 parent 6b0847e commit 0fe5492
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions eclass/meson.eclass
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,25 @@ meson_use() {
usex "$1" "-D${2-$1}=true" "-D${2-$1}=false"
}

# @FUNCTION: _meson_move_flags
# @INTERNAL
# @USAGE: PROG FLAGS
# @DESCRIPTION:
# Moves extra arguments from PROG to FLAGS.
# For example:
# CC="gcc -m32" -> CC="gcc" CFLAGS="-m32"
_meson_move_flags() {
local prog=${1}
local flags=${2}
local x=( ${!prog} )
if [[ -n ${x[0]} ]]; then
export ${prog}=${x[0]}
fi
if [[ -n ${x[1]} ]]; then
export ${flags}="${x[@]:1}${!flags:+ }${!flags}"
fi
}

# @FUNCTION: meson_src_configure
# @DESCRIPTION:
# This is the meson_src_configure function.
Expand All @@ -214,6 +233,18 @@ meson_src_configure() {
--wrap-mode nodownload
)

# Prevent multilib flags from leaking across ABIs
local -x BUILD_CFLAGS=${BUILD_CFLAGS}
local -x BUILD_CXXFLAGS=${BUILD_CXXFLAGS}

# Move multilib flags from CC to CFLAGS
local -x CC=$(tc-getCC) CFLAGS=${CFLAGS}
_meson_move_flags CC CFLAGS

# Move multilib flags from CXX to CXXFLAGS
local -x CXX=$(tc-getCXX) CXXFLAGS=${CXXFLAGS}
_meson_move_flags CXX CXXFLAGS

if tc-is-cross-compiler; then
_meson_create_cross_file || die "unable to write meson cross file"
mesonargs+=( --cross-file "${T}/meson.${CHOST}" )
Expand Down

0 comments on commit 0fe5492

Please sign in to comment.