autotools是个系列工具,首先确认你的Ubuntu系统是否安装了以下工具(可以通过which命令查看):
aclocal
autoscan
autoconf
autoheader
automake
---------------------------------------------------------------------------------
安装方法:
[email protected]:~$ sudo apt-get install autoconf
装完后,用which 命令查看
如下:
[email protected]:~$ which aclocal
/usr/bin/aclocal
[email protected]:~$ which autoscan
/usr/bin/autoscan
[email protected]:~$ which autoconf
/usr/bin/autoconf
[email protected]:~$ which auto header
[email protected]:~$ automake
automake: `configure.ac‘ or `configure.in‘ is required
[email protected]:~$ which automake
/usr/bin/automake
------------------------------------------------------------------------------
下面开始来生成一个Makefile:
建立以下代码文件:
hello.cxx hello.h
以下直接贴出我的操作过程:
[email protected]:~/work/test$ autoscan
[email protected]:~/work/test$ ls
autoscan.log configure.scan hello.cxx hello.h
[email protected]:~/work/test$ mv configure.scan configure.ac
[email protected]:~/work/test$ ls
autoscan.log configure.ac hello.cxx hello.h
[email protected]:~/work/test$ gedit configure.ac
[email protected]:~/work/test$ aclocal
[email protected]:~/work/test$ ls
aclocal.m4 autoscan.log configure.ac~ hello.h
autom4te.cache configure.ac hello.cxx
[email protected]:~/work/test$ autoconf
[email protected]:~/work/test$ ls
aclocal.m4 autoscan.log configure.ac hello.cxx
autom4te.cache configure configure.ac~ hello.h
[email protected]:~/work/test$ autoheader
[email protected]:~/work/test$ ls
aclocal.m4 autoscan.log configure configure.ac~ hello.h
autom4te.cache config.h.in configure.ac hello.cxx
[email protected]:~/work/test$ touch makefile.am
[email protected]:~/work/test$ gedit makefile.am
[email protected]:~/work/test$ automake -a
configure.ac:6: installing `./install-sh‘
configure.ac:6: installing `./missing‘
makefile.am: installing `./depcomp‘
[email protected]:~/work/test$ ls
aclocal.m4 config.h.in configure.ac~ hello.h makefile.am~
autom4te.cache configure depcomp install-sh makefile.in
autoscan.log configure.ac hello.cxx makefile.am missing
[email protected]:~/work/test$ ./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... no
checking for mawk... mawk
checking whether make sets $(MAKE)... yes
checking for g++... g++
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 g++ accepts -g... yes
checking for style of include used by make... GNU
checking dependency style of g++... gcc3
checking for gcc... gcc
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 dependency style of gcc... gcc3
configure: creating ./config.status
config.status: creating makefile
config.status: creating config.h
config.status: executing depfiles commands
[email protected]:~/work/test$ make hello
g++ -DHAVE_CONFIG_H -I. -g -O2 -MT hello.o -MD -MP -MF .deps/hello.Tpo -c -o hello.o hello.cxx
mv -f .deps/hello.Tpo .deps/hello.Po
g++ -g -O2 -o hello hello.o
[email protected]:~/work/test$
其中:
[email protected]:~/work/test$ gedit configure.ac编辑configure.ac内容为
# -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.
AC_PREREQ([2.68])
AC_INIT(hello,1.0)
AM_INIT_AUTOMAKE(hello,1.0)
AC_CONFIG_SRCDIR([hello.cxx])
AC_CONFIG_HEADERS([config.h])
# Checks for programs.
AC_PROG_CXX
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
[email protected]:~/work/test$ gedit makefile.am编辑makefile.am的内容为:
AUTOMAKE_OPTIONS=foreign
bin_PROGRAMS=hello
hello_SOURCES=hello.cxx
最后的执行.configure我们得到了makefile文件,使用make命令就输出了可执行文件hello