123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181 |
- #!/bin/bash
- SCRIPTDIR=$( cd $(dirname $0) ; pwd -L )
- usage() {
- cat << EOF
- usage: $0 [OPTIONS]
- Create Tizen development tools for certain Tizen profile (gbs sysroot)
- OPTIONS:
- -h Show this message
- -p toolchain installation prefix (cross compiler will be installed there)
- -s gbs sysroot PATH
- -r source rpm repository url
- -i do not clean temporary build directories and try to start from last error
- examples:
- $0 -p ~/toolchains \
- -s ~/GBS_ROOT/local/BUILD-ROOTS/scratch.armv7l.0 \
- -r http://download.tizen.org/snapshots/tizen/common/latest/repos/x86_64-wayland/source
- EOF
- exit
- }
- insufficientDependencies() {
- echo "Missing $1"
- echo Insufficient dependecies: you need to install:
- echo sudo apt-get install flex bison libmpfr-dev libgmp-dev libmpc-dev rpm2cpio cpio
- exit 1
- }
- checkExecutableIfExists() {
- if ! type $1 &> /dev/null; then
- insufficientDependencies $1
- fi
- }
- checkHeaderIfExists() {
- __HEADER=$(find /usr/include/ /usr/local/include/ -name $1)
- if [ "$__HEADER" == "" ]; then
- insufficientDependencies "$1 in /usr/include/ or /usr/local/include/"
- fi
- }
- checkExecutableIfExists flex
- checkExecutableIfExists rpm2cpio
- checkExecutableIfExists cpio
- checkHeaderIfExists gmp.h
- checkHeaderIfExists mpfr.h
- checkHeaderIfExists mpc.h
- set -e
- SYSROOT=""
- TOOLCHAIN_PREFIX=""
- SOURCE_RPM_REPOSITORY_URL=""
- INCREMENTAL="0"
- while getopts ":hip:r:s:" opt; do
- case $opt in
- h)
- usage
- ;;
- i)
- INCREMENTAL="1"
- ;;
- p)
- TOOLCHAIN_PREFIX=$(mkdir -p $OPTARG; cd $OPTARG; pwd -L)
- ;;
- s)
- SYSROOT=$(cd $OPTARG; pwd -L)
- ;;
- r)
- SOURCE_RPM_REPOSITORY_URL=${OPTARG}
- ;;
- ?)
- echo "Invalid option: -$OPTARG"
- usage
- ;;
- esac
- done
- if [ "$TOOLCHAIN_PREFIX" == "" ]; then
- echo "Set toolchain prefix with -p option. Cross compiler will be installed there"
- exit 1
- fi
- if [ "$SYSROOT" == "" ]; then
- echo "Set gbs sysroot path with -s option"
- exit 1
- fi
- if [ "$SOURCE_RPM_REPOSITORY_URL" == "" ]; then
- echo "Set source rpm repository url with -r option"
- exit 1
- fi
- TARGET=$(echo "/usr/bin/gcc -dumpmachine" | gbs chroot $SYSROOT | grep -v "info: chroot")
- if ! [ -e "${TOOLCHAIN_PREFIX}/bin/${TARGET}-ld" ]; then
- echo "binutils are not created - creating them now..."
- $SCRIPTDIR/create_binutils_from_gbs_sysroot -p ${TOOLCHAIN_PREFIX} \
- -s ${SYSROOT} \
- -r ${SOURCE_RPM_REPOSITORY_URL} \
- -i $INCREMENTAL
- fi
- BUILD_DIR=/tmp/crosscompilerbuild/compiler
- 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")
- if [ "$INCREMENTAL" == "0" ]; then
- rm -rf $BUILD_DIR
- fi
- mkdir -p $BUILD_DIR
- cd $BUILD_DIR
- if ! [ -e $GCC_SRCRPM -a "$INCREMENTAL" == "1" ]; then
- wget ${SOURCE_RPM_REPOSITORY_URL}/$GCC_SRCRPM
- fi
- GCC_SOURCE_ARCHIVE=$(ls | grep *.tar.* || :)
- if ! [ "$GCC_SOURCE_ARCHIVE" != "" -a "$INCREMENTAL" == "1" ]; then
- rpm2cpio $GCC_SRCRPM 2>&1 | cpio -imdv 2>&1
- GCC_SOURCE_ARCHIVE=$(ls | grep *.tar.*)
- fi
- GCC_NAME=$(echo $GCC_SOURCE_ARCHIVE | sed "s/\.tar\..*//gi")
- echo extracting $GCC_SOURCE_ARCHIVE ...
- tar -xf $GCC_SOURCE_ARCHIVE
- cd $GCC_NAME
- echo applying patches
- for tupple in $(cat ../*.spec| grep -Pi "^patch" | sed "s/^patch//gi" | sed "s/\s*\:\s*/|/gi"); do\
- tupple=(${tupple/|/ })
- PATCH_PARAMS=$(grep -P "^\s*%patch${tupple[0]}\s+" ../*.spec | sed "s/%patch[0-9]\+\s*//gi" | sed "s/-b\s\+\S\+/ /g")
- echo applying patch number ${tupple[0]} ${tupple[1]} with params: \"$PATCH_PARAMS\"
- if [ "$PATCH_PARAMS" == "" ]; then
- continue
- fi
- patch $PATCH_PARAMS < ../${tupple[1]}
- done
- cd ..
- GCC_BUILD_DIR=${GCC_NAME}-build
- mkdir -p $GCC_BUILD_DIR
- cd $GCC_BUILD_DIR
- echo "#!/bin/bash" > gcc_configure_script.sh
- chmod a+x gcc_configure_script.sh
- echo "../$GCC_NAME/configure \$@ \\">> gcc_configure_script.sh
- echo 'gcc -v 2>&1 | grep "Configured with"' | gbs chroot $SYSROOT | grep -v "info: chroot" |
- sed "s/^Configured with\s*\:.*configure\s//g" |
- sed "s/--prefix=\S\+//gi" |
- sed "s/--libdir=\S\+//gi" |
- sed "s/--with-slibdir=\S\+//gi" |
- sed "s/--with-sysroot=\S\+//gi" |
- sed "s/--with-build-sysroot=\S\+//gi" |
- sed "s/--program-transform-name=\S\+//gi" |
- sed "s/--infodir=\S\+//gi" |
- sed "s/--mandir=\S\+//gi" |
- sed "s/--libexecdir=\S\+//gi" |
- sed "s/--host=\S\+//gi" |
- sed "s/--build=\S\+//gi" |
- sed "s/--target=\S\+//gi" |
- sed "s/--with-gxx-include-dir=\S\+//gi" >> gcc_configure_script.sh
- ./gcc_configure_script.sh \
- --with-sysroot=$SYSROOT \
- --target=$TARGET \
- --prefix=$TOOLCHAIN_PREFIX
- make -j$(cat /proc/cpuinfo | grep -c "^proc") all
- make install
- if [ "$INCREMENTAL" == "0" ]; then
- rm -rf $BUILD_DIR
- fi
|