SUSE 构建教程

Jump to: navigation, search
Icon-info.png
如需 openSUSE 构建服务教程, 在线与此等效的制作过程请查看 Build Service/Tutorial.


介绍

本文档概述 openSUSE 构建服务(OBS)结构,是关于如何为 openSUSE 构建 RPM 包的教程。这些信息将助您搭建您自己的临时构建环境。文档起始的四个部分将会概述工作原理,并带有具体的例子以方便您实践。

请注意,这和具体使用构建服务是不同的。如果您需要了解具体的使用,请参考 Build_Service

预要求

您应该理解如何创建 RPM。本文档的目标不是代替现有的 RPM 文档。这类文档有很多,指南和书本可以在 资源段落 找到相应的 RPM 相关链接。

您同样应该有一些使用 PGP 相关工具特别是 GNU Privacy Guard (gpg) 的经验,因为 GPG 是应用最广泛的 OpenPGP 。我们将在之后讨论包签名的时候解释为什么 PGP 至关重要。要为软件宝签名,在使用 openSUSE 构建环境之前您需要您自己的 PGP 密钥。

当然,您应该熟悉您项目中用于构建软件包的源码环境。使用 openSUSE 构建构架时,项目维护人员可能会犯一些共同的错误,但知道如何使用 makeautoconfimake 等其他源码配置工具链将是非常有益的。

要求

要求非常简单,您只需3 GB 的硬盘空间以及我们的构建工具, 构建 。就是这么简单。

您需要3 GB 硬盘空间是因为 OBS 需要使用单独安装到您硬盘的Linux 作为包构建环境。这个独立的环境有一个很大的好处:构建软件包并不会篡改您当前安装的 Linux。唯一的不足是需要你额外的硬盘空间(零时的)用于每个独立构建环境。我想就现在这点硬盘容量不会是什么大问题。

构建工具将一个独立的构建环境安装到指定目录,然后在这个环境中构建软件包。该构建环境包含了一个基础系统,以及其他您在 RPM 文件中指定的附加软件包。


Link title

工作流程

下面的步骤给出了一个构建软件包的基本概要。当然在现实的例子中,您可能会在某些步骤上失败并且在成功之前不断重复相应步骤。该略述只是给您一个如何实现的大致感觉。

第一步 - 安装所需的东西

使用 YaST 从您的软件安装源安装下列软件包,如果您还未安装的话:

  • osc

或者,您更喜欢需要自己折腾的东西:

  • build
  • gpg

第二步 - 配置 build/osc

OSC

您首次启动 OSC,它将会询问您在 openSUSE 构建服务(OBS) 上的用户名和密码。这是大多数情况下您需要配置的。

构建

配置构建工具。有些设置您必须用心配置才可以匹配您的本地环境。例如:

  • 哪里可以获取用于安装构建环境的 RPM 软件包
  • 构建根目录的名称是什么
  • 哪里获取用以建立构建环境的 RPM 包
  • 构建根目录的基础文件名是什么

大多数设置已经在构建脚本中作为参数给出。

第三步 - 创建源文件目录

如果您正在使用 OSC,您可以跳过这一步,因为 OSC 已经自动为您下载了并储存了所需软件包。

如果您喜欢自己捣鼓构建工具,您必须创建您和root都能访问的目录.也就是您放置用于构建软件包(用于发布的 RPM)的文件的地方.你可以选择任何目录.但是,有一点必须满足,那就是您和 root 帐号都能够访问那个目录,因为只有 root 才可以执行构建环境安装步骤,而您又不想总是使用 root 帐号来构建软件包,所以,您需要一个可以共享的目录。

第四步 - 获取项目源文件

获取构建软件包所需的项目源文件.大多数项目以 tar 压缩包形式提供源代码。

第五步 - 创建规格文件

好的,现在您有了源文件,依照普通的 RPM 创建过程.为软件包创建规格文件(specfile) 。

第六步 - 构建软件包

在您创建完毕 RPM 规格文件后,您就可以尝试查看如何构建了.切换到 root 帐号,并且进入您存放规格文件,源文件,或补丁所在的目录.开始构建 After you have created the RPM spec file it is time to try to see if it builds. Switch to the root account and change into the directory where your spec file, source, and patches are. Then, start build.

第七步 - 测试软件包

在构建成功后,您应该测试您的软件包的可用性。


规格文件

RPM 规格文件应该按照 openSUSE 软件包惯例 进行编写。 As this is a fairly complex topic by itself there is an extra document about it. Please follow this Document closely while developing your specfile.

您可以在此找到一些针对不同软件包的 specfile 的例子: 构建服务 SVN

IBM developerWorks 同样有关于此话题的总结: 第 1 部分第 2 部分.


配置

构建环境变量

  • BUILD_DIST

