PRO_DIR=`pwd`
CONFIG_IVSysMan="IVSysMan_HAPO_1.xml"

check_result=`whereis patchelf | awk '{print $2}'`
if [ ! $check_result ];then
    echo -e "\e[31m no found patchelf, Plz install patchelf first\e[0m"
    exit 1
fi

app_name=(
######driver######
driver_lidar_rs16
driver_gps_hcp2
driver_can_nvidia_agx
driver_map_trace
driver_map_xodrload
driver_rpc_server
driver_cloud_grpc_client
driver_grpc_server
driver_rpc_server
driver_group_grpc_client

######detection#####
detection_lidar_PointPillars_MultiHead
detection_radar_delphi_esr
detection_chassis

######fusion#####
lidar_radar_fusion_cnn

######controller######
controller_hapo

######decition######
decition_brain_sf

######tools########
view_pointcloud
view_gps
view_rawcan
view_radar
IVSysMan
ivmapmake
view_ivlog
tool_querymsg
tool_xodrobj
ivlog_record
adciv_record
ui_ads_hmi
)

for x in ${app_name[@]}
do
	echo "deploy $x"
	cp ./bin/${x} ./
	./deploy.sh $x
	if [ $? == 1 ];then
		echo "build $x faile"
		exit 1
	fi
	rm ${x}
done

lib_name=(
	libmodulecomm.so
	libndt_cpu.so
	libxmlparam.so
	libivfault.so
	libivlog.so
	libplatformif.so
	libivexit.so
	libivchart.so
	libivbacktrace.so
)

for x in ${lib_name[@]}
do
	echo "link lib $x"
	patchelf --set-rpath '$ORIGIN' ./bin/$x
	if [ "$?" != 0 ];then
		echo -e "\e[31m patchelf $EXE faile, Ensure patchelf tool installed\e[0m"
		exit 1
	fi
done

cp ./bin/*.so ./deploy/app/lib/

qt_com=`arch`
if [ $qt_com = "aarch64" ];then
cp -r /usr/lib/aarch64-linux-gnu/nss/* ./deploy/app/lib/
else
cp -r /usr/lib/x86_64-linux-gnu/nss/* ./deploy/app/lib/
fi

cp ./sh/BaiDuMap.html ./deploy/app/
cp ./sh/car.png ./deploy/app/
cp ./sh/asphalt.jpg ./deploy/app/

echo ""
echo "***************"
echo "***  done!  ***"
echo "***************"