#!/bin/sh -e
[ -z "$DEBUG" ] || set -x
echo "########## toolchain: staging install ##########"
cd /home/ych/rk3568/buildroot
cd /home/ych/rk3568/buildroot
mkdir -p /home/ych/rk3568/buildroot/output/rockchip_rk3568/host/share/buildroot
sed -e 's#@@STAGING_SUBDIR@@#aarch64-buildroot-linux-gnu/sysroot#' -e 's#@@RELOCATED_HOST_DIR@@#${CMAKE_CURRENT_LIST_DIR}#' -e 's#@@TARGET_CFLAGS@@#-D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -Os -g0 -D_FORTIFY_SOURCE=1#' -e 's#@@TARGET_CXXFLAGS@@#-D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -Os -g0 -D_FORTIFY_SOURCE=1#' -e 's#@@TARGET_FCFLAGS@@#-Os -g0#' -e 's#@@TARGET_LDFLAGS@@##' -e 's#@@TARGET_CC@@#bin/aarch64-buildroot-linux-gnu-gcc#' -e 's#@@TARGET_CXX@@#bin/aarch64-buildroot-linux-gnu-g++#' -e 's#@@TARGET_CC@@#bin/aarch64-buildroot-linux-gnu-gcc#' -e 's#@@TARGET_CXX@@#bin/aarch64-buildroot-linux-gnu-g++#' -e 's#@@TARGET_AR@@#bin/aarch64-buildroot-linux-gnu-ar#' -e 's#@@TARGET_AS@@#bin/aarch64-buildroot-linux-gnu-as#' -e 's#@@TARGET_LD@@#bin/aarch64-buildroot-linux-gnu-ld#' -e 's#@@TARGET_NM@@#bin/aarch64-buildroot-linux-gnu-nm#' -e 's#@@TARGET_RANLIB@@#bin/aarch64-buildroot-linux-gnu-ranlib#' -e 's#@@TARGET_READELF@@#bin/aarch64-buildroot-linux-gnu-readelf#' -e 's#@@TARGET_OBJCOPY@@#bin/aarch64-buildroot-linux-gnu-objcopy#' -e 's#@@TARGET_OBJDUMP@@#bin/aarch64-buildroot-linux-gnu-objdump#' -e 's#@@TARGET_FC@@#bin/aarch64-buildroot-linux-gnu-gfortran#' -e 's#@@CMAKE_SYSTEM_PROCESSOR@@#aarch64#' -e 's#@@TOOLCHAIN_HAS_CXX@@#1#' -e 's#@@TOOLCHAIN_HAS_FORTRAN@@#0#' -e 's#@@CMAKE_BUILD_TYPE@@#Release#' /home/ych/rk3568/buildroot/support/misc/toolchainfile.cmake.in > /home/ych/rk3568/buildroot/output/rockchip_rk3568/host/share/buildroot/toolchainfile.cmake
/usr/bin/install -D -m 0644 support/misc/Buildroot.cmake /home/ych/rk3568/buildroot/output/rockchip_rk3568/host/share/buildroot/Platform/Buildroot.cmake
cd /home/ych/rk3568/buildroot
rm -f -rf  /home/ych/rk3568/buildroot/output/rockchip_rk3568/host/aarch64-buildroot-linux-gnu/sysroot/share/info/dir
cd /home/ych/rk3568/buildroot
mkdir -p /home/ych/rk3568/buildroot/output/rockchip_rk3568/host/share/cargo
sed -e 's/@RUSTC_TARGET_NAME@/aarch64-unknown-linux-gnu/' -e 's/@CROSS_PREFIX@/aarch64-buildroot-linux-gnu-/' package/rustc/cargo-config.in > /home/ych/rk3568/buildroot/output/rockchip_rk3568/host/share/cargo/config
cd /home/ych/rk3568/buildroot
if test -n "" ; then echo "[7m>>> toolchain  Fixing package configuration files[27m" ; /bin/sed -i -e  "s,/home/ych/rk3568/buildroot/output/rockchip_rk3568/host,@HOST_DIR@,g" -e "s,/home/ych/rk3568/buildroot/output/rockchip_rk3568,@BASE_DIR@,g" -e "s,^\(exec_\)\?prefix=.*,\1prefix=@STAGING_DIR@/usr,g" -e "s,-I/usr/,-I@STAGING_DIR@/usr/,g" -e "s,-L/usr/,-L@STAGING_DIR@/usr/,g" -e 's,@STAGING_DIR@,$(dirname $(readlink -e $0))/../..,g' -e 's,@HOST_DIR@,$(dirname $(readlink -e $0))/../../../..,g' -e "s,@BASE_DIR@,/home/ych/rk3568/buildroot/output/rockchip_rk3568,g"  ; fi
echo "[7m>>> toolchain  Fixing libtool files[27m"
for la in $(find /home/ych/rk3568/buildroot/output/rockchip_rk3568/host/aarch64-buildroot-linux-gnu/sysroot/usr/lib* -name "*.la"); do cp -a "${la}" "${la}.fixed" && /bin/sed -i -e "s:/home/ych/rk3568/buildroot/output/rockchip_rk3568:@BASE_DIR@:g" -e "s:/home/ych/rk3568/buildroot/output/rockchip_rk3568/host/aarch64-buildroot-linux-gnu/sysroot:@STAGING_DIR@:g"  -e "s:\(['= ]\)/usr:\\1@STAGING_DIR@/usr:g" -e "s:\(['= ]\)/lib:\\1@STAGING_DIR@/lib:g"  -e "s:@STAGING_DIR@:/home/ych/rk3568/buildroot/output/rockchip_rk3568/host/aarch64-buildroot-linux-gnu/sysroot:g" -e "s:@BASE_DIR@:/home/ych/rk3568/buildroot/output/rockchip_rk3568:g" "${la}.fixed" && if cmp -s "${la}" "${la}.fixed"; then rm -f "${la}.fixed"; else mv "${la}.fixed" "${la}"; fi || exit 1; done
