MTK MT6739P 项目克隆脚本

脚本代码如下

clone_project.sh 放在alps目录下。./clone_project.sh 新项目名即可

#!/bin/bash
#Author: tuliyuan 
#Email: [email protected]
# 基于的公司名称
BASE_COMPANY_NAME="top"
# 创建的公司名称
NEW_COMPANY_NAME="top"
# 基于的产品名称 注意 这个不是full_xxxx 是xxxx
#BASE_PROJECT_NAME="k39tv1_bsp_1g"
BASE_PROJECT_NAME="top6739_66_n1"
# 这个一般是创建的某个产品的文件夹名称...一般等同于产品名称
BASE_PROJECT_DIR_NAME=${BASE_PROJECT_NAME}
# 这是lunch的时候选择的product name一般等同于产品名称 特殊时前面可能加full 
BASE_PROJECT_LUNCH_NAME="full_${BASE_PROJECT_NAME}"
# 创建的新产品名称
NEW_PROJECT_NAME=""

# 平台代码根目录
BASE_DIR=`pwd`
# 蓝色
#ARM 类型
#ARM_NAME="arm"
ARM_NAME="arm64"
#######################
#以下为echo -e时需要制定的颜色需要 color_end 收尾。否则颜色显示不生效 颜色范围为31~37可以自行尝试

#蓝色
COLOR_BLUE="\033[34m"
#红色 多为警告
COLOR_RED="\033[31m"
#绿色
COLOR_GREEN="\033[36m"
#紫色
COLOR_PERSE="\033[35m"
#黄色
COLOR_YELLOW="\033[33m"
#结束符
COLOR_END="\033[0m"
#默认颜色
COLOR_DEFAULT=${COLOR_GREEN}
source build/envsetup.sh > /dev/null

#获取配置文件值
getProjectKey(){
	local file=$1
	local key=$2
	if [ -f "${file}" ];then
		local value=$(grep -v "^\s*#" ${file} | grep -w ${key} | tail -1 | sed 's#^[^=]*=\(.*\)$#\1#g' | sed 's#[[:space:]]##g' )
	fi
	echo ${value}
}

