Second toolchain

发布时间:2020-05-28 15:14:07 作者:tenglong88
来源:网络 阅读:357

2.2.3 preparation
1) create new user vita
groupadd vita
useradd -m -s /bin/bash -g vita vita
2) add file vita to /etc/sudoers.d, file content is below:
vita ALL=(ALL) NOPASSWD: ALL

3) mkdir /vita

4) mkdir source build cross-tool cross-gcc-tmp sysroot

5) chown -R vita.vita /vita

6) add below content to /home/vita/.bashrc

unset LANG
export HOST=i686-pc-linux-gnu
export BUILD=$HOST
export TARGET=i686-none-linux-gnu
export CROSS_TOOL=/vita/cross-tool
export CROSS_GCC_TMP=/vita/cross-gcc-tmp
export SYSROOT=/vita/sysroot
PATH=$CROSS_TOOL/bin:$CROSS_GCC_TMP/bin:/sbin:/usr/sbin:$PATH

7) su - vita

2.2.4 install binutils

1) tar xvf ../source/binutils-2.23.1.tar.bz2

2) mkdir binutils-build

3) cd binutils-build

4) ../binutils-2.23.1/configure --prefix=$CROSS_TOOL --target=$TARGET --with-sysroot=$SYSROOT

5) make

6) make install

2.2.5 compile freestanding cross tool

1) cd /vita/build

2)  tar xvf ../source/gcc-4.7.2.tar.bz2
       cd gcc-4.7.2/
       tar xvf ../../source/gmp-5.0.5.tar.bz2
       mv gmp-5.0.5/ gmp
       tar xvf ../../source/mpc-1.0.1.tar.gz
       mv mpc-1.0.1/ mpc
       tar xvf ../../source/mpfr-3.1.1.tar.bz2
       mv mpfr-3.1.1/ mpfr

       cd /vita/build

       mkdir gcc-build

       cd gcc-build

       ../gcc-4.7.2/configure --prefix=$CROSS_GCC_TMP --target=$TARGET --with-sysroot=$SYSROOT --with-newlib --enable-languages=c --with-mpfr-include=/vita/build/gcc-4.7.2/mpfr/src --with-mpfr-lib=/vita/build/gcc-build/mpfr/src/.libs --disable-shared --disable-threads --disable-decimal-float --disable-libquadmath --disable-libmudflap --disable-libgomp --disable-nls --disable-libssp

             make

             make install

             cd /vita/cross-gcc-tmp

             ln -s libgcc.a lib/gcc/i686-none-linux-gnu/4.7.2/libgcc_eh.a

2.2.6 install kernel header file

cd /vita/build

tar xvf ../source/linux-3.7.4.tar.xz 

cd linux-3.7.4/

make mrproper

make ARCH=i386 headers_check

make ARCH=i386 INSTALL_HDR_PATH=$SYSROOT/usr/ headers_install

2.2.7 compile object system C library

apt-get install gawk

cd /vita/build

tar xvf ../source/glibc-2.15.tar.xz

cd glibc-2.15

patch -p1 < ../../source/glibc-2.15-cpuid.patch

patch -p1 < ../../source/glibc-2.15-s_frexp.patch

mkdir glibc-build

cd glibc-build

../glibc-2.15/configure --prefix=/usr --host=$TARGET --enable-kernel=3.7.4 --enable-add-ons --with-headers=$SYSROOT/usr/include libc_cv_forced_unwind=yes libc_cv_c_cleanup=yes libc_cv_ctors_header=yes

make

make install_root=$SYSROOT install

2.2.8 setup whole cross compiler

cd /vita/build/gcc-build

rm -rf *

../gcc-4.7.2/configure --prefix=$CROSS_TOOL --target=$TARGET --with-sysroot=$SYSROOT --with-mpfr-include=/vita/build/gcc-4.7.2/mpfr/src --with-mpfr-lib=/vita/build/gcc-build/mpfr/src/.libs --enable-languages=c,c++ --enable-threads=posix

make

make install

2.2.9 set the environment variable

1)add below content to /home/vita/.bashrc

export CC="$TARGET-gcc" 

export CXX="$TARGET-g++" 

export AR="$TARGET-ar" 

export AS="$TARGET-as" 

export RANLIB="$TARGET-ranlib" 

export LD="$TARGET-ld" 

export STRIP="$TARGET-strip"

export DESTDIR=$SYSROOT

2) source /home/vita/.bashrc

2.2.10 encapsulate cross pkg-config

1)add below content to .bashrc

unset PKG_CONFIG_PATH  

export PKG_CONFIG_LIBDIR=$SYSROOT/usr/lib/pkgconfig:\  

    $SYSROOT/usr/share/pkgconfig 

2)add file /vita/cross-tool/bin/pkg-config

  1. #!/bin/bash  

  2. HOST_PKG_CFG=/usr/bin/pkg-config  

  3.  

  4. if [ ! $SYSROOT ]; then  

  5.     echo "Please make sure you are in cross-compile environment!"  

  6.     exit 1  

  7. fi  

  8.  

  9. $HOST_PKG_CFG --exists $*  

  10. if [ $? -ne 0 ]; then  

  11.     exit 1  

  12. fi  

  13.  

  14. if $HOST_PKG_CFG $* | sed -e "s/-I/-I\/vita\/sysroot/g;\  

  15. s/-L/-L\/vita\/sysroot/g"  

  16. then  

  17.     exit 0  

  18. else  

  19.     exit 1  

  20. fi 

3) chmod a+x /vita/cross-tool/bin/pkg-config

2.2.11 handle libtool

find $SYSROOT -name "*.la" -exec rm -f '{}' \;

2.2.12 start code

foo.c

#include <stdio.h>


void myinit(int argc, char **argv, char **envp)

{

        printf("%s\n",__FUNCTION__);

}


__attribute__((section(".init_array"))) typeof(myinit) *_myinit = myinit;


void test()

{

        printf("%s\n",__FUNCTION__);

}


bar.c

#include <stdio.h>


void main()

{

        printf("Enter main.\n");

        test();

}

#  gcc -shared -fPIC foo.c -o libfoo.so

#  gcc bar.c -o bar -L./ -lfoo

#  LD_LIBRARY_PATH=./ ./bar

myinit

Enter main.

test



推荐阅读:
  1. Pycharm与Anaconda怎么在Linux中使用
  2. Linux下安装mysql的教程详解

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

linux second ol

上一篇:MD5加密算法介绍

下一篇:Nginx 性能优化有这篇就足够了!

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》