[原创] 【OpenWRT】.2 SDK准备和helloworld

le062   2015-10-1 10:30 楼主
同样在openwrt目录下,执行
  1. make menuconfig
勾选bulid the openwrt sdk,退出并保存
  1. make V=s -j2
编译完成后,在bin/ramips下出现一个OpenWrt-SDK-ramips-mt7620_gcc-4.8-linaro_uClibc-0.9.33.2.Linux-x86_64.tar.bz2,这就是我们需要的SDK包 解压SDK,并进入package目录
  1. tar -jxvf OpenWrt-SDK-ramips-mt7620_gcc-4.8-linaro_uClibc-0.9.33.2.Linux-x86_64.tar.bz2
然后建立如下目录树
  1. .
  2. ├── helloworld
  3. │ ├── Makefile
  4. │ └── src
  5. │ ├── helloworld.c
  6. │ └── Makefile
  7. └── Makefile
编写helloworld.c
  1. #include <stdio.h>
  2. #include <unistd.h>
  3. int main(void)
  4. {
  5. printf("Hello World!\n");
  6. return 0;
  7. }
编写src/Makefile
  1. #build a Makefile for hellowrold.c
  2. helloworld: helloworld.o
  3. $(CC) $(LDFLAGS) helloworld.o -o helloworld
  4. helloworld.o: helloworld.c
  5. $(CC) $(CFLAGS) -c helloworld.c
  6. clean:
  7. rm *.o helloworld
编写helloworld/Makefile
  1. include $(TOPDIR)/rules.mk
  2. PKG_NAME:=helloworld
  3. PKG_RELEASE:=1
  4. PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)
  5. include $(INCLUDE_DIR)/package.mk
  6. define Package/helloworld
  7. SECTION:=utils
  8. CATEGORY:=Utilities
  9. TITLE:=Helloworld -- prints a snarky message
  10. endef
  11. define Package/helloworld/description
  12. It's my first package demo.
  13. endef
  14. define Build/Prepare
  15. echo "Here is Package/Prepare"
  16. mkdir -p $(PKG_BUILD_DIR)
  17. $(CP) ./src/* $(PKG_BUILD_DIR)/
  18. endef
  19. define Package/helloworld/install
  20. echo "Here is Package/install"
  21. $(INSTALL_DIR) $(1)/bin
  22. $(INSTALL_BIN) $(PKG_BUILD_DIR)/helloworld $(1)/bin/
  23. endef
  24. $(eval $(call BuildPackage,helloworld))
回到sdk目录,
  1. make V=s
ipk包会放在/bin目录下
  1. └── ramips
  2. └── packages
  3. ├── base
  4. │ ├── helloworld_1_ramips_24kec.ipk
  5. │ ├── Packages
  6. │ └── Packages.gz
  7. ├── luci
  8. │ ├── Packages
  9. │ └── Packages.gz
  10. ├── management
  11. │ ├── Packages
  12. │ └── Packages.gz
  13. ├── packages
  14. │ ├── Packages
  15. │ └── Packages.gz
  16. ├── routing
  17. │ ├── Packages
  18. │ └── Packages.gz
  19. └── telephony
  20. ├── Packages
  21. └── Packages.gz
上newifi测试:
  1. cd tmp/
  2. wget ftp://ll@192.168.1.216/linux_workspace/helloworld_1_ramips_24kec.ipk
  3. opkg install ./helloworld_1_ramips_24kec.ipk
  4. helloworld
Hello World! 本帖最后由 le062 于 2015-10-1 10:40 编辑
要666

回复评论 (1)

论坛的源码粘贴做的不是很好,容易被脚本语言强插,重试了好几次,才显示正确
要666
点赞  2015-10-1 10:42
电子工程世界版权所有 京B2-20211791 京ICP备10001474号-1 京公网安备 11010802033920号
    写回复