autoscan,aclocal,autoheader,automake,autoconf,make

简介:下面的例子是在 linux下创建的一个包含多个源文件的c语言项目,其中基本用到了整个autotools自动化工具链(autoscan,aclocal,autoheader,automake,autoconf,make)。如果读者要制作符合GNU标准的开源项目,这是一个很好的开始。
$ mkdir 1
$ cd 1
$ touch main.c plus.c plus.h minus.c minus.h
$ cat >main.c
#include <stdio.h>
#include "plus.h"
#include "minus.h"

int main(int argc, char **argv)
{
	int i0, i1, i2, i3;

	i0 = 3;
	i1 = 2;

	i2 = plus(i0, i1);
	i3 = minus(i0, i1);

	printf("%d plus %d equal to %d\n", i0, i1, i2);
	printf("%d minus %d equal to %d\n", i0, i1, i3);

	return 0;
}
$ cat >plus.c
int plus(int i0, int i1)
{
	return i0 + i1;
}
$ cat >plus.h
int plus(int i0, int i1);
$ cat >minus.c
int minus(int i0, int i1)
{
	return i0 - i1;
}
$ cat >minus.h
int minus(int i0, int i1);
$ autoscan
$ mv configure.scan configure.ac

/////////////////////////////////////////////////
// 在 configure.ac 里面增加两个宏
// AC_CONFIG_FILES([Makefile])
// AM_INIT_AUTOMAKE
// 将 AC_INIT 的值改成下面的形式
// AC_INIT(myprogram, 1.0, [email protected])
/////////////////////////////////////////////////
$ vi configure.ac
$ cat >Makefile.am
bin_PROGRAMS = myprogram
myprogram_SOURCES = main.c plus.c plus.h minus.c minus.h
$ aclocal
$ touch NEWS AUTHORS README ChangeLog
$ autoheader
$ automake --add-missing
$ autoconf
$ ./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 for gcc... gcc
checking for C compiler default output file name... a.out
checking whether the C compiler works... yes
checking whether we are cross compiling... no
checking for suffix of executables...
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 for style of include used by make... GNU
checking dependency style of gcc... gcc3
configure: creating ./config.status
config.status: creating Makefile
config.status: creating config.h
config.status: executing depfiles commands
$ make
make  all-am
make[1]: Entering directory `/home/nbz/1‘
gcc -DHAVE_CONFIG_H -I.     -g -O2 -MT main.o -MD -MP -MF .deps/main.Tpo -c -o main.o main.c
mv -f .deps/main.Tpo .deps/main.Po
gcc -DHAVE_CONFIG_H -I.     -g -O2 -MT plus.o -MD -MP -MF .deps/plus.Tpo -c -o plus.o plus.c
mv -f .deps/plus.Tpo .deps/plus.Po
gcc -DHAVE_CONFIG_H -I.     -g -O2 -MT minus.o -MD -MP -MF .deps/minus.Tpo -c -o minus.o minus.c
mv -f .deps/minus.Tpo .deps/minus.Po
gcc  -g -O2   -o myprogram main.o plus.o minus.o
make[1]: Leaving directory `/home/nbz/1‘
$ ls
aclocal.m4      autoscan.log  config.h.in    configure     depcomp     main.c
AUTHORS         ChangeLog     config.log     configure.ac  INSTALL     main.o
autom4te.cache  config.h      config.status  COPYING       install-sh  Makefile
$ ./myprogram
3 plus 2 equal to 5
3 minus 2 equal to 1
$ make dist
{ test ! -d "myprogram-1.0" || { find "myprogram-1.0" -type d ! -perm -200 -exec chmod u+w {} ‘;‘ && rm -fr "myprogram-1.0"; }; }
test -d "myprogram-1.0" || mkdir "myprogram-1.0"
test -n "" 	|| find "myprogram-1.0" -type d ! -perm -755 		-exec chmod u+rwx,go+rx {} \; -o 	  ! -type d ! -perm -444 -links 1 -exec chmod a+r {} \; -o 	  ! -type d ! -perm -400 -exec chmod a+r {} \; -o 	  ! -type d ! -perm -444 -exec /bin/sh /home/nbz/1/install-sh -c -m a+r {} {} \; 	|| chmod -R a+r "myprogram-1.0"
tardir=myprogram-1.0 && /bin/sh /home/nbz/1/missing --run tar chof - "$tardir" | GZIP=--best gzip -c >myprogram-1.0.tar.gz
{ test ! -d "myprogram-1.0" || { find "myprogram-1.0" -type d ! -perm -200 -exec chmod u+w {} ‘;‘ && rm -fr "myprogram-1.0"; }; }
$ ls
aclocal.m4      ChangeLog    config.status  depcomp     main.o       minus.c  myprogram             plus.h
AUTHORS         config.h     configure      INSTALL     Makefile     minus.h  myprogram-1.0.tar.gz  plus.o
autom4te.cache  config.h.in  configure.ac   install-sh  Makefile.am  minus.o  NEWS                  README
autoscan.log    config.log   COPYING        main.c      Makefile.in  missing  plus.c                stamp-h1
$ make dist-zip
{ test ! -d "myprogram-1.0" || { find "myprogram-1.0" -type d ! -perm -200 -exec chmod u+w {} ‘;‘ && rm -fr "myprogram-1.0"; }; }
test -d "myprogram-1.0" || mkdir "myprogram-1.0"
test -n "" 	|| find "myprogram-1.0" -type d ! -perm -755 		-exec chmod u+rwx,go+rx {} \; -o 	  ! -type d ! -perm -444 -links 1 -exec chmod a+r {} \; -o 	  ! -type d ! -perm -400 -exec chmod a+r {} \; -o 	  ! -type d ! -perm -444 -exec /bin/sh /home/nbz/1/install-sh -c -m a+r {} {} \; 	|| chmod -R a+r "myprogram-1.0"
rm -f myprogram-1.0.zip
zip -rq myprogram-1.0.zip myprogram-1.0
{ test ! -d "myprogram-1.0" || { find "myprogram-1.0" -type d ! -perm -200 -exec chmod u+w {} ‘;‘ && rm -fr "myprogram-1.0"; }; }
$ ls
aclocal.m4      ChangeLog    config.status  depcomp     main.o       minus.c  myprogram             plus.c  stamp-h1
AUTHORS         config.h     configure      INSTALL     Makefile     minus.h  myprogram-1.0.tar.gz  plus.h
autom4te.cache  config.h.in  configure.ac   install-sh  Makefile.am  minus.o  myprogram-1.0.zip     plus.o
autoscan.log    config.log   COPYING        main.c      Makefile.in  missing  NEWS                  README
$
时间: 2024-08-01 12:14:00

