Linux Makefile自动生成--实例

Linux Makefile自动生成--总体流程
Linux Makefile自动生成--实例
Linux Makefile自动生成--config.h


1. 创建程序

#include 

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

你可能感兴趣的:(操作系统)