c
OPENWRT学习笔记
1.最好使用16版本以下的ubuntn,好像说是18.4不支持
2.获取到源码后 将dl文件包放到源码目录顶层,编译的过程会出很多问题,将有问题的文件替换
**可能会面临另一个问题:**
cat: openwrt-sdk/build_dir/target-mipsel_24kec+dsp_uClibc-0.9.33.2/linux-ramips_mt7628/base-files/ipkg-ramips_24kec/base-files/etc/sdk.version
/home/user/openwrt-sdk/bin/ramips/packages/base/base-files_156-unknown_ramips_24kec.ipk
就是缺少几个sdk.version的文件。没有怎么办?
\#vi (路径)/sdk.version
内容就写V1.0.0,保存退出!
3.我们自己要加程序的话,需要openwrt-sdk/package 文件夹下,可创建一个文件夹如:helloworld
在里添加Makefile 和 src ,src中是.c 文件和Makefile编译文件
以下是顶层Makefile文件
c
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
If you can't figure out what this program does, you're probably
brain-dead and need immediate medical attention.
endef
define Build/Prepare
mkdir -p $(PKG_BUILD_DIR)
$(CP) ./src/* $(PKG_BUILD_DIR)/ #这句意思是将当前文件下的src文件夹拷贝到PKG_BUILD_DIR
$(CP) ./bin/ $(PKG_BUILD_DIR)/ #这句意思是将当前文件下的bin文件夹拷贝到PKG_BUILD_DIR
endef
define Build/Configure
endef
define Build/Compile
$(MAKE) -C $(PKG_BUILD_DIR) \
CC="$(TARGET_CC)" \
CFLAGS="$(TARGET_CFLAGS) -Wall" \
LDFLAGS="$(TARGET_LDFLAGS)"
endef
define Package/helloworld/install
$(INSTALL_DIR) $(1)/bin #$(1)/bin指网关文件夹
$(INSTALL_BIN) $(PKG_BUILD_DIR)/helloworld $(1)/bin/
$(INSTALL_DIR) $(1)/bin
$(CP) $(PKG_BUILD_DIR)/bin/* $(1)/bin/
endef
$(eval $(call BuildPackage,helloworld))
在make menuconfig 在Utilities下找到helloworld目录勾选即可编译进固件中,如果想单独编译 可以使用
- sudo make package/myapp_test/compile -j1 V=s
openwrt编译时 提示固件太大编译不出
