From Fedora Project Wiki

パッケージングガイドライン

パッケージングを行う際、パッケージに関しての問題を指摘するのはレビューアの責任で、そのパッケージャの責任はレビューアから指摘された問題に対応することです。レビューアとパッケージャは問題の重要度(そのパッケージを公開しないようにするか、リポジトリに追加した後で対応できるかどうか)を判断するために一緒に作業します。パッケージングガイドラインはパッケージング全般に共通する問題やリポジトリに追加すべきかどうかの重要度の判断方法をまとめたものです。これらのガイドラインは無視して良いものではありませんが、とにかく何でも従えば良いと言うものでもありません。

パッケージを作成していて、そのパッケージがガイドラインの一部の内容に従う必要はないと思ったら、どうか Fedora パッケージ委員会へその問題を提示するようにしてください。

どのようなパッケージでもレビューガイドラインに沿って確認しなければならないことを必ず覚えておいてください。

Author: Tom 'spot' Callaway (他の多くのドキュメントに基づいています)
Revision: 1.00
Initial Draft: Wednesday Feb 23, 2005
Last Revised: Tuesday July 21, 2009

名前付け

パッケージの名前が適切かどうかを判断するために名前付けガイドラインに目を通すべきです。

バージョンとリリース

バージョンとリリースのフィールドへの適切な番号の設定方法は名前付けガイドライン:パッケージバージョンで確認することができます。

法律

Fedora でパッケージングを行う際に考慮する必要がある様々な法的な内容があります。

ライセンス

パッケージのライセンスが適切かどうかを判断するためにライセンスライセンスガイドラインを再検討すべきです。

外部のコードなしでは使えないパッケージ

ランタイムオペレーティングシステム環境において、ソフトウェアの中には外部のコードがない状態では全く使えないものもあります。そういった依存する外部のコードが、フリーではなく、法的にも認められてないか、バイナリのみ(例外的に認められたファームウェア)の場合、その依存するソフトウェアは Fedora に含めることが認められていません。もし、そのコードの依存関係が Fedora 向けに認められたなら、準必須ソフトウェアとして Fedora に含めてパッケージングされるべきです。使える状態にするためにインターネットから集めてきたコードをダウンロードするようなソフトウェアは Fedora に含めることが認められていません(適切な依存関係として Fedora にパッケージングすることが認められているコードをダウンロードするかどうかに関係なく認められていません)。

また、これはサードパーティのソースからのパッケージ、又はコードがない状態で使えないようなパッケージは Fedora に含めることが認められていないということにもなります。

ビルド済みのバイナリやライブラリは含めない

Fedora のパッケージとして提供する全てのプログラムのバイナリやライブラリは、ソースパッケージに含められたソースコードからビルドされなければなりません。これは次のような理由から必要条件になります。

  • セキュリティ: ソースコードからビルドされていない準パッケージングされたプログラムのバイナリやライブラリは、悪意や危険、単に壊れているといった部分を含む可能性があります。また、パッチの作成もできません。
  • コンパイラフラグ: ソースコードからビルドされていない準パッケージングされたプログラムのバイナリやライブラリは、おそらくはセキュリティや最適化のための標準的な Fedora のコンパイラフラグでコンパイルされていません。

(.mo, .pdf, .png, .ps ファイルのような)コンテンツバイナリはソースコードからリビルドする必要はありません

もしプログラムのバイナリやライブラリについて何か疑問に思うことがあれば、ここに分かり易い判断基準があります。

  • それは実行可能なものですか?もしそうなら、おそらくはプログラムのバイナリです。
  • それは .so, so.#, .so.#.#.# といった拡張子のファイルを含んでいますか?もしそうなら、それはおそらくプログラムのライブラリです。
  • 疑問に思ったら、レビューアに尋ねてください。レビューアが分からない場合、そのレビューアが Fedora パッケージング委員会へ尋ねるでしょう。

また、ビルドするためにオープンソースではないコンポーネントを要求するパッケージも認められていません。(例 プロプライエタリなコンパイラが必要とか)

あるパッケージ内にビルド済みのバイナリを見つけたら、次のことを守らなければなりません

  • パッケージのビルドが行われる前に実行される %prep セクションで全てのビルド済みのプログラムのバイナリやライブラリを削除してください。例としては *.class, *.dll, *.DS_Store, *.exe, *.jar, *.o, *.pyc, *.pyo, *.egg, *.so などのファイルになりますが、これらのファイルのみに限定されるわけではありません。
  • 次のリリース時にバイナリを削除するようにアップストリームにお願いしてください。

例外事項

  • 以前のツールチェーンか、開発環境(オープンソース)を使用しないとビルドできないソフトウェア(通常はコンパイラ、又はクロスコンパイラ環境に関連します)があります。この判断が必要な状況に遭遇したら、承認をもらうために Fedora パッケージング委員会へ連絡してください。
  • バイナリのファームウェアのために作成された拡張機能は、それが必要条件であり続ける限り、ライセンスのバイナリファームウェアに記載されています。
  • 前もってパッケージングされたプログラムのバイナリやライブラリによっては再配布が許可されていない、又は特許のような法的な影響を受ける条項が含まれているかもしれません。そのような状況では、シンプルにそういったファイルを %prep セクションで削除すれば良いというわけではありません。メンテナはそういったファイルを含めないように変更したソースを作成する必要があります。パッケージング:ソース URL のアップストリームが禁止されているコードを使用しているときを参照してください。

Spec ファイルの読み易さ

全ての Fedora パッケージの spec ファイルは読み易い内容でなければなりません。レビューアが spec ファイルを読んで理解できない場合、レビュー作業ができないことになります。Fedora の spec ファイルはコードの難読化コンテストに参加するためのものではありません。

スクラッチからのパッケージ作成

スクラッチからパッケージを作成するとき、Fedora の spec ファイルテンプレート(Rpmdevtools を参照)をベースとして使用すべきです。spec ファイルのフォーマットや構成方法に関しては優先して、できるだけこのテンプレートを確認するようにしてください。その理由はこの spec ファイルが spec ファイルを書く唯一の正しい方法だと信じているからではありません。しかし、テンプレートを使用する方が誤りを発見し易かったり、やりたいことを素早く理解し易かったりするので品質を高めることになるからです。

既存のパッケージからの修正

既存の Fedora パッケージ以外のパッケージをベースにする場合、その正当性の検証とそのパッケージをインストールして使用することで何か問題が発生しないかを厳密に調査するようにしてください。何か変なことが起こらないかを調査していない状態でパッケージを追加するように提案しないでください。一見、害が無さそうに見えるコマンドも調査対象になります。

特に次のことをすべきです。

  • 全てのソースとパッチを検証する
  • spec ファイルに記載されているライセンスと実際のソフトウェアのライセンスがあっているかを検証する(タグを参照)
  • 要約とパッケージ説明内容の誤植や奇妙な箇所を修正する(要約とパッケージ説明内容を参照)
  • 正しいビルドルートが使用されているかを確認する
  • マクロの使用方法で一貫性があるかを確認する(マクロを参照)

オリジナルの作成者の履歴である古い changelog のエントリを保持してください。かなり古いバージョンか、何年分ものエントリは削除されるかもしれません。もし根本的な変更を行った場合、いずれにしても spec ファイルの大部分を書き直すことになります。 自由にスクラッチから changelog を書き始めるようにしてください。言い換えれば、自分で最良の判断をするようにしてください。

アーキテクチャのサポート

全ての Fedora パッケージは少なくとも1つの主要なアーキテクチャをサポートして、ソースのコンパイルとバイナリ RPMS をビルドできなければなりません。Fedora パッケージャは全ての主要なアーキテクチャをサポートするように努めるべきです。

コンテンツ、コンパイル/ビルドを行う必要のないコードやアーキテクチャから独立したコード(noarch)は目立った例外になります。

アーキテクチャの違いによるビルドの失敗

あるアーキテクチャ上でビルドできて動作する Fedora パッケージが他のアーキテクチャでコンパイルに失敗する場合、失敗するアーキテクチャは spec ファイルに ExcludeArch を設定すべきです。ExcludeArch に設定された各々のアーキテクチャは、そのアーキテクチャでコンパイル/ビルド/実行に失敗する理由を説明して bugzilla に登録する必要があります。登録したバグ ID は対応する ExcludeArch 行の隣にコメントとして記載すべきです。新しいパッケージはレビュープロセスの間は bugzilla エントリを持っていないので、そのパッケージが承認されるまでコメントに失敗する理由を記載するようにしてください。そして、承認された後で bugzilla に登録して、記載した長い説明をバグ ID に置き換えてください。そういったバグはシンプルに問題を追跡するために、以下のバグの blocking(もしくはそれ以上) としてマークされます。