autoscan,aclocal,autoheader,automake,autoconf,make的相关文章

autoscan; aclocal; autoconf; automake --add-missing; ./configure; make

1.autoscan 在源码目录下执行autoscan,生成configure.scan,重命名为configure.in或者configure.ac,然后编辑文件内容: ===============configure.in内容开始===================== # -*- Autoconf -*- # Process this file with autoconf to produce a configure script. AC_INIT(helloworld, 1.0, **

大型项目使用Automake/Autoconf完成编译配置

使用过开源C/C++项目的同学们都知道,标准的编译过程已经变成了简单的三部曲:configure/make/make install, 使用起来很方便,不像平时自己写代码,要手写一堆复杂的Makefile,而且换个编译环境,Makefile还需要修改(Eclipse也是这样). 这么好的东东当然要拿来用了,但GNU的Autotool系列博大精深,工具数量又多,涉及的语言也多,要是自己从头看到尾,黄花菜都凉了,项目估计早就结束了:上网搜样例倒是有一大堆,但都是“hello world”的样例,离真

大型项目使用Automake/Autoconf完成编译配置(标准的编译过程已经变成了简单的三部曲:configure/make/make install,)

使用过开源C/C++项目的同学们都知道,标准的编译过程已经变成了简单的三部曲:configure/make/make install, 使用起来很方便,不像平时自己写代码,要手写一堆复杂的Makefile,而且换个编译环境,Makefile还需要修改(Eclipse也是这样). 这么好的东东当然要拿来用了,但GNU的Autotool系列博大精深,工具数量又多,涉及的语言也多,要是自己从头看到尾,黄花菜都凉了,项目估计早就结束了:上网搜样例倒是有一大堆,但都是“hello world”的样例,离真

automake/autoconf的简单例子

项目一 helloworld 整个基础上仅有一个helloworld.c文件,功能也非常简单,只是向屏蔽输出一句hello. 新建一个helloworld目录,然后在里面新建一个文件helloworld.c,内容为: #include <stdio.h> int main(int argc, char **agrv) { printf("Hello, Merlin\n"); return 0; } 执行命令autoscan生成一个架构configure.scan,将其重新命

automake,autoconf使用详解

作为Linux下的程序开发人员,大家一定都遇到过Makefile,用make命令来编译自己写的程序确实是很方便.一般情况下,大家都是手工写一个简单Makefile,如果要想写出一个符合自由软件惯例的Makefile就不那么容易了. 在本文中,将给大家介绍如何使用autoconf和automake两个工具来帮助我们自动地生成符合自由软件惯例的 Makefile,这样就可以象常见的 GNU程序一样,只要使用”./configure”,”make”,”make instal”就可以把程序安装到Linu

gcc automake autoconf m4

http://ftp.gnu.org/gnu/gcc/ http://ftp.gnu.org/gnu/automake/ http://ftp.gnu.org/gnu/autoconf/ http://ftp.gnu.org/gnu/m4/

MAC下安装automake autoconf工具

I noticed today that while Mac OS 10.6 (specifically, 10.6.2) comes with automake and autoconf, the versions are a little bit dated. Normally I wouldn’t care, but I ran into an issue when trying to generate a portable distribution using those tools o

工程管理之makefile与自动创建makefile文件过程

(风雪之隅 http://www.laruence.com/2009/11/18/1154.html) Linux Makefile自动编译和链接使用的环境 想知道到Linux Makefile系统的真相么,想知道Linux Makefile系统中藏有的内在奥义么,只有我来给大家全面讲解介绍Linux Makefile系统作为Linux下的程序开发人员,大家一定都遇到过Linux Makefile,用make命令来编译自己写的程序确实是很方便.一般情况下,大家都是手工写一个简单Linux Mak

C/C++ makefile自动生成工具(comake2,autotools,linux),希望能为开源做点微薄的贡献!

序 在linux下C或C++项目开发,Makefile是必备的力气,但是发现手写很麻烦. 在百度有个comake2工具,用于自动生成Makefile工具,而在外边本想找一个同类工具,但发现很难做到,只发现有个类似的智能生成工具autotools,但是操作比较麻烦,奔着“一人学习,大家共享”的原则,手动写了一个工具类,帮助自己和大家生成现成的c或者cpp框架. 代码比较简单,希望我们能一起改善下. git路径:https://github.com/chuanshanjia/ccpp/blob/ma