[转]openwrt makefile

原创 2012年03月24日 17:35:52

原文地址:http://hi.baidu.com/haojiubujianru/blog/item/c5e562ac9afbd2db7dd92a71.html

其他参考:如何在OpenWRT环境下做开发

http://hi.baidu.com/gouoooo/blog/item/24bd512f5c3b83474fc226ec.html?timeStamp=1304643450250

http://hi.baidu.com/gouoooo/blog/item/a17595c5d1e752bc8326ac41.html


echo "this is my string string" | sed "s/string/broing/" 显示的是this is my broing string

echo "this is my string string" | sed "s/string/broing/g" 显示的是this is my broing broing

"s/A/B/"表示用B代替A,+了g表示在sed的内存表中追加替换。

 

Makefile中的自动化变量:

    $@ : 表示目标文件

    $^ : 表示所有依赖文件(去除重复) $+ 与之类似(包括重复)

    $< : 表示依赖文件列表中第一个依赖文件

    $? : 表示比目标文件更新的所有依赖文件

    $* : 表示“茎”,即出后缀以外的字符串。例如“dir/a.foo.b”表示为“%a.%.b”则 $* 表示“dir/a.foo”

 

busybox在openwrt中是一个特殊的包,其中可以包含大量Linux的常用命令,也可自己添加命令,但是它却很小。因为他用的是代码复用这一思想,充分利用系统原有的代码库以实现各种命令。在单独的busybox中添加自己的小程序已经可以做到了,但是再把添加了程序的busybox编译进openwrt中遇到了些苦难,明天继续努力。

 

在openwrt中添加自己的package。步骤是在package文件夹下建立一个文件夹,在文件夹中新建一个src文件夹用以存放你package的源代码还有相应规定如何编译的Makefile文件,src文件夹外可以添加一些配置文件和patch,但是必须有一个Makefile文件用以把你的package链接到openwrt中,保证在编译时.config文件中有此package的注册也就是在make menuconfig是配置界面中有你新加的package。最后就是在配置界面中把你的package选中。最后make。

而最重要的就是编写你package目录下的Makefile文件,一下是openwrt论坛上的一个例子:

###############################################################################################

As an example, this package was created for some C++ wrapper classes around C socket calls. The source code is available here. It contains the “normal” makefile within it. These are the steps which were carried out :

1. Write the OpenWRT makefile : This is a special makefile which OpenWRT uses. The Makefile is listed and explained at the end of this post. Understanding how to write this makefile is the key to building packages on OpenWRT.

2. Copy this makefile in the appropriate folder : This should be package/<packageName>/Makefile within your buildroot system.

3. make menuconfig : Once the makefile has been placed in the appropriate directory, calling make menuconfig in the buildroot system should show the package in the appropriate section. The package should be selected.

4. make package/<package name>-compile V=99 : This does two things — downloads your package from the URL you specified and compiles the package as well. By default the compilation is done as per the “normal” makefile. You should be able to see the package source code in the dl folder and the compiled images in build_i386/<package-name>.

5. make package/<package name>-install V=99 : This should create the appropriate ipkg package in /bin/packages. Now you can go ahead and port the ipkg to your wrap board and install it using ipkg install <package name>

 

# This is free software, licensed under the GNU General Public License v2.

# See /LICENSE for more information.

#

# $Id$

include $(TOPDIR)/rules.mk

#These lines concatanate the package name and list the URL location from which the package source code is to be downloaded

PKG_NAME:=commonclasses

PKG_VERSION:=0.1

PKG_RELEASE:=1

PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz

PKG_SOURCE_URL:=http://www.cs.uh.edu/~vivekian/downloads/

#md5 can be computed using the md5sum utility available on linux

PKG_MD5SUM:=6607524493ff74de82cc114e32674d40

PKG_CAT:=zcat

PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)-$(PKG_VERSION)

include $(INCLUDE_DIR)/package.mk

#These lines describe what your package does and its place in the menu config

define Package/commonclasses

