1、源文件結構概述linux
GNU組織提供的都是源代碼,供用戶自行編譯使用。好比著名的apache web服務器就是典型的源文件:web
咱們能夠下載這個源代碼,在windows平臺上經過firezillar上傳到linux機器上:apache
[root@localhost ~]# cd /yum/bin_src/windows
[root@localhost bin_src]# llbash
total 4940 -rw-r--r--. 1 root root 5054838 Aug 17 17:51 httpd-2.4.12.tar.bz2
若是該程序包不是經過filezilla等ftp工具上傳的,而是直接從服務器上下載的,則爲了確保本地的程序包能和服務器上的程序包時間一致,建議使用 ntpdate SERVER_IP將本地時間調整爲服務器時間服務器
[root@localhost bin_src]# dateide
Sun Aug 17 17:57:25 EDT 2014
[root@localhost bin_src]# ntpdate 192.168.56.103工具
17 Aug 18:00:32 ntpdate[24526]: no server suitable for synchronization found # 因爲本地尚未搭建成服務器,故沒法同步,後文中將介紹服務器的搭建
[root@localhost bin_src]# tar xf httpd-2.4.12.tar.bz2 優化
# 展開該壓縮包ui
[root@localhost bin_src]# ls
httpd-2.4.12 httpd-2.4.12.tar.bz2
[root@localhost bin_src]# cd httpd-2.4.12
[root@localhost httpd-2.4.12]# ls server/
buildmark.c gen_test_char.dsp provider.c util_expr_parse.c util_pcre.c config.c listen.c request.c util_expr_parse.h util_regex.c ... error_bucket.c NWGNUmakefile util_ebcdic.c util_md5.c gen_test_char.c protocol.c util_expr_eval.c util_mutex.c
[root@localhost httpd-2.4.12]# cd server/
[root@localhost server]# cat buildmark.c
# 能夠看到以.c結尾的文件的內容,是c語言源代碼 /* Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with ... * limitations under the License. */ #include "ap_config.h" #include "httpd.h" #if defined(__DATE__) && defined(__TIME__) static const char server_built[] = __DATE__ " " __TIME__; #else static const char server_built[] = "unknown"; #endif AP_DECLARE(const char *) ap_get_server_built() { return server_built; }
二.軟件包的安裝步驟
server目錄中有*.c文件即爲源程序,因爲以前安裝過包組Development tools, Server Platform Development 和Desktop Platform Development, 所以用戶能夠使用gcc來編譯這些文件。可是要成功安裝編譯一個源程序,是不能簡單使用gcc *.c的,由於這些*.c文件互相存在依賴關係,有必定的編譯順序,若是不按照順序進行,則會出錯。爲了簡化操做,出現了make工具:
[root@localhost server]# which make
/usr/bin/make [root@localhost server]# man make MAKE(1) LOCAL USER COMMANDS MAKE(1) NAME make - GNU make utility to maintain groups of programs —— # make能夠管理一組文件,即管理一個工程 SYNOPSIS make [ -f makefile ] [ options ] ... [ targets ] ...
make的出現大大簡化了編譯工做,但make的使用須要配合一個配置文件 Makefile,Makefile指定了具體的編譯方式,如編譯的順序,編譯的優化方式等等。這個文件一般很難手動寫出來,而是使用一個腳本configure,結合Makefile.in來生成Makefile文件:
[root@localhost httpd-2.4.12]# ls
ABOUT_APACHE BuildAll.dsp configure.in InstallBin.dsp NOTICE server acinclude.m4 BuildBin.dsp docs LAYOUT NWGNUmakefile srclib Apache-apr2.dsw buildconf emacs-style libhttpd.dsp os support Apache.dsw CHANGES httpd.dsp LICENSE README test apache_probes.d CMakeLists.txt httpd.spec Makefile.in READMENaNake VERSIONING ap.d config.layout include Makefile.win README.platforms build configure INSTALL modules ROADMAP
一般configure這個腳本也很難手動生成,而是軟件包的做者使用autoconf這個工具,結合軟件包的各類參數來自動生成的:
[root@localhost httpd-2.4.12]# rpm -qi autoconf
Name : autoconf Relocations: (not relocatable) ... Description : GNU Autoconf is a tool for configuring source code and Makefiles. Using Autoconf, programmers can create portable and configurable packages, since the person building the package is allowed to specify various configuration options. # configure文件一般是由軟件包的做
configure腳本須要結合Makefile.in來生成Makefile文件,而Makefile.in文件是使用automake這個工具來生成的:
root@localhost httpd-2.4.12]# rpm -qi automake
Name : automake Relocations: (not relocatable) ... Summary : A GNU tool for automatically creating Makefiles Description : Automake is a tool for automatically generating `Makefile.in' files compliant with the GNU Coding Standards.
綜上,編譯安裝一個軟件包的過程以下圖:
可能咱們會有一個疑問,既然make最終使用的Makefile文件,那麼爲什麼不直接將配置寫入到Makefile中,而要畫蛇添足的生產configure文件呢?這是由於./configure有以下做用:
1)查編譯環境是否完備; 2) 讓用戶定製編譯配置(經過腳本選項,如使用--help來查看)
[root@localhost httpd-2.4.12]# ./configure --help
`configure' configures this package to adapt to many kinds of systems. Usage: ./configure [OPTION]... [VAR=VALUE]... To assign environment variables (e.g., CC, CFLAGS...), specify them as VAR=VALUE. See below for descriptions of some of the useful variables. Defaults for the options are specified in brackets. Configuration: -h, --help display this help and exit --help=short display options specific to this package --help=recursive display the short help of all the included packages -V, --version display version information and exit Installation directories: # 如下選項多爲通用選項 --prefix=PREFIX install architecture-independent files in PREFIX [/usr/local/apache2] # 前綴,指定安裝路徑,之後若是要刪除該程序,也能夠指定該路徑 --sysconfdir=DIR read-only single-machine data [PREFIX/etc] # 指定conf文件的目錄,若是不指定,則自動建立爲/usr/local/apache2/conf --mandir=DIR man documentation [DATAROOTDIR/man] # 指定man目錄,若是不指定,則自動建立爲/usr/local/apache2/man --exec-prefix=EPREFIX install architecture-dependent files in EPREFIX [PREFIX] ... --with-suexec-gidmin Minimal allowed GID --with-suexec-logfile Set the logfile ... Report bugs to the package provider.