Chinaunix首页 | 论坛 | 博客
  • 博客访问: 788250
  • 博文数量: 83
  • 博客积分: 7030
  • 博客等级: 少将
  • 技术积分: 1097
  • 用 户 组: 普通用户
  • 注册时间: 2007-08-06 15:50
文章分类

全部博文(83)

文章存档

2011年(2)

2010年(9)

2009年(56)

2008年(16)

我的朋友

分类: 系统运维

2009-07-14 13:24:40

引用请注明出处:http://blog.chinaunix.net/u1/45185/showart_1995662.html

最近在添加LDAPClient functionvxworks OS去,但网上找了很久没有找到vxworks相应的Open Source,所以只好用OpenLDAP进行移植了,
但网上也没有找到关于OpenLDAP移植到vxworks的文章.所以把我的移植之路共享出来,供大家参考。

1. 先讲讲OpenLDAPlinux下面的build&install过程。
1.1 ./configure
   
后面添加一些参数,如--prefix--enable-xxxx--build,--target,--host 这个可以按照需求添加. configure的作用包括:
1.1.1
通过头文件来找目标系统所支持的功能和module,检测完成以后会把宏定义写在xxxx/include/portable.h 头文件里面,在后面的Compile时候会用到。接下来的移植工作也会用到这个头文件。
1.1.2
在每个文件夹下自动生成Makefile,其中使用的模版就是xxx/build/top.mk. 这些Makefile compile 资源文件的必要条件。
1.2. make depend
  
这个就是在每个文件夹下面自动生成的Makefile里面添加依赖.
1.3. make
  
用上面生成的Makefile文件真正的Compile资源文件。
1.4. make test
  
自动生成exampleserver配置.这个要用root 权限。
1.5. make install
  
把生产的elf可执行文件添加到系统目录,以后要运行OpenLDAP server不用去安装目录去执行操作,而是任何目录。
 
上面的5步是移植过程中必须知道的东西。下面的移植也是按照上面步骤来的。

2. 现在普及下交叉编译的知识。
 
详情请看:http://blog.chinaunix.net/u1/45185/showart_527681.html
 
现在要Build vxworks 认得的lib,这个时候就不能用原来的gccarld,ranlib,...了,而是需要与vxworks对应的编译环境。
 
幸好vxworks已经给了我们编译好了的编译环境gcc->ccmips, ar->armips, ld->ldmips, ranlib->ranlibmips, ...
 
在后面的compile就需要重载这些编译器.

3.  现在构建下如何把OpenLDAP 放到vxworks里面去.
3.1
直接添加文件,并手动添加Makefile,然后统一buildImage.
    
这种方法可行,但在以后的build新的image时候,每次都要跑这个模块,太费时间了,而且手痛添加Makefile 很累,这种方法不推荐.
3.2
buildOpenLDAP LIB,然后在buildvxworks Image 之前link 进去。
  
这种方法简便快捷,也减少了以后build vxwoks image 的时间,有所谓build一次后人无限享用。 

4.下面就进入正题了---Porting OpenLDAP to vxworks
4.1.
我当前的交叉编译环境是Cygwin。同时也要设置环境变量,把PATH环境变量添加vxworks编译环境的bin目录。这样可以直接运行bin下面的编译器了。其中OpenLdap版本是

4.2. 进入OpenLDAP source code目录下,打开configure文件并修改其中的一部分,因为OpenLDAP没有添加Vxworks编译器的条件判断。结果请看附件

文件: configure.rar
大小: 99KB
下载: 下载


4.2.1 搜索----ac_tool_prefix=----,在之前添加以下内容:

case $target in
    *vxwork*)
     CC="ccmips"
     AR="armips"
     AR_FLAGS="cruvs"
     AS="asmips"
     LD="ldmips"
     NM="nmmips"
     RANLIB="ranlibmips"
     STRIP="stripmips"
     OBJCOPY="objcopymips"
      CPPFLAGS="-I$WIND_BASE/target/h -I$GG_DIR/OpenSSL -I$GG_DIR/OpenSSL/include -I$GG_DIR/OpenSSL/crypto"
     LDFLAGS="-L$WIND_BASE/host/x86-win32/mips-wrs-vxworks/lib/MIPS32sfgnu -L${GG_DIR}product/PCF_VPD020/sw/lib -L${GG_DIR}/lib -L${GG_DIR}/lib/common -L$WIND_BASE/target/lib -L$WIND_BASE/target/lib/mips -L$WIND_BASE/target/lib/mips/MIPS32/sfcommon -L$WIND_BASE/target/lib/mips/MIPS32/sfgnu -L${GG_DIR}target/lib/mips/MIPS32/sfcommon -L${GG_DIR}target/target/lib/mips/MIPS32/sfgnu-EB -mno-branch-likely -G 0 -fno-builtin -msoft-float -DCPU=MIPS32 -DMIPSEL -DNO_STRINGS_H"
     ;;
    *)
     echo "Not vxworks OS"
   esac

上面的意思就是重载原来的Cygwin编译环境为Vxworks编译环境。

4.2.2 搜索----echo "$as_me:$LINENO: result: $ac_cv_func_select" >&5---,并更改如下:

 

fi
   { echo "$as_me:$LINENO: result: $ac_cv_func_select" >&5
   echo "${ECHO_T}$ac_cv_func_select" >&6; }
   if test $ac_cv_func_select = yes; then
     :
   else
   echo "Andy ignore select check"
   # Andy marked 2009/07/08
   # { { echo "$as_me:$LINENO: error: select() required." >&5
   # echo "$as_me: error: select() required." >&2;}
   # { (exit 1); exit 1; }; }
   fi