SECTION:=net

CATEGORY:=Network

TITLE:=CommonClasses is a group of classes which are C++ wrappers around C socket functions

DESCRIPTION:=\

You can use this in your C++ code \\\

It will make your life easier \\\

It will save you time !

URL:=http://www.cs.uh.edu/~vivekian

endef

#For the compile rules you need to specify the cross compiler which needs to be used :

 

define Build/Compile

$(MAKE) -C $(PKG_BUILD_DIR) \

CXX="$(TARGET_CROSS)g++"

endef

 

#These lines describe where your binary images are to be installed – its the equivalent to make install

# This particular package is a library and the installation rules reflect it

define Package/commonclasses/install

$(INSTALL_DIR) $(1)/usr/lib

$(INSTALL_DIR) $(1)/usr/include

$(INSTALL_BIN) $(PKG_BUILD_DIR)/libcppsocket.so $(1)/usr/lib/

$(INSTALL_DATA) $(PKG_BUILD_DIR)/SockException.h $(1)/usr/include/

$(INSTALL_DATA) $(PKG_BUILD_DIR)/Socket.h $(1)/usr/include/

$(INSTALL_DATA) $(PKG_BUILD_DIR)/SocketReaderWriter.h $(1)/usr/include/

$(INSTALL_DATA) $(PKG_BUILD_DIR)/TcpSocket.h $(1)/usr/include/

$(INSTALL_DATA) $(PKG_BUILD_DIR)/UdpSocket.h $(1)/usr/include/

endef

$(eval $(call BuildPackage,commonclasses))

############################################################################################


版权声明:本文为博主原创文章,未经博主允许不得转载。

相关文章推荐

OpenWrt的主Makefile工作过程-转

本文是对OpenWrt的Makefile的理解,转载来自恩山。 OpenWrt的主Makefile工作过程 http://www.right.com.cn/forum/thread-73443...
  • xp5xp6
  • xp5xp6
  • 2016年01月17日 12:52
  • 111

Makefile-openwrt

http://my.oschina.net/hevakelcj/blog/417448#OSC_h2_3 前言 在之前的博文里详细地讲述了如何在OpenWrt下建立一个软件包(pa...

openwrt Makefile 理解

本篇的主要目的是想通过分析Makefile,了解openwrt编译过程。着重关注以下几点: openwrt目录结构 主Makefile的解析过程,各子目录的目标生成。 kernel编译过程 ...

OpenWRT开发之——研究包的Makefile

本文将带大家一起深入地学习一下OpenWrt包的 Makefile。我们不仅要知其然,还要知其所以然。 在上篇博文里,包里的 Makefile 内容如下: ? 1 2 ...

OpenWRT添加模块Makefile

第一次接触到openwrt,真是被毁三观啊,不要说makefile,连源代码在哪里都找不到,知道嵌入式系统水深,没想到迈出第一步就没过了脖子。好在旁边有人指点,直接在芯片厂商提供的既有代码上做二次开发...

openwrt简单ipk生成及Makefile解释

1.创建helloworld项目 首先我们新建helloworld.c文件和对应的Makefile文件   $mkdir -p ~/temp/hellworld/src $cd ~/tem...

OpenWrt SDK 编写交叉编译Makefile的简单方法

如果你在浏览github的时候发现一个很好的Linux c语言程序,在桌面平台编译一下发现很好用,这时你想把它移植到OpenWrt平台上放到路由器上使用,那么要是能把它编译成ipk文件直接安装到路由器...

OpenWrt集成非官方包之Makefile规则

原文地址:http://www.right.com.cn/forum/thread-48530-1-1.html 其他可参考:http://www.asxzy.net/?p=228 最近看到有...

OpenWrt Makefile 整体分析

分析版本: svn://svn.openwrt.org.cn/openwrt/branches/backfire OpenWrt基本结构 –target/Linux/ 目录里面是各平台(arc...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:[转]openwrt makefile
举报原因:
原因补充:

(最多只允许输入30个字)