2014年1月19日 星期日

Making a debian package

**需要用到的軟體dh_make, fakeroot, build-essential**

首先要決定的是套件名稱及版本
本範例使用的套件名稱為hello-kuntelin。版本為1.0.1
要注意的是套件名稱皆為小寫。分隔字元為"-"


首次debian化
環境變數
DEBEMAIL=套件管理者的電子信箱
DEBFULLNAME=套件管理者的名稱
設定檔時部份檔案會使用到這二個變數

先建立套件的目錄
切換到該目錄後執行 dh_make --native --single --copyright bsd --packagenae ${套件名稱}_${套件版本}
--native 這是個自己編寫的程式
--single 這是個Single binary的套件
--copyright bsd 本套件使用BSD授權
對參數有與趣的可以man dh_make使用其他的參數
要注意的是如果使用非自己編寫的程式。需先將原始來源打包於上一層目錄。並命名為 ${套件名稱}_${套件版本}.orig.tar.gz

檢查目錄下是否多出個debian的目錄。目錄存在代表成功


編輯主要檔案
debian下必要的檔案為control, copyright, changelog, rules

control 詳細內容請參照這裡
範例
Source: hello-kuntelin                                                                                                                                                   
Section: misc                                                                                                                                                            
Priority: extra                                                                                                                                                          
Maintainer: example                                                                                                                                 
Build-Depends: debhelper (>= 8.0.0)                                                                                                                                      
Standards-Version: 3.9.2                                                                                                                                                 
                                                                                                                                                                         
Package: hello-kuntelin                                                                                                                                                  
Architecture: all                                                                                                                                                        
Depends:                                                                                                                                                                 
Description: This is first line description                                                                                                                              
 This is second line description                                                                                                                                         
 This is third line description          

copyright 版權宣告
Files: *                                                                                                                                                                 
Copyright: 2014 example                                                                                                                             
License: BSD-3-Clause                                                                                                                                                    
                                                                                                                                                                         
Files: debian/*                                                                                                                                                          
Copyright: 2014 example                                                                                                                             
License: BSD-3-Clause                                                                                                                                                    
                                                                                                                                                                         
License: BSD-3-Clause                                                                                                                                                    
 Redistribution and use in source and binary forms, with or without                                                                                                      
 modification, are permitted provided that the following conditions                                                                                                      
 are met:                                                                                                                                                                
 1. Redistributions of source code must retain the above copyright                                                                                                       
    notice, this list of conditions and the following disclaimer.                                                                                                        
 2. Redistributions in binary form must reproduce the above copyright                                                                                                    
    notice, this list of conditions and the following disclaimer in the                                                                                                  
    documentation and/or other materials provided with the distribution.                                                                                                 
 3. Neither the name of the University nor the names of its contributors                                                                                                 
    may be used to endorse or promote products derived from this software                                                                                                
    without specific prior written permission.                                                                                                                           
 .                                                                                                                                                                       
 THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND                                                                                                 
 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE                                                                                                   
 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE                                                                                              
 ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE                                                                                                
 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL                                                                                              
 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS                                                                                                 
 OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)                                                                                                   
 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT                                                                                              
 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY                                                                                               
 OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF                                                                                                  
 SUCH DAMAGE.                                                                                                                                                            

changelog 詳細內容請參照這裡
hello-kuntelin (1.0.1) unstable; urgency=low                                                                                                                             
                                                                                                                                                                         
  * Initial Release.                                                                                                                                                     
                                                                                                                                                                         
 -- example   Mon, 20 Jan 2014 11:31:19 +0800       

rules 其實是另一個Makefile用來安裝本例使用預設
#!/usr/bin/make -f                                                                                                                                                       
# -*- makefile -*-                                                                                                                                                       
# Sample debian/rules that uses debhelper.                                                                                                                               
# This file was originally written by Joey Hess and Craig Small.                                                                                                         
# As a special exception, when this file is copied by dh-make into a                                                                                                     
# dh-make output file, you may use that output file without restriction.                                                                                                 
# This special exception was added by Craig Small in version 0.37 of dh-make.                                                                                            
                                                                                                                                                                         
# Uncomment this to turn on verbose mode.                                                                                                                                
#export DH_VERBOSE=1                                                                                                                                                     
                                                                                                                                                                         
%:                                                                                                                                                                       
    dh $@            


其他檔案
debian/install 安裝時一併裝到系統的檔案(不在make install安裝的檔案),詳細的用法請看這裡
debian/dirs 安裝時一併建立的目錄(不在make install建立的目錄),詳細的用法請看這裡


打包套件
dpkg-buildpackage -b -uc -rfakeroot
打包完成後會在上層的目錄

參考來源:
Debian 新維護人員手冊