日本免费全黄少妇一区二区三区-高清无码一区二区三区四区-欧美中文字幕日韩在线观看-国产福利诱惑在线网站-国产中文字幕一区在线-亚洲欧美精品日韩一区-久久国产精品国产精品国产-国产精久久久久久一区二区三区-欧美亚洲国产精品久久久久

Linux下Makefile的automake生成全攻略( 二 )


AC_INIT(helloworld.c)
AM_INIT_AUTOMAKE(helloworld, 1.0)
# 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)
============================configure.in內(nèi)容結(jié)束=========================================
然后執(zhí)行命令aclocal和autoconf,分別會(huì)產(chǎn)生aclocal.m4及configure兩個(gè)文件:
$ aclocal
$ls
aclocal.m4 configure.in helloworld.c
$ autoconf
$ ls
aclocal.m4 autom4te.cache configure configure.in helloworld.c

大家可以看到configure.in內(nèi)容是一些宏定義,這些宏經(jīng)autoconf處理后會(huì)變成檢查系統(tǒng)特性、環(huán)境變量、軟件必須的參數(shù)的shell腳本 。
autoconf 是用來生成自動(dòng)配置軟件源代碼腳本(configure)的工具 。configure腳本能獨(dú)立于autoconf運(yùn)行,且在運(yùn)行的過程中,不需要用戶的干預(yù) 。
要生成configure文件,你必須告訴autoconf如何找到你所用的宏 。方式是使用aclocal程序來生成你的aclocal.m4 。
aclocal根據(jù)configure.in文件的內(nèi)容,自動(dòng)生成aclocal.m4文件 。aclocal是一個(gè)perl 腳本程序,它的定義是:“aclocal - create aclocal.m4 by scanning configure.ac” 。
autoconf從configure.in這個(gè)列舉編譯軟件時(shí)所需要各種參數(shù)的模板文件中創(chuàng)建configure 。
autoconf需要GNU m4宏處理器來處理aclocal.m4,生成configure腳本 。
m4是一個(gè)宏處理器 。將輸入拷貝到輸出,同時(shí)將宏展開 。宏可以是內(nèi)嵌的,也可以是用戶定義的 。除了可以展開宏,m4還有一些內(nèi)建的函數(shù),用來引用文件,執(zhí)行命令,整數(shù)運(yùn)算,文本操作,循環(huán)等 。m4既可以作為編譯器的前端,也可以單獨(dú)作為一個(gè)宏處理器 。
4、新建Makefile.am
新建Makefile.am文件,命令:

$ vi Makefile.am

內(nèi)容如下:

AUTOMAKE_OPTIONS=foreign
bin_PROGRAMS=helloworld
helloworld_SOURCES=helloworld.c

automake會(huì)根據(jù)你寫的Makefile.am來自動(dòng)生成Makefile.in 。
Makefile.am中定義的宏和目標(biāo),會(huì)指導(dǎo)automake生成指定的代碼 。例如,宏bin_PROGRAMS將導(dǎo)致編譯和連接的目標(biāo)被生成 。
5、運(yùn)行automake
命令:

$ automake --add-missing
configure.in: installing `./install-sh"
configure.in: installing `./mkinstalldirs"
configure.in: installing `./missing"
Makefile.am: installing `./depcomp"

automake會(huì)根據(jù)Makefile.am文件產(chǎn)生一些文件,包含最重要的Makefile.in 。
6、執(zhí)行configure生成Makefile

$ ./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... 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
configure: creating ./config.status
config.status: creating Makefile
config.status: executing depfiles commands
$ ls -l Makefile
-rw-rw-r-- 1 yutao yutao 15035 Oct 15 10:40 Makefile

你可以看到,此時(shí)Makefile已經(jīng)產(chǎn)生出來了 。
7、使用Makefile編譯代碼
$ make
if gcc -DPACKAGE_NAME="" -DPACKAGE_TARNAME="" -DPACKAGE_VERSION="" -
DPACKAGE_STRING="" -DPACKAGE_BUGREPORT="" -DPACKAGE="helloworld" -DVERSION="1.0"
-I. -I. -g -O2 -MT helloworld.o -MD -MP -MF ".deps/helloworld.Tpo"
-c -o helloworld.o `test -f "helloworld.c" || echo "./"`helloworld.c;

推薦閱讀