其他语言

本类阅读TOP10

·基于Solaris 开发环境的整体构思
·使用AutoMake轻松生成Makefile
·BCB数据库图像保存技术
·GNU中的Makefile
·射频芯片nRF401天线设计的分析
·iframe 的自适应高度
·BCB之Socket通信
·软件企业如何实施CMM
·入门系列--OpenGL最简单的入门
·WIN95中日志钩子(JournalRecord Hook)的使用

分类导航
VC语言Delphi
VB语言ASP
PerlJava
Script数据库
其他语言游戏开发
文件格式网站制作
软件工程.NET开发
Building a GCC PowerPC/Linux Cross Compiler For SPARC/Solaris

作者:未知 来源:月光软件站 加入时间:2005-2-28 月光软件站

Building a GCC PowerPC/Linux Cross Compiler For SPARC/Solaris

There are a number of resources on the Internet serving as a guide for building a cross compiler. However, each addresses a particular version of the compiler as well as a particular host/target combination; which while generally useful as a base instruction set, doesn't cover the intricacies of performing the feat for a different version and host/target combination. This attempts to document the process of building a GCC 2.95.2 cross compiler for PowerPC/Linux 2.4.0 on SPARC/ Solaris 2.7 (aka Solaris 7, SunOS 5.7).

Conventions

In the instructions below, the following conventions are used:

<archive dir> Location in which you store your archive (i.e. *.tar.gz) files.
<source dir> Location in which you unpack your archive files as various source directories.
<object dir> Location in which you will build object files from the source dirctories located in <source dir>. This may be the same as <source dir>; however, that is not recommended.
<tool dir> Location in which you will place all of the built cross-compiler tools and libraries.
gmake GNU version of make
gtar GNU version of tar

Instructions

Most of the following steps should work fine with default system tools. However, the process for building tends to make a number of assumptions about running with a GNU tool set, in particular, a native GCC compiler. That said, it may be useful (I certainly found it to be) to have /usr/local/gnu/bin or an equivalent GNU tool set in your PATH before your normal system tools (/usr/bin, /usr/xpg4/bin, /usr/ucb, etc.). I used these tools.

It is also highly encouraged that all the below commands be run while using bash (preferrably) or ksh as your shell. You will likely even have better luck if you set the environment variable SHELL to bash or ksh. All the subsequent examples will assume that this is the case. Adjust accordingly if you are using csh, tcsh or some other shell.

