目的


兼容
复用
专业标准

构建步骤


  1. ./configure
  2. make
  3. make install # with root

练习


code

  1. /* hello.c: A standard "Hello, world!" program */
  2. #include <stdio.h>
  3. int main(int argc, char* argv[]) {
  4. printf("Hello, world!\n");
  5. return 0;
  6. }

手写的makefile

  1. # Makefile: A standard Makefile for hello.c
  2. all:
  3. gcc -o hello main.c
  4. clean:
  5. rm -f hello

自动完成过程

image.png

  1. 染指的文件
  2. 1 源码
  3. 2 Makefile.am
  4. 3 configure.ac + AM_INIT_AUTOMAKE
  5. 4 config.h.in 修改宏开关
  6. -------------------------------------------------------------------------
  7. autoscan
  8. mv configure.scan configure.ac
  9. AM_INIT_AUTOMAKE --> configure.ac
  10. aclocal
  11. touch NEWS README ChangeLog AUTHORS
  12. automake --add-missing
  13. autoheader
  14. autoconf
  15. ./configure
  16. config.h --> source code
  17. make

● 如果不想出现以下错误
image.png

  1. AM_INIT_AUTOMAKE([foreign color-tests dist-bzip2 parallel-tests])

一般的做法


  1. 采用autoreconf —install 完成编译环境的构建
  2. 通过提供configure.ac文件完成以下功能的触发
    • 摆平文件夹required依赖 — AM_INIT_AUTOMAKE([foreign color-tests dist-bzip2 parallel-tests])
    • 一些依赖库的check
  3. Makefile.am
    • 导引输出
    • 引入m4依赖 ACLOCAL_AMFLAGS = -I m4

参考


● GNU Autoconf, Automake, and Libtool:
http://sources.redhat.com/autobook/
● The GNU Autoconf Macro archive
http://www.gnu.org/software/ac-archive/
● Autotools Tutorial for Beginners
http://www.cbreak.org/