# kernel dir名称
KERNEL_DIR_NAME=$(getProjectKey device/${BASE_COMPANY_NAME}/${BASE_PROJECT_NAME}/ProjectConfig.mk LINUX_KERNEL_VERSION)
PLATFORM_NAME=$(getProjectKey device/${BASE_COMPANY_NAME}/${BASE_PROJECT_NAME}/ProjectConfig.mk MTK_PLATFORM) 
MTK_PLATFORM_NAME=$(echo ${PLATFORM_NAME} | tr A-Z a-z)
usage(){
   echo "基础产品名称为:${BASE_PROJECT_LUNCH_NAME}"
   echo "新产品名称为空,退出脚本"
   echo "根目录为:${BASE_DIR}"
   echo -e "$0 [new_project_name] clone一个新的名为new_project_name产品"
}
make_new_project(){
  NEW_PROJECT_NAME=$1
  if [ "$1" = "" ] ;then
    usage
    exit 1
  fi
  if [ "${#NEW_PROJECT_NAME}" -gt "32" ]; then
    echo "**********error occured with project name $NEW_PROJECT***************"
    echo "error!!! 工程名长度请不要超过32个字符,否则可能出现一些奇怪的问题 "
    echo "**********error occured with project name $NEW_PROJECT***************"
    exit 1
  fi
  echo "即将创建名为${NEW_PROJECT_NAME}的产品....." 
  _copy_device_dir
  _copy_kerner_dir
  _copy_vendor_dir
  echo "工程创建完成!!!" 		
}
#拷贝device目录
_copy_device_dir(){

   local company_name_dir_old="device/${BASE_COMPANY_NAME}/"
   local project_name_dir_old="device/${BASE_COMPANY_NAME}/${BASE_PROJECT_DIR_NAME}"
   local company_name_dir="device/${NEW_COMPANY_NAME}/"
   local project_name_dir="device/${NEW_COMPANY_NAME}/${NEW_PROJECT_NAME}"
   echo -e "${COLOR_DEFAULT}开始为${NEW_PROJECT_NAME}进行device目录的复制.....${COLOR_END}" 
#判断是否存在此要创建的路径,如果存在说明已有此工程,请检查该工程目录下的vendorsetup.sh
#判断是否需要创建对应的文件夹
#aaaa note
   rm -rf ${project_name_dir}
   if [ -d "${project_name_dir}" ] ;then
       echo -e "[device]  ${COLOR_RED}当前已存在此工程....请重新创建新的工程名,退出程序!${COLOR_END}"
       exit 1
   fi


   if [ ! -d "${company_name_dir}" ] ;then
       echo "[device]  当前没有${company_name_dir}公司目录...将会创建...."
       mkdir -pv ./device/${NEW_COMPANY_NAME}
   fi
   
   if [ ! -d "${project_name_dir}" ] ;then
        echo "[device]  当前没有${NEW_PROJECT_NAME}产品目录...将会创建...."
        mkdir -pv ${project_name_dir}
     fi
#开始拷贝数据
   echo "[device]  正在从初始工程中拷贝文件到新工程目录下...." 
   cp -r ${project_name_dir_old}/* ${project_name_dir}
#make文件的更名
   echo "[device]  ${NEW_PROJECT_NAME}.mk 正在更名...." 
   mv ${project_name_dir}/${BASE_PROJECT_LUNCH_NAME}.mk ${project_name_dir}/${NEW_PROJECT_NAME}.mk
#lunch combo相关
   echo "[device]  vendorsetup.sh 正在替换字符串...." 
   sed -i "s/${BASE_PROJECT_LUNCH_NAME}/${NEW_PROJECT_NAME}/g" ${project_name_dir}/vendorsetup.sh
   echo "[device]  AndroidProducts.mk 正在替换字符串...." 
   sed -i "s/${BASE_PROJECT_LUNCH_NAME}/${NEW_PROJECT_NAME}/g" ${project_name_dir}/AndroidProducts.mk
#产品配置相关 
   echo "[device]  BoardConfig.mk 正在替换字符串...." 
   sed -i "s/${BASE_PROJECT_DIR_NAME}/${NEW_PROJECT_NAME}/g" ${project_name_dir}/BoardConfig.mk	
   sed -i "s/${BASE_COMPANY_NAME}/${NEW_COMPANY_NAME}/g" ${project_name_dir}/BoardConfig.mk
   echo "[device]  board-info.txt 正在替换字符串...." 
   sed -i "s/${BASE_PROJECT_DIR_NAME}/${NEW_PROJECT_NAME}/g" ${project_name_dir}/board-info.txt
#device.mk用的copy file
   echo "[device]  device.mk 正在替换字符串...." 
   sed -i "s/${BASE_PROJECT_DIR_NAME}/${NEW_PROJECT_NAME}/g" ${project_name_dir}/device.mk
   sed -i "s/${BASE_COMPANY_NAME}/${NEW_COMPANY_NAME}/g" ${project_name_dir}/device.mk
   
#产品mk的主要配置替换,如产品名词产品型号等
   echo "[device] ${NEW_PROJECT_NAME}.mk 正在替换字符串...." 
   sed -i "s/${BASE_PROJECT_LUNCH_NAME}/${NEW_PROJECT_NAME}/g" ${project_name_dir}/${NEW_PROJECT_NAME}.mk
   sed -i "s/${BASE_PROJECT_DIR_NAME}/${NEW_PROJECT_NAME}/g" ${project_name_dir}/${NEW_PROJECT_NAME}.mk
   sed -i "s/${BASE_COMPANY_NAME}/${NEW_COMPANY_NAME}/g" ${project_name_dir}/${NEW_PROJECT_NAME}.mk
 
#需要使用自己的签名
#   sed -i s/'MTK_SIGNATURE_CUSTOMIZATION = no'/'MTK_SIGNATURE_CUSTOMIZATION = yes'/g  "device/${NEW_COMPANY_NAME}/"${NEW_PROJECT_NAME}"/ProjectConfig.mk"
#   mkdir -pv device/mediatek/security/${NEW_PROJECT_NAME}
   echo -e "${COLOR_DEFAULT}为${NEW_PROJECT_NAME}进行device目录的复制完成.....${COLOR_END}" 
   
}


#拷贝kernel目录
_copy_kerner_dir(){
   local _old_dconfig="${KERNEL_DIR_NAME}/arch/${ARM_NAME}/configs/${BASE_PROJECT_DIR_NAME}_defconfig"
   local _old_debugconfig="${KERNEL_DIR_NAME}/arch/${ARM_NAME}/configs/${BASE_PROJECT_DIR_NAME}_debug_defconfig"
   local _old_dts="${KERNEL_DIR_NAME}/arch/${ARM_NAME}/boot/dts/${BASE_PROJECT_DIR_NAME}.dts"
   local _old_dws="${KERNEL_DIR_NAME}/drivers/misc/mediatek/dws/${MTK_PLATFORM_NAME}/${BASE_PROJECT_DIR_NAME}.dws"

   if [  "${ARM_NAME}" = "arm64" ] ; then
        _old_dts="${KERNEL_DIR_NAME}/arch/${ARM_NAME}/boot/dts/mediatek/${BASE_PROJECT_DIR_NAME}.dts"
   fi 
   local _new_dconfig="${KERNEL_DIR_NAME}/arch/${ARM_NAME}/configs/${NEW_PROJECT_NAME}_defconfig"
   local _new_debugconfig="${KERNEL_DIR_NAME}/arch/${ARM_NAME}/configs/${NEW_PROJECT_NAME}_debug_defconfig"
   local _new_dts="${KERNEL_DIR_NAME}/arch/${ARM_NAME}/boot/dts/${NEW_PROJECT_NAME}.dts"
   local _new_dws="${KERNEL_DIR_NAME}/drivers/misc/mediatek/dws/${MTK_PLATFORM_NAME}/${NEW_PROJECT_NAME}.dws"

   if [  "${ARM_NAME}" = "arm64" ] ; then
        _new_dts="${KERNEL_DIR_NAME}/arch/${ARM_NAME}/boot/dts/mediatek/${NEW_PROJECT_NAME}.dts"
   fi 

#aaaaa note 
   rm -rf ${_new_dconfig}
   rm -rf ${_new_debugconfig}
   rm -rf ${_new_dts}
   echo -e "${COLOR_DEFAULT}开始为${NEW_PROJECT_NAME}进行kernel目录的复制.....${COLOR_END}" 
   echo "[kernel]  kernel目录为${KERNEL_DIR_NAME} 平台名称为${MTK_PLATFORM_NAME}"
   if [ -f "${_new_dconfig}" ] ;then
       echo -e "[kernel]  ${COLOR_RED}当前已存在此工程defconfig....请重新创建新的工程名,正在退出程序!${COLOR_END}"
       exit 1
   fi
   
   if [ -f "${_new_debugconfig}" ] ;then
       echo -e "[kernel]  ${COLOR_RED}当前已存在此工程debug_config....请重新创建新的工程名,正在退出程序!${COLOR_END}"
       exit 1
   fi
   
   if [ -f "${_new_dts}" ] ;then
       echo -e "[kernel]  ${COLOR_RED}当前已存在此工程dts....请重新创建新的工程名,正在退出程序!${COLOR_END}"
       exit 1  
   fi
#拷贝defconfig 为user版本的使用
   echo "[kernel]  正在复制defconfig...."
   cp -r ${_old_dconfig} ${_new_dconfig}
   sed -i "s/${BASE_PROJECT_DIR_NAME}/${NEW_PROJECT_NAME}/g" ${_new_dconfig}
#拷贝defconfig 为userdebug or eng 版本的使用
   echo "[kernel]  正在复制debug_defconfig...."
   cp -r ${_old_debugconfig} ${_new_debugconfig}
   sed -i "s/${BASE_PROJECT_DIR_NAME}/${NEW_PROJECT_NAME}/g" ${_new_debugconfig}
#拷贝dts配置
   echo "[kernel]  正在复制dts...."
   cp -r ${_old_dts} ${_new_dts}
    cp -r ${_old_dws} ${_new_dws}
   sed -i "s/${BASE_PROJECT_DIR_NAME}/${NEW_PROJECT_NAME}/g" ${_new_dts}
   echo -e "${COLOR_DEFAULT}为${NEW_PROJECT_NAME}进行kernel目录的复制完成.....${COLOR_END}" 
}
#拷贝vendor目录
_copy_vendor_dir(){
   local old_lk="vendor/mediatek/proprietary/bootable/bootloader/lk/project/${BASE_PROJECT_DIR_NAME}.mk"
   local old_preloader_dir="vendor/mediatek/proprietary/bootable/bootloader/preloader/custom/${BASE_PROJECT_DIR_NAME}/"
   local old_custom_dir="vendor/mediatek/proprietary/custom/${BASE_PROJECT_DIR_NAME}/"
   local old_custom_trust_zone="vendor/mediatek/proprietary/trustzone/custom/build/project/${BASE_PROJECT_DIR_NAME}.mk" 

   local new_lk="vendor/mediatek/proprietary/bootable/bootloader/lk/project/${NEW_PROJECT_NAME}.mk"
   local new_preloader_dir="vendor/mediatek/proprietary/bootable/bootloader/preloader/custom/${NEW_PROJECT_NAME}/"
   local new_custom_dir="vendor/mediatek/proprietary/custom/${NEW_PROJECT_NAME}/"
   local new_custom_trust_zone="vendor/mediatek/proprietary/trustzone/custom/build/project/${NEW_PROJECT_NAME}.mk" 
# aaaa note
   rm -rf ${new_lk}
   rm -rf ${new_preloader_dir}
   rm -rf ${new_custom_dir}
   if [ -f "${new_lk}" ] ;then
       echo -e "[vendor]  ${COLOR_RED}当前已存在此工程lk文件....请重新创建新的工程名,正在退出程序!${COLOR_END}"
       exit 1
   fi
   
   if [ -d "${new_preloader_dir}" ] ;then
       echo -e "[vendor]  ${COLOR_RED}当前已存在此工程preloader...请重新创建新的工程名,正在退出程序!${COLOR_END}"
       exit 1
   fi
   
   if [ -d "${new_custom_dir}" ] ;then
       echo -e "[vendor]  ${COLOR_RED}当前已存在此工程custom....请重新创建新的工程名,正在退出程序!${COLOR_END}"
       exit 1  
   fi

   echo -e "${COLOR_DEFAULT}开始为${NEW_PROJECT_NAME}进行vendor目录的复制.....${COLOR_END}" 

#为新工程创建对应的lk
   echo "[vendor]  开始复制lk文件,并替换旧工程为新工程的名称....."
   cp -r ${old_lk} ${new_lk}
   cp -r vendor/mediatek/proprietary/bootable/bootloader/lk/target/${BASE_PROJECT_DIR_NAME} vendor/mediatek/proprietary/bootable/bootloader/lk/target/${NEW_PROJECT_NAME} 
   sed -i "s/${BASE_PROJECT_DIR_NAME}/${NEW_PROJECT_NAME}/g" ${new_lk}
   echo "[vendor]  开始创建preloader目录,并替换旧工程为新工程的名称....."

#为新工程创建对应的preloader目录
   mkdir -pv ${new_preloader_dir}
   cp -r ${old_preloader_dir}/* ${new_preloader_dir}
   mv ${new_preloader_dir}/${BASE_PROJECT_DIR_NAME}.mk ${new_preloader_dir}/${NEW_PROJECT_NAME}.mk 
   sed -i "s/${BASE_PROJECT_DIR_NAME}/${NEW_PROJECT_NAME}/g" ${new_preloader_dir}/${NEW_PROJECT_NAME}.mk 

##为新工程创建对应的custom目录
   echo "[vendor]  开始创建custom目录,并替换旧工程为新工程的名称....."
   mkdir -pv ${new_custom_dir}
   cp -r ${old_custom_dir}/* ${new_custom_dir}
   sed -i "s/${BASE_PROJECT_DIR_NAME}/${NEW_PROJECT_NAME}/g" ${new_custom_dir}/Android.mk 
   sed -i "s/${BASE_PROJECT_DIR_NAME}/${NEW_PROJECT_NAME}/g" ${new_custom_dir}/security/efuse/input.xml
   echo -e "${COLOR_DEFAULT}为${NEW_PROJECT_NAME}进行vendor目录的复制完成.....${COLOR_END}" 

#为新的工程创建对应的trustzone
   cp -r ${old_custom_trust_zone} ${new_custom_trust_zone}

#TOP 项目专属
  # cp -rf vendor/${BASE_COMPANY_NAME}/ vendor/${NEW_COMPANY_NAME}/
   mkdir -pv  vendor/${NEW_COMPANY_NAME}/libs/$NEW_PROJECT_NAME/
   cp -rf vendor/${BASE_COMPANY_NAME}/libs/$BASE_PROJECT_NAME/device-vendor.mk vendor/${NEW_COMPANY_NAME}/libs/$NEW_PROJECT_NAME/device-vendor.mk
}


make_new_project $1

你可能感兴趣的:(Android)