LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 1229|回复: 15

PKGBUILD的高级用法:一个PKGBUILD生成两个软件包

[复制链接]
发表于 2009-8-27 16:08:18 | 显示全部楼层 |阅读模式
分包:
一直都很期待这个功能,可能出来的有段时间了。今天准备编译gstreamer支持oss的时候发现的

这样写打包软件的时候就可以分成很多包而不用编译两次,最典型的就是给内核打包。

方法:
大体上就是在pkgname处写多个名称,每个名称定义一个package_name()函数,自由定义包如何分。比如此处就是在build()函数里面编译,然后在两个子包package_gstreamer0.10-good和package_gstreamer0.10-good-plugins里面make install,只不过不同部分。

至于包的说明就都可以各自定义,默认使用最前面的定义。非常灵活

实例:
可以看看这个例子,应该不难理解。
http://repos.archlinux.org/viewv ... 6/PKGBUILD?view=log

文档:
从PKGBUILD的doc里面找到一点点资料,manpage和wiki上似乎都没有介绍:
分包
makepkg支持从单个PKGBUILD里面构建多个包。
这是通过定义PKGBUILD中的pkgname数组实现的。
每个子包使用相应的名称为'package_foo()'包函数,其中foo用子包的名称

每个子包的每个指令和选项默认使用全局指定的值,除非你在子包函数里面单独指定,如下变量可以被重新定义:
`pkgdesc`, `license`, `groups`, `depends`, `optdepends`, `provides`, `conflicts`, `replaces`, `backup`, `options` and `install`.

当构造一个分包的软件的时候,这个额外的指令(变量)可以使用:
*pkgbase*::这个名称用来在makepkg的时候输出显示时候使用。
        当然,也可以用来构建只有源代码的包。

  1. Package Splitting
  2. -----------------
  3. makepkg supports building multiple packages from a single PKGBUILD. his is achieved
  4. by assigning an array of package names to the `pkgname` directive. Each sub-package
  5. uses a corresponding package function with name `package_foo()`, where `foo` is the
  6. name of the package.

  7. All options and directives for the split packages default to the global values given
  8. within the PKGBUILD. However, some of these can be overridden within each sub-package's
  9. package function. The following variables can be overridden: `pkgdesc`, `license`,
  10. `groups`, `depends`, `optdepends`, `provides`, `conflicts`, `replaces`, `backup`,
  11. `options` and `install`.

  12. An additional directive is available when building a split package:

  13. *pkgbase*::
  14.         The name used to refer to the group of packages in the output of makepkg.
  15.         Also, used when creating source-only tarballs.
复制代码


提示:
如果遇到提示
  1. ERROR: missing package function for split package 'foo'
复制代码
或者
  1. 错误:拆分软件包 'foo' 缺少软件包功能
复制代码
的时候,检查是否存在package_foo()这个函数。
发表于 2009-8-27 16:12:51 | 显示全部楼层
很好 效率更高了~
回复 支持 反对

使用道具 举报

发表于 2009-8-27 17:31:58 | 显示全部楼层
是有段时间了,上次官方的svn突然没了intel-dri和libgl的目录,都进mesa那个PKGBUILD里了
回复 支持 反对

使用道具 举报

发表于 2009-8-27 18:57:10 | 显示全部楼层
记得好早  virtualbox-ose 就如此了。。。

学习了
回复 支持 反对

使用道具 举报

 楼主| 发表于 2009-8-27 20:21:11 | 显示全部楼层
为何wiki上和manpage上都没有。。
回复 支持 反对

使用道具 举报

发表于 2009-8-27 23:02:39 | 显示全部楼层
这功能真棒,感谢jarryson 分享
回复 支持 反对

使用道具 举报

发表于 2009-8-28 00:31:14 | 显示全部楼层
这个是在pacman的git仓库里发现的例子:
# This is an example of a PKGBUILD for splitting packages. Use this as a
# start to creating your own, and remove these comments. For more information,
# see 'man PKGBUILD'. NOTE: Please fill out the license field for your package!
# If it is unknown, then please put 'unknown'.

# Contributor: Your Name <youremail@domain.com>
pkgname=('pkg1' 'pkg2')
pkgbase=""
pkgver=VERSION
pkgrel=1
pkgdesc=""
arch=()
url=""
license=('GPL')
groups=()
depends=()
makedepends=()
provides=()
conflicts=()
replaces=()
backup=()
options=()
install=
source=($pkgbase-$pkgver.tar.gz)
noextract=()
md5sums=() #generate with 'makepkg -g'

build() {
  cd "$srcdir/$pkgbase-$pkgver"
  ./configure --prefix=/usr
  make || return 1
}

package_pkg1() {
# options and directives that can be overridden
  pkgdesc=""
  license=()
  groups=()
  depends=()
  optdepends=()
  provides=()
  conflicts=()
  replaces=()
  backup=()
  options=()
  install=

  cd "$srcdir/$pkgbase-$pkgver"
  make DESTDIR="$pkgdir/" install-pkg1
}

package_pkg2() {
  # options and directives overrides
  pkgdesc=""

  cd "$srcdir/$pkgbase-$pkgver"
  make DESTDIR="$pkgdir/" install-pkg2
}
回复 支持 反对

使用道具 举报

发表于 2009-8-28 09:39:21 | 显示全部楼层
謝謝!像你學習了!
回复 支持 反对

使用道具 举报

发表于 2009-8-28 10:40:43 | 显示全部楼层
都这样做的话,arch 也许会象 debian 那样把包分的很细了,比如语言包,一种语言一个包?
回复 支持 反对

使用道具 举报

 楼主| 发表于 2009-8-28 13:08:02 | 显示全部楼层
我想官方应该不会有较大改动,该怎么样还是怎么样。除非是有些软件为了方便网络传输或者某部分内容长期一致的。比如kernel,mesa。

为了把头文件,语言文件之类的独立出来就没必要了吧,才多大点东西
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表