1、编译脚本auto_build.sh中
查找 配置文件product_feature.h 中的,如下内容,判断有没有 #define DEEP_SLEEP_NEW
有,编译deep_sleep_new.c
否则,编译deep_sleep.c
product_feature.h相关代码
#if (8456449 == PRODUCT_ID)
#undef PROD_IS_INPUT_DEVICE
#undef WATCH_DOG_ENABLE
#undef PROD_IS_INFRARED_SENSOR
#define PROD_SENSOR_RADAR
#define NO_FACTORY_TEST
#define NO_DTM_FACTORY_TEST
#define FEATURE_LOW_POWER
#define DEEP_SLEEP_NEW
// #define AGING_PHASE_HAVE_NUM 1
#endif
auto_build.sh相关代码
function prod_confs
{
local prod=$1
echo "prod="$prod
find . -name product_feature.h | xargs awk '/^#if.*\('${prod}'.*==.*PRODUCT_ID\)'\$'/{b=1} /^#if/{if(b)c++;} /^#endif/{if(c) c--; if(!c) b=0;} {if(b) print}'
}
# check if deep_sleep_new is defined
if prod_confs $PROD_ID | egrep -q "^#define.*DEEP_SLEEP_NEW" ; then
deep_sleep_new=1
else
deep_sleep_new=0
fi
echo "********************************************"
echo "deep_sleep_new=$deep_sleep_new"
echo "********************************************"
export PROD_ID="$PROD_ID"
命令解析:
find -name product_feature.h #查找配置文件
xargs awk #提取特征文本
'/^#if.*\('${prod}'.*==.*PRODUCT_ID\)' #定位 #if (8456449 == PRODUCT_ID)
\$ #定位回车符
'/{b=1} /^#if/{if(b)c++;} /^#endif/{if(c) c--; if(!c) b=0;} {if(b) print}' #查找到enndif结束
2、区分编译