您的位置:首页 > 运维架构

[转]openwrt makefile

2012-03-24 17:35 232 查看
原文地址: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))

############################################################################################
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息