ファイルシステムの置き場所

Fedora はファイルシステムの階層に関してファイルシステム階層標準(FHS)に準拠しています。FHS はシステム上のファイルの置き場所を定義します。Fedora パッケージは FHS に準拠しなければなりません。パッケージがレビューされるときに FHS から逸脱していたら正しい置き場所に修正すべきです。

このガイドラインに対して(GNU コーディング標準で特別扱いされている) libexecdir とクロスコンパイラのための /usr/target に目立った例外があります。

libexecdir

ファイルシステム階層標準(FHS)には libexecdir に関しての定義はありませんが、Fedora パッケージはその場所にファイルを置くことができます。libexecdir(Fedora システム上では /usr/libexec)はユーザが使用するというよりも主に他のプログラムによって実行されるように設計された実行プログラムのためのディレクトリとして使用すべきです。 Fedora の rpm は libexecdir のためのマクロ、%{_libexecdir} があります。パッケージャは %{_libexecdir}/%{name} のような、パッケージに特化した %{_libexecdir} のサブディレクトリに libexecdir ファイルを保存することが強く推奨されます。

rpmlint の使用

共通エラーの調査のために rpmlint を実行して、(rpmlint が間違っていない限り発生するエラーも含めて) RPM のエラーを修正するようにしてください。もし rpmlint の出力がよく分からないなら、大半のエラーとワーニングのもっと詳細な情報を取得できる -i オプションを付けるようにします。rpmlint パッケージは Fedora のリポジトリで利用可能です。

rpmlint エラー

rpmlint は完全に有効なパッケージだったとしても実行時に多くのゴミ出力を生成することがあります。このセクションでは、必要に応じて修正できるように、たくさん出力されるメッセージを解釈するのに役立つ情報を記載します。

  • E: foo-package no-packager-tag: このエラーは spec ファイルで Packager: が定義されていないときに発生します。Fedora では Packager タグを使用しないので、このエラーは無視することができます。
  • E: foo-package no-signature: このエラーはパッケージが署名されていないときに発生します。Fedora は CVS に SRPMS を保存しないので(SRPMS の中に含まれるファイルのみ保存する)、パッケージに署名する必要はありません。そのため、このエラーは無視することができます。
  • W: foo-package summary-ended-with-dot Summary of my package.: このエラーは spec ファイルの Summary: の内容がピリオドで終わっているときに発生します。ただ、行の最後からピリオドを削除してください。
  • E: foo-package wrong-script-end-of-line-encoding /path/to/somefile: このエラーはファイル中で DOS の改行が使用されているときに発生します。%prep セクションで sed を使用して %{__sed} -i 's/\r//' src/somefile とするか、dos2unix で修正してください。
  • E: foo-package invalid-lc-messages-dir /usr/share/locale/xx_XX/LC_MESSAGES/foo.mo: このエラーはよくある誤り検出で、通常は無視されます。

Changelogs

何か変更するときはいつも、パッケージの E-V-R(エポック-バージョン-リリース)を増加させて、changelog エントリに追加してください。changelog はパッケージの履歴を管理するのみでなく、さらにユーザ、仲間のパッケージャ、QA 担当者にあなたが行った変更を見つけ易くなるといった点でも重要です。

個々の変更が Bugzilla のバグに関連する場合、簡易リファレンスのために changelog のエントリにバグ ID を含めてください。

