PKGBUILD的高级用法:一个PKGBUILD生成两个软件包
时间:2009-08-27
来源:互联网
一直都很期待这个功能,可能出来的有段时间了。今天准备编译gstreamer支持oss的时候发现的
这样写打包软件的时候就可以分成很多包而不用编译两次,最典型的就是给内核打包。
方法:
大体上就是在pkgname处写多个名称,每个名称定义一个package_name()函数,自由定义包如何分。比如此处就是在build()函数里面编译,然后在两个子包package_gstreamer0.10-good和package_gstreamer0.10-good-plugins里面make install,只不过不同部分。
至于包的说明就都可以各自定义,默认使用最前面的定义。非常灵活
实例:
可以看看这个例子,应该不难理解。
http://repos.archlinux.org/viewvc.cg...BUILD?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的时候输出显示时候使用。 当然,也可以用来构建只有源代码的包。
代码:
Package Splitting ----------------- makepkg supports building multiple packages from a single PKGBUILD. his is achieved by assigning an array of package names to the `pkgname` directive. Each sub-package uses a corresponding package function with name `package_foo()`, where `foo` is the name of the package. All options and directives for the split packages default to the global values given within the PKGBUILD. However, some of these can be overridden within each sub-package's package function. The following variables can be overridden: `pkgdesc`, `license`, `groups`, `depends`, `optdepends`, `provides`, `conflicts`, `replaces`, `backup`, `options` and `install`. An additional directive is available when building a split package: *pkgbase*:: The name used to refer to the group of packages in the output of makepkg. Also, used when creating source-only tarballs. |
如果遇到提示
ERROR: missing package function for split package 'foo'
错误:拆分软件包 'foo' 缺少软件包功能
作者: jarryson 发布时间: 2009-08-27
作者: lolilolicon 发布时间: 2009-08-27
作者: huntxu 发布时间: 2009-08-27
学习了
作者: carbonjiao 发布时间: 2009-08-27
作者: jarryson 发布时间: 2009-08-28
作者: axlrose 发布时间: 2009-08-28
# 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 <[email protected]>
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
}
作者: mrmuxl 发布时间: 2009-08-28
作者: jiuny0209 发布时间: 2009-08-28
作者: tocer 发布时间: 2009-08-28
为了把头文件,语言文件之类的独立出来就没必要了吧,才多大点东西
作者: jarryson 发布时间: 2009-08-28
作者: james6688 发布时间: 2009-08-29
作者: jiuny0209 发布时间: 2009-09-10
作者: athurg 发布时间: 2009-09-10
我也写了个关于内核的。。。
一个PKGBUILD 四个包 http://archlive-pkg.googlecode.com/h...aders/PKGBUILD
但这种PKGBUILD 好像无法提交到aur
编译好的包 可以从 http://archlive-pkg.googlecode.com/files 下载
或者添加 archlive-pkg 软件源 直接 pacman 来安装
# Archlive <http://archlive-pkg.googlecode.com> pkgname=('kernel26-base-git' 'kernel26-firmware' kernel26-source-git 'kernel-headers') pkgbase="" pkgver=20090909 pkgrel=1 _realpkgname=kernel26 _configure_as_ARCH_way=y _kernelname=${_realpkgname#kernel26} ## if you want your own version, such as 2.6.31-archlive, then ## "_configure_as_ARCH_way" set to "1" and ## "_realpkgname" change to "kernel26-archlive" _include_aufs2=y _include_squashfs=y # 是否保存编译目录 _keep_build_dir=y ## More special selection as below items. # url="http://www.kernel.org/" arch=(i686 x86_64) license=('GPL2') makedepends=('git' 'gcc') backup=(etc/mkinitcpio.d/kernel26.preset) source=(kernel26.preset config.{i686,x86_64} \ logo_linux_{clut224.ppm,mono.pbm,vga16.ppm} ## reiserfs4 patch http://www.kernel.org/pub/linux/kernel/people/edward/reiser4/reiser4-for-2.6/reiser4-for-2.6.30.patch.gz ## Gentoo patches 4100_dm-bbr.patch 4202_fbcondecor-0.9.6.patch 4400_alpha-sysctl-uac.patch ### Chinese Characters Patches 孙海勇 大侠的 内核中文补丁 http://youbest.cublog.cn/ #http://zdbr.net.cn/download/utf8-kernel-2.6.29-core-1.patch.bz2 utf8-kernel-2.6.29-core-1.patch http://zdbr.net.cn/download/utf8-kernel-2.6-fonts-2.patch.bz2 http://zdbr.net.cn/download/utf8-kernel-2.6.28-fbcondecor-1.patch.bz2 ) md5sums=() _gitroot="git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6.git" _gitname="linux-2.6.git" #################################################################### # KERNEL CONFIG FILES # This PKGBUILD searches for config files in the current directory # and will use the first one it finds from the following # list as base configuration: # config.local # config.saved.$CARCH # config.$CARCH #################################################################### # PATCHES # This package builds the vanilla git kernel by default, # but it is possible to patch the source without modifying # this PKGBUILD. # Simply create a directory 'patches' in your PKGBUILD # directory and _any_ file (dotfiles excluded) in this # folder will be applied to the kernel source. # Prefixing the patch file names with dots will obviously # excluded them from the patching process. ############################################################# # CONFIGURATION # Uncomment desired options ####### # Set to menuconfig, xconfig, gconfig or oldconfig # If you set it to something else, the # (manual) kernel configuration step will # be skipped _menu_method="menuconfig" ####### # The directory where the kernel should be built # Can be useful, for example, if you want to compile on a # tmpfs mount, which can speed up the compilation process _build_dir="$srcdir" ####### # Stop build process after kernel configuration # This option enables _save_config implicitly. # _configure_only=1 ####### # Save the .config file to package directory # as config.saved.$CARCH # _save_config=1 ####### # Make the kernel build process verbose # _verbose=1 #################################################################### extrapatch() { msg2 "Add Gentoo patches 加入Gentoo官方基本补丁..." for i in $(ls $srcdir/4[0-9][0-9][0-9]*);do echo "Applying $(basename $i)" patch -Np1 -i $i || return 1 done msg2 "Add the kernel Chinese characters patches 加入孙海勇 大侠的 内核中文补丁 http://youbest.cublog.cn/" patch -Np1 -i $srcdir/utf8-kernel-2.6.29-core-1.patch || return 1 patch -Np1 -i $srcdir/utf8-kernel-2.6.28-fbcondecor-1.patch || return 1 patch -Np1 -i $srcdir/utf8-kernel-2.6-fonts-2.patch || return 1 msg2 "Adding reiserfs4 patch reiser4-for-2.6.30.patch" patch -Np1 -i ${srcdir}/reiser4-for-2.6.30.patch || return 1 if [ "${_include_aufs2}" = "y" ]; then msg2 "Get aufs2 standalone patch from git tree" if [ -d $srcdir/aufs2-standalone ]; then cd $srcdir/aufs2-standalone git pull origin else git clone http://git.c3sl.ufpr.br/pub/scm/aufs/aufs2-standalone.git $srcdir/aufs2-standalone || return 1 fi cd $srcdir/aufs2-standalone git checkout origin/aufs2 cp -r $srcdir/aufs2-standalone/{Documentation,fs,include,aufs2-base.patch,aufs2-kbuild.patch,aufs2-standalone.patch} \ $srcdir/$_gitname-build/ cd $srcdir/$_gitname-build patch -Np1 -i aufs2-kbuild.patch || return 1 patch -Np1 -i aufs2-base.patch || return 1 patch -Np1 -i aufs2-standalone.patch || return 1 fi } build() { KARCH="x86" msg "Fetching sources..." cd "$startdir" if [ -d "$_gitname" ]; then msg2 "Updating sources..." cd "$_gitname" && git fetch && cd "$OLDPWD" || return 1 else msg2 "Cloning the project..." git clone --mirror "$_gitroot" "$_gitname" || return 1 fi msg "Creating build branch..." rm -rf "$_build_dir/$_gitname-build" git clone "$_gitname" "$_build_dir/$_gitname-build" || return 1 cd "$_build_dir/$_gitname-build" # Add Gentoo patches, Fedora patches, reiserfs4 patch and kernel Chinese characters patches. extrapatch msg "Adding Archlinux logo..." cp "$srcdir/logo_linux_clut224.ppm" drivers/video/logo/ && cp "$srcdir/logo_linux_mono.pbm" drivers/video/logo/ && cp "$srcdir/logo_linux_vga16.ppm" drivers/video/logo/ || return 1 # Apply other patches if [ -d "$startdir/patches" ]; then msg "Applying patches..." for i in "$startdir/patches/"*; do msg2 "Applying ${i##*/}..." patch -Np1 -i "$i" || (error "Applying ${i##*/} failed" && return 1) done fi ################# # CONFIGURATION ################# msg "Loading configuration..." for i in local "saved.$CARCH" "$CARCH"; do if [ -e "$startdir/config.$i" ]; then msg2 "Using kernel config file config.$i..." cp -f "$startdir/config.$i" .config || return 1 break fi done [ ! -e .config ] && warning "No suitable kernel config file was found. You'll have to configure the kernel from scratch." ########################### # Configure as ARCH way ########################### if [ "$_configure_as_ARCH_way" = "y" ]; then msg "Configure the kernel version as ARCH way, like 2.6.31-ARCH" if [ "${_kernelname}" != "" ]; then local_version=${_kernelname}; else local_version="-ARCH"; fi sed -i "s|^EXTRAVERSION = .*$|EXTRAVERSION =|g" Makefile sed -i "s|.*CONFIG_LOCALVERSION=.*|CONFIG_LOCALVERSION=\"${local_version}\"|g" .config sed -i "s|.*CONFIG_LOCALVERSION_AUTO.*|\# CONFIG_LOCALVERSION_AUTO is not set|g" .config fi # The default .config without support for squashfs, can change it by set "_include_squashfs" as "y". if [ "$_include_squashfs" = "y" ]; then msg "Selected squashfs4 included in kernel package." if [ "x$(grep "CONFIG_SQUASHFS=m" .config)" = "x" ]; then sed -i "s|.*CONFIG_SQUASHFS.*|CONFIG_SQUASHFS=m\ \n# CONFIG_SQUASHFS_EMBEDDED is not set\ \nCONFIG_SQUASHFS_FRAGMENT_CACHE_SIZE=3|g" ./.config fi else if [ "x$(grep "CONFIG_SQUASHFS=m" .config)" != "x" ]; then sed -i "s|CONFIG_SQUASHFS=m|\# CONFIG_SQUASHFS is not set|g" .config fi fi if [ "${_include_aufs2}" = "y" ]; then msg "Selected aufs2 included in kernel package." if [ "x$(grep "CONFIG_AUFS_FS=m" .config)" = "x" ]; then sed -i "/.*CONFIG_NILFS2_FS.*/ a\ \CONFIG_AUFS_FS=m\ \n# CONFIG_AUFS_BRANCH_MAX_127 is not set\ \n# CONFIG_AUFS_BRANCH_MAX_511 is not set\ \nCONFIG_AUFS_BRANCH_MAX_1023=y\ \n# CONFIG_AUFS_BRANCH_MAX_32767 is not set\ \nCONFIG_AUFS_HINOTIFY=y\ \nCONFIG_AUFS_EXPORT=y\ \nCONFIG_AUFS_RDU=y\ \nCONFIG_AUFS_SHWH=y\ \nCONFIG_AUFS_BR_RAMFS=y\ \nCONFIG_AUFS_BR_FUSE=y\ \n# CONFIG_AUFS_DEBUG is not set\ \nCONFIG_AUFS_BDEV_LOOP=y\ \nCONFIG_AUFS_POLL=y" ./.config fi else if [ "x$(grep "CONFIG_AUFS_FS=m" .config)" != "x" ]; then sed -i "s|CONFIG_AUFS_FS=m|\# CONFIG_AUFS_FS is not set|g" .config fi fi make prepare msg "Update .config Finished" ########################### # Start the configuration ########################### msg "Updating configuration..." yes "" | make config > /dev/null # Save the config file to the package directory if [[ -n "$_save_config" || -n "$_configure_only" ]]; then msg "Saving configuration..." msg2 "Saving $_build_dir/$_gitname-build/.config as $startdir/config.saved.$CARCH" cp .config "$startdir/config.saved.$CARCH" || return 1 fi # Stop after configuration if desired if [ -n "$_configure_only" ]; then rm -rf "$_build_dir/$_gitname-build" return 1 fi ################# # BUILD PROCESS ################# msg "Checking the kernel version..." _kernver="$(make kernelrelease)" if [ "$_configure_as_ARCH_way" = "y" ]; then # Check the _kernver again, if it is your wanted (Special for _configure_as_ARCH_way) _localversion=$(grep CONFIG_LOCALVERSION= .config | cut -d "\"" -f 2) if [ "${_kernver#*-}" != ${_localversion#-} ]; then msg "There are some errors when get your own kernel version." msg "_kernver=${_kernver}, _localversion=${_localversion}." exit 1 else msg "Get the right kernel version as ${_kernver}" fi fi msg "Building kernel and modules..." make V="$_verbose" bzImage modules || return 1 msg "Compile finished!" } package_kernel26-base-git(){ pkgdesc="The Linux Kernel and modules from Linus' git tree with Gentoo patches, aufs2 and reiserfs4 file system patch, and kernel Chinese characters patches. Linux内核及模块git版,包含内核中文字符支持,Gentoo官方补丁、aufs2补丁、reiser4补丁." provides=('kernel26=2.6.31' 'kernel26=2.6.31-ARCH' 'kernel26-git' 'aufs') conflicts=('kernel24' 'kernel24-scsi' 'kernel26-scsi' 'kernel26' 'unionfs' 'aufs') depends=('coreutils' 'module-init-tools' 'mkinitcpio>=0.5.15') install=kernel26.install KARCH="x86" cd "$_build_dir/$_gitname-build" _kernver="$(make kernelrelease)" msg "Installing kernel image..." install -D -m644 System.map "$pkgdir/boot/System.map26" && install -D -m644 arch/$KARCH/boot/bzImage "$pkgdir/boot/vmlinuz26" && install -D -m644 .config "$pkgdir/boot/kconfig26" || return 1 msg "Installing kernel modules..." make INSTALL_MOD_PATH="$pkgdir" modules_install msg "Installing preset file..." install -D -m644 "$srcdir/kernel26.preset" \ "$pkgdir/etc/mkinitcpio.d/kernel26.preset" || return 1 msg "Generating kernel26.kver..." echo -e "# DO NOT EDIT THIS FILE\nALL_kver='$_kernver'" \ > "$pkgdir/etc/mkinitcpio.d/kernel26.kver" || return 1 msg "Remove the firmware..." rm -rf "$pkgdir/lib/firmware" msg "Kernel and modules installing finished." } package_kernel26-firmware() { pkgdesc="The included firmware files of the Linux Kernel, from Linus' git tree." provides=('kernel26-firmware') conflicts=('kernel26-firmware') cd "$_build_dir/$_gitname-build" msg "Install the kernel26-firmware..." make INSTALL_MOD_PATH="$pkgdir" modules_install rm -rf $pkgdir/lib/modules msg "kernel firmware installing finished." } package_kernel26-source-git() { pkgdesc="Kernel source from git tree, patched with aufs2 reiser4." provides=('kernel26-source') conflicts=('kernel26-source') KARCH="x86" cd "$_build_dir/$_gitname-build" _kernver="$(make kernelrelease)" msg "Installing the kernel source..." # Install configuration and other files... install -D -m644 Module.symvers "$pkgdir/usr/src/linux-$_kernver/Module.symvers" && install -D -m644 Makefile "$pkgdir/usr/src/linux-$_kernver/Makefile" && install -D -m644 kernel/Makefile "$pkgdir/usr/src/linux-$_kernver/kernel/Makefile" && install -D -m644 .config "$pkgdir/usr/src/linux-$_kernver/.config" && install -D -m644 .config "$pkgdir/lib/modules/$_kernver/.config" || return 1 # Install scripts directory and fix permissions on it cp -a scripts "$pkgdir/usr/src/linux-$_kernver" && chmod og-w -R "$pkgdir/usr/src/linux-$_kernver" || return 1 msg "Installing header files..." # kernel headers msg2 "kernel" for i in acpi asm-{generic,$KARCH} config linux math-emu media net pcmcia scsi sound trace video; do mkdir -p "$pkgdir/usr/src/linux-$_kernver/include/$i" && cp -a include/$i "$pkgdir/usr/src/linux-$_kernver/include" || return 1 done # lirc headers msg2 "lirc" mkdir -p "$pkgdir/usr/src/linux-$_kernver/drivers/media/video" && cp drivers/media/video/*.h "$pkgdir/usr/src/linux-$_kernver/drivers/media/video/" || return 1 for i in bt8xx cpia2 cx25840 cx88 em28xx et61x251 pwc saa7134 sn9c102 usbvideo zc0301; do mkdir -p "$pkgdir/usr/src/linux-$_kernver/drivers/media/video/$i" && cp -a drivers/media/video/$i/*.h "$pkgdir/usr/src/linux-$_kernver/drivers/media/video/$i" || return 1 done # md headers msg2 "md" mkdir -p "$pkgdir/usr/src/linux-$_kernver/drivers/md" && cp drivers/md/*.h "$pkgdir/usr/src/linux-$_kernver/drivers/md" || return 1 # inotify.h msg2 "inotify.h" mkdir -p "$pkgdir/usr/src/linux-$_kernver/include/linux" && cp include/linux/inotify.h "$pkgdir/usr/src/linux-$_kernver/include/linux/" || return 1 # CLUSTERIP file for iptables msg2 "CLUSTERIP file for iptables" mkdir -p "$pkgdir/usr/src/linux-$_kernver/net/ipv4/netfilter/" && cp net/ipv4/netfilter/ipt_CLUSTERIP.c "$pkgdir/usr/src/linux-$_kernver/net/ipv4/netfilter/" || return 1 # wireless headers msg2 "wireless" mkdir -p "$pkgdir/usr/src/linux-$_kernver/net/mac80211/" && cp net/mac80211/*.h "$pkgdir/usr/src/linux-$_kernver/net/mac80211/" || return 1 # Kconfig files msg2 "Kconfig files" for i in $(find . -name "Kconfig*"); do mkdir -p "$pkgdir/usr/src/linux-$_kernver/${i%/*}" && cp "$i" "$pkgdir/usr/src/linux-$_kernver/$i" || return 1 done # Install architecture dependent files msg "Installing architecture files..." mkdir -p "$pkgdir/usr/src/linux-$_kernver/arch/$KARCH/kernel" && cp arch/$KARCH/kernel/asm-offsets.s "$pkgdir/usr/src/linux-$_kernver/arch/$KARCH/kernel" cp arch/$KARCH/Makefile* "$pkgdir/usr/src/linux-$_kernver/arch/$KARCH" cp -r arch/$KARCH/configs "$pkgdir/usr/src/linux-$_kernver/arch/$KARCH" # copy arch includes for external modules and fix the nVidia issue mkdir -p "$pkgdir/usr/src/linux-$_kernver/arch/$KARCH" && cp -a "arch/$KARCH/include" "$pkgdir/usr/src/linux-$_kernver/arch/$KARCH/" || return 1 # create a necessary symlink to the arch folder cd "$pkgdir/usr/src/linux-$_kernver/arch" || return 1 if [ "$CARCH" = "x86_64" ]; then ln -s $KARCH x86_64 || return 1 else ln -s $KARCH i386 || return 1 fi cd "$OLDPWD" || return 1 msg "Removing unneeded architectures..." for i in "$pkgdir/usr/src/linux-$_kernver/arch/"*; do [ "${i##*/}" != "$KARCH" ] && rm -rf "$i" done msg "Creating important symlinks..." cd "$pkgdir/usr/src/linux-$_kernver/include" && ln -s asm-$KARCH asm && cd "$OLDPWD" || return 1 mkdir -p $pkgdir/lib/modules/$_kernver cd "$pkgdir/lib/modules/$_kernver" && rm -rf source build && ln -s ../../../usr/src/linux-$_kernver build && cd "$OLDPWD" || return 1 msg "Fixing permissions..." chown -R root:root "$pkgdir/usr/src/linux-$_kernver" && find "$pkgdir/usr/src/linux-$_kernver" -type d -exec chmod 755 {} \; || return 1 msg "Kernel source installing finished." } package_kernel-headers() { pkgdesc="Kernel headers sanitized for use in userspace, from git tree." provides=('kernel-headers') conflicts=('kernel-headers') cd "$_build_dir/$_gitname-build" _kernver="$(make kernelrelease)" msg "Installing the kernel headers..." #make mrproper || return 1 #make headers_check || return 1 make INSTALL_HDR_PATH="${pkgdir}/usr" headers_install || return 1 rm -rf "${pkgdir}/usr/include/drm" #find ${pkgdir} -type f -name "*.cmd" -exec rm -rf {}\; msg "Updating pkgver to ${_kernver%-*}..." pkgver=${_kernver%-*} if [ "$_keep_build_dir" != "y" ]; then # Remove build directory rm -rf "$_build_dir/$_gitname-build" fi msg "kernel headers installed finished." }
作者: carbonjiao 发布时间: 2009-09-10
(我第一次看到這麼長的PKGBUILD)
作者: jiuny0209 发布时间: 2009-09-11
作者: firefoxmmx 发布时间: 2009-09-11
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28