希望和广大热爱技术的童鞋一起交流,成长。
分类: LINUX
2011-11-09 09:49:14
1. 利用autoscan工具产生一个configure.in文件的模板文件configure.scan文件:
#autoscan
# ls
autoscan.log configure.scan hello.c
2. 把configure.scan文件更名为configure.in文件,并编译其内容如下:
# mv configure.scan configure.in
# gedit configure.in
将内容:
# -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.
AC_PREREQ([2.65])
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.65])
#AC_INIT([FULL-PACKAGE-NAME], [VERSION], [BUG-REPORT-ADDRESS])
AC_INIT(hello.c)//括号里主要是存放主程序的文件名
AM_INIT_AUTOMAKE(hello,1.0)
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
3.执行aclocal,会产生aclocal.m4文件:
# aclocal
# ls
aclocal.m4 autom4te.cache autoscan.log configure.in hello.c
4.执行autoconf,会产生configure文件:
# autoconf
# ls
aclocal.m4 autom4te.cache autoscan.log configure configure.in hello.c
5.执行autoheader,会产生config.h.in文件:
# ls
aclocal.m4 autoscan.log configure hello.c
autom4te.cache config.h.in configure.in
6.创建文件Makefile.am文件,并编辑内容如下:
AUTOMAKE_OPTIONS=foreign
bin_PROGRAMS=hello
MyFirst_EXE_SOURCES=hello.c
注: 其中,hello为编译后产生的可执行文件名称,而第三行等号后面为源文件列表,所有的源文件都要写出。
7.接下来执行一系列命令,直到生成可执行文件并执行:
# automake --add-missing
# ls
# ./configure
# make
# ls
aclocal.m4 config.h.in configure.in hello.o Makefile.in
autom4te.cache config.log depcomp install-sh missing
autoscan.log config.status hello Makefile stamp-h1
config.h configure hello.c Makefile.am
# ./hello
hello,gnu!
OK,至此所有就结束了。