* Wed Jun 14 2003 Joe Packager <joe at gmail.com> - 1.0-2
- Added README file (#42).

次のフォーマットからどれか1つを使用しなければなりません。

* Fri Jun 23 2006 Jesse Keating <jkeating@redhat.com> - 0.6-4
- And fix the link syntax.
* Fri Jun 23 2006 Jesse Keating <jkeating@redhat.com> 0.6-4
- And fix the link syntax.
* Fri Jun 23 2006 Jesse Keating <jkeating@redhat.com>
- 0.6-4
- And fix the link syntax.


タグ

  • Packager タグは spec ファイルで使用すべきではありません。パッケージャの正体は changelog のエントリから明らかになります。Packager タグを使用しないことによって、ヘッダにあなたの名前があるのに、誰かがリビルドした良くないバイナリを見なくてすみます。また、www.rpm.org にある Packager タグの Maximum RPM の定義を参照してください。あなた自身がビルドした RPMS のパッケージャについての情報を含める必要があるなら、代わりに ~/.rpmmacros%packager を使用するようにしてください。
  • Vendor タグは使用すべきではありません。それはビルドシステムが自動的に設定するようにします。
  • Copyright タグは廃止予定です。ライセンスガイドラインの詳細を確認して、代わりに License タグを使用してください。そのソフトウェアを再配布するライセンスが何になるかに疑問があるなら、アップストリームの作者に連絡してください。
  • Summary タグで記載した内容はビリオドで終わるべきではありません。文法的な観点からこれが気になるなら、一旦座って、深呼吸して、そして克服してください。
  • 通常は、PreReq タグはそのままの Requires タグに置き換えるべきです。詳細については、Maximum RPM snapshot の素晴らしく木目の細かい依存関係の章を参照してください。
  • Source タグはアップストリームのソースを見つけるための場所を記載します。大抵の場合、アップストリームの tar ボールへの完全な URL にすべきです。特別なケースでは、Packaging:SourceURL のガイドラインを参照してください。

BuildRoot タグ

Fedora(現在は F-10) は spec ファイルに BuildRoot タグを設定することを必要としません。そして、もし BuildRoot タグが定義されても無視されます。既に提供済みの buildroot は %install セクションにあるコマンドが呼び出される前に自動的に削除されます。

Note.png
EPEL での違い
EPEL5 やそれ以下の rpm は BuildRoot タグを必要とします。そして手動で %install を削除しなければなりません。EPEL ガイドライン を参照してください

%clean

%clean セクションは F-13 やそれ以上から不要になります。F-12 やそれ以下(又は EPEL)では rm -rf %{buildroot} (又は $RPM_BUILD_ROOT) を含む %clean セクションを設定しなければなりません。

Requires

RPM は、例えば Perl モジュールなど、自動的にライブラリの依存関係を調べるというとても素晴らしい機能を持っています。要するに車輪の再発明をしなくて済みますが、rpm は依存関係のみを教えてくれます。libX11 パッケージのライブラリに依存している状態で rpm が既にその依存関係を取得している場合、通常は明示的に Requires: libX11 と定義する必要はありません。

BuildRequires は違います。自動的に依存関係を見つける処理はありません。それはつまり、ビルドが成功するために必要なパッケージの機能を明示的に定義しなければなりません。典型的な例として、BuildRequires に -devel パッケージが定義されます。 BuildRequires セクション を参照してください。

時々、ビルドするために gtk+-devel 1.2 かそれ以上のバージョンを要求をするパッケージを見かけます(そして、実行するためには gtk+ 1.2 かそれ以上が必要ですが、それは自動的に扱われます)。ここで考慮しておくことが2つあります。

1つ目は、要求する最も低いバージョンのパッケージがかなり古いもので、対象とするディストリビューションのリリースでインストールされているパッケージよりも古いバージョンなら、依存関係にそのバージョンを含める必要は全くありません。そのような例では、利用できるソフトウェアは新しいバージョンで十分です。gtk+-devel 1.2 以上の依存関係におけるバージョンは、(少なくとも)リリース 6.2 以降の全ての Red Hat のディストリビューションには不要です。大まかなルールとして、そのバージョンを要求しないなら、冗談半分にそのバージョンを追加しないでください。

2つ目は、エポック-バージョン-リリースの比較を堅牢にするためにバージョン指定された依存関係を追加するときに Epoch も定義しなければなりません。パッケージ foo の Epoch をチェックするための簡単な方法は次のように実行します。

rpm --query --qf "%{EPOCH}\n" packagename

典型的な例として、-devel パッケージのために他のパッケージを要求します。通常は rpm によって自動的に取得されません。foo-devel パッケージが foo-config スクリプトを持っているなら、どのパッケージを foo が要求しているかの強力な手掛かりとして foo-config --libs や foo-config --cflags を実行するようにしてください。

$ gtk-config --cflags
-I/usr/include/gtk-1.2 -I/usr/include/glib-1.2 -I/usr/lib/glib/include -I/usr/X11R6/include
$ gtk-config --libs
-L/usr/lib -L/usr/X11R6/lib -lgtk -lgdk -rdynamic -lgmodule -lglib -ldl -lXi -lXext -lX11 -lm

これは gtk+-devel が次のパッケージを要求していることになります。

Requires: glib-devel libXi-devel libXext-devel libX11-devel

PreReq

パッケージには PreReq を使用しないでください。昔々、RPM がインストールトランザクションの中でインストールの順番を決定するとき、依存解決のループの中で PreReq は標準の Require よりも "優先" するために使用していました。しかし、現在はこの用途には使用しません。

ファイルの依存関係

rpm にはパッケージの代わりにファイルの依存関係を持つ機能もあります。できるだけ /etc, /bin, /sbin, /usr/bin 又は /usr/sbin 以外でファイルの依存関係を使用しないようにしてください。そのようなディレクトリ以外のファイルの依存関係を使用することは依存関係を探す巨大な xml ファイルをダウンロードして解析するために yum (や repmod 形式を使用するその他の依存関係解決ツール)を必要とします。エンドユーザに待ち時間を取らせないために、ファイルではなくパッケージの依存関係を持たせることで依存関係解決ツールはこの処理を行いません。ファイルの依存関係は、こういった懸念事項よりも優先する他の技術的な検討事項があるときもあります。特別な例の1つとして %{_libdir}/mozilla/plugins にインストールされるパッケージです。この場合、ただこのディレクトリを所有するために特定ブラウザをパッケージの依存関係に持つと、多くの不要なパッケージを一緒にインストールされてしまいます。そういった依存関係を解決するためにディレクトリを要求する方が良い選択でしょう。

明示的な Requires

パッケージには絶対的に必要な場合を除いてライブラリの明示的な Requires を定義してはいけません。明示的なライブラリの Requires が必要なときは、そのことを説明するコメントを spec ファイルに残すべきです。

一般的にはライブラリの SONAME の依存関係を自動的に追加する rpmbuild を信頼します。最近のパッケージ管理ツールは必要なパッケージを探してきて依存関係を解決する機能があります。特定のパッケージの明示的な依存関係は手動で RPM パッケージをインストールしようとしている経験の浅いユーザにとっては助けになるかもしれません。しかし、ライブラリ/ファイルをあるパッケージから別のものに移行した場合、パッケージ名が変更された場合、複数の代替パッケージのうち1つだけあれば十分な場合、バージョン指定された明示的な依存関係が古くなってしまった場合など、このような依存関係は混乱を招くことがこれまでの歴史から分かっています。さらに、あるケースでは、古い明示的な依存関係が不要なアップデート/リビルドを要求します。例えば、Fedora パッケージは2回のフルリリースサイクル向けに、過去の Provides を維持するためにのみ Requires します。

バージョン指定された明示的な依存関係のための模範的な定義は次の通りです。

  # libfubar.so.1 の自動検出される依存関係は十分ではありません
  # 最低でも2つのセグメンテーションフォールトを修正したリリースを厳密に必要とします
  Requires: libfubar >= 0:1.2.3-7

パッケージャは明示的な依存関係が不正確で余分なものにならないように、必要に応じて見直すべきです。上述した例において、現時点の Fedora リリースが libfubar < 1.2.3-7 を提供していないなら、この明示的なバージョン指定された依存関係を今後も残しておく必要はありません。

自動生成された Requires/Provides を取り除く

RPM は Requires/Provides をビルド時に自動生成しようとしますが、状況によっては、自動生成された Requires/Provides は正しくないものか、望まないものです。自動生成された Requires/Provides を取り除く方法の詳細については Packaging:AutoProvidesAndRequiresFiltering を参照してください。

BuildRequires

パッケージ開発やテストの中で、ビルドに必要な依存関係が欠落していないかを検証してください。適切なビルドのための依存関係を定義することは自動ビルドシステムと同様に、全ての開発者とテスターの作業を効率化します。というのは、手動で欠落したビルドの依存関係を探す必要がないからです。また、それは何らかの要因によるビルドエラーではなく、極めて重要な機能を欠落させた状態でビルドしないようにするための安全な機能です。例えば、グラフのアプリケーションは、そのパッケージの configure スクリプトによって libpng がインストールされていないことを検出すると PNG サポートを排除するかもしれません。

BuildRequires をパッケージへ追加する前に、 Requires を適切に定義してください。

欠落した BuildRequires を検出する方法として2つの方法が提案されています。rpmdev-rmdevelrpmsmock です。rpmdev-rmdevelrpms はシステムから全ての開発関連パッケージを削除するように設計されています。もしビルドに失敗するか、ビルドのための依存関係が欠落して特定の機能がなくなってしまったら、欠落した依存関係を探して追加されます。詳細は rpmdev-rmdevelrpms セクションを参照してください。
mock はビルドの依存関係を確認する優れたもう1つの方法です。全ての開発関連パッケージ削除するよりも、chroot を行ってパッケージをビルドしようとします。その方法だと、通常の、毎日使用する環境を変更する必要はありません。そして、パッケージが正常にビルドされることを確認します。しかし、mock は要求された全てのパッケージをダウンロードするためにインターネットとの接続が必要です。 MockTricks に詳細があります。他に mock に似たツールで、 mach も Fedora のリポジトリで利用することができます。

rpmdev-rmdevelrpms

rpmdevtools ツールキットに含まれている rpmdev-rmdevelrpms スクリプトは、欠落した BuildRequires を探すために Ville Skyttä によって開発されました。シンプルにそのスクリプトを実行して、この例のような全ての *-devel パッケージとビルドツールを削除してください。

[root@build-fc1 /] # rpmdev-rmdevelrpms
Found 52 devel packages:
guile-devel-1.6.4-8.2
bison-1.875-5
m4-1.4.1-14
flex-2.5.4a-30
openssl-devel-0.9.7a-23
automake-1.7.8-1
fontconfig-devel-2.2.1-6.1
XFree86-devel-4.3.0-42
tcl-devel-8.3.5-93
SDL_image-devel-1.2.3-3
SDL_ttf-devel-2.0.6-0.fdr.3.1
pth-devel-2.0.0-0.fdr.1.1
libIDL-devel-0.8.2-1
atk-devel-1.4.0-1
gtk2-devel-2.2.4-5.1
libmng-devel-1.0.4-4
glib-devel-1.2.10-11
gtk+-devel-1.2.10-28.1
audiofile-devel-0.2.3-7
compface-1.4-0.fdr.3.1
esound-devel-0.2.31-1
libungif-devel-4.1.0-16
gnome-libs-devel-1.4.1.2.90-35
openldap-devel-2.1.22-8
aspell-devel-0.50.3-16
gpgme03-devel-0.3.16-0.fdr.2.1
freeglut-devel-1.3-1.20020125.3
e2fsprogs-devel-1.34-1
db4-devel-4.1.25-14
krb5-devel-1.3.1-6
autoconf-2.57-3
libtool-1.5-8
gdbm-devel-1.8.0-21
freetype-devel-2.1.4-5
pkgconfig-0.14.0-6
ncurses-devel-5.3-9
tk-devel-8.3.5-93
SDL-devel-1.2.5-9
SDL_mixer-devel-1.2.4-9
zlib-devel-1.2.0.7-2
libgpg-error-devel-0.6-0.fr.3.1
glib2-devel-2.2.3-1.1
pango-devel-1.2.5-1.1
libjpeg-devel-6b-29
libpng-devel-1.2.2-17
ORBit-devel-0.5.17-10.3
clamav-devel-0.65-0.fdr.4.1
cyrus-sasl-devel-2.1.15-6
libtiff-devel-3.5.7-14
imlib-devel-1.9.13-14
gdk-pixbuf-devel-0.22.0-3.0
pilot-link-devel-0.11.8-1
Remove them? [y/N]  y[
]Removing.................................................................................................
................................................................Done.

その後、あなたの RPM パッケージをビルドしようとしてください。既に BuildRequires に定義しているパッケージは yum で再インストールしてください。もしこの時点でビルドに失敗したら、ビルド処理を調査する必要があります。そして、エラーログから欠落した BuildRequires を究明します。

パッケージに望まれるツールか、オプションのライブラリが欠落していないか、ビルド処理の configure の部分を特に注意深く確認してください。

デフォルトでは、rpmdev-rmdevelrpms スクリプトは、システムが正常に動作するために必要なパッケージを削除しようとするかもしれません。通常は、不十分な依存関係のために失敗するでしょう(これが、つまり yum remove の代わりに rpm -e を使用している理由です)。

この例としては gettext や libgcj パッケージがあります。gettext は通常は開発のみに使用されるパッケージですが、例えば redhat-lsb は gettext に依存します。また、RH9 の Konqueror は SSL のために openssl-devel を必要とします。rpmdev-rmdevelrpms が無視するパッケージを幾つかマークしたいなら、/etc/rpmdevtools/rmdevelrpms.conf か、ホームディレクトリの .rmdevelrpmsrc にその内容を設定してください。そして、ビルド時はこの方法で設定した対象パッケージに対して十分に注意するようにしてください。

例外事項

次のパッケージやその BuildRequires としての依存関係は、一般的によく使用されるので spec ファイルに定義する必要はありません。これらのパッケージは最小ビルド環境として認識されています。

bash
bzip2
coreutils
cpio
diffutils
fedora-release
findutils
gawk
gcc
gcc-c++
grep
gzip
info
make
patch
redhat-rpm-config
rpm-build
sed
shadow-utils
tar
unzip
util-linux-ng
which

要約とパッケージ説明

要約は短くパッケージの説明内容を簡潔にしたものにすべきです。パッケージ説明は要約から発展させます。パッケージ説明にインストールガイドを含めないでください。それはマニュアルではありません。パッケージが手動設定か、ユーザに対する重要なインストールガイドを必要とするなら、パッケージのドキュメントを参照させるようにしてください。必要だと思ったら README.Fedora か、似たようなものを追加してください。また、パッケージ説明の1行は80文字以上にならないように注意してください。

個人的な優先度は置いておいて、要約やパッケージ説明にはアメリカ英語のつづりを使用してください。パッケージには、可能なら非英語圏のために翻訳された要約やパッケージ説明を追加で含めることもできます。

要約やパッケージ説明内容の商標

パッケージャは要約やパッケージ説明に商標を使用する方法に注意すべきです。次にルールがあります。

  • 決して "(TM)"、"(R)" (又はユニコードの ™/®) を使用しないでください。これらのマークを適切に使用するには信じられないぐらい複雑です。そのため、これらのマークを全く使用しないのが我々にとっては安全です。
  • 曖昧ではない方法で商標を使用してください。"似ている" とか "ような" というフレーズは避けてください。例があります。
  • 悪い例: Adobe Photoshop に似たものです
  • 良い例: Adobe Photoshop の PSD ファイルをサポートします ...
  • 悪い例: Microsoft Office の Linux バージョンです
  • 良い例: Microsoft Office の DOC ファイルをサポートするワードプロセッサです

あなたがよく分からないなら、誰かが混乱する可能性はないかと自問してください。そして、このパッケージは商標が必要かを考えてください。疑問に思ったら、商標を外すようにしてください。

文字エンコーディング

ASCII 文字の範囲外で文字を使用する必要がない限り、spec ファイルのエンコーディングについて考慮する必要はないでしょう。ASCII 文字以外を使用する必要があるなら、UTF-8 で spec ファイルを記述するようにしてください。ASCII 文字が何なのか分からないなら、このグラフを参照してください。

ASCII 文字ではないファイル名

同様に、ASCII 文字以外の文字を含むファイル名は UTF-8 でエンコードされなければなりません。ファイル名が何のエンコーディングかを設定する方法がないので、全てのファイル名に同じエンコーディングを使用することがユーザがファイル名を読めることを保証するために最も良い方法です。もしアップストリームが UTF-8 でエンコードされていないファイル名でリリースしていたら、%install セクションで(convmv パッケージにある)convmv のようなユーティリティを使用してファイル名を変換することができます。

ドキュメント

配布されているソースに含まれる、いかなる関連ドキュメントもパッケージ内に含まれるべきです。ビルド方法については無関係なドキュメントもあります。よくある INSTALL ファイルは一般的なビルド方法について記載していたり、例えば、README.MSDOS のように Linux 以外のシステムのドキュメントがあったりします。どのサブパッケージにドキュメントを含めるかにも注意を払ってください。例えば、API の例に関するドキュメントは -devel パッケージに含めて、メインパッケージには含めません。さらに大量にドキュメントがあるなら、サブパッケージに分割することを検討してください。この例では、サブパッケージの名前として *-doc が推奨されます。そして Group タグの設定は Documentation になります。

また、あるパッケージが %doc にドキュメントを含んでいるなら、アプリケーションの実行に影響を与えてはいけません。要約すると、ドキュメントが %doc にあるなら、そのプログラムはそこにドキュメントがなかったとしても正常に実行されなければなりません。

コンパイラフラグ

パッケージをビルドするために使用するコンパイラはシステム内で rpm 設定としてセットされた適切なコンパイラフラグを受け取るべきです。2006年8月以後は、C/C++ や Fortran コンパイラのために $RPM_OPT_FLAGS/%{optflags} が実際に使用されます。その変数の中身がパッケージのビルドにおいてコンパイラによって実際に使用される基本フラグになります。このフラグをフィルタリングしたり、追加や上書きしたりすることは、理由があるときには許可されています。そのように変更する論理的根拠は、特に上書きやフィルターするときに spec ファイル内に記載してレビューされるべきです。

Debuginfo パッケージ

パッケージングするときはデバッグに役立つ -debuginfo パッケージも作成すべきです。又は -debuginfo パッケージを生成できない場合は明示的に無効にすべきです。とは言え、いずれにしても rpmbuild がそうします。-debuginfo パッケージが明示的に無効にするなら、spec ファイル内にその理由を説明したコメントを記載します。Debuginfo パッケージの詳細については Packaging:Debuginfo を参照してください。

Devel パッケージ

あるソフトウェアで開発に必要なファイルを含めるようにパッケージングする場合、そのようなファイルは -devel サブパッケージに含めるようにすべきです。以下に -devel に含めるべきファイル種別の例を示します。

  • ヘッダファイル(.h ファイル)
  • バージョン指定のない共有ライブラリ(libfoo.so)。バージョン指定のある共有ライブラリ(libfoo.so.3, libfoo.so.3.0.0)は -devel に含めるべきではありません。

分かり易い基本原則として、あるファイルが開発のために使用されてベースパッケージで実行するのに必要ないなら、そのファイルを -devel に含めるべきです。

Pkgconfig ファイル

pkgconfig(.pc) ファイルをどのパッケージに含めるかは、その使用方法に依存します。pkgconfig ファイルは、ほとんど開発の目的のために使用されるので、-devel パッケージに含められます。分かり易い例外としては、メインパッケージそのものがユーザ向けのランタイムをインストールしない開発向けのツールがあります。例えば、gcc や gdb になります。

Note.png
EPEL との違い
Fedora の rpm は自動的に pkgconfig と pkgconfig ファイルに関連する依存関係を検出します。EPEL5 又はそれ以下のバージョンの rpm はこの機能がないので EPEL ガイドラインに従うべきです。

ベースパッケージの要求

-devel パッケージは Requires: %{name} = %{version}-%{release} のようにフルバージョンの依存関係を使用してベースパッケージを要求しなければなりません。普通は、-devel 以外のサブパッケージもフルバージョンの依存関係を使用してベースパッケージを要求すべきです。

共有ライブラリ

できるだけ(そして適切なら)、ライブラリを含む Fedora パッケージは共有ライブラリとしてパッケージングすべきです。さらに、動的リンカの全てのデフォルトパスに存在する共有ライブラリファイル(単なるシンボリックリンクではない)を含むバイナリ RPM パッケージは %post%postun スクリプトで /sbin/ldconfig コマンドを実行しなければなりません。パッケージがライブラリを含む複数のサブパッケージで構成される場合、各々のサブパッケージもまた %post%postun スクリプトを /sbin/ldconfig コマンドを実行すべきです。正しい構文の例は次の通りです。

%post -p /sbin/ldconfig

%postun -p /sbin/ldconfig

この特殊な構文は /sbin/ldconfig%post%postun で実行される場合にのみ有効であることを覚えておいてください。%post%postun のスクリプトレットの中で他のコマンドを実行したい場合、次のように、そのスクリプトレットの最初に /sbin/ldconfig を実行するようにします。

%post
/sbin/ldconfig
/usr/bin/foo --add

%postun
/sbin/ldconfig
/usr/bin/foo --remove

静的ライブラリのパッケージング

Packages including libraries should exclude static libs as far as possible (eg by configuring with --disable-static). Static libraries should only be included in exceptional circumstances. Applications linking against libraries should as far as possible link against shared libraries not static versions.

Libtool archives, foo.la files, should not be included. Packages using libtool will install these by default even if you configure with --disable-static, so they may need to be removed before packaging. Due to bugs in older versions of libtool or bugs in programs that use it, there are times when it is not always possible to remove *.la files without modifying the program. In most cases it is fairly easy to work with upstream to fix these issues. Note that if you are updating a library in a stable release (not devel) and the package already contains *.la files, removing the *.la files should be treated as an API/ABI change -- ie: Removing them changes the interface that the library gives to the rest of the world and should not be undertaken lightly.

静的ライブラリのパッケージング

  • In general, packagers are strongly encouraged not to ship static libs unless a compelling reason exists.
  • We want to be able to track which packages are using static libraries (so we can find which packages need to be rebuilt if a security flaw in a static library is fixed, for instance). There are two scenarios in which static libraries are packaged:
  1. Static libraries and shared libraries. In this case, the static libraries must be placed in a *-static subpackage. Separating the static libraries from the other development files in *-devel allow us to track this usage by checking which packages BuildRequire the *-static package. The intent is that whenever possible, packages will move away from using these static libraries, to the shared libraries.
  2. Static libraries only. When a package only provides static libraries you can place all the static library files in the *-devel subpackage. When doing this you also must have a virtual Provide for the *-static package:
%package devel
Provides: foo-static = %{version}-%{release}

Packages which explicitly need to link against the static version must BuildRequire: foo-static, so that the usage can be tracked.

  • If (and only if) a package has shared libraries which require static libraries to be functional, the static libraries can be included in the *-devel subpackage. The devel subpackage must have a virtual Provide for the *-static package, and packages dependent on it must BuildRequire the *-static package.

実行ファイルを静的にリンクすること

  • Static linkage is a special exception and should be decided on a case-by-case basis. The packager must provide rationale for linking statically, including precedences where available, to FESCO for approval.
  • If you link statically against a library, add yourself to the initialcc list for the library so you can watch for any security issues or bug fixes for which you'd want to rebuild your package against a new version of the library. Here are instructions for making that request.

FESCo へ知らせる必要のないプログラム

  • Programs written in OCaml do not normally link dynamically to OCaml libraries. Because of that this requirement is waived. (OCaml code that calls out to libraries written in C should still link dynamically to the C libraries, however.)
  • If a library you depend on only provides a static version your package can link against it provided that you BuildRequire the *-static subpackage. Packagers in such a situation should be aware that if a shared library becomes available, that you should adjust your package to use the shared library.

例外として許可されたプログラム

  • yaboot has permission to link statically since it's a boot loader that uses e2fsprogs-libs to read the filesystem

システムライブラリの重複

システムに存在するライブラリのローカルコピーをパッケージに含めてビルドすべきではありません。そういったパッケージはシステムライブラリを使用するように修正すべきです。こうすることにより、システムのコアライブラリが修正された後でも古いバグやセキュリティホールが残り続けるのを防ぐことができます。詳細については一括りにまとめないライブラリを参照してください。

Rpath に気を付けること

Sometimes, code will hardcode specific library paths when linking binaries (using the -rpath or -R flag). This is commonly referred to as an rpath. Normally, the dynamic linker and loader (ld.so) resolve the executable's dependencies on shared libraries and load what is required. However, when -rpath or -R is used, the location information is then hardcoded into the binary and is examined by ld.so in the beginning of the execution. Since the Linux dynamic linker is usually smarter than a hardcoded path, we usually do not permit the use of rpath in Fedora.

There is a tool called check-rpaths which is included in the rpmdevtools package. It is a good idea to add it to the %__arch_install_post macro in your ~/.rpmmacros config file:

%__arch_install_post            \
/usr/lib/rpm/check-rpaths     \
/usr/lib/rpm/check-buildroot

When check-rpaths is run, you might see output like this:

ERROR   0001: file '/usr/bin/xapian-tcpsrv' contains a standard rpath '/usr/lib64' in [/usr/lib64] 

Any rpath flagged by check-rpaths MUST be removed.

内部ライブラリのための Rpath

When a program installs internal libraries they are often not installed in the system path. These internal libraries are only used for the programs that are present in the package (for example, to factor out code that's common to the executables). These libraries are not intended for use outside of the package. When this occurs, it is acceptable for the programs within the package to use an rpath to find these libraries.

Example:

# Internal libraries for myapp are present in:
%{_libdir}/myapp/
%{_libdir}/myapp/libmyapp.so.0.3.4
%{_libdir}/myapp/libmyapp.so

# myapp has an rpath to %{_libdir}/myapp/
readelf -d /usr/bin/myapp | grep RPATH
 0x0000000f (RPATH)                      Library rpath: [/usr/lib/myapp]
Idea.png
Non-Internal Libraries
When programs outside of the package are supposed to link against the library, it is better to use the Alternative to Rpath or simply move the libraries into %{_libdir} instead. That way the dynamic linker can find the libraries without having to link all the programs with an rpath.

Rpath に代わるもの

Often, rpath is used because a binary is looking for libraries in a non-standard location (standard locations are /lib, /usr/lib, /lib64, /usr/lib64). If you are storing a library in a non-standard location (e.g. /usr/lib/foo/), you should include a custom config file in /etc/ld.so.conf.d/. For example, if I was putting 32 bit libraries of libfoo in /usr/lib/foo, I would want to make a file called "foo32.conf" in /etc/ld.so.conf.d/, which contained the following:

/usr/lib/foo

Make sure that you also make a 64bit version of this file (e.g. foo64.conf) as well (unless the package is disabled for 64bit architectures, of course).

Rpath を削除すること

There are several different ways to fix the rpath issue:

  • If the application uses configure, try passing the --disable-rpath flag to configure.
  • If the application uses a local copy of libtool, add the following lines to the spec after %configure:
%configure
sed -i 's|^hardcode_libdir_flag_spec=.*|hardcode_libdir_flag_spec=""|g' libtool
sed -i 's|^runpath_var=LD_RUN_PATH|runpath_var=DIE_RPATH_DIE|g' libtool
  • Sometimes, the code/Makefiles can be patched to remove the -rpath or -R flag from being called. This is not always easy or sane to do, however.
  • As a last resort, Fedora has a package called chrpath. When this package is installed, you can run chrpath --delete on the files which contain rpaths. So, in our earlier example, we'd run:
chrpath --delete $RPM_BUILD_ROOT%{_bindir}/xapian-tcpsrv

Make sure that you remember to add a BuildRequires: chrpath if you end up using this method.

設定ファイル

パッケージの設定ファイルはすぐに分かる状態でなければなりません。

大まかな方法として、よく考えて変更することで何かを壊してしまうと推測されない限り、%config の代わりに %config(noreplace) を使用してください。言い換えれば、パッケージのアップグレード時にローカルでの設定ファイルの変更内容を上書きする前に真剣に考えてください。noreplace を使用しない例としては、新しいリビジョンのパッケージが以前のリビジョンのパッケージの設定ファイルでは動作しないように設定ファイルを変更するときです。%config が使用されているときはいつでも、その理由を説明した簡潔なコメントを spec ファイルに追加してください。

/usr 配下で %config や %config(noreplace) を使用しないでください。Fedora では /usr に設定ファイルを置かないようにしています。

初期化スクリプト

現時点では、Fedora は SystemV スタイルの初期化スクリプトのみをサポートしています。SystemV スタイルの詳細なガイドラインについては Packaging:SysVInitScript を参照してください。

デスクトップファイル

If a package contains a GUI application, then it needs to also include a properly installed .desktop file. For the purposes of these guidelines, a GUI application is defined as any application which draws an X window and runs from within that window. Installed .desktop files MUST follow the desktop-entry-spec , paying particular attention to validating correct usage of Name, GenericName, Categories , StartupNotify entries.

アイコンタグとデスクトップファイル

The icon tag can be specified in two ways:

  • Full path to specific icon file:

Icon=/usr/share/pixmaps/comical.png

  • Short name without file extension:

Icon=comical

The short name without file extension is preferred, because it allows for icon theming (it assumes .png by default, then tries .svg and finally .xpm), but either method is acceptable.

.desktop ファイルの作成

If the package doesn't already include and install its own .desktop file, you need to make your own. You can do this by including a .desktop file you create as a Source: (e.g. Source3: %{name}.desktop) or generating it in the spec file. Here are the contents of a sample .desktop file (comical.desktop):

[Desktop Entry]
Name=Comical
GenericName=Comic Archive Reader
Comment=Open .cbr & .cbz files
Exec=comical
Icon=comical
Terminal=false
Type=Application
Categories=Graphics;

desktop-file-install の使用方法

It is not simply enough to just include the .desktop file in the package, one MUST run desktop-file-install OR desktop-file-validate in %install (and have BuildRequires: desktop-file-utils), to help ensure .desktop file safety and spec-compliance. desktop-file-install MUST be used if the package does not install the file or there are changes desired to the .desktop file (such as add/removing categories, etc). desktop-file-validate MAY be used instead if the .desktop file's content/location does not need modification. Here are some examples of usage:

desktop-file-install                                    \
--dir=${RPM_BUILD_ROOT}%{_datadir}/applications         \
%{SOURCE3}
desktop-file-install                                    \
--add-category="AudioVideo"                             \
--delete-original                                       \
--dir=%{buildroot}%{_datadir}/applications              \
%{buildroot}/%{_datadir}/foo.desktop
desktop-file-validate %{buildroot}/%{_datadir}/applications/foo.desktop
  • For new packages, do not apply a vendor tag to desktop files. Existing packages that use a vendor tag must continue to do so for the life of the package. This is mostly for the sake of menu-editing (which bases off of .desktop file/path names).

マクロ

Use macros instead of hard-coded directory names (see Packaging:RPMMacros ).

Having macros in a Source: or Patch: line is a matter of style. Some people enjoy the ready readability of a source line without macros. Others prefer the ease of updating for new versions when macros are used. In all cases, remember to be consistent in your spec file and verify that the URLs you list are valid. spectool (from the rpmdevtools package) can aid you in checking that whether the URL contains macros or not.

If you need to determine the actual string when it contains macros, you can use rpm. For example, to determine the actual Source: value, you can run:

rpm -q --specfile foo.spec --qf "$(grep -i ^Source foo.spec)\n"

%{buildroot} と %{optflags} vs $RPM_BUILD_ROOT と $RPM_OPT_FLAGS を使用すること

There are two styles of defining the rpm Build Root and Optimization Flags in a spec file:

macro style variable style
Build Root %{buildroot} $RPM_BUILD_ROOT
Opt. Flags %{optflags} $RPM_OPT_FLAGS

There is very little value in choosing one style over the other, since they will resolve to the same values in all scenarios. You should pick a style and use it consistently throughout your packaging.

Mixing the two styles, while valid, is bad from a QA and usability point of view, and should not be done in Fedora packages.

%makeinstall マクロを使用しない理由

Fedora's RPM includes a %makeinstall macro but it must NOT be used when make install DESTDIR=%{buildroot} works. %makeinstall is a kludge that can work with Makefiles that don't make use of the DESTDIR variable but it has the following potential issues:

  • %makeinstall overrides a set of Make variables during "make install" and prepends the %{buildroot} path. I.e. it performs make prefix="%{buildroot}%{_prefix}" libdir="%{buildroot}%{_libdir} ...".
  • It is error-prone and can have unexpected effects when run against less than perfect Makefiles, e.g. the buildroot path may be included in installed files where variables are substituted at install-time.
  • It can trigger unnecessary and wrong rebuilds when executing "make install", since the Make variables have different values compared with the %build section.
  • If a package contains libtool archives, it can cause broken *.la files to be installed.

Instead, Fedora packages should use: make DESTDIR=%{buildroot} install or make DESTDIR=$RPM_BUILD_ROOT install

ソース RPM ビルド時間のマクロ

All macros in Summary: and %description need to be expandable at srpm buildtime. Because SRPMs are built without the package's BuildRequires installed, depending on macros defined outside of the spec file can easily lead to the unexpanded macros showing up in the built SRPM. One way to check is to create a minimal chroot and build the srpm:

mock --init
mock --copyin [SRPM] /
mock --shell bash
rpm -ivh [SRPM]
cd /builddir/build/SPECS
rpmbuild -bs --nodeps [SRPM]
rpm -qpiv /builddir/build/SRPMS/[SRPM]

Check the rpm output for unexpanded macros (%{foo}) or missing information (when%{?foo} is expanded to the empty string). Even easier is to simply avoid macros in Summary: and %description unless they are defined in the current spec file.

%define よりも優先される %global

Use %global instead of %define, unless you really need only locally defined submacros within other macro definitions (a very rare case).

Rationale: The two macro defining statements behave the same when they are a the top level of rpm's nesting level.

But when they are used in nested macro expansions (like in  %{!?foo: ... } constructs, %define theoretically only lasts until the end brace (local scope), while %global definitions have global scope.

Note.png
In Fedora 12 and earlier, a minor bug in rpm caused the local macro definition to not be garbage collected unless other events forced rpm to. So the bug is seldom triggered but when it is it is difficult to diagnose the issue. Using %global by default helps to avoid creation of new latent bugs. Bugfix description

ローカルファイルを扱うこと

If the package includes translations, add

BuildRequires: gettext

If you don't, your package could fail to generate translation files in the buildroot.

Fedora includes an rpm macro called %find_lang. This macro will locate all of the locale files that belong to your package (by name), and put this list in a file. You can then use that file to include all of the locales. %find_lang should be run in the %install section of your spec file, after all of the files have been installed into the buildroot. The correct syntax for %find_lang is usually:

%find_lang %{name}

In some cases, the application may use a different "name" for its locales. You may have to look at the locale files and see what they are named. If they are named myapp.mo, then you will need to pass myapp to %find_lang instead of %{name}. After %find_lang is run, it will generate a file in the active directory (by default, the top level of the source dir). This file will be named based on what you passed as the option to the %find_lang macro. Usually, it will be named %{name}.lang. You should then use this file in the %files list to include the locales detected by %find_lang. To do this, you should include it with the -f parameter to %files.

%files -f %{name}.lang
%defattr(-,root,root,-)
%{_bindir}/foobar
...

If you are already using the -f parameter for the %files section where the locales should live, just append the contents of %{name}.lang to the end of the file that you are already using with -f. (Note that only one file may be used with %files -f.)

Here is an example of proper usage of %find_lang, in foo.spec:

...
%prep
%setup -q

%build
%configure --with-cheese
make %{?_smp_mflags}

%install
make DESTDIR=%{buildroot} install
%find_lang %{name}

%clean
rm -rf %{buildroot}

%files -f %{name}.lang
%defattr(-,root,root,-)
%doc LICENSE README
%{_bindir}/foobar

%changelog
* Thu May 4 2006 Tom "spot" Callaway <tcallawa@redhat.com> 0.1-1
- sample spec that uses %%find_lang

%find_lang を使用する必要がある理由

Using %find_lang helps keep the spec file simple, and helps avoid several other packaging mistakes.

  • Packages that use %{_datadir}/* to grab all the locale files in one line also grab ownership of the locale directories, which is not permitted.
  • Most packages that have locales have lots of locales. Using %find_lang is much easier in the spec file than having to do:
%{_datadir}/locale/ar/LC_MESSAGES/%{name}.mo
%{_datadir}/locale/be/LC_MESSAGES/%{name}.mo
%{_datadir}/locale/cs/LC_MESSAGES/%{name}.mo
%{_datadir}/locale/de/LC_MESSAGES/%{name}.mo
%{_datadir}/locale/es/LC_MESSAGES/%{name}.mo
...
  • As new locale files appear in later package revisions, %find_lang will automatically include them when it is run, preventing you from having to update the spec any more than is necessary.

Keep in mind that usage of %find_lang in packages containing locales is a MUST.

タイムスタンプ

When adding file copying commands in the spec file, consider using a command that preserves the files' timestamps, eg. cp -p or install -p.

When downloading sources, patches etc, consider using a client that preserves the upstream timestamps. For example wget -N or curl -R. To make the change global for wget, add this to your ~/.wgetrc: timestamping = on, and for curl, add to your ~/.curlrc: -R.

並列に make

Whenever possible, invocations of make should be done as

make %{?_smp_mflags}

This generally speeds up builds and especially on SMP machines.

Do make sure, however, that the package builds cleanly this way as some make files do not support parallel building. Therefore you should consider adding

%_smp_mflags -j3

to your ~/.rpmmacros file -- even on UP machines -- as this will expose most of these errors.

スクリプトレット

Great care should be taken when using scriptlets in Fedora packages. If scriptlets are used, those scriptlets must be sane. Some common scriptlets are documented here: Packaging:ScriptletSnippets.

スクリプトレットの要求仕様

Do not use the Requires(pre,post) style notation for scriptlet dependencies, because of two bugs in RPM. Instead, they should be split like this:

Requires(pre): ...
Requires(post): ...

For more information, see www.redhat.com .

特定状況でのみのスクリプトレットの実行

When the rpm command executes the scriptlets in a package it indicates if the action preformed is an install, erase, upgrade or reinstall by passing an integer argument to the script in question according to the following:

          install   erase   upgrade  reinstall
%pre         1        -         2         2
%post        1        -         2         2
%preun       -        0         1         -
%postun      -        0         1         -

This means that for example a package that installs an init script with the chkconfig command should uninstall it only on erase and not upgrade with the following snippet:

%preun
if [ $1 -eq 0 ] ; then
/sbin/chkconfig --del %{name}
fi

See also /usr/share/doc/rpm-*/triggers, which gives a more formal, generalized definition about the integer value(s) passed to various scripts.

特定ディレクトリの書き込みのみが許可されているスクリプトレット

Build scripts of packages (%prep, %build, %install, %check and %clean) may only alter files (create, modify, delete) under %{buildroot}, %{_builddir} and valid temporary locations like /tmp, /var/tmp (or $TMPDIR or %{_tmppath} as set by the rpmbuild process) according to the following matrix

/tmp, /var/tmp, $TMPDIR, %{_tmppath} %{_builddir} %{buildroot}
%prep yes yes no
%build yes yes no
%install yes yes yes
%check yes yes no
%clean yes yes yes

Further clarification: That should hold true irrespective of the builder's uid.

条件付きの依存関係

If the spec file contains conditional dependencies selected based on presence of optional --with(out) foo arguments to rpmbuild, build the source RPM to be submitted with the default options, ie. so that none of these arguments are present in the rpmbuild command line. The reason is that those requirements get "serialized" into the resulting source RPM, ie. the conditionals no longer apply.

ユーザアカウントを分離したパッケージのビルド

When building software, which you have not conducted a full security-audit on, protect sensitive data, such as your GPG private key, in a separate user account.

The same applies to reviewers/testers. Rebuild src.rpms in a separate account which does not have access to any sensitive data.

再配置可能なパッケージ

The use of RPM's facility for generating relocatable packages is strongly discouraged. It is difficult to make work properly, impossible to use from the installer or from yum, and not generally necessary if other packaging guidelines are followed. However, in the unlikely event that you have a good reason to make a package relocatable, you MUST state this intent and reasoning in the request for package review.


コード Vs コンテンツ

It is important to make distinction between computer executable code and content. While code is permitted (assuming, of course, that it has an open source compatible license, is not legally questionable, etc.), only some kinds of content are permissable.

The rule is this:

If the content enhances the OS user experience, then the content is OK to be packaged in Fedora. This means, for example, that things like: fonts, themes, clipart, and wallpaper are OK.

Content still has to be reviewed for inclusion. It must have an open source compatible license, must not be legally questionable. In addition, there are several additional restrictions for content:

  • Content must not be pornographic, or contain nudity, whether animated, simulated, or photographed. There are better places on the Internet to get porn.
  • Content should not be offensive, discriminatory, or derogatory. If you're not sure if a piece of content is one of these things, it probably is.
  • All content is subject to review by FESCo, who has the final say on whether or not it can be included.

Some examples of content which is permissable:

  • Package documentation or help files
  • Clipart for use in office suites
  • Background images (non-offensive, discriminatory, with permission to freely redistribute)
  • Fonts (under an open source license, with no ownership/legal concerns)
  • Game levels are not considered content, since games without levels would be non functional.
  • Sound or graphics included with the source tarball that the program or theme uses (or the documentation uses) are acceptable.
  • Game music or audio content is permissible, as long as the content is freely distributable without restriction, and the format is not patent encumbered.
  • Example files included with the source tarball are not considered content.

Some examples of content which are not permissable:

  • Comic book art files
  • Religious texts
  • mp3 files (patent encumbered)

If you are unsure if something is considered approved content, ask on fedora-devel-list.

ファイルとディレクトリの所有者

Your package should own all of the files that are installed as part of the %install process. Packages must not own files already owned by other packages. The rule of thumb here is that the first package to be installed should own the files that other packages may rely upon. This means, for example, that no package in Fedora should ever share ownership with any of the files owned by the filesystem or man package. If you feel that you have a good reason to own a file or that another package owns, then please present that at package review time.

Directory ownership is a little more complex than file ownership. Although the rule of thumb is the same: own all the directories you create but none of the directories of packages you depend on, there are several instances where it's desirable for multiple packages to own a directory.

In all cases we are guarding against unowned directories being present on a system. Please see Packaging:UnownedDirectories for the details.

Important.png
Note on multiple ownership
Note that when co-owning directories, you must ensure that the ownership and permissions on the directory match in all packages that own it.
Important.png
Note on directories
If a directory is explicitly required by packages in Fedora (such as /usr/lib/mozilla/plugins), only one package should own it, so that dependency solving is deterministic.

Here are examples that describe how to handle most cases of directory ownership.

パッケージの全てに含まれる、又はコアな機能によって使用されるディレクトリ

An example:

gnucash places many files under the /usr/share/gnucash directory

Solution: the gnucash package should own the /usr/share/gnucash directory

巨大な環境インフラの一部になる多くのディレクトリに存在するファイルを置くパッケージ

An example:

kdeutils places files in (among other places)
 /usr/share/applications/kde4
 /usr/share/kde4/apps
 /usr/share/kde4/services

Solution: the infrastructure directories above should be placed in a kde-filesystem package, and kdeutils should Require: the kde-filesystem package.

要求されたパッケージの機能を実装するパッケージによっても所有されるディレクトリ

An example:

pam owns the /etc/pam.d directory
gdm places files into /etc/pam.d

Solution: the pam package should own the /etc/pam.d directory, and gdm should Require: the pam package.

複数パッケージが共通ディレクトリにあるファイルを所有するが、それらのファイルは他のパッケージを要求する必要がない

An example:

bash-completion owns the /etc/bash_completion.d directory and uses the files placed there to configure itself.
git places files into /etc/bash_completion.d
bzr places files into /etc/bash_completion.d

Solution: Both the git and bzr packages should own the /etc/bash_completion.d directory as bash-completion is optional functionality and the installation of git or bzr should not force the installation of bash-completion.

Important.png
Rule of Thumb
When determining whether this exception applies, packagers and reviewers should ask this question: Do the files in this common directory enhance or add functionality to another package, where that other package is not necessary to be present for the primary functionality of this package?

あるディレクトリを提供するために依存するパッケージは、後のバージョンになって違うディレクトリを所有するように変更されるかもしれません、そして、あなたのパッケージはその後のバージョンで何の変更もなく実行されます

One common example of this is a Perl module. Assume perl-A-B depends on perl-A and installs files into /usr/lib/perl5/vendor_perl/5.8.8/i386-linux-thread-multi/A/B. The base Perl package guarantees that it will own /usr/lib/perl5/vendor_perl/5.8.8/i386-linux-thread-multi for as long as it remains compatible with version 5.8.8, but a future upgrade of the perl-A package may install into (and thus own) /usr/lib/perl5/vendor_perl/5.9.0/i386-linux-thread-multi/A. So the perl-A-B package needs to own /usr/lib/perl5/vendor_perl/5.8.8/i386-linux-thread-multi/A as well as /usr/lib/perl5/vendor_perl/5.8.8/i386-linux-thread-multi/A/B in order to maintain proper ownership.

重複したファイル

A Fedora package must not list a file more than once in the spec file's %files listings. If you think your package is a valid exception to this, please bring it to the attention of the Packaging Committee so they can improve on this Guideline.

ファイルパーミッション

Permissions on files must be set properly. Executables should be set with executable permissions, for example. Every %files section must include a %defattr(...) line. Here is a good default:

%files
%defattr(-,root,root,-)

Unless you have a very good reason to deviate from that, you should use %defattr(-,root,root,-) for all %files sections in your package.

ユーザとグループ

パッケージによってはユーザとグループの両方またはどちらか一方を実行時に指定するように要求したり、又はその方が利点があったりするものがあります。そういったケースを扱うガイドラインはユーザとグループにあります。

ウェブアプリケーション

Fedora のウェブアプリケーションは /var/www/ の中ではなく、/usr/share/%{name} の中にコンテンツを保存すべきです。その理由は以下になります。

  • /var は様々なデータファイルやログの保存をサポートしています。コンテンツは /usr/share の方がより適切です。
  • 多くのユーザは既に /var/www にコンテンツを保存しています。どのような Fedora パッケージにおいても /var/www のトップに誤って上書きしてしまうようなことは望んでいません。
  • /var/www は今ではファイルシステム階層標準(FHS)ではありません。

競合

Whenever possible, Fedora packages should avoid conflicting with each other. Unfortunately, this is not always possible. For full details on Fedora's Conflicts policy, see: Packaging:Conflicts .

Tools such as Alternatives and Environment Modules can also help prevent package conflicts.

代替のもの

The "alternatives" tool provides a means for parallel installation of packages which provide the same functionality by maintaining sets of symlinks. For full details on how to properly use alternatives, see Packaging:Alternatives.

環境モジュール

When there are multiple variants that each serve the needs of some user and thus must be available simultaneously by users, the alternatives system simply isn't enough since it is system-wide. In such situations, use of Environment Modules can avoid conflicts. For full details on how to properly use Environment Modules, see Packaging:Environment Modules.

拡張カーネルモジュールはありません

The Packaging:KernelModules page used to be transcluded into the main guidelines page. Instead its contents have been pasted there.

If you're seeing this page, you really should be looking here instead.

/srv 配下のファイルやディレクトリはありません

The FHS says :

"...no program should rely on a specific subdirectory structure of /srv existing
or data necessarily being stored in /srv. However /srv should always exist on FHS
compliant systems and should be used as the default location for such data.

Distributions must take care not to remove locally placed files in these
directories without administrator permission."

/srv is a poorly implemented section of the FHS, and its intended use case is unclear. At this time, no Fedora package can have any directories or files under /srv.

It is important to note that a Fedora package, once installed, and run by a user, can use /srv as a default location for data. The package simply must not own any directories or files in /srv.

複数プロジェクトをビルドすること

Fedora packages should make every effort to avoid having multiple, separate, upstream projects bundled together in a single package.

他のパッケージにあるフォントを1つにまとめないこと

Fonts in general-purpose formats such as Type1, OpenType TT (TTF) or OpenType CFF (OTF) are subject to specific packaging guidelines (1), and should never be packaged in a private application directory instead of the system-wide font repositories. For more information, see: Packaging:FontsPolicy#Package_layout_for_fonts.

全てのパッチはアップストリームのバグへのリンクやコメントを持つべきであること

All patches in Fedora spec files SHOULD have a comment above them about their upstream status. Any time you create a patch, it is best practice to file it in an upstream bug tracker, and include a link to that in the comment above the patch. For example:

# http://bugzilla.gnome.org/show_bug.cgi?id=12345
Patch0: gnome-panel-fix-frobnicator.patch

The above is perfectly acceptable; but if you prefer, a brief comment about what the patch does above can be helpful:

# Don't crash with frobnicator applet
# http://bugzilla.gnome.org/show_bug.cgi?id=12345
Patch0: gnome-panel-fix-frobnicator.patch

Sending patches upstream and adding this comment will help ensure that Fedora is acting as a good FLOSS citizen (see Why Upstream? ). It will help others (and even you) down the line in package maintenance by knowing what patches are likely to appear in a new upstream release.

アップストリームがバグトラッキングシステムを持っていない場合

You can indicate that you have sent the patch upstream and any known status:

# Sent upstream via email 20080407
Patch0: foobar-fix-the-bar.patch
# Upstream has applied this in SVN trunk
Patch0: foobar-fix-the-baz.patch

Fedora に特化した(アップストリームで拒否された)パッチ

It may be that some patches truly are Fedora-specific; in that case, say so:

# This patch is temporary until we land the long term System.loadLibrary fix in OpenJDK
Patch0: jna-jni-path.patch

Epoch の使用

RPM の Epoch タグは、できるだけ使用しないようにすべきで、最後の手段としてのみ使用されます。とは言え、アップストリームのバージョン番号ルールの変更、又はサードパーティリポジトリから簡単に移行するために Epoch を使用するなど必要になるときがあります。

サードパーティリポジトリの Epoch

あるパッケージがインポートされる、又は既にリポジトリで公開されていた場合、パッケージャはサードパーティパッケージの最新バージョンと同じ Epoch タグを任意で設定することができます。

シンボリックリンク

There are two ways of making a symlink, either as a relative link or an absolute link. In Fedora, neither method is required. Packagers should use their best judgement when deciding which method of symlink creation is appropriate.

関連のあるシンボリックリンク

A relative symlink is a symlink which points to a file or directory relative to the position of the symlink. For example, this command would create a relative symlink:

ln -s ../..%{_bindir}/foo %{buildroot}/bin/foo

Pros:

  • Relative symlinks will point to the same file inside or outside of a chroot.

Cons:

  • Much more complicated to create than absolute symlinks
  • Relative symlinks may break or behave unexpectedly when a part of a filesystem is mounted to a custom location.
  • Relative symlinks may break when bind mounting or symlinking directories.
  • Relative symlinks may make it more difficult to use rpm system macros.

廃止されたシンボリックリンク

An absolute symlink is a symlink which points to an absolute file or directory path. For example, this command would create an absolute symlink:

ln -s %{_bindir}/foo %{buildroot}/bin/foo

Pros:

  • Much easier to create than relative symlinks.
  • Absolute symlinks work properly when bind mounting or symlinking directories.
  • Absolute symlinks work well with rpm system macros.

Cons:

  • Absolute symlinks may break when used with chroots.

man ページ

man ページは unix システムにおけるヘルプを見る伝統的な方法です。パッケージの全てのバイナリ/スクリプトのために man ページを作成すべきです。もし man ページがないなら、アップストリームで man ページを追加するように働きかけてください。時々、他のディストリビューション(特に Debian)では、man ページで問題が発生します。そういったことに遭遇したら、問題解決のための出発点にしましょう。

アプリケーションに特化したガイドライン

Packaging:Namespace に個々のページを持つアプリケーションに特化したガイドラインがあります。

Eclipse

Eclipse プラグインパッケージのためのガイドライン: Packaging:EclipsePlugins

Emacs

Emacs/X-Emacs パッケージのためのガイドライン: Packaging:Emacs

Fonts

font パッケージのためのガイドライン: Packaging:FontsPolicy

Fortran

Fortran パッケージのためのガイドライン: Packaging:Fortran

Globus Toolkit

Globus Toolkit のパッケージのためのガイドライン: Packaging:Globus

Haskell

Haskell パッケージのためのガイドライン: Packaging:Haskell

Java

java パッケージのためのガイドライン: Packaging:Java

Lisp

lisp パッケージのためのガイドライン: Packaging:Lisp

Mono

Mono パッケージのためのガイドライン: Packaging:Mono

MPI

MPI パッケージのためのガイドライン: Packaging:MPI

OCaml

OCaml パッケージのためのガイドライン: Packaging:OCaml

OpenOffice.org

OpenOffice.org の拡張パッケージのためのガイドライン: Packaging:OpenOffice.orgExtensions

Perl

Perl パッケージのためのガイドライン: Packaging:Perl

PHP

PHP パッケージのためのガイドライン: Packaging:PHP

Python

Python アドインモジュールのためのガイドライン: Packaging:Python

R

R モジュールパッケージのためのガイドライン: Packaging:R

Ruby

Ruby パッケージのためのガイドライン: Packaging:Ruby

Sugar

Sugar Activity パッケージのためのガイドライン: Packaging:SugarActivityGuidelines

Tcl/Tk

Tcl/Tk 拡張パッケージのためのガイドライン: Packaging:Tcl

Wordpress

Wordpress 拡張パッケージのためのガイドライン: Packaging:WordPress plugin packaging guidelines