(1)hello目录下,新建一个hello.c , 写入代码如:
#include <stdio.h>
int main(int argc, char** argv){
printf("%s", 'Hello, Linux World!\n");
return 0;
}
(2)使用autoscan命令来帮助我们根据目录下的 源代码生成一个configure.in的 模板文件.
root@Ubuntu32:/home/zhangbin/alex/codeStore/testCODE/testAUTOCONF/hello# autoscan
root@Ubuntu32:/home/zhangbin/alex/codeStore/testCODE/testAUTOCONF/hello# ls
autoscan.log configure.scan hello.c
(3)将configure.scan改名为configure.ac,改为configure.in会有警告的:
root@Ubuntu32:/home/zhangbin/alex/codeStore/testCODE/testAUTOCONF/hello# mv configure.scan configure.in
root@Ubuntu32:/home/zhangbin/alex/codeStore/testCODE/testAUTOCONF/hello# vi configure.in
我改为了configure.ac,家红字的要注意,否则,会报错的:
# -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.
AC_PREREQ([2.69])
AC_INIT([FULL-PACKAGE-NAME], [1.0], [zhangbin@163.com])
AM_INIT_AUTOMAKE
AC_CONFIG_SRCDIR([hello.c])
AC_CONFIG_HEADERS([config.h])
# Checks for programs.
AC_PROG_CC
# Checks for libraries.
# Checks for header files.
AC_CHECK_HEADERS([stdlib.h])
# Checks for typedefs, structures, and compiler characteristics.
# Checks for library functions.
AC_CONFIG_FILES([Makefile])
AC_OUTPUT
修改Makefile.am :
AUTOMAKE_OPTIONS=foreign
bin_PROGRAMS=helloworld
helloworld_SOURCES=hello.c
(4) 执行aclocal
root@Ubuntu32:/home/zhangbin/alex/codeStore/testCODE/testAUTOCONF/hello# aclocal
aclocal: warning: autoconf input should be named 'configure.ac', not 'configure.in'
这个时候, 会生成这个autom4te.cache的目录 :
root@Ubuntu32:/home/zhangbin/alex/codeStore/testCODE/testAUTOCONF/hello# ls
autom4te.cache autoscan.log configure.in hello.c
root@Ubuntu32:/home/zhangbin/alex/codeStore/testCODE/testAUTOCONF/hello# ls autom4te.cache/
output.0 requests traces.0
(4)autoheader
(5)执行autoconf会生成confgure文件:
root@Ubuntu32:/home/zhangbin/alex/codeStore/testCODE/testAUTOCONF/hello# autoconf
root@Ubuntu32:/home/zhangbin/alex/codeStore/testCODE/testAUTOCONF/hello# ls
autom4te.cache autoscan.log configure configure.in hello.c
(6) automake --add-missing
(7) ./configure
(8) make
参考 http://blog.csdn.net/mymtom/article/details/2044225
=======================过程
zhangbin@Ubuntu32:~/alex/codeStore/testCODE/testAUTOCONF/hello$ sudo su
[sudo] password for zhangbin:
root@Ubuntu32:/home/zhangbin/alex/codeStore/testCODE/testAUTOCONF/hello# ls
autom4te.cache autoscan.log configure configure.in hello.c Makefile.am
root@Ubuntu32:/home/zhangbin/alex/codeStore/testCODE/testAUTOCONF/hello# ls -al
总用量 148
drwxr-xr-x 3 root root 4096 Oct 10 09:59 .
drwxrwxr-x 4 zhangbin zhangbin 4096 Oct 10 15:04 ..
drwxr-xr-x 2 root root 4096 Oct 10 10:00 autom4te.cache
-rw-r--r-- 1 root root 0 Oct 10 09:54 autoscan.log
-rwxr-xr-x 1 root root 123928 Oct 10 09:56 configure
-rw-r--r-- 1 root root 496 Oct 10 09:54 configure.in
-rw-r--r-- 1 root root 118 Oct 10 09:53 hello.c
-rw-r--r-- 1 root root 77 Oct 10 09:59 Makefile.am
root@Ubuntu32:/home/zhangbin/alex/codeStore/testCODE/testAUTOCONF/hello# chown zhangbin *
root@Ubuntu32:/home/zhangbin/alex/codeStore/testCODE/testAUTOCONF/hello# ls
autom4te.cache autoscan.log configure configure.in hello.c Makefile.am
root@Ubuntu32:/home/zhangbin/alex/codeStore/testCODE/testAUTOCONF/hello# mv configure.in configure.ac
root@Ubuntu32:/home/zhangbin/alex/codeStore/testCODE/testAUTOCONF/hello# aclocal
root@Ubuntu32:/home/zhangbin/alex/codeStore/testCODE/testAUTOCONF/hello# autoheader
root@Ubuntu32:/home/zhangbin/alex/codeStore/testCODE/testAUTOCONF/hello# autoconf
root@Ubuntu32:/home/zhangbin/alex/codeStore/testCODE/testAUTOCONF/hello# automake --add-missing
configure.ac: error: no proper invocation of AM_INIT_AUTOMAKE was found.
configure.ac: You should verify that configure.ac invokes AM_INIT_AUTOMAKE,
configure.ac: that aclocal.m4 is present in the top-level directory,
configure.ac: and that aclocal.m4 was recently regenerated (using aclocal)
automake: error: no 'Makefile.am' found for any configure output
automake: Did you forget AC_CONFIG_FILES([Makefile]) in configure.ac?
root@Ubuntu32:/home/zhangbin/alex/codeStore/testCODE/testAUTOCONF/hello# automake --add-missing
configure.ac:21: error: `#' is already registered with AC_CONFIG_FILES.
../../lib/autoconf/status.m4:288: AC_CONFIG_FILES is expanded from...
configure.ac:21: the top level
autom4te: /usr/bin/m4 failed with exit status: 1
automake: error: autoconf failed with exit status: 1
root@Ubuntu32:/home/zhangbin/alex/codeStore/testCODE/testAUTOCONF/hello# automake --add-missing
configure.ac: error: no proper invocation of AM_INIT_AUTOMAKE was found.
configure.ac: You should verify that configure.ac invokes AM_INIT_AUTOMAKE,
configure.ac: that aclocal.m4 is present in the top-level directory,
configure.ac: and that aclocal.m4 was recently regenerated (using aclocal)
Makefile.am: installing './depcomp'
/usr/share/automake-1.14/am/depend2.am: error: am__fastdepCC does not appear in AM_CONDITIONAL
/usr/share/automake-1.14/am/depend2.am: The usual way to define 'am__fastdepCC' is to add 'AC_PROG_CC'
/usr/share/automake-1.14/am/depend2.am: to 'configure.ac' and run 'aclocal' and 'autoconf' again
/usr/share/automake-1.14/am/depend2.am: error: AMDEP does not appear in AM_CONDITIONAL
/usr/share/automake-1.14/am/depend2.am: The usual way to define 'AMDEP' is to add one of the compiler tests
/usr/share/automake-1.14/am/depend2.am: AC_PROG_CC, AC_PROG_CXX, AC_PROG_OBJC, AC_PROG_OBJCXX,
/usr/share/automake-1.14/am/depend2.am: AM_PROG_AS, AM_PROG_GCJ, AM_PROG_UPC
/usr/share/automake-1.14/am/depend2.am: to 'configure.ac' and run 'aclocal' and 'autoconf' again
root@Ubuntu32:/home/zhangbin/alex/codeStore/testCODE/testAUTOCONF/hello# automake --add-missing
configure.ac: error: no proper invocation of AM_INIT_AUTOMAKE was found.
configure.ac: You should verify that configure.ac invokes AM_INIT_AUTOMAKE,
configure.ac: that aclocal.m4 is present in the top-level directory,
configure.ac: and that aclocal.m4 was recently regenerated (using aclocal)
/usr/share/automake-1.14/am/depend2.am: error: am__fastdepCC does not appear in AM_CONDITIONAL
/usr/share/automake-1.14/am/depend2.am: The usual way to define 'am__fastdepCC' is to add 'AC_PROG_CC'
/usr/share/automake-1.14/am/depend2.am: to 'configure.ac' and run 'aclocal' and 'autoconf' again
/usr/share/automake-1.14/am/depend2.am: error: AMDEP does not appear in AM_CONDITIONAL
/usr/share/automake-1.14/am/depend2.am: The usual way to define 'AMDEP' is to add one of the compiler tests
/usr/share/automake-1.14/am/depend2.am: AC_PROG_CC, AC_PROG_CXX, AC_PROG_OBJC, AC_PROG_OBJCXX,
/usr/share/automake-1.14/am/depend2.am: AM_PROG_AS, AM_PROG_GCJ, AM_PROG_UPC
/usr/share/automake-1.14/am/depend2.am: to 'configure.ac' and run 'aclocal' and 'autoconf' again
root@Ubuntu32:/home/zhangbin/alex/codeStore/testCODE/testAUTOCONF/hello#
root@Ubuntu32:/home/zhangbin/alex/codeStore/testCODE/testAUTOCONF/hello#
root@Ubuntu32:/home/zhangbin/alex/codeStore/testCODE/testAUTOCONF/hello#
root@Ubuntu32:/home/zhangbin/alex/codeStore/testCODE/testAUTOCONF/hello#
root@Ubuntu32:/home/zhangbin/alex/codeStore/testCODE/testAUTOCONF/hello# automake --add-missing
configure.ac: error: no proper invocation of AM_INIT_AUTOMAKE was found.
configure.ac: You should verify that configure.ac invokes AM_INIT_AUTOMAKE,
configure.ac: that aclocal.m4 is present in the top-level directory,
configure.ac: and that aclocal.m4 was recently regenerated (using aclocal)
/usr/share/automake-1.14/am/depend2.am: error: am__fastdepCC does not appear in AM_CONDITIONAL
/usr/share/automake-1.14/am/depend2.am: The usual way to define 'am__fastdepCC' is to add 'AC_PROG_CC'
/usr/share/automake-1.14/am/depend2.am: to 'configure.ac' and run 'aclocal' and 'autoconf' again
/usr/share/automake-1.14/am/depend2.am: error: AMDEP does not appear in AM_CONDITIONAL
/usr/share/automake-1.14/am/depend2.am: The usual way to define 'AMDEP' is to add one of the compiler tests
/usr/share/automake-1.14/am/depend2.am: AC_PROG_CC, AC_PROG_CXX, AC_PROG_OBJC, AC_PROG_OBJCXX,
/usr/share/automake-1.14/am/depend2.am: AM_PROG_AS, AM_PROG_GCJ, AM_PROG_UPC
/usr/share/automake-1.14/am/depend2.am: to 'configure.ac' and run 'aclocal' and 'autoconf' again
root@Ubuntu32:/home/zhangbin/alex/codeStore/testCODE/testAUTOCONF/hello# aclocal
root@Ubuntu32:/home/zhangbin/alex/codeStore/testCODE/testAUTOCONF/hello#
root@Ubuntu32:/home/zhangbin/alex/codeStore/testCODE/testAUTOCONF/hello# autoheader
root@Ubuntu32:/home/zhangbin/alex/codeStore/testCODE/testAUTOCONF/hello# autoconf
root@Ubuntu32:/home/zhangbin/alex/codeStore/testCODE/testAUTOCONF/hello# ls
aclocal.m4 autoscan.log config.h.in~ configure.ac hello.c
autom4te.cache config.h.in configure depcomp Makefile.am
root@Ubuntu32:/home/zhangbin/alex/codeStore/testCODE/testAUTOCONF/hello# automake --add-missing
configure.ac:11: installing './compile'
configure.ac:6: installing './install-sh'
configure.ac:6: installing './missing'
root@Ubuntu32:/home/zhangbin/alex/codeStore/testCODE/testAUTOCONF/hello# ls
aclocal.m4 compile configure hello.c Makefile.in
autom4te.cache config.h.in configure.ac install-sh missing
autoscan.log config.h.in~ depcomp Makefile.am
root@Ubuntu32:/home/zhangbin/alex/codeStore/testCODE/testAUTOCONF/hello# ./configure --help
`configure' configures FULL-PACKAGE-NAME 1.0 to adapt to many kinds of systems.
Usage: ./configure [OPTION]... [VAR=VALUE]...
To assign environment variables (e.g., CC, CFLAGS...), specify them as
VAR=VALUE. See below for descriptions of some of the useful variables.
Defaults for the options are specified in brackets.
Configuration:
-h, --help display this help and exit
--help=short display options specific to this package
--help=recursive display the short help of all the included packages
-V, --version display version information and exit
-q, --quiet, --silent do not print `checking ...' messages
--cache-file=FILE cache test results in FILE [disabled]
-C, --config-cache alias for `--cache-file=config.cache'
-n, --no-create do not create output files
--srcdir=DIR find the sources in DIR [configure dir or `..']
Installation directories:
--prefix=PREFIX install architecture-independent files in PREFIX
[/usr/local]
--exec-prefix=EPREFIX install architecture-dependent files in EPREFIX
[PREFIX]
By default, `make install' will install all the files in
`/usr/local/bin', `/usr/local/lib' etc. You can specify
an installation prefix other than `/usr/local' using `--prefix',
for instance `--prefix=$HOME'.
For better control, use the options below.
Fine tuning of the installation directories:
--bindir=DIR user executables [EPREFIX/bin]
--sbindir=DIR system admin executables [EPREFIX/sbin]
--libexecdir=DIR program executables [EPREFIX/libexec]
--sysconfdir=DIR read-only single-machine data [PREFIX/etc]
--sharedstatedir=DIR modifiable architecture-independent data [PREFIX/com]
--localstatedir=DIR modifiable single-machine data [PREFIX/var]
--libdir=DIR object code libraries [EPREFIX/lib]
--includedir=DIR C header files [PREFIX/include]
--oldincludedir=DIR C header files for non-gcc [/usr/include]
--datarootdir=DIR read-only arch.-independent data root [PREFIX/share]
--datadir=DIR read-only architecture-independent data [DATAROOTDIR]
--infodir=DIR info documentation [DATAROOTDIR/info]
--localedir=DIR locale-dependent data [DATAROOTDIR/locale]
--mandir=DIR man documentation [DATAROOTDIR/man]
--docdir=DIR documentation root
[DATAROOTDIR/doc/full-package-name]
--htmldir=DIR html documentation [DOCDIR]
--dvidir=DIR dvi documentation [DOCDIR]
--pdfdir=DIR pdf documentation [DOCDIR]
--psdir=DIR ps documentation [DOCDIR]
Program names:
--program-prefix=PREFIX prepend PREFIX to installed program names
--program-suffix=SUFFIX append SUFFIX to installed program names
--program-transform-name=PROGRAM run sed PROGRAM on installed program names
Optional Features:
--disable-option-checking ignore unrecognized --enable/--with options
--disable-FEATURE do not include FEATURE (same as --enable-FEATURE=no)
--enable-FEATURE[=ARG] include FEATURE [ARG=yes]
--enable-silent-rules less verbose build output (undo: "make V=1")
--disable-silent-rules verbose build output (undo: "make V=0")
--enable-dependency-tracking
do not reject slow dependency extractors
--disable-dependency-tracking
speeds up one-time build
Some influential environment variables:
CC C compiler command
CFLAGS C compiler flags
LDFLAGS linker flags, e.g. -L<lib dir> if you have libraries in a
nonstandard directory <lib dir>
LIBS libraries to pass to the linker, e.g. -l<library>
CPPFLAGS (Objective) C/C++ preprocessor flags, e.g. -I<include dir> if
you have headers in a nonstandard directory <include dir>
CPP C preprocessor
Use these variables to override the choices made by `configure' or to help
it to find libraries and programs with nonstandard names/locations.
Report bugs to <zhangbin@163.com>.
root@Ubuntu32:/home/zhangbin/alex/codeStore/testCODE/testAUTOCONF/hello# ls
aclocal.m4 compile configure hello.c Makefile.in
autom4te.cache config.h.in configure.ac install-sh missing
autoscan.log config.h.in~ depcomp Makefile.am
root@Ubuntu32:/home/zhangbin/alex/codeStore/testCODE/testAUTOCONF/hello# ./configure
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... /bin/mkdir -p
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
checking whether make supports nested variables... yes
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking whether gcc understands -c and -o together... yes
checking for style of include used by make... GNU
checking dependency style of gcc... gcc3
checking how to run the C preprocessor... gcc -E
checking for grep that handles long lines and -e... /bin/grep
checking for egrep... /bin/grep -E
checking for ANSI C header files... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking for stdlib.h... (cached) yes
checking that generated files are newer than configure... done
configure: creating ./config.status
config.status: creating Makefile
config.status: creating config.h
config.status: executing depfiles commands
root@Ubuntu32:/home/zhangbin/alex/codeStore/testCODE/testAUTOCONF/hello# make
make all-am
make[1]: 正在进入目录 `/home/zhangbin/alex/codeStore/testCODE/testAUTOCONF/hello'
gcc -DHAVE_CONFIG_H -I. -g -O2 -MT hello.o -MD -MP -MF .deps/hello.Tpo -c -o hello.o hello.c
mv -f .deps/hello.Tpo .deps/hello.Po
gcc -g -O2 -o helloworld hello.o
make[1]:正在离开目录 `/home/zhangbin/alex/codeStore/testCODE/testAUTOCONF/hello'
root@Ubuntu32:/home/zhangbin/alex/codeStore/testCODE/testAUTOCONF/hello# ls
aclocal.m4 config.h config.status hello.c Makefile stamp-h1
autom4te.cache config.h.in configure hello.o Makefile.am
autoscan.log config.h.in~ configure.ac helloworld Makefile.in
compile config.log depcomp install-sh missing
root@Ubuntu32:/home/zhangbin/alex/codeStore/testCODE/testAUTOCONF/hello# 塔机配件大全