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, support@qq.com)
/
$ 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
$ 

		


  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值