@cyysu
2017-10-23T11:43:27.000000Z
字数 1826
阅读 754
- 时间:2017年10月18日
- 作者:Kali
- 邮箱:cyysu.github.io@gmail.com/2869905223@qq.com/微信lwyx1413
- 版本:4.0
- 描述:自动生成Makefile脚本
脚本编写
#!/bin/bash
#==============================================================================
# Author : MJ_DZ chenyuan
#
# Email : cyysu.github.io@gmail.com
#
# Last modified : 2017-10-18 14:54
#
# Filename : 桌面/test/generateMakefile.sh
#
# Description : 自动生成Makefile脚本
#
#
#
#==============================================================================
# 设置信息
FULL_PACKAGE_NAME=MJ
VERSION=4.0
BUG_REPORT_ADDRESS=MJ@cyysu.github.io
# 删除信息
info="[FULL-PACKAGE-NAME]"
# 添加源代码
SOURCE="main.c test.c test.h"
# 添加临时文件夹
TEMP=temp
# 非root用户不可登录
function checkLogin(){
if [ "$UID" -eq 0 ];then
echo -e "\033[32m[INFO] Begin to generate necessary files!\033[0m"
else
echo -e "\033[41m[ERROR] System permission denied!\033[0m"
exit 0
fi
}
# 首先解决依赖问题,自动安装所需软件包
function autoInstall(){
# 判断系统类型分别执行
if [ -f /etc/issue ];then
OS=`cat /etc/issue | grep -i ubuntu | cut -d " " -f 1 | tr '[:lower:]' '[:upper:]'`
case "$OS" in
UBUNTU)
sudo apt-get install -y automake >/dev/null 2>& 1
;;
CENTOS)
yum install -y automake >/dev/null 2>& 1
;;
*)
echo -e "$(OS)\033[41m[ERROR] The current script does not support the current operating system type!\033[0m"
exit 3
esac
fi
}
# 其次处理makefile几个步骤
function autoScan(){
# 生成文件
(autoscan) && [[ $? -eq 0 ]] && (cp configure.scan configure.ac)
# 替换变量
sed -i '/AC_INIT/d' configure.ac
sed -i "s/AC_OUTPUT*/AC_OUTPUT(Makefile)/" configure.ac
line=`awk '/AC_PREREQ/{print NR}' configure.ac`
sed -i "$line a\AC_INIT(${FULL_PACKAGE_NAME},${VERSION},${BUG_REPORT_ADDRESS})" configure.ac
let line++
sed -i "$line a\AM_INIT_AUTOMAKE(${FULL_PACKAGE_NAME},${VERSION})" configure.ac
# aclocal
(aclocal)
# autoconf
(autoconf)
# atuoheader
(autoheader)
# 修改变量
(touch Makefile.am)
echo "AUTOMAKE_OPTIONS=foreign" >> Makefile.am
echo "bin_PROGRAMS=${FULL_PACKAGE_NAME}" >> Makefile.am
echo "MJ_SOURCES=${SOURCE}" >> Makefile.am
# automake
(automake --add-missing) && (rm -rf *.o )
}
autoScan
支付宝 微信