1. 程式人生 > 實用技巧 >openwrt軟體安裝包ipk的編譯方法

openwrt軟體安裝包ipk的編譯方法

方法主要有兩種:1) SDK編譯 2)原始碼編譯

1.SDK編譯軟體安裝包IPK

從上邊的教程我們已經可以看到怎麼去獲得SDK包了,然後怎麼使用這個包,看教程:

http://my.oschina.net/hevakelcj/blog/410633

這個教程已經詳實地介紹了編譯的步驟,步驟是沒有問題的。但是!SDK編譯比較坑,就算你完全正確,他就是給你報錯,我就死在了下圖這個錯誤上:

意思是makefile 32行前邊少了個Tab,但是無論是怎麼改,他就是報錯 = = 所有努力都是徒勞無意義的。

同樣的程式碼同樣的makefile,在用原始碼編譯的方法是完全可行的。

所以,強烈採用原始碼編譯而不是SDK編譯。

2.原始碼編譯軟體安裝包IPK

前邊的教程已經講到怎麼編譯出ipk包了,其實就是那個步驟,下邊講講怎麼寫自己package,下邊以helloworld為例:

先建立自己的包目錄,以及外層makefile:

mkdir helloworld

cd helloworld

mkdir src

vi makefile

然後在這個makefile裡邊填寫如下內容,(內容可以參考官網的說明)

include $(TOPDIR)/rules.mk

# Name and release number of this package

PKG_NAME:=helloworld

PKG_RELEASE:
=1 PKG_BUILD_DIR := $(BUILD_DIR)/$(PKG_NAME) include $(INCLUDE_DIR)/package.mk define Package/helloworld SECTION:=utils CATEGORY:=Utilities TITLE:=helloworld -- prints a snarky message endef # Uncomment portion below for Kamikaze and delete DESCRIPTION variable above define Package
/helloworld/description It is Duval`s demo. endef define Build/Prepare mkdir -p $(PKG_BUILD_DIR) $(CP) ./src/* $(PKG_BUILD_DIR)/ endef #define Build/Compile # $(MAKE) -C $(PKG_BUILD_DIR) \ # $(TARGET_CONFIGURE_OPTS) CFLAGS="$(TARGET_CFLAGS) -I$(LINUX_DIR)/include" #endef define Package/helloworld/install $(INSTALL_DIR) $(1)/bin $(INSTALL_BIN) $(PKG_BUILD_DIR)/helloworld $(1)/bin/ endef $(eval $(call BuildPackage,helloworld))

然後 進入src,去編寫helloworld.C

cd src
vi helloworld.c

helloworld.c 裡邊填寫

#include<stdio.h>
    
int main(void)
    
{

    printf("yyyy\n");

    return 0;

}

為helloworld.c編寫makefile

vi makefile

makefile 裡邊填寫

# build helloworld executable when user executes "make"  

    
helloworld: helloworld.o  


    $(CC) $(LDFLAGS) helloworld.o -o helloworld  

    
helloworld.o: helloworld.c  

    $(CC) $(CFLAGS) -c helloworld.c  

# remove object files and executable when user executes "make clean"  

clean:  

    rm *.o helloworld  

 

然後把 這個helloworld的package包拷貝到原始碼的./package目錄下邊。

然後執行

make defconfig

make menuconfig

然後在 menuconfig的選單中找到helloworld,具體是選單那裡,就看你外層makefile怎麼寫的。然後找到後在前邊勾選M ,表示僅編譯不固化到韌體中。

然後執行編譯

make -j1 V=s

最後在bin目錄下可以找到自己要的ipk包。