Linux Makefile自动生成--实例

来源:互联网 发布:阿里云 个人 试用 编辑:程序博客网 时间:2024/06/03 04:47

原始出处:http://blog.csdn.net/spch2008/article/details/12506061


1. 创建程序

[cpp] view plain copy
 print?
  1. #include <stdio.h>  
  2.   
  3. int main(int argc, char* argv[])  
  4. {  
  5.     printf("Hello, world!\n");  
  6.   
  7.     return 0;  
  8. }  
状态如下:

[plain] view plain copy
 print?
  1. root@nova-controller:/home/spch2008/AutoMake# ls  
  2. hello.c  

2. Makefile.am

[plain] view plain copy
 print?
  1. AUTOMAKE_OPTIONS = foreign   
  2.   
  3. bin_PROGRAMS = hello  
状态如下:

[plain] view plain copy
 print?
  1. root@nova-controller:/home/spch2008/AutoMake# ls  
  2. hello.c  Makefile.am  

3. autoscan

[plain] view plain copy
 print?
  1. root@nova-controller:/home/spch2008/AutoMake# autoscan  
  2. root@nova-controller:/home/spch2008/AutoMake# ls  
  3. autoscan.log  configure.scan  hello.c  Makefile.am  
更改configure.scan为configure.ac,查看文件。

[plain] view plain copy
 print?
  1. # Process this file with autoconf to produce a configure script.  
  2.   
  3. AC_PREREQ([2.68])  
  4. AC_INIT([FULL-PACKAGE-NAME], [VERSION], [BUG-REPORT-ADDRESS])  
  5. AC_CONFIG_SRCDIR([hello.c])  
  6. AC_CONFIG_HEADERS([config.h])  
  7.   
  8. # Checks for programs.  
  9. AC_PROG_CC  
  10.   
  11. # Checks for libraries.  
  12. # Checks for header files.  
  13. # Checks for typedefs, structures, and compiler characteristics.  
  14. # Checks for library functions.  
  15.   
  16. AC_CONFIG_FILES([Makefile])  
  17. AC_OUTPUT  
添加宏AM_INIT_AUTOMAKE,用于初始化automake。

[plain] view plain copy
 print?
  1. # Process this file with autoconf to produce a configure script.  
  2.   
  3. AC_PREREQ([2.68])  
  4. AC_INIT([hello], [1.0], [BUG-REPORT-ADDRESS])  
  5. AC_CONFIG_SRCDIR([hello.c])  
  6. AC_CONFIG_HEADERS([config.h])  
  7. AM_INIT_AUTOMAKE(hello, 1.0)  
  8.   
  9. # Checks for programs.  
  10. AC_PROG_CC  
  11.   
  12. # Checks for libraries.  
  13. # Checks for header files.  
  14. # Checks for typedefs, structures, and compiler characteristics.  
  15. # Checks for library functions.  
  16.   
  17. AC_CONFIG_FILES([Makefile])  
  18. AC_OUTPUT  
此时状态如下:

[plain] view plain copy
 print?
  1. root@nova-controller:/home/spch2008/AutoMake# ls  
  2. autoscan.log  configure.ac  hello.c  Makefile.am  
4.aclocal

[plain] view plain copy
 print?
  1. root@nova-controller:/home/spch2008/AutoMake# aclocal  
  2. root@nova-controller:/home/spch2008/AutoMake# ls  
  3. aclocal.m4  autom4te.cache  autoscan.log  configure.ac  hello.c  Makefile.am  
5.autoconf

[plain] view plain copy
 print?
  1. root@nova-controller:/home/spch2008/AutoMake# autoconf  
  2. root@nova-controller:/home/spch2008/AutoMake# ls  
  3. aclocal.m4  autom4te.cache  autoscan.log  configure  configure.ac  hello.c  Makefile.am  
6.autoheader

[plain] view plain copy
 print?
  1. root@nova-controller:/home/spch2008/AutoMake# autoheader  
  2. root@nova-controller:/home/spch2008/AutoMake# ls  
  3. aclocal.m4      autoscan.log  configure     hello.c  
  4. autom4te.cache  config.h.in   configure.ac  Makefile.am  
7.automake

[plain] view plain copy
 print?
  1. root@nova-controller:/home/spch2008/AutoMake# automake --add-missing  
  2. configure.ac:8: installing `./install-sh'  
  3. configure.ac:8: installing `./missing'  
  4. Makefile.am: installing `./depcomp'  
  5. root@nova-controller:/home/spch2008/AutoMake# ls  
  6. aclocal.m4      autoscan.log  configure     depcomp  install-sh   Makefile.in  
  7. autom4te.cache  config.h.in   configure.ac  hello.c  Makefile.am  missing  
8. ./configure

[plain] view plain copy
 print?
  1. root@nova-controller:/home/spch2008/AutoMake# ls  
  2. aclocal.m4      config.h     config.status  depcomp     Makefile     missing  
  3. autom4te.cache  config.h.in  configure      hello.c     Makefile.am  stamp-h1  
  4. autoscan.log    config.log   configure.ac   install-sh  Makefile.in  
9. make

[plain] view plain copy
 print?
  1. root@nova-controller:/home/spch2008/AutoMake# ls  
  2. aclocal.m4      config.h     config.status  depcomp  hello.o     Makefile.am  stamp-h1  
  3. autom4te.cache  config.h.in  configure      hello    install-sh  Makefile.in  
  4. autoscan.log    config.log   configure.ac   hello.c  Makefile    missing  
10.运行

[plain] view plain copy
 print?
  1. root@nova-controller:/home/spch2008/AutoMake# ./hello   
  2. Hello, world!  


有关Makefile.am的写法,参见:http://airs.com/ian/configure/configure_2.html#SEC8


0 0
原创粉丝点击