create_binutils_from_gbs_sysroot 3.2 KB

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