[关闭]
@cyysu 2017-10-18T07:07:00.000000Z 字数 2415 阅读 917

Makefile-项目篇(七)

  • 时间:2017年10月18日
  • 作者:Kali
  • 邮箱:cyysu.github.io@gmail.com/2869905223@qq.com/微信lwyx1413
  • 版本:4.0
  • 描述:自动生成Makefile

Makefile系列教程


安装步骤

  1. # 测试文件
  2. mj@DZ:~/桌面/test$ cat test.c
  3. #include "test.h"
  4. void test()
  5. {
  6. printf("Hello World");
  7. }
  8. mj@DZ:~/桌面/test$ cat test.h
  9. #include <stdio.h>
  10. void test();
  11. mj@DZ:~/桌面/test$
  12. mj@DZ:~/桌面/test$ cat main.c
  13. #include <stdio.h>
  14. #include "test.h"
  15. int main()
  16. {
  17. test();
  18. }
  19. # 脚本执行方式 我这里测试去掉了root限制
  20. mj@DZ:~/桌面/test$ ./generateMakefile.sh
  21. configure.ac:6: warning: AM_INIT_AUTOMAKE: two- and three-arguments forms are deprecated. For more info, see:
  22. configure.ac:6: http://www.gnu.org/software/automake/manual/automake.html#Modernize-AM_005fINIT_005fAUTOMAKE-invocation
  23. configure.ac:12: installing './compile'
  24. configure.ac:6: installing './install-sh'
  25. configure.ac:6: installing './missing'
  26. Makefile.am: installing './depcomp'

脚本内容

  1. #!/bin/bash
  2. # 设置信息
  3. FULL_PACKAGE_NAME=MJ
  4. VERSION=4.0
  5. BUG_REPORT_ADDRESS=MJ@cyysu.github.io
  6. # 删除信息
  7. info="[FULL-PACKAGE-NAME]"
  8. # 添加源代码
  9. SOURCE="main.c test.c test.h"
  10. # 添加临时文件夹
  11. TEMP=temp
  12. # 非root用户不可登录
  13. function checkLogin(){
  14. if [ "$UID" -eq 0 ];then
  15. echo -e "\033[32m[INFO] Begin to generate necessary files!\033[0m"
  16. else
  17. echo -e "\033[41m[ERROR] System permission denied!\033[0m"
  18. exit 0
  19. fi
  20. }
  21. # 首先解决依赖问题,自动安装所需软件包
  22. function autoInstall(){
  23. # 判断系统类型分别执行
  24. if [ -f /etc/issue ];then
  25. OS=`cat /etc/issue | grep -i ubuntu | cut -d " " -f 1 | tr '[:lower:]' '[:upper:]'`
  26. case "$OS" in
  27. UBUNTU)
  28. sudo apt-get install -y automake >/dev/null 2>& 1
  29. ;;
  30. CENTOS)
  31. yum install -y automake >/dev/null 2>& 1
  32. ;;
  33. *)
  34. echo -e "$(OS)\033[41m[ERROR] The current script does not support the current operating system type!\033[0m"
  35. exit 3
  36. esac
  37. fi
  38. }
  39. # 其次处理makefile几个步骤
  40. function autoScan(){
  41. # 生成文件
  42. (autoscan) && [[ $? -eq 0 ]] && (cp configure.scan configure.ac)
  43. # 替换变量
  44. sed -i '/AC_INIT/d' configure.ac
  45. sed -i "s/AC_OUTPUT*/AC_OUTPUT(Makefile)/" configure.ac
  46. line=`awk '/AC_PREREQ/{print NR}' configure.ac`
  47. sed -i "$line a\AC_INIT(${FULL_PACKAGE_NAME},${VERSION},${BUG_REPORT_ADDRESS})" configure.ac
  48. let line++
  49. sed -i "$line a\AM_INIT_AUTOMAKE(${FULL_PACKAGE_NAME},${VERSION})" configure.ac
  50. # aclocal
  51. (aclocal)
  52. # autoconf
  53. (autoconf)
  54. # atuoheader
  55. (autoheader)
  56. # 修改变量
  57. (touch Makefile.am)
  58. echo "AUTOMAKE_OPTIONS=foreign" >> Makefile.am
  59. echo "bin_PROGRAMS=${FULL_PACKAGE_NAME}" >> Makefile.am
  60. echo "MJ_SOURCES=${SOURCE}" >> Makefile.am
  61. # automake
  62. (automake --add-missing) && (rm -rf *.o )
  63. }
  64. autoScan

部分错误解决方案

  1. After compiling and installing GNU automake 1.15, I get this error whenever I run automake:
  2. Unescaped left brace in regex is deprecated, passed through in regex;
  3. marked by <-- HERE in m/\${ <-- HERE ([^ \t=:+{}]+)}/
  4. at /usr/local/bin/automake line 3936

解决方案: 点我跳转

执行流程

参考1

参考2

打赏

                    支付宝                                                         微信

微信与支付宝支付

添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注