openSUSE:Packaging Haskell
将 Haskell 打包到 openSUSE
大多数 Haskell 源代码都发布在 Hackage 上 [[1]],使用名为 Cabal 的构建和安装工具。Cabal 工具用于从 Hackage 源代码创建 openSUSE RPM 软件包。ghc-rpm-macros 软件包提供了一小套 RPM 宏。
cabal2spec:自动生成 spec 文件
通过 cabal2spec 从 OBS 的 devel:languages:haskell、Tumbleweed 的官方仓库或通过 cabal 获取,可以最快地进行 Haskell 打包。
cabal install cabal2spec
要生成 spec 文件,只需运行
cabal2spec your-awesome-project.cabal
它将创建一个同名的 spec 文件,但带有“.spec”前缀。
潜在问题
首先,cabal2spec 生成的 spec 文件将根据软件包名称从 hackage 获取原始源代码。如果您的项目不在 hackage 上,请将其上传或将源代码与 spec 文件一起上传到 OBS。
其次,如果您对 spec 文件不做任何更改并希望 OBS 从 hackage 获取源代码,则软件包的元数据可能会发生更改。元数据修订是指 hackage 软件包维护者更改 spec 文件中的小功能(例如放宽对依赖项的上限)以允许软件包在无需重新加载源代码的情况下构建。在这种情况下,只能使用 cabal 获取修订后的源代码,后者会下载源代码并对其进行修补。OBS 不这样做!您必须手动修补源代码中的 cabal 文件以使软件包与修订保持最新。
最后,如果您计划允许获取源代码,则必须启用软件包中的源服务。这就像创建一个名为 _service 的文件并用以下内容填充它一样
<services> <service name="download_files" /> </services>
软件包类型和软件包命名
Haskell 的 cabal 软件包有三种类型:Bin、Lib 和 BinLib。
程序(Bin 软件包)
对于程序,如果它不与其他 openSUSE 软件包冲突,请使用上游软件包名称。
库(Lib 软件包)
库软件包名称是通过在上游名称前加上 ghc- 来获得的。该库软件包包含共享库。相应的开发软件包名称是库软件包名称加上后缀 -devel,其中包含预编译的头文件、文档以及分析和静态库。后者是 ghci 所必需的。上游计划在 ghc 的 7.8.1 版本中支持 ghci 中的动态链接。
包含库的程序(BinLib 软件包)
包含程序和库的 cabal 软件包被打包为 BinLib 软件包。spec 文件必须指定程序(Bin)和库(Lib)的打包。
依赖关系
构建依赖关系(BuildRequires)
所有 Haskell 软件包都必须需要 ghc-rpm-macros 和 ghc-Cabal-devel 进行构建。Haskell 软件包不应需要 hscolour(sic!)进行构建,因为此要求由 ghc-rpm-macros 控制。目前我们需要在引导期间关闭 hscolour,这是对所有软件包执行此操作的最简单方法。
通过 ghc-<library-name>-devel 需要 Haskell 库,无需版本号约束,以降低维护开销。库 ghc 和 prim 包含在 ghc-compiler 中,因此不应需要进行构建。
库依赖关系(Requires)
Haskell 和其他依赖项将自动生成。
开发包依赖关系
Haskell 开发包的依赖项将自动生成。其他库必须添加到 Requires 标签中。此外,每个开发包都需要以下内容
Requires: ghc-compiler
Requires(post): ghc-compiler
Requires(postun): ghc-compiler
Requires: %{name} = %{version}-%{release}
配置和构建
要配置和构建源代码,请对 Bin 软件包使用 %ghc_bin_build 宏,对 Lib 和 BinLib 软件包使用 %ghc_lib_build 宏。这将使用所有默认值配置软件包并构建它。
覆盖软件包默认值
要覆盖软件包默认值,请定义一个宏 cabal_configure_options。这些选项将传递给 cabal configure 命令。或者使用 ghc-rpm-macros 中的 cabal-tweak-flag 命令。示例
%define cabal_configure_options -f"utf8"
或者相同
cabal-tweak-flag utf8 True
要更改 cabal 依赖项版本,请使用 ghc-rpm-macros 中的 cabal-tweak-dep-ver 命令。xmonad.spec 中的示例
%prep %setup -q cabal-tweak-dep-ver utf8-string '< 0.4' '< 1.1'
安装
在大多数情况下,%ghc_bin_install 分别或 %ghc_lib_install 可以完成工作。有时,手册页和其他文档未由底层的 cabal 安装,需要手动安装。
修复损坏的 RPATH
如果程序链接到由同一软件包提供的 Haskell 库,cabal 会将 RPATH 设置为构建目录而不是安装目录。需要通过调用 %ghc_fix_dynamic_rpath 后跟所有受影响的程序来修复 RPATH。如果您忘记了一个,rpmlint 会抱怨并导致构建失败。
用于复杂软件包的额外宏(仅限编译器黑客)
- %ghc_lib_subpackage 宏生成 ghc-<name> 和相应开发包的标签
- %ghc_suse_disable_debug_packages 以 openSUSE 的方式禁用调试和 debuginfo 软件包
- %ghc_gen_filelist 为 ghc-<name> 和相应的开发包创建文件列表
- %ghc_strip_dynlinked 剥离程序和共享对象
示例
程序
# # spec file for package cabal-install # # Copyright (c) 2013 SUSE LINUX Products GmbH, Nuernberg, Germany. # # All modifications and additions to the file contributed by third parties # remain the property of their copyright owners, unless otherwise agreed # upon. The license for this file, and modifications and additions to the # file, is the same license as for the pristine package itself (unless the # license for the pristine package is not an Open Source License, in which # case the license is the MIT License). An "Open Source License" is a # license that conforms to the Open Source Definition (Version 1.9) # published by the Open Source Initiative. # Please submit bugfixes or comments via http://bugs.opensuse.org/ # Name: cabal-install Version: 1.16.0.2 Release: 0 Summary: Command-line program to manage Haskell software License: BSD-3-Clause Group: Development/Languages/Other BuildRoot: %{_tmppath}/%{name}-%{version}-build Url: http://hackage.haskell.org/package/%{name} Source0: http://hackage.haskell.org/packages/archive/%{name}/%{version}/%{name}-%{version}.tar.gz ExclusiveArch: %{ix86} x86_64 %{ghc_arches} BuildRequires: ghc-Cabal-devel BuildRequires: ghc-HTTP-devel BuildRequires: ghc-array-devel BuildRequires: ghc-bytestring-devel BuildRequires: ghc-containers-devel BuildRequires: ghc-directory-devel BuildRequires: ghc-filepath-devel BuildRequires: ghc-mtl-devel BuildRequires: ghc-network-devel BuildRequires: ghc-old-time-devel BuildRequires: ghc-pretty-devel BuildRequires: ghc-process-devel BuildRequires: ghc-random-devel BuildRequires: ghc-rpm-macros BuildRequires: ghc-time-devel BuildRequires: ghc-unix-devel BuildRequires: ghc-zlib-devel %description Command-line program to manage Haskell software by automating the fetching, configuration, compilation, and installation of Haskell libraries and programs %prep %setup -q %build %ghc_bin_build %install %ghc_bin_install %files %doc LICENSE README %attr(755,root,root) %{_bindir}/cabal %changelog
库
# # spec file for package ghc-utf8-string # # Copyright (c) 2013 SUSE LINUX Products GmbH, Nuernberg, Germany. # # All modifications and additions to the file contributed by third parties # remain the property of their copyright owners, unless otherwise agreed # upon. The license for this file, and modifications and additions to the # file, is the same license as for the pristine package itself (unless the # license for the pristine package is not an Open Source License, in which # case the license is the MIT License). An "Open Source License" is a # license that conforms to the Open Source Definition (Version 1.9) # published by the Open Source Initiative. # Please submit bugfixes or comments via http://bugs.opensuse.org/ # %global pkg_name utf8-string Name: ghc-utf8-string Version: 0.3.7 Release: 0 Summary: Support for reading and writing UTF8 Strings License: BSD-3-Clause Group: System/Libraries Url: http://hackage.haskell.org/package/%{pkg_name} Source0: http://hackage.haskell.org/packages/archive/%{pkg_name}/%{version}/%{pkg_name}-%{version}.tar.gz BuildRoot: %{_tmppath}/%{name}-%{version}-build BuildRequires: ghc-Cabal-devel BuildRequires: ghc-rpm-macros %description A UTF8 layer for IO and Strings. The utf8-string package provides operations for encoding UTF8 strings to Word8 lists and back, and for reading and writing UTF8 without truncation. %package devel Summary: Haskell %{pkg_name} library development files Group: Development/Libraries/Other Requires: ghc-compiler Requires(post): ghc-compiler Requires(postun): ghc-compiler Requires: %{name} = %{version}-%{release} %description devel A UTF8 layer for IO and Strings. The utf8-string package provides operations for encoding UTF8 strings to Word8 lists and back, and for reading and writing UTF8 without truncation. %prep %setup -q -n %{pkg_name}-%{version} %build %ghc_lib_build %install %ghc_lib_install %post devel %ghc_pkg_recache %postun devel %ghc_pkg_recache %files -f %{name}.files %doc LICENSE %files devel -f %{name}-devel.files %changelog
程序和库
# # spec file for package pandoc # # Copyright (c) 2013 SUSE LINUX Products GmbH, Nuernberg, Germany. # # All modifications and additions to the file contributed by third parties # remain the property of their copyright owners, unless otherwise agreed # upon. The license for this file, and modifications and additions to the # file, is the same license as for the pristine package itself (unless the # license for the pristine package is not an Open Source License, in which # case the license is the MIT License). An "Open Source License" is a # license that conforms to the Open Source Definition (Version 1.9) # published by the Open Source Initiative. # Please submit bugfixes or comments via http://bugs.opensuse.org/ # %global pkg_name pandoc Name: pandoc Version: 1.11.1 Release: 0 Summary: Conversion between markup formats License: GPL-2.0 Group: Development/Languages/Other Url: http://hackage.haskell.org/package/%{name} Source0: http://hackage.haskell.org/packages/archive/%{name}/%{version}/%{name}-%{version}.tar.gz BuildRoot: %{_tmppath}/%{name}-%{version}-build BuildRequires: ghc-Cabal-devel BuildRequires: ghc-rpm-macros # Begin cabal-rpm deps: BuildRequires: ghc-HTTP-devel BuildRequires: ghc-base64-bytestring-devel BuildRequires: ghc-blaze-html-devel BuildRequires: ghc-blaze-markup-devel BuildRequires: ghc-bytestring-devel BuildRequires: ghc-citeproc-hs-devel BuildRequires: ghc-containers-devel BuildRequires: ghc-data-default-devel BuildRequires: ghc-directory-devel BuildRequires: ghc-extensible-exceptions-devel BuildRequires: ghc-filepath-devel BuildRequires: ghc-highlighting-kate-devel BuildRequires: ghc-json-devel BuildRequires: ghc-mtl-devel BuildRequires: ghc-network-devel BuildRequires: ghc-old-locale-devel BuildRequires: ghc-old-time-devel BuildRequires: ghc-pandoc-types-devel BuildRequires: ghc-parsec-devel BuildRequires: ghc-process-devel BuildRequires: ghc-random-devel BuildRequires: ghc-syb-devel BuildRequires: ghc-tagsoup-devel BuildRequires: ghc-temporary-devel BuildRequires: ghc-texmath-devel BuildRequires: ghc-text-devel BuildRequires: ghc-time-devel BuildRequires: ghc-xml-devel BuildRequires: ghc-zip-archive-devel BuildRequires: ghc-zlib-devel # End cabal-rpm deps BuildRequires: chrpath %description Pandoc is a Haskell library for converting from one markup format to another, and a command-line tool that uses this library. It can read markdown and (subsets of) HTML, reStructuredText, LaTeX, DocBook, MediaWiki markup, and Textile, and it can write markdown, reStructuredText, HTML, LaTeX, ConTeXt, Docbook, OpenDocument, ODT, Word docx, RTF, MediaWiki, Textile, groff man pages, plain text, Emacs Org-Mode, AsciiDoc, EPUB (v2 and v3), FictionBook2, and S5, Slidy and Slideous HTML slide shows. Pandoc extends standard markdown syntax with footnotes, embedded LaTeX, definition lists, tables, and other features. A compatibility mode is provided for those who need a drop-in replacement for Markdown.pl. In contrast to existing tools for converting markdown to HTML, which use regex substitutions, pandoc has a modular design: it consists of a set of readers, which parse text in a given format and produce a native representation of the document, and a set of writers, which convert this native representation into a target format. Thus, adding an input or output format requires only adding a reader or writer. %package -n ghc-%{name} Summary: Haskell %{name} library Group: System/Libraries %description -n ghc-%{name} Pandoc is a Haskell library for converting from one markup format to another, and a command-line tool that uses this library. It can read markdown and (subsets of) HTML, reStructuredText, LaTeX, DocBook, MediaWiki markup, and Textile, and it can write markdown, reStructuredText, HTML, LaTeX, ConTeXt, Docbook, OpenDocument, ODT, Word docx, RTF, MediaWiki, Textile, groff man pages, plain text, Emacs Org-Mode, AsciiDoc, EPUB (v2 and v3), FictionBook2, and S5, Slidy and Slideous HTML slide shows. Pandoc extends standard markdown syntax with footnotes, embedded LaTeX, definition lists, tables, and other features. A compatibility mode is provided for those who need a drop-in replacement for Markdown.pl. In contrast to existing tools for converting markdown to HTML, which use regex substitutions, pandoc has a modular design: it consists of a set of readers, which parse text in a given format and produce a native representation of the document, and a set of writers, which convert this native representation into a target format. Thus, adding an input or output format requires only adding a reader or writer. %package -n ghc-%{name}-devel Summary: Haskell %{name} library development files Group: Development/Languages/Other Requires: ghc-compiler Requires(post): ghc-compiler Requires(postun): ghc-compiler Requires: %{name} = %{version}-%{release} %description -n ghc-%{name}-devel Pandoc is a Haskell library for converting from one markup format to another, and a command-line tool that uses this library. It can read markdown and (subsets of) HTML, reStructuredText, LaTeX, DocBook, MediaWiki markup, and Textile, and it can write markdown, reStructuredText, HTML, LaTeX, ConTeXt, Docbook, OpenDocument, ODT, Word docx, RTF, MediaWiki, Textile, groff man pages, plain text, Emacs Org-Mode, AsciiDoc, EPUB (v2 and v3), FictionBook2, and S5, Slidy and Slideous HTML slide shows. Pandoc extends standard markdown syntax with footnotes, embedded LaTeX, definition lists, tables, and other features. A compatibility mode is provided for those who need a drop-in replacement for Markdown.pl. In contrast to existing tools for converting markdown to HTML, which use regex substitutions, pandoc has a modular design: it consists of a set of readers, which parse text in a given format and produce a native representation of the document, and a set of writers, which convert this native representation into a target format. Thus, adding an input or output format requires only adding a reader or writer. %prep %setup -q %build %ghc_lib_build %install %ghc_lib_install %ghc_fix_dynamic_rpath pandoc %post -n ghc-%{name}-devel %ghc_pkg_recache %postun -n ghc-%{name}-devel %ghc_pkg_recache %files %doc COPYING %doc README %{_bindir}/%{name} %{_datadir}/%{name}-%{version} %{_mandir}/man1/pandoc.1* %{_mandir}/man5/pandoc_markdown.5* %files -n ghc-%{name} -f ghc-%{name}.files %doc COPYING %files -n ghc-%{name}-devel -f ghc-%{name}-devel.files %doc README %changelog