@cyysu
2017-10-18T07:07:00.000000Z
字数 2415
阅读 917
- 时间:2017年10月18日
- 作者:Kali
- 邮箱:cyysu.github.io@gmail.com/2869905223@qq.com/微信lwyx1413
- 版本:4.0
- 描述:自动生成Makefile
Makefile系列教程
# 测试文件
mj@DZ:~/桌面/test$ cat test.c
#include "test.h"
void test()
{
printf("Hello World");
}
mj@DZ:~/桌面/test$ cat test.h
#include <stdio.h>
void test();
mj@DZ:~/桌面/test$
mj@DZ:~/桌面/test$ cat main.c
#include <stdio.h>
#include "test.h"
int main()
{
test();
}
# 脚本执行方式 我这里测试去掉了root限制
mj@DZ:~/桌面/test$ ./generateMakefile.sh
configure.ac:6: warning: AM_INIT_AUTOMAKE: two- and three-arguments forms are deprecated. For more info, see:
configure.ac:6: http://www.gnu.org/software/automake/manual/automake.html#Modernize-AM_005fINIT_005fAUTOMAKE-invocation
configure.ac:12: installing './compile'
configure.ac:6: installing './install-sh'
configure.ac:6: installing './missing'
Makefile.am: installing './depcomp'
#!/bin/bash
# 设置信息
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
After compiling and installing GNU automake 1.15, I get this error whenever I run automake:
Unescaped left brace in regex is deprecated, passed through in regex;
marked by <-- HERE in m/\${ <-- HERE ([^ \t=:+{}]+)}/
at /usr/local/bin/automake line 3936
解决方案: 点我跳转
支付宝 微信