码迷,mamicode.com
首页 > 其他好文 > 详细

Makefile自动生成(autotools工具的使用)

时间:2015-04-25 01:42:13      阅读:216      评论:0      收藏:0      [点我收藏+]

标签:makefile autotool 自动

autotools是个系列工具,首先确认你的Ubuntu系统是否安装了以下工具(可以通过which命令查看):

aclocal
autoscan
autoconf
autoheader

automake

---------------------------------------------------------------------------------


安装方法:

lin@lenovo:~$ sudo apt-get install autoconf

装完后,用which 命令查看

如下:
lin@lenovo:~$ which aclocal
/usr/bin/aclocal
lin@lenovo:~$ which autoscan
/usr/bin/autoscan
lin@lenovo:~$ which autoconf
/usr/bin/autoconf
lin@lenovo:~$ which auto header
lin@lenovo:~$ automake
automake: `configure.ac‘ or `configure.in‘ is required
lin@lenovo:~$ which automake
/usr/bin/automake

------------------------------------------------------------------------------

下面开始来生成一个Makefile:

建立以下代码文件:

hello.cxx  hello.h

以下直接贴出我的操作过程:

weijl@weijl-virtual-machine:~/work/test$ autoscan
weijl@weijl-virtual-machine:~/work/test$ ls
autoscan.log  configure.scan  hello.cxx  hello.h
weijl@weijl-virtual-machine:~/work/test$ mv configure.scan configure.ac
weijl@weijl-virtual-machine:~/work/test$ ls
autoscan.log  configure.ac  hello.cxx  hello.h
weijl@weijl-virtual-machine:~/work/test$ gedit configure.ac
weijl@weijl-virtual-machine:~/work/test$ aclocal
weijl@weijl-virtual-machine:~/work/test$ ls
aclocal.m4      autoscan.log  configure.ac~  hello.h
autom4te.cache  configure.ac  hello.cxx
weijl@weijl-virtual-machine:~/work/test$ autoconf
weijl@weijl-virtual-machine:~/work/test$ ls
aclocal.m4      autoscan.log  configure.ac   hello.cxx
autom4te.cache  configure     configure.ac~  hello.h
weijl@weijl-virtual-machine:~/work/test$ autoheader
weijl@weijl-virtual-machine:~/work/test$ ls
aclocal.m4      autoscan.log  configure     configure.ac~  hello.h
autom4te.cache  config.h.in   configure.ac  hello.cxx
weijl@weijl-virtual-machine:~/work/test$ touch makefile.am
weijl@weijl-virtual-machine:~/work/test$ gedit makefile.am
weijl@weijl-virtual-machine:~/work/test$ automake -a
configure.ac:6: installing `./install-sh‘
configure.ac:6: installing `./missing‘
makefile.am: installing `./depcomp‘
weijl@weijl-virtual-machine:~/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
weijl@weijl-virtual-machine:~/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
weijl@weijl-virtual-machine:~/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  
weijl@weijl-virtual-machine:~/work/test$ 

其中:

weijl@weijl-virtual-machine:~/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

weijl@weijl-virtual-machine:~/work/test$ gedit makefile.am编辑makefile.am的内容为:

AUTOMAKE_OPTIONS=foreign
bin_PROGRAMS=hello
hello_SOURCES=hello.cxx

最后的执行.configure我们得到了makefile文件,使用make命令就输出了可执行文件hello

Makefile自动生成(autotools工具的使用)

标签:makefile autotool 自动

原文地址:http://blog.csdn.net/lclwjl/article/details/45259549

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!