基于Newlib库的PowerPC交叉编译器制作详解

      对PowerPC的交叉编译工具的介绍确实不像ARM那么多,之前用ELDK费了好大的力气,但是它太大了,使用不方便。所以转载下这篇文章,使用的东西较小,留着以后学习。 

 

如果有需要转载,请在使用的地方,随手附上我的空间地址,谢谢。

http://blog.csdn.net/pro_or_gram/article/details/6642079 

 

基于Newlib库的PowerPC交叉编译器的制作

第一阶段:准备工作

   在电脑d盘中建立4个目录cross_source,cross_configure,cross_build,cross_archives。

   cross_archives目录包含下载的binutils,gcc,newlib 工具压缩包

{

    binutils-2.21.tar.bz2

    gcc-core-4.1.1.tar.bz2

    newlib-1.14.0.tar

}

 

  cross_source目录用于存储压缩包解压后的文件,可以手动解压或者在Cygwin命令下解压缩。

{

    binutils-2.21

    gcc-4.1.1

    newlib-1.14.0

}

  cross_configure目录用于存储对binutils,gcc,newlib进行/configure时的配置信息,以及makefile等

{

    binutils

    gcc

    newlib

}

  cross_build 目录将用于存储对binutils,gcc,newlib编译make后的文件

{

    // 以下文件都是编译生成,并非手动创建

    bin

    include

    info

    lib

    libexec

    man

    powerpc-elf

    share

}

 

第二阶段:制作交叉编译工具的具体步骤

第一步,编译 binutils

(1)$ cd  /cygdrive/d/cross_source          /*此时该路径下应该是空的*/

(2)$ tar xvjf /cygdrive/d/cross_archives/binutils-2.16.1.tar.bz2       

/*该命令将解压后的文件放在当前目录,即/cygdrive/d/cross_source 目录下,如果手动解压了,跳过此步*/

(3)$ cd /cygdrive/d/cross_configure/binutils  

/*进入用于存储configure信息的目录,它与cross_source中的binutils是对应的(4)远程访问 cross_source目录中binutils-2.21下的configure文件

$/cygdrive/d/cross_source/binutils-2.21/configure --prefix=/cygdrive/d/cross_build --target=powerpc-elf

/*--prefix=/cygdrive/d/cross_build指出接下来make编译后文件的存放路径*/

(5)$ make 2>&1 | tee make.log

(6)$ make install 2>&1 | tee install.log

 

第二步,编译gcc

(1)在编译gcc前,要添加新的环境变量PATH,“Ensure that the GNU binary utilities, e.g. powerpc-elf-ar are at the head of the PATH.”

 命令:$ PATH=/cygdrive/d/cross_build/bin:$PATH

进行确认,命令:$ echo $PATH,如果出现 /usr/local/bin:[...] 或者/opt/cross/bin:[...]

说明成功添加。

(2)$ cd /cygdrive/d/cross_configure/gcc  

/*进入用于存储configure信息的目录,它与cross_source中的gcc是对应的

(3)远程访问 cross_source目录中gcc-4.1.1下的configure文件

$/cygdrive/d/cross_source/gcc-4.1.1/configure --prefix=/cygdrive/d/cross_build --target=powerpc-elf --with-gnu-as --with-gnu-ld --with-newlib --disable-shared --enable-languages=c --disable-libssp

/* prefix指向的路径必须与编译binutils时的路径一致,即在编译安装 binutils 和 gcc 的时候,prefix是相同的参数设置*/

(4)$ make 2>&1 | tee make.log

(5)$ make install 2>&1 | tee install.log

注: --disable-libssp 选项并不是都需要设置,应该是在这个版本的 gcc 下,需要设置   For --disable-libssp (Stack Protector Support) see GCC Bugzilla Bug 25035. Anyhow, the Stack Protector Support is not needed for embedded standalone applications.

    Now powerpc-elf is installed, but no header files are present. Until now it is only usable for embedded standalones which provide their own header files.

 

第三步,编译newlib

   对newlib进行configure的时候,不支持--prefix 选项。

(1)$ cd /cygdrive/d/cross_configure/newlib

/*进入用于存储configure信息的目录,它与cross_source中的newlib是对应的

(2)远程访问 cross_source目录中newlib-1.14.0下的configure文件

$/cygdrive/d/cross_source/newlib-1.14.0/configure  --target=powerpc-elf 2>&1 | tee configure.log

(3)configure 运行OK之后,查看/cygdrive/d/cross_configure/newlib下的makefile文件,搜索MAKEINFO ,如果发现如下的信息:

MAKEINFO = /cygdrive/d/package_source/newlib-1.14.0/missing makeinfo

必须确认是否在cygwin 环境下安装了texinfo。

确认的方法是命令:$cygcheck -c texinfo

如果显示如下:

Cygwin Package Information

Package              Version        Status

texinfo              4.13-3         OK     

说明已经安装成功了,如果显示没有安装,需用再次运行Cygwin安装程序setup.exe安装texinfo。

如果已经成功安装了,而makefile中的信息是

MAKEINFO = /cygdrive/d/package_source/newlib-1.14.0/missing makeinfo

则要对MAKEINFO进行修改,将原来的这一行注释掉,新增加一行:

MAKEINFO = /bin/makeinfo

如果不进行修改,会在make newlib的时候,出现下面字样的信息

WARNING: `makeinfo' is missing on your system.  You should only need it if

         you modified a `.texi' or `.texinfo' file, or any other file

         indirectly affecting the aspect of the manual.  The spurious

         call might also be the consequence of using a buggy `make' (AIX,

         DU, IRIX).  You might want to install the `Texinfo' package or

         the `GNU make' package.  Grab either from any GNU archive site.

(4)make 2>&1 | tee make.log

(5)make install 2>&1 | tee install.log

至此,binutils gcc,newlib就编译完毕了,交叉编译器已经制作成功。

 

编译过程中问题集锦:

(1)configure: /bin/sh:bad interpreter: Permission denied 类的问题,

解决办法:

可以尝试使用setup.exe重装 bash等 shell 解释程序

(2)as: unrecognized option `-mppc' 如as: unrecognized option `-G'

The trick is to always build the cross-binutils *first* and install

them before trying to configure/build the cross-gcc, because gcc needs

a working cross-assembler to build its runtime.

     解决办法:创建4个目录分别保存不同的文件与配置信息即可,如上面步骤所述

(3)tar命令解压时,出现 cannot change ownership to uid ***, gid ***

解决办法:

使用tar命令的 --no-same-permissions 参数选项或者 尝试 --no-same-owner options 参数选项

tar --no-same-permissions -xvjf /cygdrive/e/cross_archives/binutils-2.21.tar.bz2

或者在cygwin命令行下,使用如下引号中的命令

“chown $USER /cygdrive/d”

该命令将 /cygdrive/d 路径加入到用户可访问的权限内

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值