TFTP自动生成Makefile

autoconf和automake是可以自动生成符合GNU自由软件惯例的./configure和Makefile文件。

Makefile :目标,依赖,命令;

root@liujie-desktop:/software/tftp-1.0# vim Makefile 
root@liujie-desktop:/software/tftp-1.0# cat Makefile 

CC = gcc
CFLAGS = -Wall

all: tftpc tftpd

tftpc: tftpc.c
	$(CC) $(CFLAGS) -o tftpc tftpc.c

tftpd: tftpd.c
	$(CC) $(CFLAGS) -o tftpd tftpd.c

clean:
	rm -f tftpd tftpc

strip:
	strip tftpd tftpc

make:根据Makefile文件编译链接生成目标文件;

make clean:清除生成的*.o 和二进制执行文件;

make install :将编译成功的可执行文件安装到系统目录;

make uninstall:从系统目录删除;

make dist:产生发布文件*.tar.gz,AM_INIT_AUTOMAKE(PACKAGE, VERSION);

make distcheck:生成发布文件并对其进行测试检查;

make distclean:将生成的./confirgure 和Makefile文件及生成的其他文件删除。


 安装autoconf 

root@liujie-desktop:/tftp-1.1# apt-get -y install autoconf

利用autoscan 生成configure.

root@liujie-desktop:/tftp-1.1# ls
tftpc.c  tftpd.c  tftp.h
root@liujie-desktop:/tftp-1.1# autoscan
root@liujie-desktop:/tftp-1.1# ls
autoscan.log  configure.scan  tftpc.c  tftpd.c  tftp.h

将configure.scan 改名为configure.in

root@liujie-desktop:/autoconftest# cat configure.in 
AC_INIT(tftp.h)
AM_INIT_AUTOMAKE(tftp, 1.1)
# 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)

利用aclocal 生成aclocal.m4

root@liujie-desktop:/tftp-1.1# aclocal
root@liujie-desktop:/tftp-1.1# ls
aclocal.m4  autom4te.cache  autoscan.log  configure.in  tftpc.c  tftpd.c  tftp.h
root@liujie-desktop:/tftp-1.1# autoconf
root@liujie-desktop:/tftp-1.1# ls
aclocal.m4      autoscan.log  configure.in  tftpd.c
autom4te.cache  configure     tftpc.c       tftp.h

新建Makefile.am 添加

root@liujie-desktop:/autoconftest# vim Makefile.am 
root@liujie-desktop:/autoconftest# cat Makefile.am 
AUTOMAKE_OPTIONS=foreign
bin_PROGRAMS=tftpd tftpc
tftpd_SOURCES=tftpd.c tftp.h
#bin_PROGRAMS=tftpc
tftpc_SOURCES=tftpc.c tftp.h

运行automake

