自动生成Makefile文件

主要的工具有autoscan, aclocal, autoheader, autoconfig,automake

1 .创建c源文件hello.c

1 #include <stdio.h>
2 
3 int main(){
4     return 0;
5 }

2.执行autoscan命令

  这是目录下会多出configure.scan和autoscan.log文件,我们以configure.scan文件为模板进行修改,将configure.scan重命名改为configure.ac (好多博客写的是configure.in虽然不能说错,但是autoscan会报出一个warning)。

configure.scan修改之前是这个样子的

 1 #                                               -*- Autoconf -*-
 2 # Process this file with autoconf to produce a configure script.
 3 
 4 AC_PREREQ([2.69])
 5 AC_INIT([FULL-PACKAGE-NAME], [VERSION], [BUG-REPORT-ADDRESS])
 6 AC_CONFIG_SRCDIR([hello.c])
 7 AC_CONFIG_HEADERS([config.h])
 8 
 9 # Checks for programs.
10 AC_PROG_CC
11 
12 # Checks for libraries.
13 
14 # Checks for header files.
15 
16 # Checks for typedefs, structures, and compiler characteristics.
17 
18 # Checks for library functions.
19 
20 AC_OUTPUT

修改之后的样子为:

#                                               -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.

AC_PREREQ([2.69])
AC_INIT([hello], [1.0], [hello.txt])
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

3.执行aclocal命令

  目录下多出aclocal.m4(文件)  autom4te.cache(目录)

4.autoconf

  目录下多出configure文件,当然还有其他的比如说config.h config.status config.log 等

5.autoheader

  目录下多出config.h.in(文件)

好至此为止configure文件已经生成了,我们常用的./confgure命令中的configure已经有了,但是仅仅有configure文件还不足以生成Makefile文件,还需要Makefile.in,所以有下面的这一步

6. 手动创建Makefile.am文件(注意大小写)

1 AUTOMAKE_OPTIONS=foreign
2 bin_PROGRAMS=hello
3 hello_SOURCES=hello.c

  然后执行automake,改命令生成Makefile.in  

7. 是时候去生成Makefile文件了。

  ./configure

参考:     http://blog.csdn.net/initphp/article/details/43705765 (详细)

    http://blog.csdn.net/evilbinary_root/article/details/6848092

原文地址:https://www.cnblogs.com/cdwodm/p/5043361.html