編譯編寫簡易ipk程式

2021-07-24 02:38:55 字數 3013 閱讀 6572

[隱藏] 

配置編譯openwrt

...

make menuconfig

make v=s

...

成功編譯openwrt

成功編譯後,發現此檔案

/bin/ramips/openwrt-sdk-ramips-for-linux-x86_64-gcc-4.6-linaro_uclibc-0.9.33.2.tar.bz2
然後解壓這個檔案

tar xvf openwrt-sdk-ramips-for-linux-x86_64-gcc-4.6-linaro_uclibc-0.9.33.2.tar.bz2
進入上面解壓的sdk,會看見乙個package,在下新建兩個目錄

mkdir -p helloworld/src
在目錄src下新建 helloworld.c:

#include#include int main(void)  

然後在此目錄下建立makefile(注意makefile的語法)

helloworld: helloworld.o  

$(cc) $(ldflags) helloworld.o -o helloworld

helloworld.o: helloworld.c

$(cc) $(cflags) -c helloworld.c

clean:

rm *.o helloworld

然後返回上層目錄,即helloworld目錄,在此目錄下建立乙個makefile

##############################################

#openwrt的helloworld程式檔案##

#大多數這裡使用的變數的定義

#將包括以下指令。我們只需要

#指定包的基本描述,

#在**建立我們的計畫,在**可以找到

#原始檔,並在**安裝

#編譯的程式在路由器上。

##要非常小心間距在這個檔案中。

#縮排應該是製表符,而不是空格,

#沒有結尾的空格。

##############################################

include $(topdir)/rules.mk

#名字和版本

pkg_name:=helloworld

pkg_release:=1

#這裡指定的地方,我們要構建的程式的目錄。

#建立根目錄是$(build_dir),預設情況下是build_mipsel

#在openwrt的sdk目錄下

pkg_build_dir := $(build_dir)/$(pkg_name)

include $(include_dir)/package.mk

#指定該程式包的資訊。

#這裡定義的變數應該解釋自己的作用。

#如果你執行的是kamikaze,刪除描述下面變數並取消了kamikaze定義,

#指令進行以下的說明

define package/helloworld

section:=utils

category:=utilities

title:=helloworld -- prints a snarky message

endef

#取消下面的kamikaze部分,並刪除上面的描述

define package/helloworld/description

if you can't figure out what this program does, you're probably

brain-dead and need immediate medical attention.

endef

#指定哪些需要做,為構建軟體包做好準備。

#在我們的例子中,我們需要將原始檔複製到構建目錄。

#這不是預設設定。在預設情況下使用pkg_source_url

define build/prepare

mkdir -p $(pkg_build_dir)

$(cp) ./src/* $(pkg_build_dir)/

endef

#我們並不需要定義構建/配置或編譯/編譯指令

#預設值是合適的編譯乙個簡單的程式,像這樣的

#指定在何處以及如何安裝該程式。因為我們只有乙個檔案,

#將helloworld可執行檔案,通過它複製到/bin目錄安裝到

#路由器。$(1)變數表示在路由器執行的目錄

#openwrt.$(install_dir)變數包含乙個命令來準備安裝

#目錄,如果它不存在。同樣$(install_bin)包含

#命令將二進位制檔案從當前位置複製(在我們的案例中構建

#的目錄)安裝目錄

define package/helloworld/install

$(install_dir) $(1)/bin

$(install_bin) $(pkg_build_dir)/helloworld $(1)/bin/

endef

#這一行執行必要的命令來編譯我們的程式。

#以上定義指令指定所有需要的資訊,但是這

#行呼叫buildpackage從而實際上使用該資訊來

#建立乙個軟體包。

$(eval $(call buildpackage,helloworld))

然後回到openwrt-sdk-ramips-for-linux-x86_64-gcc-4.6-linaro_uclibc-0.9.33.2目錄,執行

make
編譯過程會在build_dir目錄下完成

make[1] world

make[2] package/compile

make[3] -c package/helloworld compile

make[2] package/index

說明編譯成功 編譯好的檔案放置在bin/[yourtarget]/package目錄下。

自新增LUCI選單及編譯為ipk

目錄 新增漢化編譯為ipk配置檔案入口函式介面檔案makefile 新增新增自己的luci介面,有3個必要的要素 它們的作用關係是 b文件是讓c文件在luci的選單中顯示出來,c文件是內容和指令碼,a文件是c文件定義的變數,一切的主體是c文件。漢化修改 usr lib lua luci contro...

flask框架 簡易編寫

flaks框架 先導報 from flask import flask 重定向模組 redirect url for是簡易定址跳轉 jsonify強轉為json格式 指定fkask路由器,指定 和控制器 使用重定向模組來進行跳轉 使用url for方法來實現建議的站內跳轉,引數指定路由方法名稱 使用...

用Mac終端編寫 編譯C程式

步驟 建立c檔案 用vim編寫c程式 編譯c程式檔案 執行編譯後生成的.out檔案。touch hello.c 建立乙個hello.c檔案 本目錄下 vim hello.c 用vim編輯hello.c檔案 輸入 i 開啟vim後先輸入i進入編輯狀態 以下為vim中輸入的程式 int main esc...