mirror of
https://github.com/LibreELEC/LibreELEC.tv
synced 2025-09-24 19:46:01 +07:00
buildsystem: add BUILD_FLAG support
- replace strip_lto/strip_gold (only allowed to disable) - add flag for PIC feature - add flag to stop build parallel - add support for hardening option (initial copy from debian 9) All build parameters, are added in setup_toolchain. `PKG_[FLAG]_[HOST/TARGET]_ENABLED` variable is introduced for checking the flag (yes/no) in the package.mk Thanks to @MilhouseVH, for support and fixing
This commit is contained in:
@@ -1,4 +1,44 @@
|
||||
setup_toolchain() {
|
||||
# lto flag
|
||||
if flag_enabled "lto" "$LTO_SUPPORT" "only-disable"; then
|
||||
export TARGET_CFLAGS+=" $CFLAGS_OPTIM_LTO"
|
||||
export TARGET_CXXFLAGS+=" $CXXFLAGS_OPTIM_LTO"
|
||||
export TARGET_LDFLAGS+=" $LDFLAGS_OPTIM_LTO"
|
||||
fi
|
||||
|
||||
# gold flag
|
||||
if flag_enabled "gold" "$GOLD_SUPPORT" "only-disable"; then
|
||||
export TARGET_LDFLAGS+=" $LDFLAGS_OPTIM_GOLD"
|
||||
fi
|
||||
|
||||
# position-independent code
|
||||
if flag_enabled "pic" "no"; then
|
||||
export TARGET_CFLAGS+=" $CFLAGS_OPTIM_PIC"
|
||||
export TARGET_CXXFLAGS+=" $CXXFLAGS_OPTIM_PIC"
|
||||
export TARGET_LDFLAGS+=" $LDFLAGS_OPTIM_PIC"
|
||||
fi
|
||||
if flag_enabled "pic:host" "no"; then
|
||||
export HOST_CFLAGS+=" $CFLAGS_OPTIM_PIC"
|
||||
export HOST_CXXFLAGS+=" $CXXFLAGS_OPTIM_PIC"
|
||||
export HOST_LDFLAGS+=" $LDFLAGS_OPTIM_PIC"
|
||||
fi
|
||||
|
||||
# hardening support
|
||||
if flag_enabled "hardening" "$HARDENING_SUPPORT"; then
|
||||
export TARGET_CFLAGS+=" $CFLAGS_OPTIM_HARDENING"
|
||||
export TARGET_CXXFLAGS+=" $CXXFLAGS_OPTIM_HARDENING"
|
||||
export TARGET_CFLAGS+=" $CPPFLAGS_OPTIM_HARDENING"
|
||||
export TARGET_LDFLAGS+=" $LDFLAGS_OPTIM_HARDENING"
|
||||
fi
|
||||
|
||||
# parallel
|
||||
if ! flag_enabled "parallel" "yes"; then
|
||||
NINJA_OPTS="$NINJA_OPTS -j1"
|
||||
export MAKEFLAGS="-j1"
|
||||
else
|
||||
export MAKEFLAGS="-j$CONCURRENCY_MAKE_LEVEL"
|
||||
fi
|
||||
|
||||
case "$1" in
|
||||
target|init)
|
||||
export DESTIMAGE="target"
|
||||
@@ -318,6 +358,37 @@ listremoveitem() {
|
||||
echo "${tmp_array[@]}"
|
||||
}
|
||||
|
||||
# check if a flag is enabled
|
||||
# $1: flag-name, $2: default (yes/no), $3: ingenious check (none,only-disable,only-enable)
|
||||
# set variable PKG_[FLAG]_[HOST/TARGET]_ENABLED=(yes/no)
|
||||
# return 0 if flag is enabled, otherwise 1
|
||||
flag_enabled() {
|
||||
# make flag name upper case and replace hyphen with underscore, to use as variable name
|
||||
local flag_name=${1^^}
|
||||
[[ $flag_name =~ : ]] || flag_name+="_TARGET"
|
||||
flag_name="PKG_${flag_name//[:-]/_}_ENABLED"
|
||||
|
||||
# check flag
|
||||
if [ -n "${PKG_BUILD_FLAGS}" ] && listcontains "${PKG_BUILD_FLAGS}" "[+]?$1"; then
|
||||
if [ "${3:none}" = "only-disable" ]; then
|
||||
echo "ERROR: $1 can not enable via PKG_BUILD_FLAGS (found in $PKG_NAME)"
|
||||
exit 1
|
||||
fi
|
||||
declare ${flag_name}="yes"
|
||||
return 0
|
||||
elif [ "$2" = "yes" ] && ! listcontains "${PKG_BUILD_FLAGS}" "-$1"; then
|
||||
declare ${flag_name}="yes"
|
||||
return 0
|
||||
else
|
||||
if [ "${3:none}" = "only-enable" ]; then
|
||||
echo "ERROR: $1 can not disable via PKG_BUILD_FLAGS (found in $PKG_NAME)"
|
||||
exit 1
|
||||
fi
|
||||
declare ${flag_name}="no"
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
target_has_feature() {
|
||||
listcontains "$TARGET_FEATURES" "$1"
|
||||
}
|
||||
@@ -662,26 +733,6 @@ do_autoreconf() {
|
||||
fi
|
||||
}
|
||||
|
||||
strip_lto() {
|
||||
# strip out LTO optimization from *FLAGS
|
||||
if [ -n "$GCC_OPTIM_LTO" ] ; then
|
||||
CFLAGS=`echo $CFLAGS | sed -e "s|$GCC_OPTIM_LTO||g"`
|
||||
CXXFLAGS=`echo $CXXFLAGS | sed -e "s|$GCC_OPTIM_LTO||g"`
|
||||
TARGET_CFLAGS=`echo $TARGET_CFLAGS | sed -e "s|$GCC_OPTIM_LTO||g"`
|
||||
TARGET_CXXFLAGS=`echo $TARGET_CXXFLAGS | sed -e "s|$GCC_OPTIM_LTO||g"`
|
||||
fi
|
||||
if [ -n "$LD_OPTIM_LTO" ] ; then
|
||||
LDFLAGS=`echo $LDFLAGS | sed -e "s|$LD_OPTIM_LTO||g"`
|
||||
TARGET_LDFLAGS=`echo $TARGET_LDFLAGS | sed -e "s|$LD_OPTIM_LTO||g"`
|
||||
fi
|
||||
}
|
||||
|
||||
strip_gold() {
|
||||
# strip out usage from GOLD linker
|
||||
LDFLAGS=`echo $LDFLAGS | sed -e "s|-fuse-ld=gold||g"`
|
||||
TARGET_LDFLAGS=`echo $TARGET_LDFLAGS | sed -e "s|-fuse-ld=gold||g"`
|
||||
}
|
||||
|
||||
fix_module_depends() {
|
||||
# modify .modinfo section in kernel module to depends on other required modules
|
||||
local MODULE="$1"
|
||||
|
||||
Reference in New Issue
Block a user