Chinaunix首页 | 论坛 | 博客
  • 博客访问: 891264
  • 博文数量: 286
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 1841
  • 用 户 组: 普通用户
  • 注册时间: 2015-05-09 16:26
文章分类

全部博文(286)

文章存档

2016年(38)

2015年(248)

我的朋友

分类: LINUX

2015-07-06 20:38:32


点击(此处)折叠或打开

  1. Openwrt编译helloworld

  2. -----------------by sheepbao

  3. helloworld文件位置放在/openwrt/trunk/package/utils


  4. #-----------------------------------------------------------------------------------------------------------------------

  5. ##############################################

  6. # OpenWrt Makefile for HelloWorld program

  7. #

  8. #

  9. # Most of the variables used here are defined in

  10. # the include directives below. We just need to

  11. # specify a basic description of the package,

  12. # where to build our program, where to find

  13. # the source files, and where to install the

  14. # compiled program on the router.

  15. #

  16. # Be very careful of spacing in this file.

  17. # Indents should be tabs, not spaces, and

  18. # there should be no trailing whitespace in

  19. # lines that are not commented.

  20. #

  21. ##############################################

  22. include $(TOPDIR)/rules.mk

  23. # Name and release number of this package

  24. PKG_NAME:=helloworld

  25. PKG_RELEASE:=1

  26.  

  27. # This specifies the directory where we're going to build the program.

  28. # The root build directory, $(BUILD_DIR), is by default the build_mipsel

  29. # directory in your OpenWrt SDK directory

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

  31.  

  32. include $(INCLUDE_DIR)/package.mk

  33.  

  34. # Specify package information for this program.

  35. # The variables defined here should be self explanatory.

  36. # If you are running Kamikaze, delete the DESCRIPTION

  37. # variable below and uncomment the Kamikaze define

  38. # directive for the description below

  39. define Package/helloworld

  40.          SECTION:=utils

  41.          CATEGORY:=Utilities

  42.          TITLE:=helloworld -- prints a snarky message

  43. endef

  44.  

  45. # Uncomment portion below for Kamikaze and delete DESCRIPTION variable above

  46. define Package/helloworld/description

  47.          If you can't figure out what this program does, you're probably brain-dead and need immediate medical attention.

  48. endef

  49.  

  50. # Specify what needs to be done to prepare for building the package.

  51. # In our case, we need to copy the source files to the build directory.

  52. # This is NOT the default. The default uses the PKG_SOURCE_URL and the

  53. # PKG_SOURCE which is not defined here to download the source from the web.

  54. # In order to just build a simple program that we have just written, it is

  55. # much easier to do it this way.

  56. define Build/Prepare

  57.          mkdir -p $(PKG_BUILD_DIR)

  58.          $(CP) ./src/* $(PKG_BUILD_DIR)/

  59. endef

  60.  

  61. # We do not need to define Build/Configure or Build/Compile directives

  62. # The defaults are appropriate for compiling a simple program such as this one

  63. # Specify where and how to install the program. Since we only have one file,

  64. # the helloworld executable, install it by copying it to the /bin directory on

  65. # the router. The $(1) variable represents the root directory on the router running

  66. # OpenWrt. The $(INSTALL_DIR) variable contains a command to prepare the install

  67. # directory if it does not already exist. Likewise $(INSTALL_BIN) contains the

  68. # command to copy the binary file from its current location (in our case the build

  69. # directory) to the install directory.

  70. define Package/helloworld/install

  71.          $(INSTALL_DIR) $(1)/bin

  72.          $(INSTALL_BIN) $(PKG_BUILD_DIR)/helloworld $(1)/bin/

  73. endef

  74.  

  75. # This line executes the necessary commands to compile our program.

  76. # The above define directives specify all the information needed, but this

  77. # line calls BuildPackage which in turn actually uses this information to

  78. # build a package.

  79. $(eval $(call BuildPackage,helloworld))

  80. #-----------------------------------------------------------------------------------------------------------------------

  81. Src文件夹Makefile的内容:

  82. #-----------------------------------------------------------------------------------------------------------------------

  83. helloworld: helloworld.o

  84.          $(CC) $(LDFLAGS) helloworld.o -o helloworld

  85. helloworld.o: helloworld.c

  86.          $(CC) $(CFLAGS) -c helloworld.c

  87. #-----------------------------------------------------------------------------------------------------------------------

  88. Helloworld.c的内容:

  89. #-----------------------------------------------------------------------------------------------------------------------

  90. #include

  91. #include

  92. int main(void)

  93. {

  94.          printf("hello world\r\n");

  95.          return 0;

  96. }

  97. #-----------------------------------------------------------------------------------------------------------------------

  98. 接着make menuconfig

  99. menuconfig.jpg

  100. menuconfig2.jpg

  101. menuconfig3.jpg


  102. 退出make menuconfig 执行:make V=99

  103. 可看到生成ipk

  104. ipk1.jpg

  105. 生成的ipk文件在:bin/x86/package/

  106. ipk2.jpg


阅读(2994) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~