#!/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
解釋:這個(gè)方法是一個(gè)簡(jiǎn)單的區(qū)分不同設(shè)備去執(zhí)行不同代碼段;還有一種在Makefile中定義宏的方法。
成都創(chuàng)新互聯(lián)自2013年創(chuàng)立以來,是專業(yè)互聯(lián)網(wǎng)技術(shù)服務(wù)公司,擁有項(xiàng)目成都做網(wǎng)站、網(wǎng)站建設(shè)網(wǎng)站策劃,項(xiàng)目實(shí)施與項(xiàng)目整合能力。我們以讓每一個(gè)夢(mèng)想脫穎而出為使命,1280元德化做網(wǎng)站,已為上家服務(wù),為德化各地企業(yè)和個(gè)人服務(wù),聯(lián)系電話:13518219792
目的:我現(xiàn)在要區(qū)分兩個(gè)不同的設(shè)備,xgepon和epon,通過執(zhí)行這個(gè)腳本的選項(xiàng),你可以生成一個(gè)文件
/products_config.h
這個(gè)文件里會(huì)有你選擇的兩個(gè)宏的其中一個(gè),對(duì)應(yīng)你的選項(xiàng)的宏,你在要區(qū)分的文件中包含這個(gè)文件,#if就可以。