小白求教,关于openwrt的Makefile makefile怎么编译ipk

\u5c0f\u767d\u6c42\u6559\uff0c\u5173\u4e8eopenwrt\u7684Makefile

\u770b\u5230openwrt\u76ee\u5f55\u4e0b\u7684\uff0cMakefile\uff0c\u4f1a\u5305\u542binclude/toplevel.mk \u5728\u6b64toplevel.mk\u4e2d\uff0c\u67093\u4e2amake\u6307\u4ee4\uff1a SUBMAKE\uff0c\u5219\u5728\u5f53\u524d\u76ee\u5f55\u4e0bmake NO_TRACE_MAKE\uff0c\u4f1a\u8fd4\u56de\u4e3b\u76ee\u5f55\u4e0b\u7684Makefile\u53bbmake MAKE\uff0c\u4f3c\u4e4e\u4e5f\u662f\u5728\u5f53\u524d\u76ee\u5f55\u4e0bmake~

\u5047\u8bbe\u6709\u4e0b\u9762\u51e0\u4e2ac++\u6587\u4ef6\uff1a wherewhen.h wherewhen.c countdown.h countdown.c \u5305\u542b\u4e86math.h\uff0c \u9700\u8981\u8fde\u63a5\u5e93\u6587\u4ef6 main.c \u4e3b\u51fd\u6570\uff0c main.c \u5305\u542b\u4e86\u4e24\u4e2a\u5934\u6587\u4ef6 wherewhen.h and countdown.h 1\u3001\u7b2c\u4e00\u79cd\u7f16\u8bd1\u65b9\u6cd5\uff1a g++ -Wall -g wherewhen.c countdown.

  1、搭建开发环境
首先,在执行make menuconfig后,

  其中,图中红框部分是我定制路由器的系统版本,大家可以根据不同的路由器进行不同的选择;绿框部分表示我们需要编译一个SDK开发环境(默认情况下,此项未勾选)。
  编译过程中需要通过官网下载很多相关的软件包,所以必须保证能够顺利连上外网。由于下载速度的限制,编译过程大概需要数小时。编译结束后,所有的产品都会放在编译根目录下的bin/yourtarget/. 例如:我所编译的产物都放在./bin/brcm47xx/下,其中文件主要有几类:
  (1).bin/.trx 文件: 这些都是在我们所选的target-system的类别之下,针对不同路由器型号、版本编译的路由器固件。这些不同路由器的型号和版本是openwrt预先设置好的,我们不需要更改。至于.bin和.trx的区别,一种说法是,第一次刷路由器的时候,需要用.bin文件,如果需要再升级,则不能再使用.bin文件,而需要用.trx文件。原因是,.bin是将路由器的相关配置信息和.trx封装在一起而生成的封包,也就是说是包含路由器版本信息的.trx。在第一次刷固件的时候,我们需要提供这样的信息,而在后续升级时,则不再需要,用.trx文件即可。
  (2)packages文件夹: 里面包含了我们在配置文件里设定的所有编译好的软件包。默认情况下,会有默认选择的软件包。
  (3)OpenWrt-SDK.**.tar.bz2: 这个也就是我们定制编译好的OpenWRT SDK环境。我们将用这个来进行OpenWrt软件包的开发。例如,我所编译好的SDK环境包为:/bin/brcm47xx/OpenWrt-SDK-brcm47xx-for-Linux-x86_64-gcc-4.3.3+cs_uClibc-0.9.30.1.tar.bz2
可以从名称上看出,target system是brcm47xx,host system是Linux-x86_64,使用的编译工具以及库是4.3.3+cs_uClibc-0.9.30.1。
  (4)md5sums 文件: 这个文件记录了所有我们编译好的文件的MD5值,来保证文件的完整性。因为文件的不完整,很容易将路由器变成“砖头”。
  需要主要的是,编译完成后,一定要将编译好的bin目录进行备份(如果里面东西对你很重要的话),因为在下次编译之前,执行make clean 会将bin目录下的所有文件给清除掉!!
  2、 更改原有packages
  在编译根目录下会有一个dl的目录,这个目录其实是“download”的简写,在编译前期,需要从网络下载的数据包都会放在这个目录下,这些软件包的一个特点就是,会自动安装在所编译的固件中,也就是我们make menuconfig的时候,为固件配置的一些软件包。如果我们需要更改这些源码包,只需要将更改好的源码包打包成相同的名字放在这个目录下,然后开始编译即可。编译时,会将软件包解压到build_dir目录下。