您要构建的软件包所在的发行版。

  • BUILD_RPMS

openSUSE RPM 设想是这样的: 如果只挂载了 openSUSE DVD ,变量将被设置成 <DVD_mount_point>/suse 。如果 DVD 是被复制到一个目录的,那么变量将被设置成 <that_directory>/suse.

BUILD_RPMS 默认值为 /media/dvd/suse

  • BUILD_ROOT

RPM 将在该独立 chroot 后的目录之中构建。

BUILD_ROOT defaults to /var/tmp/build-root

  • BUILD_RPM_BUILD_STAGE

这是传送给 rpmbuild 的实际选项(参见 rpmbuild man 页面以获取完整的选项列表)

BUILD_RPM_BUILD_STAGE 默认值为 '-ba' (例如 在 %prep, %build 以及 %install 阶段之后构建二进制和源码包)。


例子

有很多现实的例子可以为不同的软件包组以及指定的软件包特性作示范。

KDE 软件包

BuildRequires: kdelibs3-devel update-desktop-files
Name: kvpnc License: GPL Group: Productivity/Networking/System Summary: GUI frontend for openswan and vpnc Version: 0.7.2 Release: 1 URL: http://home.gna.org/kvpnc/ BuildRoot:  %{_tmppath}/%{name}-%{version}-build Source0:  %name-%{version}.tar.bz2
%description The application can create configurations for various kinds of VPN connections. You should install also the "vpnc" or "openswan" package.
%prep # extract the source and go into the kvpnc-0.7.2 directory %setup -q # source the standard build enviroment as defined in kdelibs3 package . /etc/opt/kde3/common_options # replace the admin/ folder with the version from kdelibs3 (will work for sure with # current autoconf and automake) and create Makefile.in and configure script. update_admin --no-unsermake
%build # source the standard build enviroment as defined in kdelibs3 package . /etc/opt/kde3/common_options ./configure $configkde --disable-final # do compile with the number of jobs given to the --jobs parameter of the build script. make %{?jobs:-j%jobs}
%install iconv -f iso8859-1 -t utf-8 src/kvpnc.desktop > w && mv w src/kvpnc.desktop # 将所有文件安装到 构建根目录 make DESTDIR=$RPM_BUILD_ROOT install rm -rf $RPM_BUILD_ROOT/opt/kde3/share/doc/HTML/kvpnc # updates the .desktop file. It applys additional translations and Categories for a # proper position in the KDE menu %suse_update_desktop_file %name System Network # does find all localisation files and adds proper database attributes to them %find_lang %name
%clean # 构建完毕后清理干净磁盘 rm -rf $RPM_BUILD_ROOT
%files -f %name.lang %defattr(-,root,root) %dir /opt/kde3/share/icons/hicolor/16x16/apps %dir /opt/kde3/share/icons/hicolor/32x32/apps /opt/kde3/bin/kvpnc /opt/kde3/share/appl*/*/kvpnc.desktop /opt/kde3/share/apps/kvpnc /opt/kde3/share/icons/*/*/*/kvpnc*.png

Gnome 软件包

GNOME 软件包创建指南已经被移至 GNOME 打包页面.

Perl 软件包

使用 Perl 软件包相当简单,并且和打包非常相似,因为几乎所有的包都在 CPAN 上预先准备好了。

Name:         perl-Curses
Version:      1.12
Release:      1
# define the name from CPAN
%define cpan_name Curses
# do this package was known as "perl_cur" in old times. So we do need to Provide and Obsolete
# this package. YaST will install this package during update instead of the old one in this way.
Provides:     %cpan_name
# we better require the exact perl version, which was used to create this package
Requires:     perl = %{perl_version}
Group:        Development/Libraries/Perl
License:      Artistic License, Other License(s), see package
URL:          http://cpan.org/modules/by-module/Curses/
Summary:      A Dynamic Loadable Curses Module for Perl5
Source:       %cpan_name-%{version}.tar.bz2
BuildRoot:    %{_tmppath}/%{name}-%{version}-build
%description 这是适用于 Perl5 的动态可加载 curses 模块。该包可以在任何 CPAN 打包中找到。
%prep %setup -q -n %cpan_name-%{version}
%build perl Makefile.PL OPTIMIZE="$RPM_OPT_FLAGS -Wall" make make test
%install make DESTDIR=$RPM_BUILD_ROOT install_vendor %perl_process_packlist
%clean # 构建完毕后清理干净磁盘 rm -rf $RPM_BUILD_ROOT
%files %defattr(-,root,root) %doc Artistic Copying README %doc %{_mandir}/man3/* %{perl_vendorarch}/%cpan_name.pm %{perl_vendorarch}/auto/%cpan_name /var/adm/perl-modules/%{name}

资源