Debian/Ubuntu套件打包

很久以前寫過利用dpkg-deb來打包套件,其實這個方法非常麻煩,我後來都改用dh_make了。

利用dh_make加上CDBS(The Common Debian Build System),可以很方便的建立出一個deb包,這也是標準的打包方式。CDBS演變到現在己經非常方便了,打包者幾乎不用作什麼事。CDBS可以處理非常多常見的build system包括GNU Autotools、Python的setup.py、Qt的qmake、make、cmake等等,支援的列表可以在CDBS的Documentation裡找到。

打包的步驟大約如下:
  1. 將套件壓縮成 套件名稱_版本.orig.tar.gz,並放在套件目錄的同層目錄
  2. 在套件根目錄執行dh_make -s -b。-s表示包裝成single binary,-b表示使用CDBS
  3. 編輯debian/control、debian/rules
  4. 在套件根目錄執行dpkg-buildpackage -rfakeroot
  5. 完成。

重點就在debian/rules:
如果是使用GNU Autotools,debian/rules如下:
#!/usr/bin/make -f
include /usr/share/cdbs/1/rules/debhelper.mk
include /usr/share/cdbs/1/class/autotools.mk

如果是使用Python setup.py,debian/rules如下:
#!/usr/bin/make -f
include /usr/share/cdbs/1/rules/debhelper.mk
include /usr/share/cdbs/1/class/python-distutils.mk

就這麼簡單,還有一些選項可以看CDBS的Documentation

我寫了個script來做這些部驟,把這個script還有寫好的control、rules放在'套件根目錄/dev'裡

==================== build-pkg.sh ====================
#!/bin/bash

program_name=PRG_NAME

if [ "$1" == "clean" ]; then
rm -rf ${program_name}*
exit 0
fi

echo 'Version: '
read ver

cd ../../
cp -r $program_name $program_name-$ver
rm -rf $program_name-$ver/dev
mv $program_name-$ver $program_name/dev
cd $program_name/dev/

if [ "$1" == "sdist" ]; then
tar -zcf ${program_name}-$ver.tar.gz $program_name-$ver
exit 0
else
tar -zcf ${program_name}_$ver.orig.tar.gz $program_name-$ver
fi

cd $program_name-$ver
dh_make -s -b -p $program_name

cp ../rules ../control debian
cd debian
rm *.ex *.EX README.*
dch -e
cd ..

if [ "$1" == "deb" ] || [ -z "$1" ]; then
dpkg-buildpackage -rfakeroot
elif [ "$1" == "ppa" ]; then
debuild -S
fi
Have fun :)

留言

這個網誌中的熱門文章

決定了!!!

P.S. I Love You

Tips: PPTP client on Openwrt