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.