create_binutils_from_gbs_sysroot 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. #!/bin/bash
  2. SCRIPTDIR=$( cd $(dirname $0) ; pwd -L )
  3. usage()
  4. {
  5. cat << EOF
  6. usage: $0 [OPTIONS]
  7. Create Tizen development tools for certain Tizen profile (gbs sysroot)
  8. OPTIONS:
  9. -h Show this message
  10. -p toolchain installation prefix (binutils will be installed there)
  11. -s gbs sysroot PATH
  12. -r source rpm repository url
  13. -i do not clean temporary build directories and try to start from last error
  14. examples:
  15. $0 -p ~/toolchains \
  16. -s ~/GBS_ROOT/local/BUILD-ROOTS/scratch.armv7l.0 \
  17. -r http://download.tizen.org/snapshots/tizen/common/latest/repos/x86_64-wayland/source
  18. EOF
  19. exit
  20. }
  21. insufficientDependencies() {
  22. echo "Missing $1"
  23. echo Insufficient dependecies: you need to install:
  24. echo sudo apt-get install flex bison rpm2cpio cpio texinfo
  25. exit 1
  26. }
  27. checkExecutableIfExists() {
  28. if ! type $1 &> /dev/null; then
  29. insufficientDependencies $1
  30. fi
  31. }
  32. checkExecutableIfExists bison
  33. checkExecutableIfExists makeinfo
  34. checkExecutableIfExists rpm2cpio
  35. checkExecutableIfExists cpio
  36. set -e
  37. SYSROOT=""
  38. TOOLCHAIN_PREFIX=""
  39. SOURCE_RPM_REPOSITORY_URL=""
  40. INCREMENTAL="0"
  41. while getopts ":hip:r:s:" opt; do
  42. case $opt in
  43. h)
  44. usage
  45. ;;
  46. i)
  47. INCREMENTAL="1"
  48. ;;
  49. p)
  50. TOOLCHAIN_PREFIX=$(mkdir -p $OPTARG; cd $OPTARG; pwd -L)
  51. ;;
  52. s)
  53. SYSROOT=$(cd $OPTARG; pwd -L)
  54. ;;
  55. r)
  56. SOURCE_RPM_REPOSITORY_URL=${OPTARG}
  57. ;;
  58. ?)
  59. echo "Invalid option: -$OPTARG"
  60. usage
  61. ;;
  62. esac
  63. done
  64. if [ "$TOOLCHAIN_PREFIX" == "" ]; then
  65. echo "Set toolchain prefix with -p option. Cross compiler will be installed there"
  66. exit 1
  67. fi
  68. if [ "$SYSROOT" == "" ]; then
  69. echo "Set gbs sysroot path with -s option"
  70. exit 1
  71. fi
  72. if [ "$SOURCE_RPM_REPOSITORY_URL" == "" ]; then
  73. echo "Set source rpm repository url with -r option"
  74. exit 1
  75. fi
  76. BUILD_DIR=/tmp/crosscompilerbuild/binutils
  77. TARGET=$(echo "/usr/bin/gcc -dumpmachine" | gbs chroot $SYSROOT | grep -v "info: chroot" )
  78. BINUTILS_SRCRPM=$(echo "rpm -qif \$(readlink -f /usr/bin/ld) | grep 'Source RPM' | sed 's/.*Source\s*RPM\s*:\s*//g'" | gbs chroot $SYSROOT| grep -v "info: chroot")
  79. if [ "$INCREMENTAL" == "0" ]; then
  80. rm -rf $BUILD_DIR
  81. fi
  82. mkdir -p $BUILD_DIR
  83. cd $BUILD_DIR
  84. if ! [ -e $BINUTILS_SRCRPM -a "$INCREMENTAL" == "1" ]; then
  85. echo "Downloading binutils source rpm: $BINUTILS_SRCRPM"
  86. wget ${SOURCE_RPM_REPOSITORY_URL}/$BINUTILS_SRCRPM
  87. fi
  88. BINUTILS_SOURCE_ARCHIVE=$(ls | grep *.tar.* || :)
  89. if ! [ "$BINUTILS_SOURCE_ARCHIVE" != "" -a "$INCREMENTAL" == "1" ]; then
  90. rpm2cpio $BINUTILS_SRCRPM 2>&1 | cpio -imdv 2>&1
  91. BINUTILS_SOURCE_ARCHIVE=$(ls | grep *.tar.*)
  92. fi
  93. BINUTILS_NAME=$(echo $BINUTILS_SOURCE_ARCHIVE | sed "s/\.tar\..*//gi")
  94. echo extracting $BINUTILS_SOURCE_ARCHIVE ...
  95. tar -xf $BINUTILS_SOURCE_ARCHIVE
  96. cd $BINUTILS_NAME
  97. for tupple in $(cat ../*.spec| grep -Pi "^patch" | sed "s/^patch//gi" | sed "s/\s*\:\s*/|/gi" | sort); do\
  98. tupple=(${tupple/|/ })
  99. echo applying patch number ${tupple[0]} ${tupple[1]}
  100. PATCH_PARAMS=$(grep -P "^\s*%patch${tupple[0]}" ../*.spec | sed "s/%patch[0-9]\+\s*//gi" | sed "s/-b\s\+\S\+/ /g")
  101. if [ "$PATCH_PARAMS" == "" ]; then
  102. continue
  103. fi
  104. patch $PATCH_PARAMS < ../${tupple[1]}
  105. done
  106. sed -i -e 's/\s@colophon/\s@@colophon/' \
  107. -e 's/doc@cygnus.com/doc@@cygnus.com/' ld/ld.texinfo
  108. cd ..
  109. BINUTILS_BUILD_DIR=${BINUTILS_NAME}-build
  110. mkdir -p $BINUTILS_BUILD_DIR
  111. cd $BINUTILS_BUILD_DIR
  112. ../$BINUTILS_NAME/configure \
  113. --with-sysroot=$SYSROOT \
  114. --target=$TARGET \
  115. --prefix=$TOOLCHAIN_PREFIX \
  116. --disable-nls \
  117. --disable-doc \
  118. --disable-multilib \
  119. --with-gnu-as \
  120. --with-gnu-ld \
  121. --disable-libssp \
  122. --enable-gold \
  123. --disable-werror
  124. make -j$(cat /proc/cpuinfo | grep -c "^proc") all
  125. make install
  126. if [ "$INCREMENTAL" == "0" ]; then
  127. rm -rf $BUILD_DIR
  128. fi