Linux下自动生成makefile文件

初始环境

-bash-3.2# ll

total 48

lrwxrwxrwx 1 root root    18 Sep 24 09:33 libMsuDecoder.a -> libMsuDecoder_64.a

-rw-r--r-- 1 root root 14320 Sep 24 09:29 libMsuDecoder_32.a

-rw-r--r-- 1 root root 19872 Sep 24 09:29 libMsuDecoder_64.a

-rw-r--r-- 1 root root  1304 Sep 24 09:29 msu_decoder.h

-rw-r--r-- 1 root root  4654 Sep 24 09:29 test_decoder.c
 


自动生成步骤

1.      执行autoscan命令

执行autoscan命令后,生成autoscan.logconfigure.scan两个文件,其中configure.scan文件内容如下:

 

-bash-3.2# more configure.scan

#                                               -*- Autoconf -*-

# Process this file with autoconf to produce a configure script.

 

AC_PREREQ(2.59)

AC_INIT(FULL-PACKAGE-NAME, VERSION, BUG-REPORT-ADDRESS)

AC_CONFIG_SRCDIR([test_decoder.c])

AC_CONFIG_HEADER([config.h])

 

# Checks for programs.

AC_PROG_CC

 

# Checks for libraries.

 

# Checks for header files.

AC_HEADER_STDC

AC_CHECK_HEADERS([fcntl.h stdlib.h string.h sys/socket.h unistd.h])

 

# Checks for typedefs, structures, and compiler characteristics.

AC_C_CONST

AC_HEADER_TIME

 

# Checks for library functions.

AC_FUNC_SELECT_ARGTYPES

AC_CHECK_FUNCS([memset select])

AC_OUTPUT

-bash-3.2#


其中:

  • AC_PREREQ指定autoconf版本,确保使用的是足够新的Autoconf版本。如果用于创建configureAutoconf的版本比version要早,就在标准错误输出打印一条错误消息并不会创建configure
  • AC_INIT初始化,定义软件的基本信息,包括设置包的全称,版本号以及报告BUG时需要用的邮箱地址
  • AC_CONFIG_SRCDIR用来侦测所指定的源码文件是否存在,来确定源码目录的有效性
  • AC_CONFIG_HEADER用于生成config.h文件,以便autoheader使用

 

将生成的configure.scan改名为configure.in,并修改其内容,修改结果如下:

-bash-3.2# more configure.in

#                                               -*- Autoconf -*-

# Process this file with autoconf to produce a configure script.

 

AC_PREREQ(2.59)

AC_INIT(test_decoder, 1.0, whizchen@csdn.net)

AC_CONFIG_SRCDIR([test_decoder.c])

AC_CONFIG_HEADER([config.h])

AM_INIT_AUTOMAKE(test_decoder,1.0)

 

 

 

# Checks for programs.

AC_PROG_CC

 

# Checks for libraries.

 

# Checks for header files.

AC_HEADER_STDC

AC_CHECK_HEADERS([fcntl.h stdlib.h string.h sys/socket.h unistd.h])

 

# Checks for typedefs, structures, and compiler characteristics.

AC_C_CONST

AC_HEADER_TIME

 

# Checks for library functions.

AC_FUNC_SELECT_ARGTYPES

AC_CHECK_FUNCS([memset select])

AC_OUTPUT([Makefile])

 

修改动作:

  • 修改AC_INIT里面的参数: AC_INIT(test_decoder, 1.0, whizchen@csdn.net)
  • 添加宏AM_INIT_AUTOMAKE,它是automake所必备的宏,也同前面一样,PACKAGE是所要产生软件套件的名称,VERSION是版本编号。
  • AC_OUTPUT后添加输出文件Makefile

 

2.      执行aclocal命令

运行aclocal生成一个“aclocal.m4”文件和一个缓冲文件夹autom4te.cache,该文件主要处理本地的宏定义

 

3.      执行autoconf命令

运行autoconf,生成configure文件

 

4.      执行autoheader命令

运行 autoheader,它负责生成config.h.in文件。该工具通常会从“acconfig.h”文件中复制用户附加的符号定义,因此此处没有附加符号定义,所以不需要创建“acconfig.h”文件

 

