Makefile的automake生成(HelloWorld)

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!  
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值