手机版
你好,游客 登录 注册 搜索
背景:
阅读新闻

Makefile的automake生成(HelloWorld)

[日期:2012-02-24] 来源:Linux社区  作者:deqingguo [字体:大 中 小]

环境:

Ubuntu 11.04

Autoconf 2.67

Automake 1.11.1

1、新建目录HelloWorld

2、进入该目录,编写HelloWorld.c

[cpp]
  1. int main(int argc,char** argv)  
  2. {  
  3.     printf("Hello World!\n");  
  4.     return 0;  
  5. }  
3、生成configure

a、使用autoscan来根据目录下的源代码生成一个configure.in的模板文件configure.scan:

[plain]
  1. fzuir@ubuntu:~/workspace/automake/Hellworld$ ls  
  2. HelloWorld.c  
  3. fzuir@ubuntu:~/workspace/automake/Hellworld$ autoscan  
  4. fzuir@ubuntu:~/workspace/automake/Hellworld$ ls  
  5. autoscan.log  configure.scan  HelloWorld.c  
b、将configure.scan改为configure.in,并修改其内容为:

[plain]
  1. #                                               -*- Autoconf -*-  
  2. # Process this file with autoconf to produce a configure script.  
  3.   
  4. AC_INIT(helloworld.c)  
  5. AM_INIT_AUTOMAKE(helloworld,1.0)  
  6.   
  7. # Checks for programs.  
  8. AC_PROG_CC  
  9.   
  10. # Checks for libraries.  
  11.   
  12. # Checks for header files.  
  13.   
  14. # Checks for typedefs, structures, and compiler characteristics.  
  15.   
  16. # Checks for library functions.  
  17.   
  18. AC_OUTPUT(Makefile)  

c、执行aclocal生成aclocal.m4,执行autoconf生成configure
[plain]
  1. fzuir@ubuntu:~/workspace/automake/Hellworld$ ls  
  2. autoscan.log  configure.in  HelloWorld.c  
  3. fzuir@ubuntu:~/workspace/automake/Hellworld$ aclocal  
  4. fzuir@ubuntu:~/workspace/automake/Hellworld$ ls  
  5. aclocal.m4  autom4te.cache  autoscan.log  configure.in  HelloWorld.c  
  6. fzuir@ubuntu:~/workspace/automake/Hellworld$ autoconf  
  7. fzuir@ubuntu:~/workspace/automake/Hellworld$ ls  
  8. aclocal.m4  autom4te.cache  autoscan.log  configure  configure.in  HelloWorld.c  
4、创建Makefile.am,内容如下:

[plain]
  1. AUTOMAKE_OPTIONs=foreign  
  2. bin_PROGRAMS=Helloworld  
  3. HelloWorld_SOURCES=HelloWorld.c  
5、运行automake

automake会根据Makefile.am来自动生成Makefile.in

[plain]
  1. fzuir@ubuntu:~/workspace/automake/Hellworld$ automake --add-missing  
  2. configure.in:5: installing `./install-sh'  
  3. configure.in:5: installing `./missing'  
  4. Makefile.am: installing `./depcomp'  
  5. fzuir@ubuntu:~/workspace/automake/Hellworld$ ls  
  6. aclocal.m4      autoscan.log  configure.in  HelloWorld.c  Makefile.am  missing  
  7. autom4te.cache  configure     depcomp       install-sh    Makefile.in  
6、运行configure命令生成Makefile

[plain]
  1. fzuir@ubuntu:~/workspace/automake/Hellworld$ ./configure   
  2. checking for a BSD-compatible install... /usr/bin/install -c  
  3. checking whether build environment is sane... yes  
  4. checking for a thread-safe mkdir -p... /bin/mkdir -p  
  5. checking for gawk... no  
  6. checking for mawk... mawk  
  7. checking whether make sets $(MAKE)... yes  
  8. checking for gcc... gcc  
  9. checking whether the C compiler works... yes  
  10. checking for C compiler default output file name... a.out  
  11. checking for suffix of executables...   
  12. checking whether we are cross compiling... no  
  13. checking for suffix of object files... o  
  14. checking whether we are using the GNU C compiler... yes  
  15. checking whether gcc accepts -g... yes  
  16. checking for gcc option to accept ISO C89... none needed  
  17. checking for style of include used by make... GNU  
  18. checking dependency style of gcc... gcc3  
  19. configure: creating ./config.status  
  20. config.status: creating Makefile  
  21. config.status: executing depfiles commands  
7、运行make命令进行编译

[plain]
  1. fzuir@ubuntu:~/workspace/automake/Hellworld$ make  
  2. gcc -DPACKAGE_NAME=\"\" -DPACKAGE_TARNAME=\"\" -DPACKAGE_VERSION=\"\" -DPACKAGE_STRING=\"\" -DPACKAGE_BUGREPORT=\"\" -DPACKAGE_URL=\"\" -DPACKAGE=\"HelloWorld\" -DVERSION=\"1.0\" -I.     -g -O2 -MT HelloWorld.o -MD -MP -MF .deps/HelloWorld.Tpo -c -o HelloWorld.o HelloWorld.c  
  3. HelloWorld.c: In function ‘main’:  
  4. HelloWorld.c:3: warning: incompatible implicit declaration of built-in function ‘printf’  
  5. mv -f .deps/HelloWorld.Tpo .deps/HelloWorld.Po  
  6. gcc  -g -O2   -o HelloWorld HelloWorld.o    

8、运行HelloWorld

[plain]
  1. fzuir@ubuntu:~/workspace/automake/Hellworld$ ./HelloWorld   
  2. Hello World!  
linux
相关资讯       makefile  automake 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款