2020-04-01 06:29:33 登录注册 RSS

当前位置: 公理网 >> 投诉不良 >> 利用Linux下自动生成makefile的工具:automake,autoconf生成makefile的一般过程

利用Linux下自动生成makefile的工具:automake,autoconf生成makefile的一般过程
发布时间:2017-05-25| 来源:公理网 | 点击发表评论

1.创建工程目录和各个目录下的makefile.am。工程的名字一般和最终生成应用程序的名字相同。





[email protected]~]$mkdirworkspace
[[email protected]~]$cdworkspace/
[[email protected]]$ls
[[email protected]]$mkdirtestAutoMake
[[email protected]]$ls
testAutoMake
[[email protected]]$cdtestAutoMake/
[[email protected]]$ls
[[email protected]]$mkdirsrc
[[email protected]]$ls
[[email protected]]$pwd
/home/wzb/workspace/testAutoMake
[[email protected]]$ls
[[email protected]]$vimakefile.am
[[email protected]]$cdsrc
[[email protected]]$ls
[[email protected]]$vimain.c
[[email protected]]$ls
main.c
[[email protected]]$vimain.c
[[email protected]]$clear
[[email protected]]$ls
main.c
[[email protected]]$vimakefile.am
[[email protected]]$clear
[[email protected]]$ls
main.cmakefile.am
[[email protected]]$cd..
[[email protected]]$ls
makefile.amsrc
[[email protected]]$pwd
/home/wzb/workspace/testAutoMake
[[email protected]]$ls-R
makefile.amsrc
./src:
main.cmakefile.am
[[email protected]]$

