为了方便我日常工作中的编译环境,免去我敲命令行所浪费的时间,我个人写了一个非常有用而又简单的脚本框架,该框架即可以完成的工程源码编译,也可以清除,拷贝等等操作,具体需要开发者自己来实现细节,我的框架思路就是用到了bash shell脚本的case语句,这个语句类似我们C语言的switch语句,有若干个分支,接下来我们就来看看具体的编写方法:
#bin/sh
#date:2016.12.28
#author:yang yuanxin
#!/bin/bash
#判断传进来的参数,没有参数返回出错
if [ $# -lt 1 ]; then
echo "error.. need build eng or clean"
exit 1
fi
#选择编译版本,make all 或者 make clean 或者打包工程
#其中 make all会编译工程
#make clean会清除工程
#make package会打包工程,将需要下载的文件放到/build/LFP
for arg in "$@"
do
case $arg in
"all") #第一个参数
#可以编写自己工程的一些操作,比如编译,拷贝等。
;;
"clean")
;;
"package")
;;
*) echo '...' #这里类似C语言的switch语句的default分支
;;
esac
break ;
done
以下是我在开发中写的一个脚本,拿去改改就可以实现你自己的,非常简单,框架就是这样,万能!
#bin/sh
#date:2016.12.28
#author:yang yuanxin
#!/bin/bash
#判断传进来的参数,没有参数返回出错
if [ $# -lt 1 ]; then
echo "error.. need build eng or clean"
exit 1
fi
#选择编译版本,make all 或者 make clean 或者打包工程
#其中 make all会编译工程
#make clean会清除工程
#make package会打包工程,将需要下载的文件放到/build/LFP
for arg in "$@"
do
case $arg in
"all")
echo 'You select build all eng'
cd /home/se0803/delorean
sudo ./build.sh -v -p delorean all
if test $?
then
echo "build eng success!"
else
echo "build eng fair!"
exit 1
fi
ls -l /home/se0803/delorean/deploy/delorean_bootloader.bin
ls -l /home/se0803/delorean/deploy/delorean_base.bin
ls -l /home/se0803/delorean/deploy/delorean_base_comp.bin
ls -l /home/se0803/delorean/filesys-us filesys-uk filesys-bulk
sudo chmod 777 /home/se0803/delorean/delorean/ -R
sudo chmod 777 /home/se0803/delorean/deploy/*
sudo chmod 777 filesys-bulk filesys-uk filesys-us
cp /home/se0803/delorean/deploy/delorean_bootloader.bin /home/se0803/delorean/delorean/deploy/ -r
cp /home/se0803/delorean/deploy/delorean_base.bin /home/se0803/delorean/delorean/deploy/ -r
cp /home/se0803/delorean/deploy/delorean_base_comp.bin /home/se0803/delorean/delorean/deploy/ -r
cp /home/se0803/delorean/filesys-bulk filesys-uk filesys-us/home/se0803/delorean/delorean/filesys -R
if test $?
then
sudo echo "cp file success" >> /dev/nullcd
else
echo "cp file error"
exit 2
fi
;;
"clean")
echo 'You select clean all eng'
cd /home/se0803/delorean
sudo ./build.sh -c -p delorean all
if test $?
then
echo "build clean success!"
else
echo "build clean fair!"
exit 1
fi
;;
"package")
echo 'You select Packaging and Deployment'
cd /home/se0803/delorean
chmod 755 deploy/*
./build.sh -w -p delorean all
echo "Firmware build success!"
ls -l builds/LFP/*
;;
*) echo 'You do not select a number between build or clean or make package'
;;
esac
break ;
done