rjw | 1f88458 | 2022-01-06 17:20:42 +0800 | [diff] [blame^] | 1 | #!/bin/bash |
| 2 | |
| 3 | # usage: ./tools/backtrace/prj_crt.sh clone_prj new_prj" |
| 4 | CLONE_PRJ=$1 |
| 5 | NEW_PRJ=$2 |
| 6 | # $3 is address list |
| 7 | |
| 8 | if [ "$#" -lt "2" ]; then |
| 9 | echo "Usage: $0 <clone project> <new project>" |
| 10 | exit |
| 11 | fi |
| 12 | |
| 13 | RED_PAT="\033[37;41m" |
| 14 | BLUE_PAT="\033[37;44m" |
| 15 | YELLOW_PAT="\033[30;43m" |
| 16 | RESET_PAT="\033[0m" |
| 17 | |
| 18 | # check firstly |
| 19 | if [ ! -f "make/projects/${CLONE_PRJ}.prj" ] || [ ! -d "work/custom/${CLONE_PRJ}" ]; then |
| 20 | echo -e "${RED_PAT} Cannot find ${CLONE_PRJ} in project list!${RESET_PAT}" |
| 21 | exit |
| 22 | fi |
| 23 | |
| 24 | # start to create project ... |
| 25 | echo "" |
| 26 | echo -e "Start to clone ${CLONE_PRJ} to ${NEW_PRJ}..." |
| 27 | echo -e "Copy *.prj ..." |
| 28 | rm -f make/projects/${NEW_PRJ}.prj |
| 29 | cp -f make/projects/${CLONE_PRJ}.prj make/projects/${NEW_PRJ}.prj |
| 30 | |
| 31 | echo -e "Check rel mapping ..." |
| 32 | relmap=`cat rel/mapping/prj_map | grep "${NEW_PRJ};"` |
| 33 | if [ "$relmap" != "" ]; then |
| 34 | echo -e " ${BLUE_PAT}> Find in project mapping, no need to add new ... $result${RESET_PAT}" |
| 35 | else |
| 36 | echo -e " ${RED_PAT}> Cannot find ${NEW_PRJ} in project mapping!${RESET_PAT}" |
| 37 | result=`cat rel/mapping/prj_map | grep "${CLONE_PRJ};"` |
| 38 | if [ "$result" != "" ]; then |
| 39 | echo -e " > try to clone one from ${CLONE_PRJ}" |
| 40 | relmap=`echo $result | sed "s/${CLONE_PRJ};/${NEW_PRJ};/g"` |
| 41 | echo -e " ${BLUE_PAT}> $relmap${RESET_PAT}" |
| 42 | echo $relmap >> rel/mapping/prj_map |
| 43 | else |
| 44 | echo -e " ${RED_PAT}> Still cannot find similar setting, please add manaually!${RESET_PAT}" |
| 45 | exit |
| 46 | fi |
| 47 | fi |
| 48 | |
| 49 | echo -e "Clone rel folders ..." |
| 50 | rm -fr rel/filter/${NEW_PRJ} |
| 51 | cp -fr rel/filter/${CLONE_PRJ} rel/filter/${NEW_PRJ} |
| 52 | |
| 53 | echo -e "Check internal feature option ..." |
| 54 | BUILD_FDR=`cat work/custom/${CLONE_PRJ}/build/customer_feature_option | grep "INTERNAL_FEATURE_OPTION.*=" | grep "INTERNAL_FEATURE_OPTION.*=" | sed 's/.*\/\(build\..*\)\/config.*/\1/'` |
| 55 | if [ "$BUILD_FDR" != "" ]; then |
| 56 | echo -e " ${BLUE_PAT}> Find $BUILD_FDR in cloned project ${CLOSE_PRJ}${RESET_PAT}" |
| 57 | else |
| 58 | echo -e " ${RED_PAT}> Cannot find build.xxxx in cloned project!${RESET_PAT}" |
| 59 | exit |
| 60 | fi |
| 61 | |
| 62 | echo -e "Clone internal feature option ..." |
| 63 | rm -fr work/${BUILD_FDR}/config/${NEW_PRJ} |
| 64 | cp -fr work/${BUILD_FDR}/config/${CLONE_PRJ} work/${BUILD_FDR}/config/${NEW_PRJ} |
| 65 | |
| 66 | echo -e "Clone custom folder ..." |
| 67 | rm -fr work/custom/${NEW_PRJ} |
| 68 | cp -fr work/custom/${CLONE_PRJ} work/custom/${NEW_PRJ} |
| 69 | # replace the INTERNAL_FEATURE_OPTION |
| 70 | sed -i "s/\/${CLONE_PRJ}\//\/${NEW_PRJ}\//g" work/custom/${NEW_PRJ}/build/customer_feature_option |
| 71 | # check GPIO |
| 72 | GPIO_FDR=work/custom/${NEW_PRJ}/gpio |
| 73 | if [ -f "${GPIO_FDR}/${CLONE_PRJ}.csv" ]; then |
| 74 | # find GPIO file |
| 75 | echo -e " ${BLUE_PAT}> rename ${GPIO_FDR}/${CLONE_PRJ}.csv to ${GPIO_FDR}/${NEW_PRJ}.csv${RESET_PAT}" |
| 76 | mv ${GPIO_FDR}/${CLONE_PRJ}.csv ${GPIO_FDR}/${NEW_PRJ}.csv |
| 77 | fi |
| 78 | |
| 79 | CFG=`echo $relmap | awk -F ';' '{print $2}'` |
| 80 | SDK=`echo $relmap | awk -F ';' '{print $3}'` |
| 81 | echo "" |
| 82 | echo "----------------------------------------------------------" |
| 83 | echo -e "${BLUE_PAT}${NEW_PRJ}${RESET_PAT} is cloned from ${CLONE_PRJ} done!" |
| 84 | echo "Please check/modify and upload following files/folders/configurations ..." |
| 85 | echo -e " ${YELLOW_PAT}> Config: ${CFG}" |
| 86 | echo -e " ${YELLOW_PAT}> SDK: ${SDK}" |
| 87 | echo -e " ${YELLOW_PAT}> make/${RESET_PAT}" |
| 88 | mtk_repo status make |
| 89 | echo -e " ${YELLOW_PAT}> rel/${RESET_PAT}" |
| 90 | mtk_repo status rel |
| 91 | echo -e " ${YELLOW_PAT}> work/${BUILD_FDR}/${RESET_PAT}" |
| 92 | mtk_repo status work/${BUILD_FDR} |
| 93 | echo -e " ${YELLOW_PAT}> work/custom/${RESET_PAT}" |
| 94 | mtk_repo status work/custom |
| 95 | echo "----------------------------------------------------------" |
| 96 | echo "" |