温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

GNU automake自动生成Makefile的方法及案例分析

发布时间:2021-12-23 18:52:49 来源:亿速云 阅读:373 作者:柒染 栏目:互联网科技

今天就跟大家聊聊有关GNU automake自动生成Makefile的方法及案例分析,可能很多人都不太了解,为了让大家更加了解,小编给大家总结了以下内容,希望大家根据这篇文章可以有所收获。

在GNU的世界里,存在Automake这样的工具进行自动生成Makefile文件,automake是由Perl语言编写的,必须与GNU autoconf一并使用,具体的生成过程请参看GNU automake的wikipedia中的右下角的图,地址如下:http://en.wikipedia.org/wiki/Automake,由此图可看到使用自动生成Makefile的工具使用的流程,步骤主要如下:

1、使用autoscan生成configure.scan
$ autoscan 
$ ls
autoscan.log  configure.scan  hello.c
$ aclocal
aclocal: `configure.ac' or `configure.in' is required
2、在上一步中直接执行aclocal时出现以上的提示,那么就要将生成的configure.scan修改为configure.ac或configure.in再进行aclocal的执行;
$ mv configure.scan configure.in 或 configure.ac 
$ ls
autoscan.log  configure.in  hello.c
3、执行aclocal
$ aclocal
$ ls
autom4te.cache  autoscan.log  configure.in  hello.c
4、执行autoheader
$ ls
autom4te.cache  autoscan.log  config.h.in  configure.in  hello.c
5、执行autoconf
$ autoconf 
$ ls
autom4te.cache  autoscan.log  config.h.in  configure  configure.in  hello.c
6、创建Makefile.am
$ vim Makefile.am 
$ cat Makefile.am 
bin_PROGRAMS=hello
hello_SOURCES=hello.c

关于Makefile.am中的具体内容的意思是说生成的可执行文件的名称为hello,对应的源代码为hello.c。
7、执行automake
$ automake
configure.in: no proper invocation of AM_INIT_AUTOMAKE was found.
configure.in: You should verify that configure.in invokes AM_INIT_AUTOMAKE,
configure.in: that aclocal.m4 is present in the top-level directory,
configure.in: and that aclocal.m4 was recently regenerated (using aclocal).
automake: no `Makefile.am' found for any configure output
automake: Did you forget AC_CONFIG_FILES([Makefile]) in configure.in?
这时出错了,是说configure.in文件中的AM_INIT_AUTOMAKE没有找到,只有修改configure.in文件后再从第三步进行重新执行,configure.in中的AC_INIT行下添加AM_INIT_AUTOMAKE(hello,1.0),或添加AM_INIT_AUTOMAKE,格式为AM_INIT_AUTOMAKE(package,version),再修改AC_OUTPUT为AC_OUTPUT(Makefile);

修改完configure.in文件后,再次执行2~7;

8、执行automake
$ automake
configure.in:6: required file `./install-sh' not found
configure.in:6:   `automake --add-missing' can install `install-sh'
configure.in:6: required file `./missing' not found
configure.in:6:   `automake --add-missing' can install `missing'
Makefile.am: required file `./INSTALL' not found
Makefile.am:   `automake --add-missing' can install `INSTALL'
Makefile.am: required file `./NEWS' not found
Makefile.am: required file `./README' not found
Makefile.am: required file `./AUTHORS' not found
Makefile.am: required file `./ChangeLog' not found
Makefile.am: required file `./COPYING' not found
Makefile.am:   `automake --add-missing' can install `COPYING'
Makefile.am: required file `./depcomp' not found
Makefile.am:   `automake --add-missing' can install `depcomp'

按照提示创建缺少的文件,
$ touch NEWS README AUTHORS ChangeLog
再执行: $ automake --add-missing
没有出错的情况下再次执行automake;
$ ls
aclocal.m4      ChangeLog     configure.in  INSTALL      missing
AUTHORS         config.h.in   COPYING       install-sh   NEWS
autom4te.cache  config.h.in~  depcomp       Makefile.am  README
autoscan.log    configure     hello.c       Makefile.in
此时已经生成了生成Makefile文件的cinfigure脚本;
9、./configure生成Makefile
$ ls Makefile
Makefile
10、make得到可执行程序
$ make
make  all-am
make[1]: 正在进入目录 `/home/ufo/hello'
gcc -DHAVE_CONFIG_H -I.     -g -O2 -MT hello.o -MD -MP -MF .deps/hello.Tpo -c -o hello.o hello.c
mv -f .deps/hello.Tpo .deps/hello.Po
gcc  -g -O2   -o hello hello.o  
make[1]:正在离开目录 `/home/ufo/hello'

$ ./hello 
Hello World!

看完上述内容,你们对GNU automake自动生成Makefile的方法及案例分析有进一步的了解吗?如果还想了解更多知识或者相关内容,请关注亿速云行业资讯频道,感谢大家的支持。

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI