1、新建一個我們臨時的工作目錄mkdir deb
2、新建我們程序的目錄
mkdir hello
3、編寫我們的程序
我們以我們最熟悉的helloworld程序做起,
hello.c代碼如下
#include <stdio.h>
int main()
{
printf("Hello world!\n");
return 0;
}
Makefile文件如下:
OBJS=hello.o
CC=gcc -g
all:$(OBJS)
$(CC) -o hello $(OBJS)
clean:
rm -f *.o hello
.PHONY:all clean
4、我們sudo make一下,測試程序編譯是否有問題,然后在./hello檢查程序是否正確執行
5、如果沒問題進行下一步,如果有問題我們看提示檢查程序代碼
6、我們清理下剛才編譯程序的垃圾,sudo make clean一下
7、輸入命令,切回上級目錄
cd ..
8、進行一次壓縮打包(為什么做這一步,我也不太明白,查資料說,這一步是為了給生成的deb文件進行對比,確保我們deb文件沒有錯誤)
改名:因為文件名必須包含文件名還有版本號
mv hello hello-1.0
//說明:文件名后必須用-,不能用_
tar zcvf hello_1.0.orig.tar.gz hello-1.0
說明:壓縮包的名字必須是包含文件名及版本號
9、進入我們的hello-1.0目錄
cd hello-1.0
10、我們需要dh_make工具進行打包前的配置,如果是第一使用請先安裝dh-make
dh-make安裝方法:
sudo apt-get install dh-make
安裝好后,我們就可以使用該命令了
dh_make -e linuxidc@www.linuxidc.com 修改參數,也可以不修改,執行這一步,我們將會看到,郵箱是我們剛才輸入的
如果不想改為自己的郵箱,可以執行下面命令
dh_make
上面任一命令后都會出現,一下內容:
www.linuxidc.com@linuxidc:~/deb/hello-1.0$ dh_make -e linuxidc@www.linuxidc.com
Type of package: single binary, indep binary, multiple binary, library, kernel module, kernel patch or cdbs?
[s/i/m/l/k/n/b]
11、我們輸入s
Maintainer name : zsx
Email-Address : linuxidc@www.linuxidc.com
Date : Sat, 18 Dec 2010 23:06:25 +0800
Package Name : hello
Version : 1.0
License : blank
Using dpatch : no
Type of Package : Single
Hit <enter> to confirm:
12、輸入回車,確認
Skipping creating ../hello_1.0.orig.tar.gz because it already exists
Done. Please edit the files in the debian/ subdirectory now. You should also
check that the hello Makefiles install into $DESTDIR and not in / .
13、准備工作完成
14、開始打包
dpkg-buildpackage
15、打包成功,切回上級目錄就可看到我們的helloworld的deb包
cd ..
ls后就會看到 hello_1.0-1_armhf.deb
-------------------------------------------------------------------------------------
這里有一個問題,執行hello報錯,我自己搗鼓出了解決方法「可能只對我的機器適用---樹梅派3b linux arm」
1.把deb下面的文件全刪除,我們在來一次
mkdir hello
cd hello
nano hello.c
#include <stdio.h>
int main()
{
printf("Hello world!\n");
return 0;
}
nano Makefile
all:
gcc hello.c -o hello
clean:
.PHONY:all clean//這里執行的效果和上面是一樣的咯
sudo make
sudo make clean
cd ..
mv hello hello-1.0
cd hello-1.0
dh_make --createorig
輸入s
mkdir bin/
cp hello bin/
cd debian/
nano install
#!/bin/bash
./bin/hello 這里還是有個問題hello雖然被包含到bin里去了但是可能會后台執行這個hello,install里面寫mkdir我寫過,執行不了的,linux其他機器應該是可以
cd ..
cd..
tar zcvf hello_1.0.orig.tar.gz hello-1.0
cd hello-1.0
sudo dpkg-buildpackage
Finish:]
sudo dpkg -i *.deb
-------------------------------------------------------------------------------------------------------------
下面我介紹一下debain里面腳本(沒有的可以自己創建,就和上面install一樣)
