您好,登錄后才能下訂單哦!
#!/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進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。