[2024-feb-29] Sad news: Eric Layton aka Nocturnal Slacker aka vtel57 passed away on Feb 26th, shortly after hospitalization. He was one of our Wiki's most prominent admins. He will be missed.

Welcome to the Slackware Documentation Project

这是本文档旧的修订版!


本页面目前由dom_kital进行翻译,如有疑问或建议请联系dom_kital@outlook.com

SlackBuild 脚本

SlackBuild脚本本质上是一个shell脚本(通常采用bash shell语法), 它可以自动地配置、编译和创建Slackware包(*.tgz, *.txz, *.tbz 文件)

概述

从源代码创建Slackware包的基本过程可以总结如下,然个别差异应具体问题具体分析

  • 解压源码压缩包 (.tar.gz or .tar.bz2 文件) 至安装目录下
  • 创建名为slack-desc 文件,并以正确的格式描述该软件
  • 如有需要,可自行配置源码或为其打上补丁
  • 编译/构建源代码生成可执行二进制文件(binary)
  • 将程序安装至某临时目录
这个步骤可能有点棘手,这取决于构建系统的make-install(或类似功能)是如何工作的。
在标准GNU Makefile中,传递给make-install命令的 DESTDIR 变量应该足够了。
在不支持该选项的非标准Makefile和构建系统中,这可能涉及修补Makefile(或类似文件)或编辑构建系统的构建配置。
  • 复制本程序的技术文档或其它必要文件(包括安装后所需脚本)复制到安装目录中的相应子目录中。
这些位置应该遵循Slackware用来存储包管理器安装的应用程序的默认目录结构,即 /usr/目录下。
  • 使用临时目录(安装位置)中的makepkg实用工具创建一个Slackware软件包,然后可以使用installpkg实用工具进行安装。

虽然上面的步骤可以手动完成,但这个过程很繁琐,且需要输入很多命令。通过shell脚本实现自动化安装,用户还可以与整个社区共享流程,使用和修改现有的SlackBuild脚本将同一程序升级到新版本也是很有必要的。

Creating SlackBuild scripts

A good hands-on tutorial on creating a SlackBuild script can be found here, and there are also a few templates available to get a feeling for what is needed from a script.

However, software may be written in different programming languages, use different build systems, or may even simply be written in an interpreted programming language with no obvious way to “install” it. In such cases, many steps involved in writing a SlackBuild script will differ from the standard way. Blindly copying and pasting commands from other SlackBuild scripts may or may not work.

It is recommended that anybody who wishes to write a SlackBuild script, study and understand the build system of a software project before attempting to write a SlackBuild script for it. A degree of proficiency in writing shell scripts is also a definite benefit, as it is the practice to use Bourne shell compatible scripts for SlackBuilds. Ideally, simple C projects which use the standard GNU Make system is a good way to start practicing writing SlackBuild scripts.

For new script writers, it is a good idea to perform the above steps manually to create the package from source, before actually writing a SlackBuild script. This reduces the chances of bugs and unexpected behaviour in the script.

Submitting SlackBuild scripts to a public repository such as http://www.slackbuilds.org may additionally require adherence to certain conventions and coding standards. For instance, it would be necessary for the script to determine the target architecture at runtime rather than hard-coding it into the script. These standards attempt to make SlackBuild scripts as portable as possible.

SlackBuild 自动生成器

这里有些工具也许能辅助你创建SlackBuild脚本,具体如下所示:

扩展链接

原著者

 zh:slackware:slackbuild_scripts ()