CaryStudio

 找回密码
 立即注册
搜索
查看: 1797|回复: 0

OpenWrt编译并添加自己写的应用-基于MT7620a

[复制链接]
发表于 2017-11-18 15:33:51 | 显示全部楼层 |阅读模式

请先登录

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
  • 创建应用所需的目录
    在trunk/package/ramips/applications/创建helloworld目录
    (也可以在trunk/package/目录下创建helloworld目录)
  • 目录内的文件结构

                                   
    登录/注册后可看大图
  • 其中最外层Makefile的内容

  1. ##############################################
  2. # OpenWrt Makefile for helloworld program
  3. #
  4. #
  5. # Most of the variables used here are defined in
  6. # the include directives below. We just need to
  7. # specify a basic description of the package,
  8. # where to build our program, where to find
  9. # the source files, and where to install the
  10. # compiled program on the router.
  11. #
  12. # Be very careful of spacing in this file.
  13. # Indents should be tabs, not spaces, and
  14. # there should be no trailing whitespace in
  15. # lines that are not commented.
  16. #
  17. ##############################################
  18. include $(TOPDIR)/rules.mk

  19. # Name and release number of this package
  20. PKG_NAME:=helloworld
  21. PKG_RELEASE:=1

  22. # This specifies the directory where we're going to build the program.
  23. # The root build directory, $(BUILD_DIR), is by default the build_mipsel
  24. # directory in your OpenWrt SDK directory

  25. PKG_BUILD_DIR := $(BUILD_DIR)/$(PKG_NAME)

  26. include $(INCLUDE_DIR)/package.mk

  27. # Specify package information for this program.
  28. # The variables defined here should be self explanatory.
  29. # If you are running Kamikaze, delete the DESCRIPTION
  30. # variable below and uncomment the Kamikaze define
  31. # directive for the description below
  32. define Package/helloworld
  33.     SECTION:=utils
  34.     CATEGORY:=Utilities
  35.     TITLE:=Helloworld -- prints a snarky message
  36. endef
  37. # Uncomment portion below for Kamikaze and delete DESCRIPTION variable above
  38. define Package/helloworld/description
  39.     If you can't figure out what this program does, you're probably
  40.     brain-dead and need immediate medical attention.
  41. endef
  42. # Specify what needs to be done to prepare for building the package.
  43. # In our case, we need to copy the source files to the build directory.
  44. # This is NOT the default.  The default uses the PKG_SOURCE_URL and the
  45. # PKG_SOURCE which is not defined here to download the source from the web.
  46. # In order to just build a simple program that we have just written, it is
  47. # much easier to do it this way.
  48. define Build/Prepare
  49.     mkdir -p $(PKG_BUILD_DIR)
  50.     $(CP) ./src/* $(PKG_BUILD_DIR)/
  51. endef

  52. define Build/Configure
  53. endef


  54. define Build/Compile
  55.     $(MAKE) -C $(PKG_BUILD_DIR) \
  56.         CC="$(TARGET_CC)" \
  57.         CFLAGS="$(TARGET_CFLAGS) -Wall" \
  58.         LDFLAGS="$(TARGET_LDFLAGS)"
  59. endef
  60. # We do not need to define Build/Configure or Build/Compile directives
  61. # The defaults are appropriate for compiling a simple program such as this one
  62. # Specify where and how to install the program. Since we only have one file,
  63. # the helloworld executable, install it by copying it to the /bin directory on
  64. # the router. The $(1) variable represents the root directory on the router running
  65. # OpenWrt. The $(INSTALL_DIR) variable contains a command to prepare the install
  66. # directory if it does not already exist.  Likewise $(INSTALL_BIN) contains the
  67. # command to copy the binary file from its current location (in our case the build
  68. # directory) to the install directory.
  69. define Package/helloworld/install
  70.     $(INSTALL_DIR) $(1)/bin
  71.     $(INSTALL_BIN) $(PKG_BUILD_DIR)/helloworld $(1)/bin/
  72. endef
  73. # This line executes the necessary commands to compile our program.
  74. # The above define directives specify all the information needed, but this
  75. # line calls BuildPackage which in turn actually uses this information to
  76. # build a package.
  77. $(eval $(call BuildPackage,helloworld))
复制代码


  • 列表内容
src文件夹下的Makefile内容
  1. helloworld: helloworld.o
  2.     $(CC) $(LDFLAGS) helloworld.o -o helloworld
  3. helloworld.o: helloworld.c
  4.     $(CC) $(CFLAGS) -c helloworld.c
  5. clean:
  6.     rm *.o helloworld
复制代码

  • 应用程序helloworld的代码
  1. /* ************************************************************************
  2. *       Filename:  helloworld.c
  3. *    Description:  
  4. *        Version:  1.0
  5. *        Created:  2016年01月22日 15时25分05秒
  6. *       Revision:  none
  7. *       Compiler:  gcc
  8. *         Author:  YOUR NAME (),
  9. *        Company:  
  10. * ************************************************************************/


  11. #include <stdio.h>

  12. int main(int argc, char *argv[])
  13. {
  14.     printf("Hello, world!\n");

  15.     return 0;
  16. }
复制代码


回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|CaryStudio ( 粤ICP备16022806号 )

GMT+8, 2023-6-8 10:47 , Processed in 0.087121 second(s), 12 queries .

Powered by Discuz! X3.4

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表