#!/bin/bash # Program # This program config olt products type # Version V1.0 # Author zhaoxiaohu #History #2018/01/29 First release export SWHOME=$(cd `dirname $0`;pwd) echo "export SWHOME=$SWHOME" echo "" echo "[1] make EPON" echo "[2] make XGEPON" echo "[0] make clean" read -p "Select Product Type NO.:" ProductType # 1代表epon,2代表xgepon,3代码clean if [ $ProductType -eq 1 ];then PRODUCT=EPON PRODUCT_TYPE=EPON elif [ $ProductType -eq 2 ];then PRODUCT=XGEPON PRODUCT_TYPE=XGEPON elif [ $ProductType -eq 0 ];then make clean echo "=============================" echo "Make Clean Successfully!!" echo "=============================" exit 0 else echo "Select Error!" exit 0 fi echo "You select make ${PRODUCT}" read LINE_READ < ${SWHOME}/products_config.h LINE_WRITE="#define PRODUCT_CLASS PRODUCTS_${PRODUCT}" # 生成.h文件,里面#define 你的选择 if [ "$LINE_READ" != "$LINE_WRITE" ] then echo -e "$LINE_WRITE" > ${SWHOME}/products_config.h fi function make_product(){ if make $1 then echo "=============================" echo "make ${PRODUCT} successfully!!" echo "=============================" else echo "=====================" echo "make ${PRODUCT} error!" echo "=====================" fi } sleep 1 if [ ${PRODUCT} == "EPON" ] then make_product "v=EPON" elif [ ${PRODUCT} == "XGEPON" ] then make_product "v=XGEPON" else echo "Select Error!" exit 0 fi
解释:这个方法是一个简单的区分不同设备去执行不同代码段;还有一种在Makefile中定义宏的方法。
目的:我现在要区分两个不同的设备,xgepon和epon,通过执行这个脚本的选项,你可以生成一个文件
/products_config.h
这个文件里会有你选择的两个宏的其中一个,对应你的选项的宏,你在要区分的文件中包含这个文件,#if就可以。
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。