Chinaunix首页 | 论坛 | 博客
  • 博客访问: 114335
  • 博文数量: 31
  • 博客积分: 781
  • 博客等级: 军士长
  • 技术积分: 350
  • 用 户 组: 普通用户
  • 注册时间: 2011-03-30 16:52
文章分类

全部博文(31)

文章存档

2014年(1)

2012年(9)

2011年(21)

分类: C/C++

2012-08-10 15:01:00

自动化管理工具GNU make
#a simple Makefile
hello: hello.c
 gcc hello.c -o hello
使用变量替换
OBJ=hello
DEPENDENCES=hello.c
CCFLAGS=-o
$(OBJ): $(DEPENDENCES)
 gcc $(DEPENDENCES) $(CCFLAGS) $(OBJ)

预定义的变量
$@   目标文件的名称
$^   所有的依赖文件
$<   第一个依赖文件
CC   C编译器的名称,默认值为cc
CCFLAGS  C编译器的选项

常见的目标
#make for example
example:example.o add.o modify.o delete.o
 $(cc) -o $@ $^
.c.o:
 $(cc) -c $<
all:example
clean:all
 rm -f *.o
install: clean
 cp example /usr/local/bin


automake 自动生成makefile
1)在源代目录生成configure.in的模板文件
$autoscan   //生成configure.scan,作为configure.in的蓝本
$mv configure.scan configure.in
$vi configure.in
//此文件内容必须有两个宏
AC_INIT(unique_file_in_source_dir)
AC_OUTPUT(makefile)
注:autoconf是用来生成自动配置软件源代码脚本的工具,configure能独立于autoconf运行
# Process this file with autoconf to produce a configure scrīpt.
AC_INIT(helloworld.c)
AM_INIT_AUTOMAKE(helloworld, 1.0)
#AC_CONFIG_HEADER([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(Makefile)
2)执行命令aclocal和autoconf
$aclocal  //产生aclocal.m4
$autoconf  //产生configure
//aclocal根据configure.in内容生成aclocal.m4文件,进而告诉autoconf找到所用的宏,aclocal是一个perl脚本程序"aclocal - create aclocal.m4 by scanning configure.ac"
//autoconf从configure.in列举的编译软件时所需各种参数的模板文件中创建configure。autoconf需要GNU m4宏处理器来处理aclocal.m4,生成configure脚本。m4是一个宏处理器。将输入拷贝到输出,同时将宏展开。m4既可以作为编译器的前端,也可以单独作为一个宏处理器。

3)新建makefile.am
$vi makefile.am
AUTOMAKE_OPTIONS=foreign
bin_PROGRAMS=helloworld
helloworld_SOURCES=helloworld.c
//automake会根据所写的makefile.am来自动生成makefile.in

4)运行automake命令
$automake --add-missing
//根据makefile.am文件产生一些文件,包括makefile.in

5)执行configure生成makefile
$./configure

6)编译代码
$make

autoconf这个工具用来生成configure脚本,分析你的系统以找到合适的工具使用
automake 这个工具用来生成makefile相关文件,它需要使用autoconf提供的信息,如autoconf检测到你的系统使用“gcc”

cmake 跨平台的安装(编译)工具,能够输出各种各样的makefile或者project文件,能测试编译器所支持的C++
1、手工编写makefile.am
2、运行autoscan,修改configure.scan为configure.in
3、运行aclocal,根据configure.in的内容生成aclocal.m4文件
4、运行autoconf,根据configure.in和aclcoal.m4生成configure
5、运行automake --add-missing,根据Makefile.am生成makefile.in
6、运行configure,根据makefile.in的内容生成makefile文件

注:类似地自动管理工具cmake

自动生成makefile的流程图

阅读(1451) | 评论(0) | 转发(0) |
0

上一篇:RCS vs CVS

下一篇:ctags && cscope

给主人留下些什么吧!~~