autoconf/automake学习笔记
v0.1 2013.12.12 *** 明白流程
1. 写hello.c程序
2. autoscan 生成:autoscan.log configure.scan hello.c
cat configure.scan:
# -*- Autoconf -*-
# 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_OUTPUT
修改成:
# -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.
AC_PREREQ([2.68])
AC_INIT([autoconf_test, [0.1]) # change this line!
AC_CONFIG_SRCDIR([hello.c])
AC_CONFIG_HEADERS([config.h])
AM_INIT_AUTOMAKE([autoconf], [0.1]) # add this line!
# 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_OUTPUT(Makefile) # change this line!
把文件名改成: configure.in
3. aclocal 生成:
aclocal.m4 autom4te.cache configure.in hello.c
(主要是生成aclocal.m4)
4. autoconf 生成:
aclocal.m4 autom4te.cache configure configure.in hello.c
5. autoheader 生成:
aclocal.m4 autom4te.cache config.h.in configure configure.in hello.c
5. 创建Makefile.am:
AUTOMAKE_OPTIONS=foreign
bin_PROGRAMS=hello
hello_SOURCES=hello.c
6. automake --add-missing
过程信息为:
configure.in:8: installing `./install-sh'
configure.in:8: installing `./missing'
Makefile.am: installing `./depcomp'
生成文件:
aclocal.m4 autom4te.cache config.h.in configure configure.in depcomp
hello.c install-sh Makefile.am Makefile.in missing
(makefile.in是这步生成的关键文件)
7. ./configure 生成最终的Makefile文件(该步骤中可能需要指定编译器:export CC=gcc)
8. make 生成最终的可执行的程序:hello, ./hello运行输出:test autoconf!
/* hello.c */
#include<stdio.h>
int main()
{
printf("test autoconf!\n");
#ifdef CONFIG_H_TEST
printf("test autoconf: test config.h\n");
#endif
return 0;
}
v0.1 2013.12.12 *** 明白流程
1. 写hello.c程序
2. autoscan 生成:autoscan.log configure.scan hello.c
cat configure.scan:
# -*- Autoconf -*-
# 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_OUTPUT
修改成:
# -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.
AC_PREREQ([2.68])
AC_INIT([autoconf_test, [0.1]) # change this line!
AC_CONFIG_SRCDIR([hello.c])
AC_CONFIG_HEADERS([config.h])
AM_INIT_AUTOMAKE([autoconf], [0.1]) # add this line!
# 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_OUTPUT(Makefile) # change this line!
把文件名改成: configure.in
3. aclocal 生成:
aclocal.m4 autom4te.cache configure.in hello.c
(主要是生成aclocal.m4)
4. autoconf 生成:
aclocal.m4 autom4te.cache configure configure.in hello.c
5. autoheader 生成:
aclocal.m4 autom4te.cache config.h.in configure configure.in hello.c
5. 创建Makefile.am:
AUTOMAKE_OPTIONS=foreign
bin_PROGRAMS=hello
hello_SOURCES=hello.c
6. automake --add-missing
过程信息为:
configure.in:8: installing `./install-sh'
configure.in:8: installing `./missing'
Makefile.am: installing `./depcomp'
生成文件:
aclocal.m4 autom4te.cache config.h.in configure configure.in depcomp
hello.c install-sh Makefile.am Makefile.in missing
(makefile.in是这步生成的关键文件)
7. ./configure 生成最终的Makefile文件(该步骤中可能需要指定编译器:export CC=gcc)
8. make 生成最终的可执行的程序:hello, ./hello运行输出:test autoconf!
/* hello.c */
#include<stdio.h>
int main()
{
printf("test autoconf!\n");
#ifdef CONFIG_H_TEST
printf("test autoconf: test config.h\n");
#endif
return 0;
}