qtmake="/opt/Qt5.10.1/5.10.1/gcc_64/bin/qmake"
#qtmake="/opt/Qt5.11.2/5.11.2/gcc_64/bin/qmake"
show_error=$1
check_result()
{
    if [ "$1" != 0 -a "$show_error" == "s" ];then
		echo -e "\e[33m*************************************************\e[0m"
        echo -e "\e[31m    Please modify build error first,Exit!\e[0m"
		echo -e "\e[33m*************************************************\e[0m"
 	    exit 1
	fi
}

MAKEOPT=-j8

mkdir bin

cd src/include/proto
sh ./protomake.sh
cd ../../../

cd src/common/modulecomm/
$qtmake modulecomm.pro
make $MAKEOPT
check_result $?
make clean
cp libmodulecomm.so ./../../../bin/
rm Makefile
rm .qmake.stash
cd ../../../

cd src/common/xmlparam/
$qtmake xmlparam.pro
make $MAKEOPT
check_result $?
make clean
cp libxmlparam.so ./../../../bin/
rm Makefile
rm .qmake.stash
cd ../../../

cd src/common/ivexit/
$qtmake ivexit.pro
make $MAKEOPT
check_result $?
make clean
cp libivexit.so ./../../../bin/
rm Makefile
rm .qmake.stash
cd ../../../

cd src/common/ndt_cpu/
$qtmake ndt_cpu.pro
make $MAKEOPT
check_result $?
make clean
cp libndt_cpu.so ./../../../bin/
rm Makefile
rm .qmake.stash
cd ../../../

cd src/common/ivlog/
$qtmake ivlog.pro
make $MAKEOPT
check_result $?
make clean
cp libivlog.so ./../../../bin/
rm Makefile
rm .qmake.stash
cd ../../../

cd src/common/ivfault/
$qtmake ivfault.pro
make $MAKEOPT
check_result $?
make clean
cp libivfault.so ./../../../bin/
rm Makefile
rm .qmake.stash
cd ../../../

cd src/common/platformif/
$qtmake platformif.pro
make $MAKEOPT
check_result $?
make clean
cp libplatformif.so ./../../../bin/
rm Makefile
rm .qmake.stash
cd ../../../

controller_app_name=(
	controller_ge3
	controller_vv7
)

for x in ${controller_app_name[@]}
do
	cd src/controller/${x}/
	$qtmake ${x}.pro
	make $MAKEOPT
	check_result $?
	make clean
	cp ${x} ./../../../bin/
	rm Makefile
	rm .qmake.stash
	rm ${x}
	cd ../../../
done

decition_app_name=(
	decition_brain
	#decition_brain_ge3
	#decition_brain_qingyuan
	#decition_brain_vv7
)

for x in ${decition_app_name[@]}
do
	cd src/decition/${x}/
	$qtmake ${x}.pro
	make $MAKEOPT
	check_result $?
	make clean
	cp ${x} ./../../../bin/
	rm Makefile
	rm .qmake.stash
	rm ${x}
	cd ../../../
done

driver_app_name=(
	driver_lidar_rs16
#	driver_lidar_vlp16
	driver_gps_hcp2
	#driver_gps_ins550d
	#driver_can_nvidia_agx
	driver_can_kvaser
	driver_radio_p900
#	driver_can_vci
	driver_map_trace
	driver_map_xodrload
)

for x in ${driver_app_name[@]}
do
	cd src/driver/${x}/
	$qtmake ${x}.pro
	make $MAKEOPT
	check_result $?
	make clean
	cp ${x} ./../../../bin/
	rm Makefile
	rm .qmake.stash
	rm ${x}
	cd ../../../
done

detect_app_name=(
	#detection_radar_conti_sr308
	detection_radar_delphi_esr
	detection_chassis
	detection_lidar_grid
)

for x in ${detect_app_name[@]}
do
	cd src/detection/${x}/
	$qtmake ${x}.pro
	make $MAKEOPT
	check_result $?
	make clean
	cp ${x} ./../../../bin/
	rm Makefile
	rm .qmake.stash
	rm ${x}
	cd ../../../
done

tool_app_name=(
	#view_pointcloud
	view_gps
	view_rawcan
	view_radar
	IVSysMan
	ivmapmake
	view_ivlog
	tool_querymsg
	tool_xodrobj
	ivlog_record
	adciv_record
)

for x in ${tool_app_name[@]}
do
	cd src/tool/${x}/
	$qtmake ${x}.pro
	make $MAKEOPT
	check_result $?
	make clean
	cp ${x} ./../../../bin/
	rm Makefile
	rm .qmake.stash
	rm ${x}
	cd ../../../
done

ui_app_name=(
	ui_ads_hmi
)

for x in ${ui_app_name[@]}
do
	cd src/ui/${x}/
	$qtmake ${x}.pro
	make $MAKEOPT
	check_result $?
	make clean
	cp ${x} ./../../../bin/
	rm Makefile
	rm .qmake.stash
	rm ${x}
	cd ../../../
done