当然,你也可以自己在dl里面创建自己的软件包,然后更改相关的配置文件,让openwrt可以识别这个文件包。
  由于我的项目更改的内容是底层的,需要跟固件一起安装。所以,我使用的方法就是直接更改dl目录下软件包,然后重新进行固件编译。感觉类似于Linux的内核编译。反复编过十多次,没有任何问题。
  3、 新建自己的packages
对于自己新建的package,而这个package又不需要随固件一起安装,换句话说,就是可以当做一个可选软件包的话。我们可以利用我们的SDK环境来单独编译,编译后会生成一个ipk的文件包。然后利用 opkg install xxx.ipk 来安装这个软件。
  下面具体说下,如何编译一个helloword的软件包。
(1)首先,编写helloworld程序
编写helloworld.c
/****************
* Helloworld.c
* The most simplistic C program ever written.
* An epileptic monkey on crack could write this code.
*****************/
  #include <stdio.h>
#include <unistd.h>
int main(void)
{
printf("Hell! O' world, why won't my code compile?\n\n");
return 0;
}
  编写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
在这两个文件的目录下,执行make 应该可以生成helloworld的可执行文件。执行helloworld后,能够打印出“Hell! O' world, why won't my code compile?”。 这一步,主要保证我们的源程序是可以正常编译的。下面我们将其移植到OpenWRT上。
  (2)将OpenWrt-SDK-brcm47xx-for-Linux-x86_64-gcc-4.3.3+cs_uClibc-0.9.30.1.tar.bz2解压
tar –xvf OpenWrt-SDK-brcm47xx-for-Linux-x86_64-gcc-4.3.3+cs_uClibc-0.9.30.1.tar.bz2
  (3)进入SDK
cd OpenWrt-SDK-brcm47xx-for-Linux-x86_64-gcc-4.3.3+cs_uClibc-0.9.30.1
可以看到里面的目录结构跟我们之前source的目录结构基本相同,所需要编译的软件包,需要放置在package目录下
  (4)在package目录下创建helloworld目录
cd package
mkdir helloworld
cd helloworld
  (5)创建src目录,拷贝 helloworld文件
mkdir src
cp /home/wrt/test/helloworld.c src
cp /home/wrt/test/Makefile src
  (6)在helloworld目录下创建Makefile文件
这个Makefile文件是给OpenWRT读的,而之前写的那个Makefile文件是针对helloworld给编译其读的。两个Makefile不在同一层目录下。
  touch Makefile
vim Makefile
  Makefile文件模板内容如下:
##############################################
# OpenWrt Makefile for helloworld program
#
#
# Most of the variables used here are defined in
# the include directives below. We just need to
# specify a basic description of the package,
# where to build our program, where to find
# the source files, and where to install the
# compiled program on the router.
#
# Be very careful of spacing in this file.
# Indents should be tabs, not spaces, and
# there should be no trailing whitespace in
# lines that are not commented.
#
##############################################
  include $(TOPDIR)/rules.mk
  # Name and release number of this package
PKG_NAME:=helloworld
PKG_RELEASE:=1
  # This specifies the directory where we're going to build the program.
# The root build directory, $(BUILD_DIR), is by default the build_mipsel
# directory in your OpenWrt SDK directory
PKG_BUILD_DIR := $(BUILD_DIR)/$(PKG_NAME)
  include $(INCLUDE_DIR)/package.mk
  # Specify package information for this program.
# The variables defined here should be self explanatory.
# If you are running Kamikaze, delete the DESCRIPTION
# variable below and uncomment the Kamikaze define
# directive for the description below
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
If you can't figure out what this program does, you're probably
brain-dead and need immediate medical attention.
endef
  # Specify what needs to be done to prepare for building the package.
