create_cross_compiler_from_gbs_sysroot 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. #!/bin/bash
  2. SCRIPTDIR=$( cd $(dirname $0) ; pwd -L )
  3. usage() {
  4. cat << EOF
  5. usage: $0 [OPTIONS]
  6. Create Tizen development tools for certain Tizen profile (gbs sysroot)
  7. OPTIONS:
  8. -h Show this message
  9. -p toolchain installation prefix (cross compiler will be installed there)
  10. -s gbs sysroot PATH
  11. -r source rpm repository url
  12. -i do not clean temporary build directories and try to start from last error
  13. examples:
  14. $0 -p ~/toolchains \
  15. -s ~/GBS_ROOT/local/BUILD-ROOTS/scratch.armv7l.0 \
  16. -r http://download.tizen.org/snapshots/tizen/common/latest/repos/x86_64-wayland/source
  17. EOF
  18. exit
  19. }
  20. insufficientDependencies() {
  21. echo "Missing $1"
  22. echo Insufficient dependecies: you need to install:
  23. echo sudo apt-get install flex bison libmpfr-dev libgmp-dev libmpc-dev rpm2cpio cpio
  24. exit 1
  25. }
  26. checkExecutableIfExists() {
  27. if ! type $1 &> /dev/null; then
  28. insufficientDependencies $1
  29. fi
  30. }
  31. checkHeaderIfExists() {
  32. __HEADER=$(find /usr/include/ /usr/local/include/ -name $1)
  33. if [ "$__HEADER" == "" ]; then
  34. insufficientDependencies "$1 in /usr/include/ or /usr/local/include/"
  35. fi
  36. }
  37. checkExecutableIfExists flex
  38. checkExecutableIfExists rpm2cpio
  39. checkExecutableIfExists cpio
  40. checkHeaderIfExists gmp.h
  41. checkHeaderIfExists mpfr.h
  42. checkHeaderIfExists mpc.h
  43. set -e
  44. SYSROOT=""
  45. TOOLCHAIN_PREFIX=""
  46. SOURCE_RPM_REPOSITORY_URL=""
  47. INCREMENTAL="0"
  48. while getopts ":hip:r:s:" opt; do
  49. case $opt in
  50. h)
  51. usage
  52. ;;
  53. i)
  54. INCREMENTAL="1"
  55. ;;
  56. p)
  57. TOOLCHAIN_PREFIX=$(mkdir -p $OPTARG; cd $OPTARG; pwd -L)
  58. ;;
  59. s)
  60. SYSROOT=$(cd $OPTARG; pwd -L)
  61. ;;
  62. r)
  63. SOURCE_RPM_REPOSITORY_URL=${OPTARG}
  64. ;;
  65. ?)
  66. echo "Invalid option: -$OPTARG"
  67. usage
  68. ;;
  69. esac
  70. done
  71. if [ "$TOOLCHAIN_PREFIX" == "" ]; then
  72. echo "Set toolchain prefix with -p option. Cross compiler will be installed there"
  73. exit 1
  74. fi
  75. if [ "$SYSROOT" == "" ]; then
  76. echo "Set gbs sysroot path with -s option"
  77. exit 1
  78. fi
  79. if [ "$SOURCE_RPM_REPOSITORY_URL" == "" ]; then
  80. echo "Set source rpm repository url with -r option"
  81. exit 1
  82. fi
  83. TARGET=$(echo "/usr/bin/gcc -dumpmachine" | gbs chroot $SYSROOT | grep -v "info: chroot")
  84. if ! [ -e "${TOOLCHAIN_PREFIX}/bin/${TARGET}-ld" ]; then
  85. echo "binutils are not created - creating them now..."
  86. $SCRIPTDIR/create_binutils_from_gbs_sysroot -p ${TOOLCHAIN_PREFIX} \
  87. -s ${SYSROOT} \
  88. -r ${SOURCE_RPM_REPOSITORY_URL} \
  89. -i $INCREMENTAL
  90. fi
  91. BUILD_DIR=/tmp/crosscompilerbuild/compiler
  92. GCC_SRCRPM=$(echo "rpm -qif \$(readlink -f /usr/bin/gcc) | grep 'Source RPM' | sed 's/.*Source\s*RPM\s*:\s*//g'" | gbs chroot $SYSROOT | grep -v "info: chroot")
  93. if [ "$INCREMENTAL" == "0" ]; then
  94. rm -rf $BUILD_DIR
  95. fi
  96. mkdir -p $BUILD_DIR
  97. cd $BUILD_DIR
  98. if ! [ -e $GCC_SRCRPM -a "$INCREMENTAL" == "1" ]; then
  99. wget ${SOURCE_RPM_REPOSITORY_URL}/$GCC_SRCRPM
  100. fi
  101. GCC_SOURCE_ARCHIVE=$(ls | grep *.tar.* || :)
  102. if ! [ "$GCC_SOURCE_ARCHIVE" != "" -a "$INCREMENTAL" == "1" ]; then
  103. rpm2cpio $GCC_SRCRPM 2>&1 | cpio -imdv 2>&1
  104. GCC_SOURCE_ARCHIVE=$(ls | grep *.tar.*)
  105. fi
  106. GCC_NAME=$(echo $GCC_SOURCE_ARCHIVE | sed "s/\.tar\..*//gi")
  107. echo extracting $GCC_SOURCE_ARCHIVE ...
  108. tar -xf $GCC_SOURCE_ARCHIVE
  109. cd $GCC_NAME
  110. echo applying patches
  111. for tupple in $(cat ../*.spec| grep -Pi "^patch" | sed "s/^patch//gi" | sed "s/\s*\:\s*/|/gi"); do\
  112. tupple=(${tupple/|/ })
  113. PATCH_PARAMS=$(grep -P "^\s*%patch${tupple[0]}\s+" ../*.spec | sed "s/%patch[0-9]\+\s*//gi" | sed "s/-b\s\+\S\+/ /g")
  114. echo applying patch number ${tupple[0]} ${tupple[1]} with params: \"$PATCH_PARAMS\"
  115. if [ "$PATCH_PARAMS" == "" ]; then
  116. continue
  117. fi
  118. patch $PATCH_PARAMS < ../${tupple[1]}
  119. done
  120. cd ..
  121. GCC_BUILD_DIR=${GCC_NAME}-build
  122. mkdir -p $GCC_BUILD_DIR
  123. cd $GCC_BUILD_DIR
  124. echo "#!/bin/bash" > gcc_configure_script.sh
  125. chmod a+x gcc_configure_script.sh
  126. echo "../$GCC_NAME/configure \$@ \\">> gcc_configure_script.sh
  127. echo 'gcc -v 2>&1 | grep "Configured with"' | gbs chroot $SYSROOT | grep -v "info: chroot" |
  128. sed "s/^Configured with\s*\:.*configure\s//g" |
  129. sed "s/--prefix=\S\+//gi" |
  130. sed "s/--libdir=\S\+//gi" |
  131. sed "s/--with-slibdir=\S\+//gi" |
  132. sed "s/--with-sysroot=\S\+//gi" |
  133. sed "s/--with-build-sysroot=\S\+//gi" |
  134. sed "s/--program-transform-name=\S\+//gi" |
  135. sed "s/--infodir=\S\+//gi" |
  136. sed "s/--mandir=\S\+//gi" |
  137. sed "s/--libexecdir=\S\+//gi" |
  138. sed "s/--host=\S\+//gi" |
  139. sed "s/--build=\S\+//gi" |
  140. sed "s/--target=\S\+//gi" |
  141. sed "s/--with-gxx-include-dir=\S\+//gi" >> gcc_configure_script.sh
  142. ./gcc_configure_script.sh \
  143. --with-sysroot=$SYSROOT \
  144. --target=$TARGET \
  145. --prefix=$TOOLCHAIN_PREFIX
  146. make -j$(cat /proc/cpuinfo | grep -c "^proc") all
  147. make install
  148. if [ "$INCREMENTAL" == "0" ]; then
  149. rm -rf $BUILD_DIR
  150. fi