root@liujie-desktop:/tftp-1.1# automake --add-missing
configure.in:2: installing `./install-sh'
configure.in:2: installing `./missing'
Makefile.am: installing `./depcomp'
root@liujie-desktop:/tftp-1.1# ls
aclocal.m4      autoscan.log  configure.in  install-sh   Makefile.in  tftpc.c  tftp.h
autom4te.cache  configure     depcomp       Makefile.am  missing      tftpd.c

执行./configure

root@liujie-desktop:/tftp-1.1# ./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 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 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: executing depfiles commands
root@liujie-desktop:/tftp-1.1# ls
aclocal.m4      config.log     configure.in  Makefile     missing  tftp.h
autom4te.cache  config.status  depcomp       Makefile.am  tftpc.c
autoscan.log    configure      install-sh    Makefile.in  tftpd.c

执行make

root@liujie-desktop:/tftp-1.1# make
gcc -DPACKAGE_NAME=\"\" -DPACKAGE_TARNAME=\"\" -DPACKAGE_VERSION=\"\" -DPACKAGE_STRING=\"\" -DPACKAGE_BUGREPORT=\"\" -DPACKAGE_URL=\"\" -DPACKAGE=\"tftp\" -DVERSION=\"1.1\" -I.     -g -O2 -MT tftpd.o -MD -MP -MF .deps/tftpd.Tpo -c -o tftpd.o tftpd.c
mv -f .deps/tftpd.Tpo .deps/tftpd.Po
gcc  -g -O2   -o tftpd tftpd.o  
gcc -DPACKAGE_NAME=\"\" -DPACKAGE_TARNAME=\"\" -DPACKAGE_VERSION=\"\" -DPACKAGE_STRING=\"\" -DPACKAGE_BUGREPORT=\"\" -DPACKAGE_URL=\"\" -DPACKAGE=\"tftp\" -DVERSION=\"1.1\" -I.     -g -O2 -MT tftpc.o -MD -MP -MF .deps/tftpc.Tpo -c -o tftpc.o tftpc.c
mv -f .deps/tftpc.Tpo .deps/tftpc.Po
gcc  -g -O2   -o tftpc tftpc.o  

执行make dist打包

root@liujie-desktop:/tftp-1.1# ls
aclocal.m4      config.status  install-sh   missing          tftpc.o  tftp.h
autom4te.cache  configure      Makefile     tftp-1.1.tar.gz  tftpd
autoscan.log    configure.in   Makefile.am  tftpc            tftpd.c
config.log      depcomp        Makefile.in  tftpc.c          tftpd.o

1. autoscan
  autoscan是 用来扫描源代码目录生成configure.scan文件的 .autoscan
可以用目录名做为参数,但如果你不使用参数的 话,那么autoscan将认为使用的是当前目录.
autoscan将扫描你所指定目录中的 源文件,并创建configure.scan文件.
2. configure.scan
  configure.scan包含了系统配置的 基本选项,里面都是 一些宏定义.我们需要将它改名为
configure.in
  3. aclocal
  aclocal是 一个perl 脚本程序.aclocal根据configure.in文件的 内容
,自动生成aclocal.m4文件.aclocal的 定义是 :"aclocal - create
aclocal.m4 by scanning configure.ac".
  4. autoconf
  autoconf是 用来产生configure文件的 .configure是 一个脚本,它能设置
源程序来适应各种不同的操作系统平台,并且根据不同的 系统来产生合适的 Makefile,从而可以使
你的源代码能在不同的操作系统平台上被编译出来.
  configure.in文件的 内容是 一些宏,这些宏经过autoconf 处理后会变成检查系统
特性.环境变量.软件必须的 参数的 shell脚本.configure.in文件中的 宏的 顺序并没
有规定,但是 你必须在 所有宏的 最前面和最后面分别加上AC_INIT宏和AC_OUTPUT宏.
  在 configure.ini中:
  #号表示注释,这个宏后面的 内容将被忽略.
  AC_INIT(FILE)
  这个宏用来检查源代码所在 的 路径.
AM_INIT_AUTOMAKE(PACKAGE, VERSION)
   这个宏是 必须的 ,它描述了我们将要生成的 软件包的 名字及其版本号:PACKAGE是软件包
的名字,VERSION是 版本号.当你使用make dist命令时,它会给你生成一个类似
helloworld-1.0.tar.gz的 软件发行包,其中就有对应的 软件包的 名字和版本号.
AC_PROG_CC
  这个宏将检查系统所用的 C编译器.
AC_OUTPUT(FILE)
  这个宏是 我们要输出的 Makefile的 名字.
  我们在 使用automake时,实际上还需要用到其他的 一些宏,但我们可以用aclocal 来帮
我们自动产生.执行aclocal后我们会得到aclocal.m4文件.
  产生了configure.in和aclocal.m4 两个宏文件后,我们就可以使用autocon
f来产生configure文件了.
  5. Makefile.am
  Makefile.am是 用来生成Makefile.in的 ,需要你手工书写.Makefile.
am中定义了一些内容:
AUTOMAKE_OPTIONS
  这个是 automake的 选项.在 执行automake时,它会检查目录下是 否存在 标准
GNU软件包中应具备的各种文件,例如AUTHORS.ChangeLog.NEWS等文件.
我们将其设置成foreign时,automake会改用一般软件包的 标准来检查.
bin_PROGRAMS
  这个是 指定我们所要产生的 可执行文件的 文件名.如果你要产生多个可执行文件,
那么在各个名字间用空格隔开.
helloworld_SOURCES
  这个是 指定产生"helloworld"时所需要的 源代码.如果它用到了多个源文件,
那么请使用空格符号将它们隔开.比如需要helloworld.h,helloworld.c那么请写成:
helloworld_SOURCES= helloworld.h helloworld.c.
  如果你在 bin_PROGRAMS定义了多个可执行文件,则对应每个可执行文件都要定义相对的
filename_SOURCES.
  6. automake
  我们使用automake --add-missing来产生Makefile.in.
  选项--add-missing的 定义是 "add missing standard files
 to package",它会让automake加入一个标准的 软件包所必须的 一些文件.
  我们用automake产生出来的 Makefile.in文件是 符合GNU Makefile惯例
的 ,接下来我们只要执行configure这个shell 脚本就可以产生合适的 Makefile 文
件了.
  7. Makefile
  在 符合GNU Makefiel惯例的 Makefile中,包含了一些基本的 预先定义的 操作:



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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值