# In our case, we need to copy the source files to the build directory.
# This is NOT the default. The default uses the PKG_SOURCE_URL and the
# PKG_SOURCE which is not defined here to download the source from the web.
# In order to just build a simple program that we have just written, it is
# much easier to do it this way.
define Build/Prepare
mkdir -p $(PKG_BUILD_DIR)
$(CP) ./src/* $(PKG_BUILD_DIR)/
endef
  # We do not need to define Build/Configure or Build/Compile directives
# The defaults are appropriate for compiling a simple program such as this one
  # Specify where and how to install the program. Since we only have one file,
# the helloworld executable, install it by copying it to the /bin directory on
# the router. The $(1) variable represents the root directory on the router running
# OpenWrt. The $(INSTALL_DIR) variable contains a command to prepare the install
# directory if it does not already exist. Likewise $(INSTALL_BIN) contains the
# command to copy the binary file from its current location (in our case the build
# directory) to the install directory.
define Package/helloworld/install
$(INSTALL_DIR) $(1)/bin
$(INSTALL_BIN) $(PKG_BUILD_DIR)/helloworld $(1)/bin/
endef
  # This line executes the necessary commands to compile our program.
# The above define directives specify all the information needed, but this
# line calls BuildPackage which in turn actually uses this information to
# build a package.
$(eval $(call BuildPackage,helloworld))
  (7)返回到SDK的根目录
执行make进行编译
编译过程会在build_dir目录下完成
编译结果会放在 bin/[yourtarget]/package目录下helloworld_1_bcm47xx.ipk
  (8)上传helloworld_1_bcm47xx.ipk
使用sftp软件上传helloworld_1_bcm47xx.ipk至路由器
执行 opkg install helloworld_1_bcm47xx.ipk
输入hello然后按Tab键,发现openwrt中已经有helloworld可执行命令。
执行 helloworld 查看程序的效果。

  • 灏忕櫧姹傛暀,鍏充簬openwrt鐨Makefile
    绛旓細(3)OpenWrt-SDK.**.tar.bz2: 杩欎釜涔熷氨鏄垜浠畾鍒剁紪璇戝ソ鐨OpenWRT SDK鐜銆傛垜浠皢鐢ㄨ繖涓潵杩涜OpenWrt杞欢鍖呯殑寮鍙戙備緥濡,鎴戞墍缂栬瘧濂界殑SDK鐜鍖呬负:/bin/brcm47xx/OpenWrt-SDK-brcm47xx-for-Linux-x86_64-gcc-4.3.3+cs_uClibc-0.9.30.1.tar.bz2鍙互浠庡悕绉颁笂鐪嬪嚭,target system鏄痓rcm47xx,host system鏄...
  • openwrt璺敱鍣ㄧ绾夸笅杞芥暀绋
    绛旓細鎸夋櫘閫氳矾鐢辩殑瀹夎杩炴帴濂借兘姝e父杩炵綉鍚庯紝鎺ヤ笂U鐩樻垨绉诲姩纭洏锛屽湪娴忚鍣ㄤ腑杈撳叆浣犳墍璁惧畾鐨勮矾鐢盜P銆傛瘮濡傛垜鐨勮瀹氫负锛192.168.3.1 杩涘叆鍒openwrt鐨鎿嶄綔鍚庡彴銆1    绯荤粺-鎸傝浇鐐广傛煡鐪婾鐩樻垨鏄Щ鍔ㄧ‖鐩樻寕杞芥垚鍔熸病鏈夈傜幇鍦ㄤ竴鑸兘瀹夎濂戒簡鑷姩鎸傝浇銆備富瑕佹槸璁颁綇U鐩樼殑鎸傝浇鐐广傚畨瑁呰繀闆疯繙绋嬪拰鏂囦欢...
  • 鏈夎皝鐭ラ亾鍒鍏充簬OpenWrt鍥轰欢缂栬瘧寮鍙戠殑鍏ラ棬鐨勪功绫嶅湪閭i噷涔 鎴栬呬功鍚嶅彨...
    绛旓細mkdir openwrt 鍒涘缓涓涓猳penwrt鏂囦欢澶 cd openwrt 杩涘叆openwrt鏂囦欢澶 svn co svn://svn.openwrt.org/openwrt/branches/backfire 鎴栬卻vn co svn://svn.openwrt.org/openwrt/trunk涓嬭浇瀹樼綉鐨勬簮鐮 娉細backfire鍜宼runk涓轰袱涓笉鍚屽垎鏀殑openwrt婧愮爜锛宐ackfire鎹杈冧负绋冲畾锛屼絾鏄敮鎸佺殑璺敱鍣ㄦ病鏈塼runk...
  • 鍏充簬鏍″洯缃戝拰openwrt鐨闂 鍝綅澶х浼氬晩 鏁欐暀鎴戝晩 鎴戠殑鏄崕涓篐255D...
    绛旓細1銆佸厛浣跨敤缃戠嚎杩炴帴鐢佃剳涓婄綉锛岃幏鍙朓Pv6鍦板潃鍙婄綉鍏充緥濡2001:250:3000:5b12:7889:f687:bf54:d750/64涓2001:250:3000:5b12::1 2銆佷娇鐢ㄨ缃悜瀵兼垨閫氳繃缃戠粶鎺ュ彛閰嶇疆WAN鍙o紙eth1),鍥哄畾IPV4鍙奍PV6鍦板潃 3銆佸埌鏈嶅姟H3C璁よ瘉涓嬪~鍐欒处鍙峰瘑鐮侊紝绔彛閫夋嫨eth1锛屽苟鍕鹃夊搴旈夐」锛屾渶鍚庝繚瀛&搴旂敤 4銆侀噸鍚矾鐢便
  • 鍒openwrt鏄粈涔堟剰鎬
    绛旓細QQ 41293064 openwrt鍩轰簬linux鍐呮牳鐨勮矾鐢卞櫒鎿嶄綔绯荤粺 锛 鍒蜂簡openwrt鐨璺敱鍣紝鍙互瀹夎mentohust杩欎釜杞欢锛乵entohust鍙互鏇夸唬閿愭嵎鎷ㄥ彿锛屽氨鍙互鍦ㄨ矾鐢卞櫒涓婇潰鎷ㄥ彿锛岀劧鍚庡叡浜笂缃戯紒鍍弔p 941n v4 鐗堟湰灏卞彲浠ュ埛openwrt锛岀劧鍚庡畨瑁呭吋瀹归攼鎹风殑mentohust锛岃繘琛屾嫧鍙凤紝鍏变韩涓婄綉锛
  • openwrt 鐖卞揩灏忕櫧 pandorabox 鍝釜濂
    绛旓細dd鏄openwrt鐨鎵╁睍鏉匡紝鑷韩甯︾殑鍔熻兘姣旇緝澶氫竴鐐广傚К鎻g亴搴熷紤鑲氶鑾庨偗鏋丱penWRT瀹氬埗鑳藉姏姣旇緝寮猴紝鍥犱负鏈韩鏍稿績甯︾殑涓滆タ寰堟牎濡傛灉鏄竴鑸敤鐢紝閭D鍔熻兘澶氫竴鐐广傚鏋滆鐮旂┒宓屽叆寮忕殑寮鍙戯紝閭h繕鏄粠OpenWRT寮濮嬫瘮杈冨ソ
  • 鍒稤D銆乽bnt銆openwrt杩欎笁涓湁浠涔堝尯鍒晩?
    绛旓細閫氫織鐨勮鍚э細ubnt鍦ㄦ帴鏀秝ifi淇″彿鏂归潰鏈変紭鍔匡紝鍙互璁剧疆鍙戝皠鍔熺巼鍜岃窛绂讳互鍙婂ぉ绾跨殑璋冩暣锛岃涔堟帴鏀讹紝瑕佷箞鍙戝皠锛屼笉鑳藉悓鏃惰繘琛岋紝鐢ㄤ簬杩滆窛绂荤粍缃戯紱DD鑳芥帴鏀朵俊鍙风殑鍚屾椂鍐嶅彂灏勪俊鍙凤紝涔熷氨鏄綉缁滄湳璇笂璇寸殑涓户锛屽畠鍙互寤朵几wifi淇″彿鑼冨洿锛汷P鏈塂D鐨勫姛鑳戒互澶栵紝鍙互缂栫▼鏂瑰紡鎺у埗璺敱鍣紝鍙互铏氭嫙澶氱綉鍗℃帴鏀舵垨鍙戝皠淇″彿锛屽姛鑳...
  • 杞矾鐢变繚濮嗙骇鍏ラ棬鏁欑▼ 涓绡囩湅鎳傝蒋璺敱
    绛旓細鑾峰彇鍒扮殑缃戝叧灏辨槸openwrt鐨绠$悊鍚庡彴,鐩存帴娴忚鍣ㄦ墦寮杩欎釜IP鍦板潃灏卞彲浠ャ esir鐨勫浐浠舵槸娌℃湁瀵嗙爜鐨,鐩存帴鐐圭櫥褰曞氨鑳借繘鍏ュ埌杞矾鐢辩鐞嗗悗鍙 杩涘叆鍒扮鐞嗗悗鍙,鐐圭綉缁-鎺ュ彛-WAN(淇敼) 濡傛灉鏄厜鐚嫧鍙,杩欓噷鍗忚榛樿閫夐」涓嶇敤鍔,DHCP瀹㈡埛绔傚鏋滄槸璺敱鍣ㄦ嫧鍙枫佸厜鐚ˉ鎺ユā寮,鍗忚鏀规垚PPPoE銆佺偣鍒囨崲鍗忚,鐒跺悗姝e父濉处鍙峰瘑鐮佹嫧鍙枫
  • openwrt鐨妗ユ帴鎺ュ彛浣滅敤
    绛旓細br-lan 铏氭嫙璁惧锛岀敤浜 LAN 鍙h澶囨ˉ鎺ワ紝鐢ㄦ潵浣垮涓櫄鎷熸垨鐗╃悊缃戠粶鎺ュ彛鐨勮涓哄ソ鍍忎粬浠粎鏈変竴涓綉缁滄帴鍙d竴鏍枫傜洰鍓嶈矾鐢卞櫒鏅亶灏嗘湁绾 LAN 鍙o紙涓鑸洓涓級鍜 WIFI 鏃犵嚎鎺ュ彛妗ユ帴鍦ㄤ竴璧蜂綔涓虹粺涓鐨 LAN銆傚彲浠ヤ娇鐢 brctl show 鏉ユ煡鐪嬩娇鐢ㄦ儏鍐点俥th1 濡傛灉璺敱鍣ㄦ湁涓ゅ潡缃戝崱锛屼竴鑸 eth1 浣滀负 WAN 鍙 wlan0 ...
  • 鏂愯K2P 鑰佹瘺瀛 + 鏂愯N1 openwrt 涓绘梺璺敱璁剧疆灏忚
    绛旓細濡傛灉杩炶矾鐢辩鐞嗗悗鍙颁慨鏀逛簡閮戒笉浼氳繘鐨灏忕櫧鍒帺浜嗭紝娲楁礂鐫″惂銆傚浐浠惰佹瘺瀛愶紝鍏朵粬鍥轰欢鍩烘湰鍚岀悊銆1銆佸唴缃慙AN-DHCP鏈嶅姟鍣細榛樿缃戝叧192.168.2.2锛堝嵆鏃佽矾鐢卞悗鍙板湴鍧锛夈2銆佸唴缃慙AN-DNS鏈嶅姟鍣細192.168.2.2锛堝嵆鏃佽矾鐢卞悗鍙板湴鍧锛夈傚浐浠openwrt ipv4鍦板潃 192.168.2.2 ipv4缃戝叧 192.168.2.1...
  • 扩展阅读:ai智能写作一键生成 ... openwrt路由器 ... 安装openwrt ... 高大全openwrt ... openwrt官网下载中心 ... openwrt开启无线指令 ... ax88179 openwrt ... openwrt最新固件下载 ... 笔记本openwrt ...

    本站交流只代表网友个人观点,与本站立场无关
    欢迎反馈与建议,请联系电邮
    2024© 车视网