Linux下C編程基礎之:使用autotools
下面對該腳本文件的對應項進(jìn)行解釋。
n 其中的AUTOMAKE_OPTIONS為設置automake的選項。GNU對自己發(fā)布的軟件有嚴格的規范,比如必須附帶許可證聲明文件COPYING等,否則automake執行時(shí)會(huì )報錯。automake提供了3種軟件等級:foreign、gnu和gnits,讓用戶(hù)選擇采用,默認等級為gnu。在本示例中采用foreign等級,它只檢測必須的文件。
n bin_PROGRAMS定義要產(chǎn)生的執行文件名。如果要產(chǎn)生多個(gè)執行文件,每個(gè)文件名用空格隔開(kāi)。
n hello_SOURCES定義“hello”這個(gè)執行程序所需要的原始文件。如果“hello”這個(gè)程序是由多個(gè)原始文件所產(chǎn)生的,則必須把它所用到的所有原始文件都列出來(lái),并用空格隔開(kāi)。例如:若目標體“hello”需要“hello.c”、“david.c”、“hello.h”三個(gè)依賴(lài)文件,則定義hello_SOURCES=hello.cdavid.chello.h。要注意的是,如果要定義多個(gè)執行文件,則對每個(gè)執行程序都要定義相應的file_SOURCES。
接下來(lái)可以使用automake命令來(lái)生成“configure.in”文件,在這里使用選項“-a”(或者“—adding-missing”)可以讓automake自動(dòng)添加一些必需的腳本文件。如下所示:
[root@localhostautomake]#automake–a(或者automake--add-missing)
configure.in:installing'./install-sh'
configure.in:installing'./missing'
makefile.am:installing'depcomp'
[root@localhostautomake]#ls
aclocal.m4autoscan.logconfigure.inhello.cmakefile.ammissing
autom4te.cacheconfiguredepcompinstall-shmakefile.inconfig.h.in
可以看到,在automake之后就可以生成configure.in文件。
5.運行configure
在這一步中,通過(guò)運行自動(dòng)配置設置文件configure,把makefile.in變成了最終的makefile。如下所示:
[root@localhostautomake]#./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
configure:creating./config.status
config.status:creatingmakefile
config.status:executingdepfilescommands
可以看到,在運行configure時(shí)收集了系統的信息,用戶(hù)可以在configure命令中對其進(jìn)行方便的配置。在./configure的自定義參數有兩種,一種是開(kāi)關(guān)式(--enable-XXX或--disable-XXX),另一種是開(kāi)放式,即后面要填入一串字符(--with-XXX=yyyy)參數。讀者可以自行嘗試其使用方法。另外,讀者可以查看同一目錄下的“config.log”文件,以方便調試之用。
到此為止,makefile就可以自動(dòng)生成了?;貞浾麄€(gè)步驟,用戶(hù)不再需要定制不同的規則,而只需要輸入簡(jiǎn)單的文件及目錄名即可,這樣就大大方便了用戶(hù)的使用。autotools生成makefile的流程如圖3.9所示。
圖3.9autotools生成makefile的流程圖
linux操作系統文章專(zhuān)題:linux操作系統詳解(linux不再難懂)
評論