您好,登錄后才能下訂單哦!
#!/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
解釋:這個方法是一個簡單的區(qū)分不同設(shè)備去執(zhí)行不同代碼段;還有一種在Makefile中定義宏的方法。
目的:我現(xiàn)在要區(qū)分兩個不同的設(shè)備,xgepon和epon,通過執(zhí)行這個腳本的選項,你可以生成一個文件
/products_config.h
這個文件里會有你選擇的兩個宏的其中一個,對應(yīng)你的選項的宏,你在要區(qū)分的文件中包含這個文件,#if就可以。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。