上面的意思就是忽略select函数check,因为vxworksselect()函数存在的头文件位置和linux下的存放位置不同。

4.2.3 搜索----error: POSIX regex required.----并更改如下:

 

if test "$ac_res" != no; then
     test "$ac_res" = "none required" || LIBS="$ac_res $LIBS"
     :
   else
   echo "Andy ignore regex check"
   # Andy marked in 2009/07/08
   # { { echo "$as_me:$LINENO: error: POSIX regex required." >&5
   # echo "$as_me: error: POSIX regex required." >&2;}
   # { (exit 1); exit 1; }; }
   fi

上面的意思就是忽略正则表达式(regex)功能,这个功能server用得到,Client用不到.

4.2.4 搜索----error: broken POSIX regex!----并更改如下:

 

# if test "$ol_cv_c_posix_regex" = no ; then
   # { { echo "$as_me:$LINENO: error: broken POSIX regex!" >&5
   # echo "$as_me: error: broken POSIX regex!" >&2;}
   # { (exit 1); exit 1; }; }
   # fi
   echo "Andy ignore posix regex check!" >&2

上面的意思就是忽略POSIX regex正则表达式的check,这个功能server用得到,Client用不到.


4.2.5 搜索----error: could not locate usable POSIX Threads----并更改如下:

 

echo "Andy ignore POSIX Threads check!"
# Andy marked in 2009/07/08
# { { echo "$as_me:$LINENO: error: could not locate usable POSIX Threads" >&5
# echo "$as_me: error: could not locate usable POSIX Threads" >&2;}
# { (exit 1); exit 1; }; }

上面的意思就是忽略POSIX Threadscheck,因为vxworksselect()函数存在的头文件位置和linux下的存放位置不同。不过在重新修改portable.h文件时候要改下。

4.2.6 搜索----BDB/HDB: BerkeleyDB not available----并修改如下:

 

# if test $ol_cv_berkeley_db = no ; then
   # { { echo "$as_me:$LINENO: error: BDB/HDB: BerkeleyDB not available" >&5
   # echo "$as_me: error: BDB/HDB: BerkeleyDB not available" >&2;}
   # { (exit 1); exit 1; }; }
   # fi
   echo "Andy ignore BerkeleyDB check!" >&2

上面的意思就是忽略BerkeleyDBcheck,这个功能server用得到,Client用不到.

4.3 进入OpenLDAP目录进行环境参数配置,会在每个目录下面生成Makefilexx/include/portable.h检测结果。

./configure --host=mips-wrs-vxworks --target=mipseb-gnu-vxworks --build=i686-pc-cygwin \
--disable-syslog --disable-slapd --disable-cleartext --disable-rewrite \
--disable-backends --disable-bdb --disable-hdb --disable-relay --disable-overlays --enable-share=yes --disable-fast-install | tee ${GG_DIR}/image/${PRODUCT}/BuildLog/ldap_config.log;

4.4 修改portable.h文件,请参考附件:

文件: portable.rar
大小: 6KB
下载: 下载

4.5 搜索Makefile和Makefile.in里面的的PROGRAMS关键字,然后删除资源文件定义,因为它里面的资源文件都是test用的,对我们只需要build LIB无关。

4.6 make depend;make 2>&1 | tee ${GG_DIR}/image/${PRODUCT}/BuildLog/ldap.log;
    如compile的时候有出错就靠大家自己更改了,只需要更改很小部分,一般都是头文件。

4.7 如果编译成功的话就可以得到想要的LIB了
    a)
xx/libraries/liblber/.libs/liblber.a
    b) xx/libraries/libldap/.libs/libldap.a
    c) xx/libraries/libldap_r/.libs/libldap_r.a
4.8 接下来怎么用就不用我说了吧!---^_^

5.在修改code时候碰到的问题。

5.1 显示message:"ldap_pvt_connect: -1"
    这时是有个select函数出了问题,在函数ldap_int_poll&ldap_int_select里面具体不明白为什么select里面的第一个参数不能是一个最大值,如:2048,而应该是当前的Socket ID的值+1.即:

----------function ldap_int_poll-----------
rc = select( ldap_int_tblsize, z, &wfds,
#ifdef HAVE_WINSOCK
    &efds,
#else
    z,

#endif
    tvp ? &tv : NULL );
#endif

=============改成==============>>

rc = select( s+1, z, &wfds,z, tvp ? &tv : NULL );

 

 

-----------function ldap_int_select -------------
    rc = select( ldap_int_tblsize,
        &sip->si_use_readfds, &sip->si_use_writefds,
        NULL, timeout );


===========改成=========>>


    {
        ber_socket_t sd;
        ber_sockbuf_ctrl(ld->ld_sb, LBER_SB_OPT_GET_FD, &sd );
        Debug( LDAP_DEBUG_TRACE, "ldap_int_select,sd:%d\n", sd, 0, 0 );
        rc = select( sd+1,
            &sip->si_use_readfds, &sip->si_use_writefds,
            NULL, timeout );
    }

5.2 测试下你们的vxworks下面time()是否有效,如果不能得到值的话就把time()-> tickGet()/sysClkRateGet()

5.3 更改vxworks环境下config文件放置的位置,ldap_config.h

如果有什么问题,大家可以再讨论讨论,QQ:42082806,URL:http://blog.chinaunix.net/u1/45185/showart_1995662.html

阅读(3139) | 评论(0) | 转发(0) |
0

上一篇:以太网概述

下一篇:__attribute__ 详解

给主人留下些什么吧!~~