《linux高級(jí)程序設(shè)計(jì)》第2章Linux下C語(yǔ)言開(kāi)發(fā)工具,這一章主要介紹Linux下進(jìn)行C語(yǔ)言程序開(kāi)發(fā)所必備的工具。本節(jié)為Autoconf/Automake工具組簡(jiǎn)介。
Autoconf/Automake工具用于自動(dòng)創(chuàng)建功能完善的makefile文件。當(dāng)前大多數(shù)軟件包都是用這一工具生成makefile文件的。本節(jié)首先介紹Autoconf/Automake工具的功能以及makefile創(chuàng)建過(guò)程中所涉及的文件和命令。最后以一個(gè)實(shí)例介紹如何使用Autoconf/Automake工具自動(dòng)創(chuàng)建makefile文件。
2.6.1 autoconf安裝automake工具組簡(jiǎn)介(1)
Autoconf/Automake工具組主要包括autoconf、automake、perl語(yǔ)言環(huán)境和m4。其中FC4默認(rèn)安裝的autoconf和automake軟件包信息如下:
[root@localhost hello]# rpm -qa |grep autoconf //查看是否安裝autoconf autoconf-2.59-5 [root@localhost hello]# rpm -qa |grep automake //查看是否安裝automake automake14-1.4p6-12 automake-1.9.5-1 automake17-1.7.9-6 automake15-1.5-13 automake16-1.6.3-5
|
默認(rèn)安裝的perl語(yǔ)言環(huán)境如下:
[root@localhost ~]# rpm -qa |grep perl // 查看perl的安裝情況,已經(jīng)安裝后才有以下信息 perl-Filter-1.30-7 perl-URI-1.35-2 perl-HTML-Tagset-3.04-1 perl-libwww-perl-5.803-2 perl-XML-Encoding-1.01-27 perl-XML-NamespaceSupport-1.08-7 perl-Crypt-SSLeay-0.51-6 perl-XML-Grove-0.46alpha-27 perl-5.8.6-15 perl-DateManip-5.42a-4 perl-HTML-Parser-3.45-1 perl-Compress-Zlib-1.34-2 perl-XML-Parser-2.34-6 perl-XML-Dumper-0.71-4 perl-libxml-enno-1.02-31 perl-Convert-ASN1-0.19-1 perl-XML-SAX-0.12-7 perl-LDAP-0.33-1 perl-XML-LibXML-1.58-2 perl-XML-Twig-3.17-1 perl-Parse-Yapp-1.05-33 perl-libxml-perl-0.08-1 perl-XML-LibXML-Common-0.13-8
|
autoconf安裝默認(rèn)安裝的m4軟件包如下:
[root@localhost ~]# rpm -qa |grep m4 //查看是否安裝m4工具 m4-1.4.3-1
|
如果讀者沒(méi)有獲得以上任何一個(gè)軟件包的完全安裝,請(qǐng)直接插入FC4安裝盤(pán),使用"system-config-packages"命令更新,在開(kāi)發(fā)工具中選中以上選項(xiàng)即可。
以下命令用來(lái)查看本節(jié)所使用的Autoconf/Automake命令所在位置:
[root@localhost hello]# whereis aclocal //查看aclocal命令所在位置 aclocal: /usr/bin/aclocal /usr/share/aclocal [root@localhost hello]# whereis autoscan //查看autoscan命令所在位置 autoscan: /usr/bin/autoscan /usr/share/man/man1/autoscan.1.gz [root@localhost hello]# whereis autoconf //查看autoconf命令所在位置 autoconf: /usr/bin/autoconf /usr/share/autoconf /usr/share/man/man1/autoconf.1.gz [root@localhost hello]# whereis autoheader //查看autoheader命令所在位置 autoheader: /usr/bin/autoheader /usr/share/man/man1/autoheader.1.gz [root@localhost hello]# whereis automake //查看automake命令所在位置 automake: /usr/bin/automake /usr/local/automake
|
使用Autoconf/Automake工具自動(dòng)生成Makefile文件的流程圖如圖2-5所示。在此過(guò)程中使用的命令主要有aclocal、autoscan、autoconf、autoheader和automake。由圖可知運(yùn)行步驟如下:
|
(點(diǎn)擊查看大圖)圖2-5 自動(dòng)創(chuàng)建Makefile文件流程 |
(1)創(chuàng)建源代碼文件,使用"autoscan"生成configure.scan文件,將其重命名為configure.ac,并做適當(dāng)修改,然后使用"aclocal"命令生成aclocal.m4文件,使用"autoconf"命令由configure.ac和aclocal.m4文件生成configure文件。
(2)手工編輯Makefile.am文件,使用"automake"命令生成configure.in文件。
(3)手工編輯或由系統(tǒng)給定acconfig.h文件,使用"autoheader"命令生成config.h.in文件。
(4)使用"configure"命令由configuer、configure.in和config.h.in文件生成Makefile文件。從而完成Makefile文件的創(chuàng)建過(guò)程。
下面以自動(dòng)編譯hello.c程序?yàn)槔榻B如何使用這組工具生成makefile文件。
1.使用Vi編輯器編輯源程序
在Linux操作Shell提示符使用Vi編輯器下創(chuàng)建hello.c源程序。
[root@localhost ch0206]# mkdir hello //創(chuàng)建文件夾 [root@localhost ch0206]# cd hello //切換文件 [root@localhost hello]# ls //已經(jīng)創(chuàng)建的hello.c文件 hello.c [root@localhost hello]# cat hello.c //C源程序代碼 int main(int argc,char** argv) { printf("hello!GNU\n"); return 0; }
|
2.使用autoconf安裝工具生成configure.ac文件
Autoscan工具用來(lái)掃描源代碼以搜尋一般的可移植性問(wèn)題,比如檢查編譯器、庫(kù)和頭文件等,并創(chuàng)建configure.scan文件,它會(huì)在給定目錄及其子目錄樹(shù)中檢查源文件,若沒(méi)有給出目錄,就在當(dāng)前目錄及其子目錄樹(shù)中進(jìn)行檢查。如下所示:
[root@localhost hello]# autoscan .///在當(dāng)前文件夾中搜索 autom4te: configure.ac: no such file or directory autoscan: /usr/bin/autom4te failed with exit status: 1 [root@localhost hello]# ls //生成configure.scan文件,它是configure.ac文件原型 autoscan.log configure.scan hello.c [root@localhost hello]# cat configure.scan //configure.scan文件內(nèi)容 # -*- Autoconf -*- # Process this file with autoconf to produce a configure script.
AC_PREREQ(2.59) //autoconf版本號(hào)
AC_INIT(FULL-PACKAGE-NAME, VERSION, BUG-REPORT-ADDRESS) //軟件的名稱和版本等信息
AC_CONFIG_SRCDIR([hello.c]) //偵測(cè)源碼文件
AC_CONFIG_HEADER([config.h]) //用于生成config.h文件
# 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 //輸入文件名
|
【編輯推薦】
- Linux 查看磁盤(pán)空間實(shí)現(xiàn)代碼介紹
- Linux操作系統(tǒng)需要微軟的十大幫助
- 探尋Linux到底需要多低的配置
- Linux測(cè)試工具tcpdump監(jiān)視TCP/IP連接命令介紹
- Linux流量控制實(shí)例應(yīng)用介紹