Linux Makefile自动生成--实例
来源:互联网 发布:阿里云 个人 试用 编辑:程序博客网 时间:2024/06/03 04:47
原始出处:http://blog.csdn.net/spch2008/article/details/12506061
1. 创建程序
- #include <stdio.h>
-
- int main(int argc, char* argv[])
- {
- printf("Hello, world!\n");
-
- return 0;
- }
状态如下:- root@nova-controller:/home/spch2008/AutoMake# ls
- hello.c
2. Makefile.am
- AUTOMAKE_OPTIONS = foreign
-
- bin_PROGRAMS = hello
状态如下:- root@nova-controller:/home/spch2008/AutoMake# ls
- hello.c Makefile.am
3. autoscan
- root@nova-controller:/home/spch2008/AutoMake# autoscan
- root@nova-controller:/home/spch2008/AutoMake# ls
- autoscan.log configure.scan hello.c Makefile.am
更改configure.scan为configure.ac,查看文件。- # Process this file with autoconf to produce a configure script.
-
- AC_PREREQ([2.68])
- AC_INIT([FULL-PACKAGE-NAME], [VERSION], [BUG-REPORT-ADDRESS])
- AC_CONFIG_SRCDIR([hello.c])
- AC_CONFIG_HEADERS([config.h])
-
- # Checks for programs.
- AC_PROG_CC
-
- # Checks for libraries.
- # Checks for header files.
- # Checks for typedefs, structures, and compiler characteristics.
- # Checks for library functions.
-
- AC_CONFIG_FILES([Makefile])
- AC_OUTPUT
添加宏AM_INIT_AUTOMAKE,用于初始化automake。- # Process this file with autoconf to produce a configure script.
-
- AC_PREREQ([2.68])
- AC_INIT([hello], [1.0], [BUG-REPORT-ADDRESS])
- AC_CONFIG_SRCDIR([hello.c])
- AC_CONFIG_HEADERS([config.h])
- AM_INIT_AUTOMAKE(hello, 1.0)
-
- # Checks for programs.
- AC_PROG_CC
-
- # Checks for libraries.
- # Checks for header files.
- # Checks for typedefs, structures, and compiler characteristics.
- # Checks for library functions.
-
- AC_CONFIG_FILES([Makefile])
- AC_OUTPUT
此时状态如下:- root@nova-controller:/home/spch2008/AutoMake# ls
- autoscan.log configure.ac hello.c Makefile.am
4.aclocal- root@nova-controller:/home/spch2008/AutoMake# aclocal
- root@nova-controller:/home/spch2008/AutoMake# ls
- aclocal.m4 autom4te.cache autoscan.log configure.ac hello.c Makefile.am
5.autoconf- root@nova-controller:/home/spch2008/AutoMake# autoconf
- root@nova-controller:/home/spch2008/AutoMake# ls
- aclocal.m4 autom4te.cache autoscan.log configure configure.ac hello.c Makefile.am
6.autoheader- root@nova-controller:/home/spch2008/AutoMake# autoheader
- root@nova-controller:/home/spch2008/AutoMake# ls
- aclocal.m4 autoscan.log configure hello.c
- autom4te.cache config.h.in configure.ac Makefile.am
7.automake- root@nova-controller:/home/spch2008/AutoMake# automake --add-missing
- configure.ac:8: installing `./install-sh'
- configure.ac:8: installing `./missing'
- Makefile.am: installing `./depcomp'
- root@nova-controller:/home/spch2008/AutoMake# ls
- aclocal.m4 autoscan.log configure depcomp install-sh Makefile.in
- autom4te.cache config.h.in configure.ac hello.c Makefile.am missing
8. ./configure- root@nova-controller:/home/spch2008/AutoMake# ls
- aclocal.m4 config.h config.status depcomp Makefile missing
- autom4te.cache config.h.in configure hello.c Makefile.am stamp-h1
- autoscan.log config.log configure.ac install-sh Makefile.in
9. make- root@nova-controller:/home/spch2008/AutoMake# ls
- aclocal.m4 config.h config.status depcomp hello.o Makefile.am stamp-h1
- autom4te.cache config.h.in configure hello install-sh Makefile.in
- autoscan.log config.log configure.ac hello.c Makefile missing
10.运行- root@nova-controller:/home/spch2008/AutoMake# ./hello
- Hello, world!
有关Makefile.am的写法,参见:http://airs.com/ian/configure/configure_2.html#SEC8
0 0