自己移植Asterisk1.8到OpenWRT下

来源:互联网 发布:开票软件金税盘版电话 编辑:程序博客网 时间:2024/05/16 10:26

众所周知OpenWRT是目前最流行的嵌入式Linux之一。支持广泛的CPU包括:x86、MIPS、ARM、PPC等。

OpenWRT的trunk中所带的那个asterisk问题很多,缺少很多包,作者似乎仅仅是为了自己使用而移植的,
而目前网上除了不详细的官方资料外也无太多资料介绍怎么做这个包,我在分析摸索以后,自己编写了一个移植包。特别在这里说明下。

首先看看最需要的几个文件:
主目录  ./feeds/packages/net/myasterisk
编译配置 ./feeds/packages/net/myasterisk/Makefile
补丁文件 ./feeds/packages/net/myasterisk/patches/xxxx
其他文件  ./feeds/packages/net/files

编译时系统是先执行patches里的补丁进行打补丁,具体的补丁可以参考系统已有的那个asterisk18的目录下patches里的东西。

files都是自己执行的一些文件,比如复制启动文件什么的。

这里最主要的就是Makefile了。

openwrt下包的编译流程:
1. 进入包目录
2. 如果没有文件根据makefile下载asterisk
3. 打补丁
4. 根据Makefile设置进行配置和编译
5. 完成工作

相关目录:
编译过程的文件都保存在./build_dir/targetxxxxx/xxx目录下的ipk-install目录中。

这里我把我的makefile共享给大家看看吧:

#
# Copyright by Sun Bing<hoowa.sun@gmail.com>
#

include $(TOPDIR)/rules.mk

PKG_NAME:=freeiriswrt-ast18
PKG_VERSION:=1.8.10.1
PKG_RELEASE:=1

PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
PKG_SOURCE_URL:=http://downloads.asterisk.org/pub/telephony/asterisk/releases/
PKG_MD5SUM:=415738d347b9037cbe5f8bfbe66843de

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

#include $(INCLUDE_DIR)/ltqtapi.mk
include $(INCLUDE_DIR)/package.mk

define Package/freeiriswrt-ast18/Default
  SUBMENU:=Telephony
  SECTION:=net
  CATEGORY:=Network
  URL:=http://www.asterisk.org/
  MAINTAINER:=Sun Bing<hoowa.sun@gmail.com>
endef

define Package/freeiriswrt-ast18/Default/description
 FreeirisWRT Combined Asterisk 1.8.X
endef


define Package/freeiriswrt-ast18
$(call Package/freeiriswrt-ast18/Default)
  TITLE:=FreeirisWRT Combined Asterisk1.8.X
  DEPENDS:= +libsqlite3 +sqlite3-cli+libopenssl +libncurses +libpopt +libpthread +zlib@!TARGET_avr32
endef

define Package/freeiriswrt-ast18/description
$(call Package/freeiriswrt-ast18/Default/description)
endef

CONFIGURE_ARGS+= \
--without-curses \
--with-gsm=internal \
--without-cap \
--without-gtk \
--without-gtk2 \
--without-isdnnet \
--without-kde \
--without-misdn \
--without-nbs \
--with-ncurses="$(STAGING_DIR)/usr" \
--without-netsnmp \
--without-newt \
--without-odbc \
--without-ogg \
--without-osptk \
--with-popt="$(STAGING_DIR)/usr" \
--with-sqlite3="$(STAGING_DIR)/usr" \
--without-pri \
--without-qt \
--without-radius \
--without-sdl \
--without-suppserv \
--without-tds \
--without-termcap \
--without-tinfo \
--without-vorbis \
--without-vpb \
--with-z="$(STAGING_DIR)/usr" \
--with-sounds-cache="$(DL_DIR)" \
--without-dahdi \
--without-gnutls \
--without-iksemel \
--without-curl \
--without-mysqlclient \
--without-spandsp \
--without-bluetooth \
--without-srtp \
--disable-xmldoc

