嵌入式linux基于netkit-ftp-0.17的ftp客户端移植

来源:互联网 发布:网络用语及其意思 编辑:程序博客网 时间:2024/06/06 09:45

这两天客户需要一个在arm linux下面运行的ftp客户端,我发现我们产品上面没有所以就移植一个。
在编译客户端的时候参考了网上的一些方法,并对其进行整理补充。
首先在网上下载ftp客户端源文件netkit-ftp-0.17或者下载我已经下载已经加入我整理后的netkit-ftp-0.17源文件http://download.csdn.net/detail/zhitouniao/9570727。

在我整理后的netkit-ftp-0.17中已经加入了netkit-ftp-0.17-cross.patch补丁文件,并且对glob.c文件进行了修改。

1,将下载的源文件解压

tar zxvf netkit-ftp-0.17.tar.gz

2,打入补丁

如果下载的是我整理的原码直接打入补丁,如果是网上下载的原码则在源文件根目录下创建文件netkit-ftp-0.17-cross.patch并在文件中加入代码


打入补丁方法:

patch -p1< netkit-ftp-0.17-cross.patch   


etkit-ftp-0.17-cross.patch中代码如下

diff -Naur netkit-ftp-0.17.orig/configure netkit-ftp-0.17/configure  --- netkit-ftp-0.17.orig/configure  2008-01-21 15:27:56.000000000 -0500  +++ netkit-ftp-0.17/configure   2008-01-21 15:27:58.000000000 -0500  @@ -93,7 +93,6 @@            echo 'no'            echo 'Compiler '"$CC"' does not exist or cannot compile C; try another.'            rm -f __conftest*  -         exit        fi   fi     @@ -180,7 +179,6 @@           echo 'no'           echo 'This package needs BSD signal semantics to run.'           rm -f __conftest*  -        exit       fi   fi   rm -f __conftest*  @@ -238,7 +236,6 @@           echo 'not found'           echo 'This package needs termcap to run.'           rm -f __conftest*  -        exit       fi   fi   rm -f __conftest*  @@ -323,7 +320,6 @@               echo 'no'               echo 'Cannot work out what to use for socklen_t. Help...'               rm -f __conftest*  -            exit           fi       fi   fi  @@ -400,7 +396,6 @@               echo 'missing'               echo 'This package requires snprintf.'               rm -f __conftest*  -            exit           fi       fi   fi  diff -Naur netkit-ftp-0.17.orig/ftp/cmds.c netkit-ftp-0.17/ftp/cmds.c  --- netkit-ftp-0.17.orig/ftp/cmds.c 2008-01-21 15:27:56.000000000 -0500  +++ netkit-ftp-0.17/ftp/cmds.c  2008-01-21 15:27:58.000000000 -0500  @@ -68,6 +68,10 @@   #include "cmds.h"   #include "glob.h"     +#ifndef index  +#define index strchr  +#endif  +   void intr(int);      extern FILE *cout;  diff -Naur netkit-ftp-0.17.orig/ftp/ftp.c netkit-ftp-0.17/ftp/ftp.c  --- netkit-ftp-0.17.orig/ftp/ftp.c  2008-01-21 15:27:56.000000000 -0500  +++ netkit-ftp-0.17/ftp/ftp.c   2008-01-21 15:27:58.000000000 -0500  @@ -65,6 +65,13 @@      #include "../version.h"     +#ifndef index  +#define index strchr  +#endif  +#ifndef rindex  +#define rindex strrchr  +#endif  +   int data = -1;   off_t restart_point = 0;     diff -Naur netkit-ftp-0.17.orig/ftp/Makefile netkit-ftp-0.17/ftp/Makefile  --- netkit-ftp-0.17.orig/ftp/Makefile   2008-01-21 15:27:56.000000000 -0500  +++ netkit-ftp-0.17/ftp/Makefile    2008-01-21 15:30:01.000000000 -0500  @@ -16,11 +16,12 @@   cmds.o glob.o: glob.h      install: ftp  -   install -s -m$(BINMODE) ftp $(INSTALLROOT)$(BINDIR)  -   ln -sf ftp $(INSTALLROOT)$(BINDIR)/pftp  -   install -m$(MANMODE) ftp.1 $(INSTALLROOT)$(MANDIR)/man1  -   ln -sf ftp.1 $(INSTALLROOT)$(MANDIR)/man1/pftp.1  -   install -m$(MANMODE) netrc.5 $(INSTALLROOT)$(MANDIR)/man5  +   mkdir -p $(DESTDIR)$(BINDIR) $(DESTDIR)$(MANDIR)/man{1,5}  +   install -m$(BINMODE) ftp $(DESTDIR)$(BINDIR)  +   cd $(DESTDIR)$(BINDIR)/ && ln -sf ftp pftp  +   install -m$(MANMODE) ftp.1 $(DESTDIR)$(MANDIR)/man1  +   cd $(DESTDIR)$(MANDIR)/man1 && ln -sf ftp.1 pftp.1  +   install -m$(MANMODE) netrc.5 $(DESTDIR)$(MANDIR)/man5      clean:      rm -f *.o ftp  diff -Naur netkit-ftp-0.17.orig/ftp/ruserpass.c netkit-ftp-0.17/ftp/ruserpass.c  --- netkit-ftp-0.17.orig/ftp/ruserpass.c    2008-01-21 15:27:56.000000000 -0500  +++ netkit-ftp-0.17/ftp/ruserpass.c 2008-01-21 15:27:58.000000000 -0500  @@ -58,6 +58,10 @@   #define    ID  10   #define    MACH    11     +#ifndef index  +#define index strchr  +#endif  +   static char tokval[100];      static struct toktab {  


3,配置编译工具

网上介绍说使用

./configure --with-c-compiler=arm-none-linux-gnueabi-gcc这种方法来配置,但是由于我的编译工具arm-none-linux-gnueabi-gcc-4.3.2在我的arm 文件系统的某个目录下使用这种方式一直找不到编译工具。一怒之下我直接在makefile中对编译工具进行修改

修改ftp目录下的makefile,我发现编译时ftp编译方法为

$(CC) $(LDFLAGS) $^ $(LIBS) -o $@

所以我直接对CC进行修改,在编译的代码前面指定CC为

CC = /root/buildroot/gcc//usr/bin/arm-none-linux-gnueabi-gcc-4.3.2

CC后面为编译器路径

4,make

编译的时候提示如下错误:

glob.c: In function 'ftpglob':
glob.c:126:15: error: 'ARG_MAX' undeclared (first use in this function)
glob.c:126:15: note: each undeclared identifier is reported only once for each function it appears in
glob.c: In function 'ginit':
glob.c:167:11: error: 'ARG_MAX' undeclared (first use in this function)
glob.c: In function 'Gcat':

参考网上的方法

修改文件glob.c,在代码#include "glob.h"下面加入

#if defined(_POSIX_ARG_MAX)
#if defined(ARG_MAX)
#undef ARG_MAX
#endif
#endif

结果还是报错。我上网上搜索了一个linux中关于ARG_MAX的定义,然后去掉上面的代码在#include "glob.h"下面重新加入

#ifndef ARG_MAX
#define ARG_MAX (sysconf(_SC_ARG_MAX))
#endif

再次make通过。


5,接下来直接将编译出来的ftp文件拷贝到arm开发板就可以使用了。

编译出来的文件在ftp目录下面。







0 0
原创粉丝点击