create_gdb_from_gbs_sysroot 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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 libncurses5-dev
  25. exit 1
  26. }
  27. checkExecutableIfExists() {
  28. if ! type $1 &> /dev/null; then
  29. insufficientDependencies $1
  30. fi
  31. }
  32. checkHeaderIfExists() {
  33. __HEADER=$(find /usr/include/ /usr/local/include/ -name $1)
  34. if [ "$__HEADER" == "" ]; then
  35. insufficientDependencies "$1 in /usr/include/ or /usr/local/include/"
  36. fi
  37. }
  38. checkExecutableIfExists rpm2cpio
  39. checkExecutableIfExists cpio
  40. checkHeaderIfExists termcap.h
  41. set -e
  42. SYSROOT=""
  43. TOOLCHAIN_PREFIX=""
  44. SOURCE_RPM_REPOSITORY_URL=""
  45. INCREMENTAL="0"
  46. while getopts ":hip:r:s:" opt; do
  47. case $opt in
  48. h)
  49. usage
  50. ;;
  51. i)
  52. INCREMENTAL="1"
  53. ;;
  54. p)
  55. TOOLCHAIN_PREFIX=$(mkdir -p $OPTARG; cd $OPTARG; pwd -L)
  56. ;;
  57. s)
  58. SYSROOT=$(cd $OPTARG; pwd -L)
  59. ;;
  60. r)
  61. SOURCE_RPM_REPOSITORY_URL=${OPTARG}
  62. ;;
  63. ?)
  64. echo "Invalid option: -$OPTARG"
  65. usage
  66. ;;
  67. esac
  68. done
  69. if [ "$TOOLCHAIN_PREFIX" == "" ]; then
  70. echo "Set toolchain prefix with -p option. Cross compiler will be installed there"
  71. exit 1
  72. fi
  73. if [ "$SYSROOT" == "" ]; then
  74. echo "Set gbs sysroot path with -s option"
  75. exit 1
  76. fi
  77. if [ "$SOURCE_RPM_REPOSITORY_URL" == "" ]; then
  78. echo "Set source rpm repository url with -r option"
  79. exit 1
  80. fi
  81. BUILD_DIR=/tmp/crosscompilerbuild/gdb
  82. TARGET=$(echo "/usr/bin/gcc -dumpmachine" | gbs chroot $SYSROOT | grep -v "info: chroot" )
  83. GDB_SRCRPM=$(echo "rpm -qif \$(readlink -f /usr/bin/gdb) | grep 'Source RPM' | sed 's/.*Source\s*RPM\s*:\s*//g'" | gbs chroot $SYSROOT| grep -v "info: chroot")
  84. if [ "$INCREMENTAL" == "0" ]; then
  85. rm -rf $BUILD_DIR
  86. fi
  87. mkdir -p $BUILD_DIR
  88. cd $BUILD_DIR
  89. if ! [ -e $GDB_SRCRPM -a "$INCREMENTAL" == "1" ]; then
  90. echo "Downloading gdb source rpm: $GDB_SRCRPM"
  91. wget ${SOURCE_RPM_REPOSITORY_URL}/$GDB_SRCRPM
  92. fi
  93. GDB_SOURCE_ARCHIVE=$(ls | grep *.tar.* || :)
  94. if ! [ "$GDB_SOURCE_ARCHIVE" != "" -a "$INCREMENTAL" == "1" ]; then
  95. rpm2cpio $GDB_SRCRPM 2>&1 | cpio -imdv 2>&1
  96. GDB_SOURCE_ARCHIVE=$(ls | grep *.tar.*)
  97. fi
  98. GDB_NAME=$(echo $GDB_SOURCE_ARCHIVE | sed "s/\.tar\..*//gi")
  99. echo extracting $GDB_SOURCE_ARCHIVE ...
  100. tar -xf $GDB_SOURCE_ARCHIVE
  101. cd $GDB_NAME
  102. for tupple in $(cat ../*.spec| grep -Pi "^patch" | sed "s/^patch//gi" | sed "s/\s*\:\s*/|/gi" | sort); do\
  103. tupple=(${tupple/|/ })
  104. echo applying patch number ${tupple[0]} ${tupple[1]}
  105. PATCH_PARAMS=$(grep -P "^\s*%patch${tupple[0]}" ../*.spec | sed "s/%patch[0-9]\+\s*//gi" | sed "s/-b\s\+\S\+/ /g")
  106. if [ "$PATCH_PARAMS" == "" ]; then
  107. continue
  108. fi
  109. patch $PATCH_PARAMS < ../${tupple[1]}
  110. done
  111. cd ..
  112. GDB_BUILD_DIR=${GDB_NAME}-build
  113. mkdir -p $GDB_BUILD_DIR
  114. cd $GDB_BUILD_DIR
  115. ../$GDB_NAME/configure \
  116. --with-sysroot=$SYSROOT \
  117. --prefix=$TOOLCHAIN_PREFIX \
  118. --target=$TARGET \
  119. --with-expat \
  120. --without-lzma \
  121. --without-guile \
  122. --without-zlib \
  123. --without-babeltrace
  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