LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
12
返回列表 发新帖
楼主: jarryson

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

[复制链接]
发表于 2009-8-28 23:48:41 | 显示全部楼层
谢谢jarryson
回复 支持 反对

使用道具 举报

发表于 2009-9-10 16:26:58 | 显示全部楼层
請問一下,假如我要把startdict的一堆字典打成一個包,那要怎饃寫PKGBUILD?
回复 支持 反对

使用道具 举报

发表于 2009-9-10 17:48:05 | 显示全部楼层
这东西值得探究
回复 支持 反对

使用道具 举报

发表于 2009-9-10 18:13:50 | 显示全部楼层
编译 pacman 的时候里面有文档。。。

我也写了个关于内核的。。。

一个PKGBUILD 四个包  http://archlive-pkg.googlecode.c ... ce_headers/PKGBUILD


但这种PKGBUILD 好像无法提交到aur

编译好的包 可以从 http://archlive-pkg.googlecode.com/files 下载
或者添加 archlive-pkg 软件源  直接 pacman 来安装


  1. # Archlive <http://archlive-pkg.googlecode.com>

  2. pkgname=('kernel26-base-git' 'kernel26-firmware' kernel26-source-git 'kernel-headers')
  3. pkgbase=""
  4. pkgver=20090909
  5. pkgrel=1
  6. _realpkgname=kernel26
  7. _configure_as_ARCH_way=y
  8. _kernelname=${_realpkgname#kernel26}
  9. ## if you want your own version, such as 2.6.31-archlive, then
  10. ## "_configure_as_ARCH_way" set to "1" and
  11. ## "_realpkgname" change to "kernel26-archlive"
  12. _include_aufs2=y
  13. _include_squashfs=y
  14. # 是否保存编译目录
  15. _keep_build_dir=y
  16. ## More special selection as below items.
  17. #
  18. url="http://www.kernel.org/"
  19. arch=(i686 x86_64)
  20. license=('GPL2')
  21. makedepends=('git' 'gcc')
  22. backup=(etc/mkinitcpio.d/kernel26.preset)
  23. source=(kernel26.preset config.{i686,x86_64} \
  24.         logo_linux_{clut224.ppm,mono.pbm,vga16.ppm}
  25.         ## reiserfs4 patch
  26.         http://www.kernel.org/pub/linux/kernel/people/edward/reiser4/reiser4-for-2.6/reiser4-for-2.6.30.patch.gz
  27.         ## Gentoo patches
  28.         4100_dm-bbr.patch   4202_fbcondecor-0.9.6.patch 4400_alpha-sysctl-uac.patch
  29.         ### Chinese Characters Patches 孙海勇 大侠的 内核中文补丁  http://youbest.cublog.cn/
  30.         #http://zdbr.net.cn/download/utf8-kernel-2.6.29-core-1.patch.bz2
  31.         utf8-kernel-2.6.29-core-1.patch
  32.         http://zdbr.net.cn/download/utf8-kernel-2.6-fonts-2.patch.bz2
  33.         http://zdbr.net.cn/download/utf8-kernel-2.6.28-fbcondecor-1.patch.bz2
  34. )
  35. md5sums=()
  36. _gitroot="git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6.git"
  37. _gitname="linux-2.6.git"

  38. ####################################################################
  39. # KERNEL CONFIG FILES
  40. # This PKGBUILD searches for config files in the current directory
  41. # and will use the first one it finds from the following
  42. # list as base configuration:
  43. #         config.local
  44. #         config.saved.$CARCH
  45. #         config.$CARCH
  46. ####################################################################
  47. # PATCHES
  48. # This package builds the vanilla git kernel by default,
  49. # but it is possible to patch the source without modifying
  50. # this PKGBUILD.
  51. # Simply create a directory 'patches' in your PKGBUILD
  52. # directory and _any_ file (dotfiles excluded) in this
  53. # folder will be applied to the kernel source.
  54. # Prefixing the patch file names with dots will obviously
  55. # excluded them from the patching process.
  56. #############################################################
  57. # CONFIGURATION
  58. # Uncomment desired options
  59. #######
  60. # Set to menuconfig, xconfig, gconfig or oldconfig
  61. # If you set it to something else, the
  62. # (manual) kernel configuration step will
  63. # be skipped
  64. _menu_method="menuconfig"       
  65. #######
  66. # The directory where the kernel should be built
  67. # Can be useful, for example, if you want to compile on a
  68. # tmpfs mount, which can speed up the compilation process
  69. _build_dir="$srcdir"
  70. #######
  71. # Stop build process after kernel configuration
  72. # This option enables _save_config implicitly.
  73. # _configure_only=1
  74. #######
  75. # Save the .config file to package directory
  76. # as config.saved.$CARCH
  77. # _save_config=1
  78. #######
  79. # Make the kernel build process verbose
  80. # _verbose=1
  81. ####################################################################

  82. extrapatch() {
  83.   msg2 "Add Gentoo patches 加入Gentoo官方基本补丁..."
  84.   for i in $(ls $srcdir/4[0-9][0-9][0-9]*);do
  85.             echo "Applying $(basename $i)"
  86.           patch -Np1 -i $i || return 1
  87.   done

  88.   msg2 "Add the kernel Chinese characters patches 加入孙海勇 大侠的 内核中文补丁  http://youbest.cublog.cn/"
  89.   patch -Np1 -i $srcdir/utf8-kernel-2.6.29-core-1.patch || return 1
  90.   patch -Np1 -i $srcdir/utf8-kernel-2.6.28-fbcondecor-1.patch || return 1
  91.   patch -Np1 -i $srcdir/utf8-kernel-2.6-fonts-2.patch || return 1

  92.   msg2 "Adding reiserfs4 patch reiser4-for-2.6.30.patch"
  93.   patch -Np1 -i ${srcdir}/reiser4-for-2.6.30.patch || return 1

  94.   if [ "${_include_aufs2}" = "y" ]; then
  95.         msg2 "Get aufs2 standalone patch from git tree"
  96.         if [ -d $srcdir/aufs2-standalone ]; then
  97.                 cd $srcdir/aufs2-standalone
  98.                 git pull origin
  99.         else
  100.                 git clone http://git.c3sl.ufpr.br/pub/scm/aufs/aufs2-standalone.git $srcdir/aufs2-standalone || return 1
  101.         fi
  102.         cd $srcdir/aufs2-standalone
  103.         git checkout origin/aufs2
  104.         cp -r $srcdir/aufs2-standalone/{Documentation,fs,include,aufs2-base.patch,aufs2-kbuild.patch,aufs2-standalone.patch} \
  105.                   $srcdir/$_gitname-build/
  106.         cd $srcdir/$_gitname-build
  107.         patch -Np1 -i aufs2-kbuild.patch || return 1
  108.         patch -Np1 -i aufs2-base.patch || return 1
  109.         patch -Np1 -i aufs2-standalone.patch || return 1
  110.   fi
  111. }

  112. build() {
  113.         KARCH="x86"

  114.         msg "Fetching sources..."
  115.         cd "$startdir"
  116.         if [ -d "$_gitname" ]; then
  117.                 msg2 "Updating sources..."
  118.                 cd "$_gitname" && git fetch && cd "$OLDPWD" || return 1
  119.         else
  120.                 msg2 "Cloning the project..."
  121.                 git clone --mirror "$_gitroot" "$_gitname" || return 1
  122.         fi

  123.         msg "Creating build branch..."
  124.         rm -rf "$_build_dir/$_gitname-build"
  125.         git clone "$_gitname" "$_build_dir/$_gitname-build" || return 1

  126.         cd "$_build_dir/$_gitname-build"
  127.         # Add Gentoo patches, Fedora patches, reiserfs4 patch and kernel Chinese characters patches.
  128.         extrapatch

  129.         msg "Adding Archlinux logo..."
  130.         cp "$srcdir/logo_linux_clut224.ppm"  drivers/video/logo/ &&
  131.         cp "$srcdir/logo_linux_mono.pbm"     drivers/video/logo/ &&
  132.         cp "$srcdir/logo_linux_vga16.ppm"    drivers/video/logo/ || return 1

  133.         # Apply other patches
  134.         if [ -d "$startdir/patches" ]; then
  135.                 msg "Applying patches..."
  136.                 for i in "$startdir/patches/"*; do
  137.                         msg2 "Applying ${i##*/}..."
  138.                         patch -Np1 -i "$i" || (error "Applying ${i##*/} failed" && return 1)
  139.                 done
  140.         fi

  141.         #################
  142.         # CONFIGURATION
  143.         #################
  144.         msg "Loading configuration..."
  145.         for i in local "saved.$CARCH" "$CARCH"; do
  146.                 if [ -e "$startdir/config.$i" ]; then
  147.                         msg2 "Using kernel config file config.$i..."
  148.                         cp -f "$startdir/config.$i" .config || return 1
  149.                         break
  150.                 fi
  151.         done
  152.         [ ! -e .config ] &&
  153.                 warning "No suitable kernel config file was found. You'll have to configure the kernel from scratch."

  154.         ###########################
  155.         # Configure as ARCH way
  156.         ###########################
  157.         if [ "$_configure_as_ARCH_way" = "y" ]; then
  158.                 msg "Configure the kernel version as ARCH way, like 2.6.31-ARCH"
  159.                 if [ "${_kernelname}" != "" ]; then local_version=${_kernelname}; else local_version="-ARCH"; fi
  160.                 sed -i "s|^EXTRAVERSION = .*$|EXTRAVERSION =|g" Makefile
  161.                 sed -i "s|.*CONFIG_LOCALVERSION=.*|CONFIG_LOCALVERSION="${local_version}"|g" .config
  162.                 sed -i "s|.*CONFIG_LOCALVERSION_AUTO.*|\# CONFIG_LOCALVERSION_AUTO is not set|g" .config
  163.         fi
  164.         # The default .config without support for squashfs, can change it by set "_include_squashfs" as "y".
  165.         if [ "$_include_squashfs" = "y" ]; then
  166.                 msg "Selected squashfs4 included in kernel package."
  167.                 if [ "x$(grep "CONFIG_SQUASHFS=m" .config)" = "x" ]; then
  168.                         sed -i "s|.*CONFIG_SQUASHFS.*|CONFIG_SQUASHFS=m\
  169.                                 \n# CONFIG_SQUASHFS_EMBEDDED is not set\
  170.                                 \nCONFIG_SQUASHFS_FRAGMENT_CACHE_SIZE=3|g" ./.config
  171.                 fi
  172.         else
  173.                 if [ "x$(grep "CONFIG_SQUASHFS=m" .config)" != "x" ]; then
  174.                         sed -i "s|CONFIG_SQUASHFS=m|\# CONFIG_SQUASHFS is not set|g" .config
  175.                 fi
  176.         fi
  177.         if [ "${_include_aufs2}" = "y" ]; then
  178.                 msg "Selected aufs2 included in kernel package."
  179.                 if [ "x$(grep "CONFIG_AUFS_FS=m" .config)" = "x" ]; then
  180.                         sed -i "/.*CONFIG_NILFS2_FS.*/ a\
  181.                                 \CONFIG_AUFS_FS=m\
  182.                                 \n# CONFIG_AUFS_BRANCH_MAX_127 is not set\
  183.                                 \n# CONFIG_AUFS_BRANCH_MAX_511 is not set\
  184.                                 \nCONFIG_AUFS_BRANCH_MAX_1023=y\
  185.                                 \n# CONFIG_AUFS_BRANCH_MAX_32767 is not set\
  186.                                 \nCONFIG_AUFS_HINOTIFY=y\
  187.                                 \nCONFIG_AUFS_EXPORT=y\
  188.                                 \nCONFIG_AUFS_RDU=y\
  189.                                 \nCONFIG_AUFS_SHWH=y\
  190.                                 \nCONFIG_AUFS_BR_RAMFS=y\
  191.                                 \nCONFIG_AUFS_BR_FUSE=y\
  192.                                 \n# CONFIG_AUFS_DEBUG is not set\
  193.                                 \nCONFIG_AUFS_BDEV_LOOP=y\
  194.                                 \nCONFIG_AUFS_POLL=y" ./.config
  195.                 fi
  196.         else
  197.                 if [ "x$(grep "CONFIG_AUFS_FS=m" .config)" != "x" ]; then
  198.                         sed -i "s|CONFIG_AUFS_FS=m|\# CONFIG_AUFS_FS is not set|g" .config
  199.                 fi
  200.         fi
  201.         make prepare
  202.         msg "Update .config Finished"

  203.         ###########################
  204.         # Start the configuration
  205.         ###########################
  206.         msg "Updating configuration..."

  207.         yes "" | make config > /dev/null

  208.         # Save the config file to the package directory
  209.         if [[ -n "$_save_config" || -n "$_configure_only" ]]; then
  210.                 msg "Saving configuration..."
  211.                 msg2 "Saving $_build_dir/$_gitname-build/.config as $startdir/config.saved.$CARCH"
  212.                 cp .config "$startdir/config.saved.$CARCH" || return 1
  213.         fi

  214.         # Stop after configuration if desired
  215.         if [ -n "$_configure_only" ]; then
  216.                 rm -rf "$_build_dir/$_gitname-build"
  217.                 return 1
  218.         fi
  219.         #################
  220.         # BUILD PROCESS
  221.         #################

  222.         msg "Checking the kernel version..."
  223.         _kernver="$(make kernelrelease)"
  224.         if [ "$_configure_as_ARCH_way" = "y" ]; then
  225.                 # Check the _kernver again, if it is your wanted (Special for _configure_as_ARCH_way)
  226.                 _localversion=$(grep CONFIG_LOCALVERSION= .config | cut -d """ -f 2)
  227.                 if [ "${_kernver#*-}" != ${_localversion#-} ]; then
  228.                         msg "There are some errors when get your own kernel version."
  229.                         msg "_kernver=${_kernver}, _localversion=${_localversion}."
  230.                         exit 1
  231.                 else
  232.                         msg "Get the right kernel version as ${_kernver}"
  233.                 fi
  234.         fi       
  235.         msg "Building kernel and modules..."
  236.         make V="$_verbose" bzImage modules || return 1
  237.         msg "Compile finished!"
  238. }

  239. package_kernel26-base-git(){
  240.         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补丁."
  241.         provides=('kernel26=2.6.31' 'kernel26=2.6.31-ARCH' 'kernel26-git' 'aufs')
  242.         conflicts=('kernel24' 'kernel24-scsi' 'kernel26-scsi' 'kernel26' 'unionfs' 'aufs')
  243.         depends=('coreutils' 'module-init-tools' 'mkinitcpio>=0.5.15')
  244.         install=kernel26.install

  245.         KARCH="x86"
  246.         cd "$_build_dir/$_gitname-build"
  247.         _kernver="$(make kernelrelease)"

  248.         msg "Installing kernel image..."
  249.         install -D -m644 System.map                "$pkgdir/boot/System.map26" &&
  250.         install -D -m644 arch/$KARCH/boot/bzImage "$pkgdir/boot/vmlinuz26" &&
  251.         install -D -m644 .config                   "$pkgdir/boot/kconfig26"    || return 1

  252.         msg "Installing kernel modules..."
  253.         make INSTALL_MOD_PATH="$pkgdir" modules_install

  254.         msg "Installing preset file..."
  255.         install -D -m644 "$srcdir/kernel26.preset" \
  256.                 "$pkgdir/etc/mkinitcpio.d/kernel26.preset" || return 1

  257.         msg "Generating kernel26.kver..."
  258.         echo -e "# DO NOT EDIT THIS FILE\nALL_kver='$_kernver'" \
  259.                 > "$pkgdir/etc/mkinitcpio.d/kernel26.kver" || return 1

  260.         msg "Remove the firmware..."
  261.         rm -rf "$pkgdir/lib/firmware"

  262.         msg "Kernel and modules installing finished."
  263. }

  264. package_kernel26-firmware() {
  265.         pkgdesc="The included firmware files of the Linux Kernel, from Linus' git tree."
  266.         provides=('kernel26-firmware')
  267.         conflicts=('kernel26-firmware')

  268.         cd "$_build_dir/$_gitname-build"

  269.         msg "Install the kernel26-firmware..."
  270.         make INSTALL_MOD_PATH="$pkgdir" modules_install
  271.         rm -rf $pkgdir/lib/modules

  272.         msg "kernel firmware installing finished."
  273. }

  274. package_kernel26-source-git() {
  275.         pkgdesc="Kernel source from git tree, patched with aufs2 reiser4."
  276.         provides=('kernel26-source')
  277.         conflicts=('kernel26-source')

  278.         KARCH="x86"
  279.         cd "$_build_dir/$_gitname-build"
  280.         _kernver="$(make kernelrelease)"

  281.         msg "Installing the kernel source..."
  282.         # Install configuration and other files...
  283.         install -D -m644 Module.symvers  "$pkgdir/usr/src/linux-$_kernver/Module.symvers"  &&
  284.         install -D -m644 Makefile        "$pkgdir/usr/src/linux-$_kernver/Makefile"        &&
  285.         install -D -m644 kernel/Makefile "$pkgdir/usr/src/linux-$_kernver/kernel/Makefile" &&
  286.         install -D -m644 .config         "$pkgdir/usr/src/linux-$_kernver/.config"         &&
  287.         install -D -m644 .config         "$pkgdir/lib/modules/$_kernver/.config"           || return 1

  288.         # Install scripts directory and fix permissions on it
  289.         cp -a scripts "$pkgdir/usr/src/linux-$_kernver" &&
  290.                 chmod og-w -R "$pkgdir/usr/src/linux-$_kernver" || return 1

  291.         msg "Installing header files..."
  292.         # kernel headers
  293.         msg2 "kernel"
  294.         for i in acpi asm-{generic,$KARCH} config linux math-emu media net pcmcia scsi sound trace video; do
  295.                 mkdir -p "$pkgdir/usr/src/linux-$_kernver/include/$i" &&
  296.                         cp -a include/$i "$pkgdir/usr/src/linux-$_kernver/include" || return 1
  297.         done

  298.         # lirc headers
  299.         msg2 "lirc"
  300.         mkdir -p "$pkgdir/usr/src/linux-$_kernver/drivers/media/video" &&
  301.                 cp drivers/media/video/*.h "$pkgdir/usr/src/linux-$_kernver/drivers/media/video/" || return 1

  302.         for i in bt8xx cpia2 cx25840 cx88 em28xx et61x251 pwc saa7134 sn9c102 usbvideo zc0301; do
  303.                 mkdir -p "$pkgdir/usr/src/linux-$_kernver/drivers/media/video/$i" &&
  304.                         cp -a drivers/media/video/$i/*.h "$pkgdir/usr/src/linux-$_kernver/drivers/media/video/$i" || return 1
  305.         done

  306.         # md headers
  307.         msg2 "md"
  308.         mkdir -p "$pkgdir/usr/src/linux-$_kernver/drivers/md" &&
  309.                 cp drivers/md/*.h "$pkgdir/usr/src/linux-$_kernver/drivers/md" || return 1

  310.         # inotify.h
  311.         msg2 "inotify.h"
  312.         mkdir -p "$pkgdir/usr/src/linux-$_kernver/include/linux" &&
  313.                 cp include/linux/inotify.h "$pkgdir/usr/src/linux-$_kernver/include/linux/" || return 1

  314.         # CLUSTERIP file for iptables
  315.         msg2 "CLUSTERIP file for iptables"
  316.         mkdir -p "$pkgdir/usr/src/linux-$_kernver/net/ipv4/netfilter/" &&
  317.                 cp net/ipv4/netfilter/ipt_CLUSTERIP.c "$pkgdir/usr/src/linux-$_kernver/net/ipv4/netfilter/" || return 1

  318.         # wireless headers
  319.         msg2 "wireless"
  320.         mkdir -p "$pkgdir/usr/src/linux-$_kernver/net/mac80211/" &&
  321.                 cp net/mac80211/*.h "$pkgdir/usr/src/linux-$_kernver/net/mac80211/" || return 1

  322.         # Kconfig files
  323.         msg2 "Kconfig files"
  324.         for i in $(find . -name "Kconfig*"); do
  325.                 mkdir -p "$pkgdir/usr/src/linux-$_kernver/${i%/*}" &&
  326.                         cp "$i" "$pkgdir/usr/src/linux-$_kernver/$i" || return 1
  327.         done

  328.         # Install architecture dependent files
  329.         msg "Installing architecture files..."
  330.         mkdir -p "$pkgdir/usr/src/linux-$_kernver/arch/$KARCH/kernel" &&
  331.                 cp arch/$KARCH/kernel/asm-offsets.s "$pkgdir/usr/src/linux-$_kernver/arch/$KARCH/kernel"

  332.         cp arch/$KARCH/Makefile* "$pkgdir/usr/src/linux-$_kernver/arch/$KARCH"
  333.         cp -r arch/$KARCH/configs "$pkgdir/usr/src/linux-$_kernver/arch/$KARCH"

  334.         # copy arch includes for external modules and fix the nVidia issue
  335.         mkdir -p "$pkgdir/usr/src/linux-$_kernver/arch/$KARCH" &&
  336.                 cp -a "arch/$KARCH/include" "$pkgdir/usr/src/linux-$_kernver/arch/$KARCH/" || return 1

  337.         # create a necessary symlink to the arch folder
  338.         cd "$pkgdir/usr/src/linux-$_kernver/arch" || return 1

  339.         if [ "$CARCH" = "x86_64" ]; then
  340.                 ln -s $KARCH x86_64 || return 1
  341.         else
  342.                 ln -s $KARCH i386 || return 1
  343.         fi

  344.         cd "$OLDPWD" || return 1

  345.         msg "Removing unneeded architectures..."
  346.         for i in "$pkgdir/usr/src/linux-$_kernver/arch/"*; do
  347.                 [ "${i##*/}" != "$KARCH" ] && rm -rf "$i"
  348.         done

  349.         msg "Creating important symlinks..."
  350.         cd "$pkgdir/usr/src/linux-$_kernver/include" &&
  351.                 ln -s asm-$KARCH asm &&
  352.                 cd "$OLDPWD" || return 1

  353.         mkdir -p $pkgdir/lib/modules/$_kernver
  354.         cd "$pkgdir/lib/modules/$_kernver" &&
  355.                 rm -rf source build &&
  356.                 ln -s ../../../usr/src/linux-$_kernver build &&
  357.                 cd "$OLDPWD" || return 1

  358.         msg "Fixing permissions..."
  359.         chown -R root:root "$pkgdir/usr/src/linux-$_kernver" &&
  360.                 find "$pkgdir/usr/src/linux-$_kernver" -type d -exec chmod 755 {} \; || return 1

  361.         msg "Kernel source installing finished."
  362. }
  363. package_kernel-headers() {
  364.         pkgdesc="Kernel headers sanitized for use in userspace, from git tree."
  365.         provides=('kernel-headers')
  366.         conflicts=('kernel-headers')

  367.         cd "$_build_dir/$_gitname-build"
  368.         _kernver="$(make kernelrelease)"

  369.         msg "Installing the kernel headers..."
  370.         #make mrproper || return 1
  371.         #make headers_check || return 1
  372.         make INSTALL_HDR_PATH="${pkgdir}/usr" headers_install || return 1
  373.         rm -rf "${pkgdir}/usr/include/drm"
  374.         #find ${pkgdir} -type f -name "*.cmd" -exec rm -rf {}\;

  375.         msg "Updating pkgver to ${_kernver%-*}..."
  376.         pkgver=${_kernver%-*}

  377.         if [ "$_keep_build_dir" != "y" ]; then
  378.                 # Remove build directory
  379.                 rm -rf "$_build_dir/$_gitname-build"
  380.         fi
  381.         msg "kernel headers installed finished."
  382. }

复制代码
回复 支持 反对

使用道具 举报

发表于 2009-9-10 21:52:07 | 显示全部楼层
謝謝你的範例,感覺自己不懂的還是很多。

(我第一次看到這麼長的PKGBUILD)
回复 支持 反对

使用道具 举报

发表于 2009-9-11 01:07:55 | 显示全部楼层
标记了。。呵呵。
回复 支持 反对

使用道具 举报

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

本版积分规则

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