You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
133 lines
5.0 KiB
133 lines
5.0 KiB
#!/bin/bash
|
|
# Copyright © Hisilicon Technologies Co., Ltd. 2020-2021. All rights reserved.
|
|
set -e
|
|
|
|
usage(){
|
|
echo
|
|
echo "USAGE"
|
|
echo " ./build.sh [-h] [-jjobs]"
|
|
echo "EXAMPLE"
|
|
echo " Please do source and lunch frist! Then ./build.sh -h or ./build.sh -j8"
|
|
exit 1
|
|
}
|
|
|
|
check_parameter(){
|
|
if [ -z "$TARGET_PRODUCT" ]; then usage;fi
|
|
if [ -n "$(echo "$1" | sed -n '/-h/p')" ];then usage;fi
|
|
}
|
|
|
|
set_parameter(){
|
|
command_args="$@"
|
|
|
|
if [ -z "$(echo "$command_args" | sed -n '/-j/p')" ];then command_args+=" -j$(nproc)";fi
|
|
|
|
build_variants=$(echo "$command_args" |awk -F ' ' '{for(i=1;i<=NF;i++){print $i;}}' |awk '/=/{print}')
|
|
for variant in $build_variants
|
|
do
|
|
echo "$variant"
|
|
declare -g $variant
|
|
done
|
|
}
|
|
|
|
clear_intermediates(){
|
|
INTERMEDIATES=$(get_build_var TARGET_OUT_INTERMEDIATES)
|
|
SUFFIX=$(echo $(get_build_var CHIP_REVISION) | tr a-z A-Z)
|
|
|
|
# rm kernel config and boot
|
|
if [ -f "$INTERMEDIATES/KERNEL_OBJ_$SUFFIX"/.config ]; then rm -rf "$INTERMEDIATES/KERNEL_OBJ_$SUFFIX"/.config; fi
|
|
if [ -d "$INTERMEDIATES/KERNEL_OBJ_$SUFFIX"/arch/arm64/boot ]; then rm -rf "$INTERMEDIATES/KERNEL_OBJ_$SUFFIX"/arch/arm64/boot; fi
|
|
if [ -d "$INTERMEDIATES/KERNEL_OBJ_$SUFFIX"/drivers ]; then find -L "$INTERMEDIATES/KERNEL_OBJ_$SUFFIX"/drivers -name "*.ko" |xargs rm -f; fi
|
|
# rm recovery config and boot
|
|
if [ -f "$INTERMEDIATES/RECOVERY_OBJ_$SUFFIX"/.config ]; then rm -rf "$INTERMEDIATES/RECOVERY_OBJ_$SUFFIX"/.config; fi
|
|
if [ -d "$INTERMEDIATES/RECOVERY_OBJ_$SUFFIX"/arch/arm64/boot ]; then rm -rf "$INTERMEDIATES/RECOVERY_OBJ_$SUFFIX"/arch/arm64/boot; fi
|
|
# rm bootloader bin
|
|
if [ -f "$INTERMEDIATES/EMMC_FIRSTBOOT_OBJ_$SUFFIX"/fastboot-burn.bin ]; then rm -rf "$INTERMEDIATES/EMMC_FIRSTBOOT_OBJ_$SUFFIX"/fastboot-burn.bin; fi
|
|
if [ -f "$INTERMEDIATES/EMMC_SECONDBOOT_OBJ_$SUFFIX"/sbl.bin ]; then rm -rf "$INTERMEDIATES/EMMC_SECONDBOOT_OBJ_$SUFFIX"/sbl.bin; fi
|
|
if [ -f "$INTERMEDIATES/EMMC_SLAVEBOOT_OBJ_$SUFFIX"/slaveboot-burn.bin ]; then rm -rf "$INTERMEDIATES/EMMC_SLAVEBOOT_OBJ_$SUFFIX"/slaveboot-burn.bin; fi
|
|
# rm preload dir
|
|
if [ -d "$PRODUCT_OUT"/preload ]; then rm -rf "$PRODUCT_OUT"/preload; fi
|
|
# rm bootargs bin
|
|
if [ -f "$PRODUCT_OUT"/bootargs.bin ]; then rm -rf "$PRODUCT_OUT"/bootargs.bin; fi
|
|
#clean bootloader build cache
|
|
if [ -n "$(echo "$command_args" | sed -n '/installclean/p')" ]; then
|
|
rm -rf $INTERMEDIATES/EMMC_FIRSTBOOT_OBJ* $INTERMEDIATES/EMMC_SECONDBOOT_OBJ* $INTERMEDIATES/EMMC_SLAVEBOOT_OBJ*
|
|
rm -rf $INTERMEDIATES/KERNEL_OBJ* $INTERMEDIATES/RECOVERY_OBJ* $INTERMEDIATES/SECURESIGN_OBJ
|
|
fi
|
|
}
|
|
|
|
__pre_process(){
|
|
check_parameter "$@"
|
|
set_parameter "$@"
|
|
|
|
# build env setup
|
|
if [ -n "$HUANGLONG_LINUX_ENV" ];then
|
|
source build/env.sh
|
|
else
|
|
source build/envsetup.sh;
|
|
fi
|
|
lunch $TARGET_PRODUCT-$TARGET_BUILD_VARIANT
|
|
if [ -f /usr/local/bin/bep_env.sh ];then
|
|
if [ "$BUILD_CURRENT_TIMESTAMP" == 'true' ];then sh /usr/local/bin/bep_env.sh -c vendor/huanglong/build/tools/bep_env.conf;fi
|
|
source /usr/local/bin/bep_env.sh -s vendor/huanglong/build/tools/bep_env.conf
|
|
fi
|
|
|
|
if [ -f "$PRODUCT_EXT_PATH"/build/extra_process.sh ] && [ -z "$(echo "$command_args" | sed -n '/installclean/p')" ]; then
|
|
source $PRODUCT_EXT_PATH/build/extra_process.sh;
|
|
pre_process "$@"
|
|
fi
|
|
|
|
# build var
|
|
PRODUCT_USE_DYNAMIC_PARTITIONS=$(get_build_var PRODUCT_USE_DYNAMIC_PARTITIONS)
|
|
PRODUCT_OUT=$(get_build_var PRODUCT_OUT)
|
|
IMAGES_OUT=$PRODUCT_OUT/images
|
|
|
|
SANITIZE_TARGET=$(get_build_var SANITIZE_TARGET)
|
|
# rm existed images
|
|
if [ -d "$IMAGES_OUT" ]; then rm -rf $IMAGES_OUT; fi
|
|
clear_intermediates
|
|
}
|
|
|
|
__do_make(){
|
|
if [ -z "$(echo "$command_args" | sed -n '/installclean/p')" ]; then make $command_args installclean; fi
|
|
make $command_args SANITIZE_TARGET=$SANITIZE_TARGET
|
|
}
|
|
|
|
copy_img(){
|
|
for i in $@
|
|
do
|
|
if [ -f "$PRODUCT_OUT"/"$i" ]; then cp $PRODUCT_OUT/$i $IMAGES_OUT/; fi
|
|
done
|
|
}
|
|
|
|
__post_process(){
|
|
mkdir -p $IMAGES_OUT
|
|
|
|
# copy aosp images
|
|
copy_img super.img cache.img userdata.img product.img vbmeta_system.img vbmeta_vendor.img
|
|
|
|
if [ -f "$PRODUCT_OUT"/"$TARGET_PRODUCT"-ota-*.zip ]; then cp $PRODUCT_OUT/$TARGET_PRODUCT-ota-*.zip $IMAGES_OUT/update.zip; fi
|
|
|
|
if [ -f "$PRODUCT_EXT_PATH"/build/extra_process.sh ] && [ -z "$(echo "$command_args" | sed -n '/installclean/p')" ] && [[ "$TVOS_VERSION" != "TVOS-H" ]] && [[ "$TVOS_PLATFORM" != "tvos-o" ]]; then
|
|
post_process;
|
|
fi
|
|
}
|
|
|
|
build(){
|
|
start_time=$(date +%s)
|
|
echo "begin to build"
|
|
__pre_process "$@"
|
|
__do_make
|
|
__post_process
|
|
end_time=$(date +%s)
|
|
echo "build complete in $(expr $end_time - $start_time)s"
|
|
}
|
|
|
|
main(){
|
|
local result=0
|
|
if [ "$(ls $PWD/build_*.log 2> /dev/null | wc -l)" -ne 0 ]; then rm $(pwd)/build_*.log; fi
|
|
build "$@" 2>&1 | tee -p build_$(date '+%Y%m%d-%H%M%S').log
|
|
result=${PIPESTATUS[0]}
|
|
if [ $result -ne 0 ];then exit $result; fi
|
|
}
|
|
main "$@"
|