Changing the optimization level of the compiler (e.g. -O3), either via CFLAGS or by another means, is not recommened. Doing so will likely result in either a failed build step in glibc or a broken cross-compilation environment.

  1. Packages
  2. The following packages are required for this endeavor:

    Package Version Location
    binutils 2.10.1 Download
    gcc-core 2.95.2 Download
    gcc 2.95.2 Download
    glibc 2.1.3 Download
    glibc-crypt 2.1.3 Download
    glibc-linuxthreads 2.1.3 Download
    linux 2.4.0 Download

  3. Binutils
    1. Extract
      1. cd <source dir>
      2. gtar zxvf <archive dir>/binutils-2.10.1.tar.gz

    2. Build
      1. mkdir <tool dir>/host
      2. mkdir <tool dir>/host/sparc-sun-solaris
      3. mkdir <object dir>/binutils-2.10.1
      4. cd <object dir>/binutils-2.10.1
      5. <source dir>/binutils-2.10.1/configure --host=sparc-sun-solaris --target=powerpc-linux --prefix=<tool dir>/host/sparc-sun-solaris
      6. gmake

    3. Install
      1. gmake install
      2. gmake install-info

    4. Access

      Subsequent build steps will need to use the tools created by this step. As such, the path to these tools will need to be added to your environment's PATH variable:

      1. PATH=${PATH}":<tool dir>/host/sparc-sun-solaris/bin"
      2. export PATH

  4. Gcc (Core)
    1. Extract
      1. cd <source dir>
      2. gtar zxvf <archive dir>/gcc-core-2.95.2.tar.gz

    2. Build
      1. mkdir <object dir>/gcc-2.95.2
      2. cd <object dir>/gcc-2.95.2
      3. <source dir>/gcc-2.95.2/configure --host=sparc-sun-solaris --target=powerpc-linux --prefix=<tool dir>/host/sparc-sun-solaris --with-newlib
      4. gmake

    3. Install
      1. gmake install

  5. Linux Headers
  6. The 2.4.0 kernel contains PowerPC support; however, it may not contain the absolute latest bleeding-edge changes to accomodate various PowerPC architectures. Such changes are maintained elsewhere.

    1. Extract
      1. cd <source dir>
      2. gtar zxvf <archive dir>/linux-2.4.0.tar.gz

    2. Build
      1. cd <source dir>/linux
      2. Edit the Makefile
        1. Comment out the existing "ARCH :=" line and add a new line with "ARCH := ppc". line.
        2. Find the "CROSS_COMPILE =" line and append 'powerpc-linux-' so that it reads "CROSS_COMPILE = powerpc-linux-"

      3. If you have Tcl/Tk installed, then "gmake xconfig", or if you have the GNU ncurses library installed, then "gmake menuconfig", otherwise "gmake config" .
      4. gmake dep
      5. gmake clean
      6. gmake zImage

      The zImage build process does not have to complete successfully; only the headers are required.

    3. Verify

      Verify that the headers were created.

      1. find ./include/. -name "version.h"

      You should see output similar to: "./include/./linux/version.h".

      If you do not have the appropriate headers, use the "gmake distclean" command and repeat the steps for this section again.

  7. Glibc
    1. Link
      1. ln -sf <linux source dir>/include/asm <tool dir>/host/sparc-sun-solaris/powerpc-linux/include/asm
      2. ln -sf <linux source dir>/include/linux <tool dir>/host/sparc-sun-solaris/powerpc-linux/include/linux
      3. ls -la <tool dir>/host/sparc-sun-solaris/powerpc-linux/include/asm/*
      4. ls -la <tool dir>/host/sparc-sun-solaris/powerpc-linux/include/linux/*

    2. Extract
      1. cd <source dir>
      2. gtar zxvf <archive dir>/glibc-2.1.3.tar.gz
      3. cd <source dir>/glibc-2.1.3
      4. gtar zxvf <archive dir>/glibc-crypt-2.1.3.tar.gz
      5. gtar zxvf <archive dir>/glibc-linuxthreads-2.1.3.tar.gz

    3. Build
    4. First, Create a separate subdirectory, such as <tool dir> /target/powerpc-linux-gnu in which to install the glibc libraries. This will be the target of the --prefix configure switch.

      The configure script is quite specific about what versions (and flavors) of various build tools it requires. If it doesn't find what it's looking for, chance are that things won't build. Try to appease it.

      1. mkdir <tool dir>target
      2. mkdir <tool dir>target/powerpc-linux-gnu
      3. mkdir <object dir>/glibc-2.1.3
      4. cd <object dir>/glibc-2.1.3
      5. CC=powerpc-linux-gcc AR=powerpc-linux-ar RANLIB=powerpc-linux-ranlib <source dir>/glibc-2.1.3/configure --host=powerpc-linux --with-headers=<linux source dir>/include --enable-add-ons=crypt,linuxthreads --enable-shared --prefix=<tool dir>/target/powerpc-linux-gnu
      6. gmake

        There are a few likely pitfalls here. First, depending on which echo the make process finds (SVR4, BSD, GNU, shell built-in, etc.) there will be an error in csu/version-info.h if it picks the wrong one. Picking the wrong one results in '-n Version...' rather than the intended 'Version...' in csu/version-info.h.

        You will also probably notice in the csu/version-info.h file that it reports that it was compiled "on a Linux 5.7 system". This should report "on a Linux 2.4.0 system". This due to more echo problems. The actual content doesn't really matter, it just affects what it output when /usr/lib/libc.so is executed.

      7. Edit and fix the csu/version-info.h file as necessary.
      8. gmake

        The second pitfall when building on a stock Solaris 2.7 machine, is that there is a limit of 64 open file descriptors. This will result in an error building in the iconvdata/ subdirectory. This can be remedied by ratcheting up the limit to 1024:

      9. /usr/bin/ulimit -n 1024
      10. gmake

      The overall build process should take several hours to complete, even on the brawniest of hardware.

    5. Install
      1. gmake install

        If your build process has completed successfully, the install process should go fairly smoothly. One tangle may occur when the install process attempts to run in the locale/ directory. There are either missing rules for, or the rules don't work quite correctly for, the i18n/locales/ and i18n/repertoiremaps/ targets.

        If you encounter this problem, to work around it, simply create the following directories yourself:

        1. cd <tool dir>/target/powerpc-linux-gnu/share/
        2. mkdir i18n
        3. cd i18n
        4. mkdir locales
        5. mkdir repertoiremaps
        6. cd <object dir>/glibc-2.1.3
        7. gmake install

      The install process should take about 15 or so minutes, assuming that no errors are encountered.

  8. GCC
  9. Provided that glibc compiled successfully, you are ready to go back and rebuild the C compiler and, if you wish, build the Objective C, C++ and F77 compilers.

    1. Extract
      1. cd <source dir>
      2. mv gcc-2.95.2 gcc-core-2.95.2
      3. gtar zxvf <archive dir>/gcc-2.95.2.tar.gz

    2. Build
      1. cd <object dir>
      2. mv gcc-2.95.2 gcc-core-2.95.2
      3. mkdir gcc-2.95.2
      4. cd gcc-2.95.2
      5. <source dir>/gcc-2.95.2/configure --host=sparc-sun-solaris --target=powerpc-linux --prefix=<tool dir>/host/sparc-sun-solaris --with-headers=<tool dir>/target/powerpc-linux-gnu/include --with-libs=<tool dir>/target/powerpc-linux-gnu/lib --enable-shared --enable-languages="c,c++,f77"
      6. gmake

    3. Install
      1. gmake install

  10. Fix Up
  11. Once you have successfully built and installed everything, there are a few minor fix ups that need to be done to complete the installation. The primary outcome of the following steps is to remove the duplicate copies of the target headers and libraries and to permanent copy in the Linux headers. If you do not want to do this, you can safely skip this step.

    1. cd <tool dir>/host/sparc-sun-solaris/powerpc-linux/
    2. rm -f include/asm
    3. rm -f include/linux
    4. rm -rf include/
    5. mv lib/ldscripts lib/nof lib/libstdc++-* <tool dir>/target/powerpc-linux-gnu/lib
    6. rm -f lib/ sys-include/
    7. ln -si <tool dir>/target/powerpc-linux-gnu/include include
    8. ln -si <tool dir>/target/powerpc-linux-gnu/lib lib
    9. ln -si include sys-include
    10. mkdir <tool dir>/target/powerpc-linux-gnu/include/asm
    11. mkdir <tool dir>/target/powerpc-linux-gnu/include/linux
    12. (cd <source dir>/linux/include/asm; tar cf - . | (cd <tool dir>/target/powerpc-linux-gnu/include/asm; tar xfBp -))
    13. (cd <source dir>/linux/include/linux; tar cf - . | (cd <tool dir>/target/powerpc-linux-gnu/include/linux; tar xfBp -))

  12. Test
  13. user@ultraSPARC% pwd
    /home/user
    
    user@ultraSPARC% uname -a
    SunOS ultraSPARC 5.7 Generic sun4u sparc
    
    user@ultraSPARC% cat > hello.c
    #include <stdio.h>
    
    int main (int argc, char *argv[])
    {
            printf("Hello, %s!\n", argc >= 2 ? argv[1] : "world");
    
            return (0);
    }
    
    user@ultraSPARC% cat > hello.C
    #include <iostream.h>
    
    int main (int argc, char *argv[])
    {
            cout << "Hello, " << ((argc >= 2) ? argv[1] : "world") << "!" << endl;
    
            return (0);
    }
    
    user@ultraSPARC% cat > hello.f
            program hello
    
            print*,'Hello, world!'
            end
    
    user@ultraSPARC% ~/linuxppc/dev/bin/powerpc-linux-gcc -dumpmachine
    powerpc-linux
    
    user@ultraSPARC% ~/linuxppc/dev/bin/powerpc-linux-gcc -o helloc -s hello.c
    
    user@ultraSPARC% file helloc
    hello-c:        ELF 32-bit MSB executable PowerPC Version 1, dynamically linked, stripped
    
    user@ultraSPARC% ~/linuxppc/dev/bin/powerpc-linux-g++ -dumpmachine
    powerpc-linux
    
    user@ultraSPARC% ~/linuxppc/dev/bin/powerpc-linux-g++ -o helloC -s hello.C
    
    user@ultraSPARC% file helloC
    hello-c:        ELF 32-bit MSB executable PowerPC Version 1, dynamically linked, stripped
    
    user@ultraSPARC% ~/linuxppc/dev/bin/powerpc-linux-g77 -dumpmachine
    powerpc-linux
    
    user@ultraSPARC% ~/linuxppc/dev/bin/powerpc-linux-g77 -o hellof -s hello.f
    
    user@ultraSPARC% file hellof
    hello-c:        ELF 32-bit MSB executable PowerPC Version 1, dynamically linked, stripped
    
    user@ultraSPARC% rsh PowerMac
    
    user@PowerMac% pwd
    /home/user
    
    user@PowerMac% uname -a
    Linux PowerMac 2.4.0-test12 #1 Mon Jan  8 12:34:22 CST 2001 ppc unknown
    
    user@PowerMac% file helloc
    hello: ELF 32-bit MSB executable, PowerPC or cisco 4500, version 1, dynamically linked, stripped
    
    user@PowerMac% file helloC
    hello: ELF 32-bit MSB executable, PowerPC or cisco 4500, version 1, dynamically linked, stripped
    
    user@PowerMac% file hellof
    hello: ELF 32-bit MSB executable, PowerPC or cisco 4500, version 1, dynamically linked, stripped
    
    user@PowerMac% ldd ./helloc
            libc.so.6 => /lib/libc.so.6 (0x016be000)
            /lib/ld.so.1 => /lib/ld.so.1 (0x30000000)
    
    user@PowerMac% ldd ./helloC
            libstdc++.so.2.9 => /usr/lib/libstdc++.so.2.9 (0x0175b000)
            libm.so.6 => /lib/libm.so.6 (0x01783000)
            libc.so.6 => /lib/libc.so.6 (0x01641000)
            /lib/ld.so.1 => /lib/ld.so.1 (0x30000000)
    
    user@PowerMac% ldd ./hellof
    	libm.so.6 => /lib/libm.so.6 (0x01783000)
            libc.so.6 => /lib/libc.so.6 (0x01641000)
            /lib/ld.so.1 => /lib/ld.so.1 (0x30000000)
    
    user@PowerMac% ./helloc
    Hello, world!
    
    user@PowerMac% ./helloC
    Hello, world!
    
    user@PowerMac% ./hellof
    Hello, world!
    

Adding On

With a complete cross-development environment now in place, you are now ready to build and install other headers and libraries, such as termcap or readline, into the <tool dir>/target/powerpc-linux-gnu subdirectory.

Parting Notes

Building all of the above requires a significant amount of space, on the order of 150 MB for the powerpc-linux cross-development system hosted on Sun Solaris 2.7. None of the above tools are stripped by default, so doing so after installation will save an appreciable amount of space.

Useful Resources


Last modified: Thu May 10 10:42:23 CDT 2001
Grant Erickson / [email protected]



相关文章

相关软件