vp-build/common/build-style/meson.sh
maxice8 6580c8d657
build_style/meson.sh: export CFLAGS and CXXFLAGS from host
meson when compiling something with 'native: true' (for building
executables that are meant to be run on the host system) uses CFLAGS
and CXXFLAGS environment variables, we "pollute" them with
TARGET system cflags/cxxflags, such as -march= for the cross-compiled
arch.

so to fix it we export CFLAGS and CXXFLAGS to be CFLAGS_host and
CXXFLAGS_host respectively, they are set by XBPS and correspond to
the XBPS_CFLAGS/XBPS_CXXFLAGS. This same set of changes is also done
with CC and CXX see L#61

this was found when cross-compiling lighttpd which created the
'lemon' executable to generate inputs

thanks to @Cogitri from Exherbo for helping me debug this

[ci skip]
2018-08-16 01:49:38 -03:00

97 lines
2.5 KiB
Bash

#
# This helper is for templates using meson.
#
do_configure() {
: ${meson_cmd:=meson}
: ${meson_builddir:=build}
: ${meson_crossfile:=xbps_meson.cross}
if [ "$CROSS_BUILD" ]; then
_MESON_TARGET_ENDIAN=little
# drop the -musl suffix to the target cpu, meson doesn't recognize it
_MESON_TARGET_CPU=${XBPS_TARGET_MACHINE/-musl/}
case "$XBPS_TARGET_MACHINE" in
mips|mips-musl|mipshf-musl)
_MESON_TARGET_ENDIAN=big
_MESON_CPU_FAMILY=mips
;;
armv*)
_MESON_CPU_FAMILY=arm
;;
i686*)
_MESON_CPU_FAMILY=x86
;;
*)
# if we reached here that means that the cpu and cpu_family
# are the same like 'x86_64' and 'aarch64'
_MESON_CPU_FAMILY=${_MESON_TARGET_CPU}
;;
esac
# Record cross-compiling information in cross file.
# CFLAGS and LDFLAGS must be set as c_args and c_link_args.
cat > ${meson_crossfile} <<EOF
[binaries]
c = '${CC}'
cpp = '${CXX}'
ar = '${AR}'
ld = '${LD}'
strip = '${STRIP}'
readelf = '${READELF}'
pkgconfig = 'pkg-config'
[properties]
needs_exe_wrapper = true
c_args = ['$(echo ${CFLAGS} | sed -r "s/\s+/','/g")']
c_link_args = ['$(echo ${LDFLAGS} | sed -r "s/\s+/','/g")']
cpp_args = ['$(echo ${CXXFLAGS} | sed -r "s/\s+/','/g")']
cpp_link_args = ['$(echo ${LDFLAGS} | sed -r "s/\s+/','/g")']
[host_machine]
system = 'linux'
cpu_family = '${_MESON_CPU_FAMILY}'
cpu = '${_MESON_TARGET_CPU}'
endian = '${_MESON_TARGET_ENDIAN}'
EOF
configure_args+=" --cross-file=${meson_crossfile}"
# Meson tries to compile natively with CC, CXX, so when cross
# compiling, we need to set those to the host versions.
export CC=${CC_host} CXX=${CXX_host}
# Meson tries to use CFLAGS and CPPFLAGS when compiling under
# native: true, so we use XBPS_CFLAGS and XBPS_CPPFLAGS which
# are set to (C|CXX)FLAGS_host
export CFLAGS=${CFLAGS_host} CXXFLAGS=${CXXFLAGS_host}
unset _MESON_TARGET_CPU _MESON_TARGET_ENDIAN
fi
${meson_cmd} --prefix=/usr --buildtype=plain ${configure_args} . ${meson_builddir}
}
do_build() {
: ${make_cmd:=ninja}
: ${make_build_target:=all}
: ${meson_builddir:=build}
${make_cmd} -C ${meson_builddir} ${makejobs} ${make_build_args} ${make_build_target}
}
do_check() {
: ${make_cmd:=ninja}
: ${make_check_target:=test}
: ${meson_builddir:=build}
${make_cmd} -C ${meson_builddir} ${makejobs} ${make_check_args} ${make_check_target}
}
do_install() {
: ${make_cmd:=ninja}
: ${make_install_target:=install}
: ${meson_builddir:=build}
DESTDIR=${DESTDIR} ${make_cmd} -C ${meson_builddir} ${make_install_args} ${make_install_target}
}