2014年12月8日 星期一

Linux Debian - Build Package (deb),製作 (deb) 套件簡易說明

安裝要製作 Package 所需套件
  • apt-get install dh-make debhelper fakeroot 

建立並進入資料夾
  • mkdir <project name> 
  • cd <project name> 

使用 dh_make 建立套件包所需檔案之範本,
Debian Package 所需四個檔案為 (changelog, control, dirs, rules)




接下來修改內容: 

changelog 

sublime-text-3-chewing (3065) unstable; urgency=low

  * Initial release (Closes: #nnnn) <nnnn is the bug number of your ITP>

  -- disney <abc57911@gmail.com> Wed, 03 Dec 2014 16:19:15 +0800


control
Source: sublime-text-3-chewing(套件源碼名稱)
Section: misc(套件種類)
Priority: optional
Maintainer: disney <abc57911@gmail.com>
Build-Depends: debhelper (>= 9)
Standards-Version: 3065(套件版本)

Package: sublime-text-3-chewing(套件名稱)
Architecture: any
Depends:
Description: This version has chewing plugin. (摘要)
              (內容)
    La La La~ La La La~ La La La~ La La La~ La La La~
    La La La~ La La La~ La La La~ La La La~
    La La La~ La La La~ La La La~
    La La La~ La La La~
    La La La~


dirs
opt/sublime_text
usr/share



rules
#!/usr/bin/make -f
# See debhelper(7) (uncomment to enable)
# output every command that modifies files on the build system.
#DH_VERBOSE = 1

# see EXAMPLES in dpkg-buildflags(1) and read /usr/share/dpkg/*
DPKG_EXPORT_BUILDFLAGS = 1
include /usr/share/dpkg/default.mk

# see FEATURE AREAS in dpkg-buildflags(1)
#export DEB_BUILD_MAINT_OPTIONS = hardening=+all

# see ENVIRONMENT in dpkg-buildflags(1)
# package maintainers to append CFLAGS
#export DEB_CFLAGS_MAINT_APPEND = -Wall -pedantic
# package maintainers to append LDFLAGS
#export DEB_LDFLAGS_MAINT_APPEND = -Wl,--as-needed


# main packaging script based on dh7 syntax
%:
    dh $@

# debmake generated override targets
# This is example for Cmake (See http://bugs.debian.org/641051 )
#override_dh_auto_configure:
# dh_auto_configure -- \
# -DCMAKE_LIBRARY_PATH=$(DEB_HOST_MULTIARCH)

clean:
    dh_testdir
    dh_testroot
    dh_clean

build:
# Nothing to do

binary: binary-arch binary-indep
# Nothing to do

binary-arch:
# Nothing to do

#install: build
# dh_testdir
# dh_testroot
# dh_clean -k
# dh_installdirs

binary-indep:
    dh_testdir
    dh_installdirs

# Custom package commands

    cp -r --parents opt/* debian/sublime-text-3-chewing/
    cp -r --parents usr/* debian/sublime-text-3-chewing/
    gcc -shared -o debian/sublime-text-3-chewing/opt/sublime_text/libsublime-imfix.so debian/sublime-text-3-chewing/opt/sublime_text/sublime_imfix.c `pkg-config --libs --cflags gtk+-2.0` -fPIC


# Resuming debhelper scripts

    dh_testroot
    dh_installchangelogs
    dh_installdocs
    dh_fixperms
    dh_compress
    dh_gencontrol
    dh_md5sums
    dh_builddeb
.PHONY: binary binary-arch binary-indep build clean



  • cp -r --parents opt/* debian/sublime-text-3-chewing/
  • 上面的 cp 目的地資料夾的意思,就像是你的 Linux 根目錄 /
  • ex: rules 設定安裝目錄為 debian/sublime-text-3/opt/sublime_text/
  • 安裝時將會把檔案放入 /opt/sublime_tex/ 目錄底下。


注意事項:
  • 將要包進去的檔案,放在與 debian 同層目錄裡(專案的根目錄),
  • 且必須創建和指定安裝的目錄路徑相同。






製作 Package
  • 檔案皆設置完成後開始打包
  • 移動到專案根目錄底下 cd ~/package/sublime-text-3-chewing
  • dpkg-buildpackage -rfakeroot -b #製作 package.deb。


4 則留言 :

  1. 從以前就一直有在看你的文章
    每次看完都學到很多東西
    謝謝你熱心地分享
    期待外來可以看到更多技術類型的文章
    也想看看你對於其他議題的觀點和分析

    回覆刪除
  2. 回覆
    1. 真是謙虛的好版主!
      不知道版主知道米老鼠的笑話嘛?

      刪除
    2. 可以告訴我我嗎~ 沒聽過耶~

      刪除