build 类可通过执行 Bourne shell 指令创建或修改软件包对象文件。这些指令作为软件包对象提供。如果该软件包对象属于 build 类,这些指令将会在安装时自动运行。
build 类操作脚本的名称应该与对其执行指令的文件的名称相同。该名称还必须可由 sh 命令执行。该脚本的输出将成为生成或修改后的文件新版本。如果脚本未生成任何输出,表明没有创建或修改该文件。因此,该脚本可以修改或创建文件本身。
例如,如果软件包提供了一个缺省文件 /etc/randomtable,并且目标系统上尚不存在该文件,则 prototype 文件条目可能如下所示:
e build /etc/randomtable ? ? ? |
软件包对象 /etc/randomtable 可能如下所示:
!install # randomtable builder if [ -f $PKG_INSTALL_ROOT/etc/randomtable ]; then echo "/etc/randomtable is already in place."; else echo "# /etc/randomtable" > $PKG_INSTALL_ROOT/etc/randomtable echo "1121554 # first random number" >> $PKG_INSTALL_ROOT/etc/randomtable fi !remove # randomtable deconstructor if [ -f $PKG_INSTALL_ROOT/etc/randomtable ]; then # the file can be removed if it's unchanged if [ egrep "first random number" $PKG_INSTALL_ROOT/etc/randomtable ]; then rm $PKG_INSTALL_ROOT/etc/randomtable; fi fi |
有关使用 build 类的另一个示例,请参见第 5 章。