EXTRA_CFLAGS+= $(TARGET_CPPFLAGS)
EXTRA_LDFLAGS+= $(TARGET_LDFLAGS)

define Build/Prepare
$(call Build/Prepare/Default)
endef

define Build/Configure
$(call Build/Configure/Default,,$(SITE_VARS))
endef

define Build/Compile
$(MAKE) -C "$(PKG_BUILD_DIR)" \
include/asterisk/version.h \
include/asterisk/buildopts.h defaults.h \
makeopts.embed_rules
./set_menuselect $(PKG_BUILD_DIR)
ASTCFLAGS="$(EXTRA_CFLAGS) -DLOW_MEMORY" \
ASTLDFLAGS="$(EXTRA_LDFLAGS)" \
$(MAKE) -C "$(PKG_BUILD_DIR)" \
ASTVARLIBDIR="/usr/lib/asterisk" \
ASTDATADIR="/usr/lib/asterisk" \
ASTKEYDIR="/usr/lib/asterisk" \
ASTDBDIR="/usr/lib/asterisk" \
NOISY_BUILD="1" \
DEBUG="" \
OPTIMIZE="" \
DESTDIR="$(PKG_INSTALL_DIR)" \
all install
endef

define Build/InstallDev
$(INSTALL_DIR)$(1)/usr/include/asterisk-1.8/include/asterisk/
$(CP) $(PKG_INSTALL_DIR)/usr/include/asterisk/*.h$(1)/usr/include/asterisk-1.8/include/asterisk/
$(CP) $(PKG_INSTALL_DIR)/usr/include/asterisk.h$(1)/usr/include/asterisk-1.8/include/
endef

define Package/freeiriswrt-ast18/install

# $(INSTALL_DIR) $(1)/etc/asterisk

$(INSTALL_DIR) $(1)/usr/lib/asterisk/modules
$(CP) $(PKG_INSTALL_DIR)/usr/lib/asterisk/modules/*.so$(1)/usr/lib/asterisk/modules/

$(INSTALL_DIR) $(1)/usr/sbin
$(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/sbin/asterisk$(1)/usr/sbin/

# $(INSTALL_DIR) $(1)/usr/lib/asterisk/sounds/

# $(INSTALL_DIR) $(1)/usr/lib/asterisk/moh/

# $(INSTALL_DIR) $(1)/etc/default
# $(INSTALL_DATA)  ./files/asterisk.default$(1)/etc/default/asterisk

# $(INSTALL_DIR) $(1)/etc/init.d
# $(INSTALL_BIN)  ./files/asterisk.init$(1)/etc/init.d/asterisk

endef

$(eval $(call BuildPackage,freeiriswrt-ast18))


包的调试方法:
如果你已经编写好配置文件。就先建立索引
./scripts/feeds update -i
./scripts/feeds install xxxxxxx
如果这个步骤报错,就去修改makefile移植到正确为止。
如果以上步骤正确。make menuconfig 选择你自己的那个包。
然后你就可以单独编译了:
make package/你的包名字/{clean,compile} V=99

编译完成后在bin/下能找到你那个软件包的名字。

最后顺便说下:其实嵌入式下asterisk还是很稳定的,也不像很多人说的那么多问题,主要是由于嵌入式环境的性能限制导致asterisk出现很多问题。早在06年我就知道openwrt项目存在,但是由于当时的嵌入式设备能力太低,不适合HostDSP(泛指利用高性能CPU的运算能力来替代昂贵的DSP处理器的技术)这种模式软件的运行。


本文作者:hoowa.sun是国人,他也是开源运动的推广者,同时也是全球唯一出自中国的开源通信平台Freeiris的作者,其本人是一个不折不扣的技术狂人,每年1/3的时间用来写代码,但是写代码的效率是别人的5倍以上,那么2/3的时间都用来看电视剧,打游戏了。。。。。。

原创粉丝点击