[[email protected]]$pwd
/home/wzb/workspace/testAutoMake
[[email protected]]$ls
makefile.amsrc
[[email protected]]$catmakefile.am
SUBDIRS=src
[[email protected]]$vimakefile.am
[[email protected]]$cdsrc
[[email protected]]$ls
main.cmakefile.am
[[email protected]]$catmain.c
#includestdio.h
#includestdarg.h
intaccumulate(intnr,...);
intmain(intargc,char*argv[]){
intn=5;
intresult=accumulate(5,5,4,3,2,1);
printf(%d,\n,result);

2.通过命令autoscan,创建autoconf的模板,生成configure.in文件。

首先在工程目录中,通过执行autoscan命令,生成autoconf的模板文件configure.scan文件,将其改名为configure.in。


需要两处修改:


(1).将configure.in文件中的语句:AC_INIT(FULL-PACKAGE-NAME,VERSION,BUG-REPORT-ADDRESS)中的


FULL-PACKAGE-NAME:替换为你指派的开发工程包的名字:如本工程的:test_AutoMake;


VERSION:开发的版本号,一般式:主版本号.从版本号。如0.1;


BUG-REPORT-ADDRESS:提交bug的邮件地址:如[email protected]


(2).还要添加一句:AM_INIT_AUTOMAKE(testAutoMake,0.1)即AM_INIT_AUTOMAKE(package_name,version);


用来初始化automake。








[[email protected]]$pwd
/home/wzb/workspace/testAutoMake
[[email protected]]$ls
makefile.amsrc
[[email protected]]$autoscan
autom4te:configure.ac:nosuchfileordirectory
autoscan:/usr/bin/autom4tefailedwithexitstatus:1
[[email protected]]$ls
autoscan.logconfigure.scanmakefile.amsrc
[[email protected]]$viconfigure.scan
[[email protected]]$viconfigure.scan
[[email protected]]$mvconfigure.scanconfigure.in
[[email protected]]$ls
autoscan.logconfigure.inmakefile.amsrc
[[email protected]]$catconfigure.in
#-*-Autoconf-*-
#Processthisfilewithautoconftoproduceaconfigurescript.
AC_PREREQ(2.59)
AC_INIT(FULL-PACKAGE-NAME,VERSION,BUG-REPORT-ADDRESS)
AC_CONFIG_SRCDIR([src/main.c])
AC_CONFIG_HEADER([config.h])
#Checksforprograms.
AC_PROG_CC
#Checksforlibraries.
#Checksforheaderfiles.
AC_HEADER_STDC
#Checksfortypedefs,structures,andcompilercharacteristics.
#Checksforlibraryfunctions.
AC_CONFIG_FILES([makefile
src/makefile])
AC_OUTPUT
[[email protected]]$viconfigure.in
[[email protected]]$clear
[[email protected]]$ls
autoscan.logconfigure.inmakefile.amsrc
[[email protected]]$catconfigure.in
#-*-Autoconf-*-
#Processthisfilewithautoconftoproduceaconfigurescript.
AC_PREREQ(2.59)
AC_INIT(testAutoMake,0.1,[email protected])
AC_CONFIG_SRCDIR([src/main.c])
AC_CONFIG_HEADER([config.h])
AM_INIT_AUTOMAKE(testAutoMake,0.1)
#Checksforprograms.
AC_PROG_CC
#Checksforlibraries.
#Checksforheaderfiles.
AC_HEADER_STDC
#Checksfortypedefs,structures,andcompilercharacteristics.
#Checksforlibraryfunctions.
AC_CONFIG_FILES([makefile
src/makefile])
AC_OUTPUT
[[email protected]]$





3.使用aclocal,将configure.in中宏展开,生成alocal.m4和临时加速文件autom4te.cache。





[[email protected]]$pwd
/home/wzb/workspace/testAutoMake
[[email protected]]$ls
autoscan.logconfigure.inmakefile.amsrc
[[email protected]]$aclocal
[[email protected]]$ls
aclocal.m4autom4te.cacheautoscan.logconfigure.inmakefile.amsrc
[[email protected]]$
[[email protected]]$






4.使用autoheader生成config.h.in文件。





[[email protected]]$pwd
/home/wzb/workspace/testAutoMake
[[email protected]]$ls
aclocal.m4autom4te.cacheautoscan.logconfigure.inmakefile.amsrc
[[email protected]]$autoheader
[[email protected]]$ls
aclocal.m4autoscan.logconfigure.insrc
autom4te.cacheconfig.h.inmakefile.am
[[email protected]]$






5.创建文件:README、NEWS、AUTHORS、ChangeLog。touchREADMENEWSAUTHORSChangeLog





[[email protected]]$pwd
/home/wzb/workspace/testAutoMake
[[email protected]]$ls
aclocal.m4autoscan.logconfigure.insrc
autom4te.cacheconfig.h.inmakefile.am
[[email protected]]$touchNEWSREADMEAUTHORSChangeLog
[[email protected]]$ls
aclocal.m4autom4te.cacheChangeLogconfigure.inNEWSsrc
AUTHORSautoscan.logconfig.h.inmakefile.amREADME
[[email protected]]$viChangeLog
[[email protected]]$catChangeLog
[email protected]
*Created
[[email protected]]$






6.执行automake-a命令生成makefile.in文件以及其他相关文件install-sh,missing,depcomp,INSTALL,COPYING等。





[[email protected]]$pwd
/home/wzb/workspace/testAutoMake
[[email protected]]$ls
aclocal.m4autom4te.cacheChangeLogconfigure.inNEWSsrc
AUTHORSautoscan.logconfig.h.inmakefile.amREADME
[[email protected]]$automake-a
configure.in:installing`./install-sh'
configure.in:installing`./missing'
src/makefile.am:installing`./depcomp'
makefile.am:installing`./INSTALL'
makefile.am:installing`./COPYING'
[[email protected]]$ls
aclocal.m4autoscan.logconfigure.inINSTALLmakefile.inREADME
AUTHORSChangeLogCOPYINGinstall-shmissingsrc
autom4te.cacheconfig.h.indepcompmakefile.amNEWS
[[email protected]]$







7.执行autoconf命令,生成configure脚本。




[[email protected]]$pwd
/home/wzb/workspace/testAutoMake
[[email protected]]$ls
aclocal.m4autoscan.logconfigure.inINSTALLmakefile.inREADME
AUTHORSChangeLogCOPYINGinstall-shmissingsrc
autom4te.cacheconfig.h.indepcompmakefile.amNEWS
[[email protected]]$autoconf
[[email protected]]$ls
aclocal.m4autoscan.logconfiguredepcompmakefile.amNEWS
AUTHORSChangeLogconfigure.inINSTALLmakefile.inREADME
autom4te.cacheconfig.h.inCOPYINGinstall-shmissingsrc
[[email protected]]$






8.执行./configure生成makefile文件。


configure脚本的两个参数,-prefix指定bin目录的父目录;另一个-host指定处理器架构,交叉编译环境搭建时有用。





[[email protected]]$pwd
/home/wzb/workspace/testAutoMake
[[email protected]]$ls
aclocal.m4autoscan.logconfiguredepcompmakefile.amNEWS
AUTHORSChangeLogconfigure.inINSTALLmakefile.inREADME
autom4te.cacheconfig.h.inCOPYINGinstall-shmissingsrc
[[email protected]]$./configure
checkingforaBSD-compatibleinstall.../usr/bin/install-c
checkingwhetherbuildenvironmentissane...yes
checkingforgawk...gawk
checkingwhethermakesets$(MAKE)...yes
checkingforgcc...gcc
checkingforCcompilerdefaultoutputfilename...a.out
checkingwhethertheCcompilerworks...yes
checkingwhetherwearecrosscompiling...no
checkingforsuffixofexecutables...
checkingforsuffixofobjectfiles...o
checkingwhetherweareusingtheGNUCcompiler...yes
checkingwhethergccaccepts-g...yes
checkingforgccoptiontoacceptANSIC...noneneeded
checkingforstyleofincludeusedbymake...GNU
checkingdependencystyleofgcc...gcc3
checkinghowtoruntheCpreprocessor...gcc-E
checkingforegrep...grep-E
checkingforANSICheaderfiles...yes
configure:creating./config.status
config.status:creatingmakefile
config.status:creatingsrc/makefile
config.status:creatingconfig.h
config.status:executingdepfilescommands
[[email protected]]$ls
aclocal.m4ChangeLogconfig.statusdepcompmakefile.amREADME
AUTHORSconfig.hconfigureINSTALLmakefile.insrc
autom4te.cacheconfig.h.inconfigure.ininstall-shmissingstamp-h1
autoscan.logconfig.logCOPYINGmakefileNEWS
[[email protected]]$


9.一下步骤基本与我们从源码编译安装应用的步骤相。




首先,./configure-prefixbin目录所在的父目录(绝对路径)


接着make;编译


最后makeinstall;在bin目录中找到生成可执行程序测试。





[[email protected]]$pwd
/home/wzb/workspace/testAutoMake
[[email protected]]$ls
aclocal.m4autom4te.cacheChangeLogconfig.h.inconfig.statusconfigure.indepcompinstall-shmakefile.ammissingREADMEstamp-h1
AUTHORSautoscan.logconfig.hconfig.logconfigureCOPYINGINSTALLmakefilemakefile.inNEWSsrc
[[email protected]]$./configure-prefix/home/wzb/w
workspace/wzb/
[[email protected]]$./configure-prefix/home/wzb/workspace/testAutoMake/
checkingforaBSD-compatibleinstall.../usr/bin/install-c
checkingwhetherbuildenvironmentissane...yes
checkingforgawk...gawk
checkingwhethermakesets$(MAKE)...yes
checkingforgcc...gcc
checkingforCcompilerdefaultoutputfilename...a.out
checkingwhethertheCcompilerworks...yes
checkingwhetherwearecrosscompiling...no
checkingforsuffixofexecutables...
checkingforsuffixofobjectfiles...o
checkingwhetherweareusingtheGNUCcompiler...yes
checkingwhethergccaccepts-g...yes
checkingforgccoptiontoacceptANSIC...noneneeded
checkingforstyleofincludeusedbymake...GNU
checkingdependencystyleofgcc...gcc3
checkinghowtoruntheCpreprocessor...gcc-E
checkingforegrep...grep-E
checkingforANSICheaderfiles...yes
configure:creating./config.status
config.status:creatingmakefile
config.status:creatingsrc/makefile
config.status:creatingconfig.h
config.status:config.hisunchanged
config.status:executingdepfilescommands
[[email protected]]$make
makeall-recursive
make[1]:Enteringdirectory`/home/wzb/workspace/testAutoMake'
Makingallinsrc
make[2]:Enteringdirectory`/home/wzb/workspace/testAutoMake/src'
ifgcc-DHAVE_CONFIG_H-I.-I.-I..-g-O2-MTmain.o-MD-MP-MF.deps/main.Tpo-c-omain.omain.c;\
thenmv-f.deps/main.Tpo.deps/main.Poelserm-f.deps/main.Tpoexit1;fi
gcc-g-O2-otestAutoMakemain.o
make[2]:Leavingdirectory`/home/wzb/workspace/testAutoMake/src'
make[2]:Enteringdirectory`/home/wzb/workspace/testAutoMake'
make[2]:Leavingdirectory`/home/wzb/workspace/testAutoMake'
make[1]:Leavingdirectory`/home/wzb/workspace/testAutoMake'
[[email protected]]$ls
aclocal.m4autom4te.cacheChangeLogconfig.h.inconfig.statusconfigure.indepcompinstall-shmakefile.ammissingREADMEstamp-h1
AUTHORSautoscan.logconfig.hconfig.logconfigureCOPYINGINSTALLmakefilemakefile.inNEWSsrc
[[email protected]]$makeinstall
Makinginstallinsrc
make[1]:Enteringdirectory`/home/wzb/workspace/testAutoMake/src'
make[2]:Enteringdirectory`/home/wzb/workspace/testAutoMake/src'
test-z/home/wzb/workspace/testAutoMake//bin||mkdir-p--/home/wzb/workspace/testAutoMake//bin
/usr/bin/install-c'testAutoMake''/home/wzb/workspace/testAutoMake//bin/testAutoMake'
make[2]:Nothingtobedonefor`install-data-am'.
make[2]:Leavingdirectory`/home/wzb/workspace/testAutoMake/src'
make[1]:Leavingdirectory`/home/wzb/workspace/testAutoMake/src'
make[1]:Enteringdirectory`/home/wzb/workspace/testAutoMake'
make[2]:Enteringdirectory`/home/wzb/workspace/testAutoMake'
make[2]:Nothingtobedonefor`install-exec-am'.
make[2]:Nothingtobedonefor`install-data-am'.
make[2]:Leavingdirectory`/home/wzb/workspace/testAutoMake'
make[1]:Leavingdirectory`/home/wzb/workspace/testAutoMake'
[[email protected]]$ls
aclocal.m4autoscan.logconfig.hconfig.statusCOPYINGinstall-shmakefile.inREADME
AUTHORSbinconfig.h.inconfiguredepcompmakefilemissingsrc
autom4te.cacheChangeLogconfig.logconfigure.inINSTALLmakefile.amNEWSstamp-h1
[[email protected]]$./bin/testAutoMake
test.......makefile........ok
[[email protected]]$










10.当程序稳定了,可以通过命令makedist,生成工程的发布文件。(还有makedistcheck命令)
[[email protected]]$pwd
/home/wzb/workspace/testAutoMake
[[email protected]]$ls
aclocal.m4autoscan.logconfig.hconfig.statusCOPYINGinstall-shmakefile.inREADME
AUTHORSbinconfig.h.inconfiguredepcompmakefilemissingsrc
autom4te.cacheChangeLogconfig.logconfigure.inINSTALLmakefile.amNEWSstamp-h1
[[email protected]]$makedist
{test!-dtestAutoMake-0.1||{findtestAutoMake-0.1-typed!-perm-200-execchmodu+w{}';'rm-frtestAutoMake-0.1;};}
mkdirtestAutoMake-0.1
list='src';forsubdirin$list;do\
iftest$subdir=.;then:;else\
test-dtestAutoMake-0.1/$subdir\
||mkdir-p--testAutoMake-0.1/$subdir\
||exit1;\
distdir=`CDPATH=${ZSH_VERSION+.}:cdtestAutoMake-0.1pwd`;\
top_distdir=`CDPATH=${ZSH_VERSION+.}:cdtestAutoMake-0.1pwd`;\
(cd$subdir\
make\
top_distdir=$top_distdir\
distdir=$distdir/$subdir\
distdir)\
||exit1;\
fi;\
done
make[1]:Enteringdirectory`/home/wzb/workspace/testAutoMake/src'
make[1]:Leavingdirectory`/home/wzb/workspace/testAutoMake/src'
findtestAutoMake-0.1-typed!-perm-755-execchmoda+rwx,go+rx{}\;-o\
!-typed!-perm-444-links1-execchmoda+r{}\;-o\
!-typed!-perm-400-execchmoda+r{}\;-o\
!-typed!-perm-444-exec/bin/sh/home/wzb/workspace/testAutoMake/install-sh-c-ma+r{}{}\;\
||chmod-Ra+rtestAutoMake-0.1
tardir=testAutoMake-0.1/bin/sh/home/wzb/workspace/testAutoMake/missing--runtarchof-$tardir|GZIP=--bestgzip-ctestAutoMake-0.1.tar.gz
{test!-dtestAutoMake-0.1||{findtestAutoMake-0.1-typed!-perm-200-execchmodu+w{}';'rm-frtestAutoMake-0.1;};}
[[email protected]]$ls
aclocal.m4autoscan.logconfig.hconfig.statusCOPYINGinstall-shmakefile.inREADMEtestAutoMake-0.1.tar.gz
AUTHORSbinconfig.h.inconfiguredepcompmakefilemissingsrc
autom4te.cacheChangeLogconfig.logconfigure.inINSTALLmakefile.amNEWSstamp-h1
[[email protected]]$clear
[[email protected]]$ls
aclocal.m4autoscan.logconfig.hconfig.statusCOPYINGinstall-shmakefile.inREADMEtestAutoMake-0.1.tar.gz
AUTHORSbinconfig.h.inconfiguredepcompmakefilemissingsrc
autom4te.cacheChangeLogconfig.logconfigure.inINSTALLmakefile.amNEWSstamp-h1
[[email protected]]$clear
[[email protected]]$ls
aclocal.m4autoscan.logconfig.hconfig.statusCOPYINGinstall-shmakefile.inREADMEtestAutoMake-0.1.tar.gz
AUTHORSbinconfig.h.inconfiguredepcompmakefilemissingsrc
autom4te.cacheChangeLogconfig.logconfigure.inINSTALLmakefile.amNEWSstamp-h1
[[email protected]]$viChangeLog
[[email protected]]$clear
[[email protected]]$ls
aclocal.m4autoscan.logconfig.hconfig.statusCOPYINGinstall-shmakefile.inREADMEtestAutoMake-0.1.tar.gz
AUTHORSbinconfig.h.inconfiguredepcompmakefilemissingsrc
autom4te.cacheChangeLogconfig.logconfigure.inINSTALLmakefile.amNEWSstamp-h1
[[email protected]]$viconfigure.in





以上是是使用automake生成makefile的全过程,


想到了为什么,安装源码文件时,要先./configure-prefix...,接着make,接着makeinstall。很清楚了。。。











6696448">基于stm32固件库的的spi对NRF905SE无线模块操作的API

yzbiwj:
能发一份完整的程序吗,调了好几天了没结果。我的邮箱1429995445@qq.com



7877590">solrj查询SolrServer的一般流程

wzb56:
你的单例模式下,为了复用肯定不能shutdonw,应该直到该单例不再使用的时候再shutdown,...

最新新闻

手机浏览

公理网 版权所有

公理网 Total 0.063227(s) query 6, 报料QQ:点击这里

给我发消息