对话 UNIX,第 12 部分: 自己动手完成项目( 三 )


集中精力感受源代码
下一个步骤是探查系统并配置该软件,以便进行正确地构建 。(您可以将这个步骤想象为裁剪一件衣服:这件衣服大小基本合适,但是需要进行一定的修改以使其更加时尚 。)您需要进行自定义工作,并为使用 ./configure 本地脚本进行编译做好准备 。在命令行提示处,键入:$ ./configure
这个配置脚本进行了几项测试,以证明您的系统是合格的 。例如,在一台 Apple MacBook 计算机上(其中运行着 FreeBSD?UNIX 的一个变种)运行 ./configure,将产生以下结果(请参见清单 2):
清单 2. 在 Mac OS X 上运行 ./configure 的结果
checking build system type... i386-apple-darwin8.9.1
checking host system type... i386-apple-darwin8.9.1
checking for gcc... gcc
checking for C compiler default output file name... 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 ISO C89... none needed
checking for a sed that does not truncate output... /usr/bin/sed
checking for grep that handles long lines and -e... /usr/bin/grep
checking for egrep... /usr/bin/grep -E
checking for ld used by gcc... /usr/bin/ld
...
这里,./configure 可以确定编译和主机系统的类型(如果您采用交叉编译的话,它可能不同),证实是否已经安装了 GNU C 编译器(GCC),并找到其余构建过程可能需要使用的实用工具的路径 。您可以浏览一下其余的输出,但是您将看到一个较长的诊断信息列表,该列表从成功构造 SQLite 的角度分析了您的系统的特点 。
注意: ./configure 命令可能 会失败,特别是在无法找到一个先决条件的情况下(比如一个系统库或者关键的系统实用工具) 。
浏览 ./configure 的输出,寻找其中不正常之处,如命令的专用或者本地版本,它可能并不适合于构建通用的应用程序,如 SQLite 。作为一个示例,如果您的系统管理员安装了 GCC 的 alpha 版本,并且 configure 工具首选使用该版本,那么您可以选择手动地改写这个选择 。要查看您可以改写的选项的列表(该列表通常很长),可以键入 ./configure --help,如清单 3 中所示:
清单 3. 用于 ./configure 脚本的通用选项
$ ./configure --help
...
By default, `make install' will install all the files in
`/usr/local/bin', `/usr/local/lib' etc. You can specify
an installation prefix other than `/usr/local' using `--prefix',
for instance `--prefix=$HOME'.
For better control, use the options below.
Fine tuning of the installation DirectorIEs:
 --bindir=DIRuser executables [EPREFIX/bin]
 --sbindir=DIR system admin executables [EPREFIX/sbin]
 --libexecdir=DIRprogram executables [EPREFIX/libexec]
...
./configure --help 的输出中包括配置系统使用的通用选项,以及仅与您正在构建的软件相关的特定选项 。要查看后者(较短)的列表,可以键入 ./configure --help=short(请参见清单 4):
清单 4. 要构建的软件包所特定的选项
$ ./configure --help=short
Optional Features:
 --disable-FEATUREdo not include FEATURE (same as --enable-FEATURE=no)
 --enable-FEATURE[=ARG] include FEATURE [ARG=yes]
 --enable-shared[=PKGS] build shared librarIEs [default=yes]
 --enable-static[=PKGS] build static libraries [default=yes]
 --enable-fast-install[=PKGS]
 optimize for fast installation [default=yes]
 --disable-libtool-lock avoid locking (might break parallel builds)

推荐阅读