5.      创建Makefile.am文件

创建一个 Makefile.am.这一步是创建Makefile很重要的一步,automake要用的脚本配置文件是Makefile.am,用户需要自己创建相应的文件。之后,automake工具转换成Makefile.in

 

其文件内容如下:

AUTOMAKE_OPTIONS=foreign

 

bin_PROGRAMS=test_decoder

 

test_decoder_SOURCES=test_decoder.c

 

test_decoder_LDADD = -lpthread  -lMsuDecoder -ldl

 

test_decoder_LDFLAGS= -L.


其中:

  • AUTOMAKE_OPTIONS为设置automake的选项。由于GNU对自己发布的软件有严格的规范,比如必须附带许可证声明文件COPYING等,否则automake执行时会报错。automake提供了三种软件等级:foreigngnugnits,让用户选择采用,默认等级为gnu。在本例使用foreign等级,它只检测必须的文件。
  • bin_PROGRAMS定义要产生的执行文件名。如果要产生多个执行文件,每个文件名用空格隔开。
  • test_decoder_SOURCES定义“test_decoder”这个执行程序所需要的原始文件。如果” test_decoder”这个程序是由多个原始文件所产生的,则必须把它所用到的所有原始文件都列出来,并用空格隔开。要注意的是,如果要定义多个执行文件,则对每个执行程序都要定义相应的file_SOURCES
  • test_decoder_LDADD定义”test_decoder”这个程序所需的库
  • test_decoder_LDFLAGS定义”test_decoder”这个程序查找的库目录

 

6.      执行automake --add-missing命令

-bash-3.2# automake --add-missing

configure.in: installing `./install-sh'

configure.in: installing `./missing'

Makefile.am: installing `./depcomp'

 

执行automake –add-missing后生成文件Makefile.in

 

7.      执行configure命令

-bash-3.2# ./configure 

checking for a BSD-compatible install... /usr/bin/install -c

checking whether build environment is sane... yes

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 ANSI C... none needed

checking for style of include used by make... GNU

checking dependency style of gcc... gcc3

checking for test_decoder in -lMsuDecoder... no

checking how to run the C preprocessor... gcc -E

checking for egrep... grep -E

checking for ANSI C header files... yes

checking for sys/types.h... yes

checking for sys/stat.h... yes

checking for stdlib.h... yes

checking for string.h... yes

checking for memory.h... yes

checking for strings.h... yes

checking for inttypes.h... yes

checking for stdint.h... yes

checking for unistd.h... yes

checking fcntl.h usability... yes

checking fcntl.h presence... yes

checking for fcntl.h... yes

checking for stdlib.h... (cached) yes

checking for string.h... (cached) yes

checking sys/socket.h usability... yes

checking sys/socket.h presence... yes

checking for sys/socket.h... yes

checking for unistd.h... (cached) yes

checking for an ANSI C-conforming const... yes

checking whether time.h and sys/time.h may both be included... yes

checking sys/select.h usability... yes

checking sys/select.h presence... yes

checking for sys/select.h... yes

checking for sys/socket.h... (cached) yes

checking types of arguments for select... int,fd_set *,struct timeval *

checking for memset... yes

checking for select... yes

configure: creating ./config.status

config.status: creating Makefile

config.status: creating config.h

config.status: executing depfiles commands
 

8.      执行make命令

-bash-3.2# make

make  all-am

make[1]: Entering directory `/home/whizchen/ParseMsu'

if gcc -DHAVE_CONFIG_H -I. -I. -I.     -g -O2 -MT test_decoder.o -MD -MP -MF ".deps/test_decoder.Tpo" -c -o test_decoder.o test_decoder.c; \

        then mv -f ".deps/test_decoder.Tpo" ".deps/test_decoder.Po"; else rm -f ".deps/test_decoder.Tpo"; exit 1; fi

gcc  -g -O2   -o test_decoder -L.  test_decoder.o -lpthread  -lMsuDecoder -ldl

make[1]: Leaving directory `/home/chenwb/tianri/ParseMsu'

 

执行make命令后,生成了执行文件test_decoder程序

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值