Skip to content

Instantly share code, notes, and snippets.

@nkigen
Created January 7, 2015 11:33
Show Gist options
  • Save nkigen/7bc59e9dc035f27ed9e7 to your computer and use it in GitHub Desktop.
Save nkigen/7bc59e9dc035f27ed9e7 to your computer and use it in GitHub Desktop.

Revisions

  1. nkigen created this gist Jan 7, 2015.
    227 changes: 227 additions & 0 deletions mware_layers.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,227 @@
    #!/bin/bash
    #(2014)Nelson Kigen<[email protected]>
    set -x
    #path to arm compiler
    CC_PATH="/home/nkigen/development/tools/compilers/arm-2014.05/bin"
    TARGET="arm-none-linux-gnueabi"

    SRC_DIR="/home/nkigen/development/thesis/sources/src/"
    BUILD_DIR=${SRC_DIR}"../build/"
    OUTPUT_DIR=${SRC_DIR}"../output"

    ZEROMQ_SRC_DIR=${SRC_DIR}"zeromq-3.2.4"
    ZEROMQ_LINK="http://download.zeromq.org/zeromq-3.2.4.tar.gz"
    ZEROMQ_TYPE="tar.gz"

    OPENDDS_SRC_DIR=${SRC_DIR}"opendds-3.4.1"
    OPENDDS_LINK="http://download.ociweb.com/OpenDDS/previous-releases/OpenDDS-3.4.1.tar.gz"
    OPENDDS_TYPE="tar.gz"

    ORTE_SRC_DIR=${SRC_DIR}"orte-0.3.3"
    ORTE_LINK="http://downloads.sourceforge.net/project/orte/orte-0.3.3/orte-0.3.3.tar.gz?r=&ts=1417984489&use_mirror=ufpr"
    ORTE_TYPE="tar.gz"

    ACE_SRC_DIR=${SRC_DIR}"ACE+TAO-src-6.1.7"
    ACE_NATIVE_INSTALL_DIR=${BUILD_DIR}"ACE_native"
    ACE_LINK="http://download.dre.vanderbilt.edu/previous_versions/ACE+TAO-6.1.7.tar.bz2"
    #ACE_LINK="http://download.dre.vanderbilt.edu/previous_versions/ACE+TAO-6.3.0.tar.bz2"
    ACE_TYPE="tar.bz2"

    #THE MIDDLEWARE'S LOCATION
    MWARE_ROOT_DIR="/home/nkigen/development/thesis/rtlws13"

    #Download all the middleware layers
    src_download(){
    if [ ! -f ${ZEROMQ_SRC_DIR}.${ZEROMQ_TYPE} ]; then
    wget ${ZEROMQ_LINK} -O ${ZEROMQ_SRC_DIR}.${ZEROMQ_TYPE}
    else
    echo ${ZEROMQ_SRC_DIR}.${ZEROMQ_TYPE}" already exists...skipping\n"
    fi
    if [ ! -f ${OPENDDS_SRC_DIR}.${OPENDDS_TYPE} ]; then
    wget ${OPENDDS_LINK} -O ${OPENDDS_SRC_DIR}.${OPENDDS_TYPE}
    else
    echo ${OPENDDS_SRC_DIR}.${OPENDDS_TYPE}" already exists...skipping\n"
    fi
    if [ ! -f ${ORTE_SRC_DIR}.${ORTE_TYPE} ]; then
    wget ${ORTE_LINK} -O ${ORTE_SRC_DIR}.${ORTE_TYPE}
    else
    echo ${ORTE_SRC_DIR}.${ORTE_TYPE}" already exists...skipping\n"
    fi
    }

    build_prep(){

    _NUM_CPUS="$(($(grep ^processor /proc/cpuinfo 2> /dev/null | wc -l) - 1))"
    if [ "${_NUM_CPUS}" = "" ] || [ "${_NUM_CPUS}" = "0" ]; then
    _NUM_CPUS="3"
    fi
    MAKEOPTS="-j${_NUM_CPUS}"
    export MAKEOPTS
    }

    xmake(){
    make ${MAKEOPTS} "${@}"
    }

    #gets the layer name from the <LAYER>_SRC_DIR
    fetch_layer_name(){
    IN="$1"
    arrIN=(${IN//// })
    echo "This is the layer" ${arrIN[${#arrIN[@]}-1]}

    export LAYER_NAME=${arrIN[${#arrIN[@]}-1]}
    }

    #uncompress an archive
    #params(<filetype><dirname><output_di)>)
    #<output_dir> is optional but defaults to BUILD_DIR
    src_uncompress(){
    echo "Trying to uncompress $2.$1"

    UNCOMPRESS_DIR=${BUILD_DIR}
    if [ ! -z "$3" ]; then
    UNCOMPRESS_DIR="$3"
    fi

    if [ "$1" == "tar.gz" ]; then
    tar zxvf "$2"."$1" --directory=${UNCOMPRESS_DIR}
    elif [ "$1" == "tar.bz2" ]; then
    tar xjvf "$2"."$1" --directory=${UNCOMPRESS_DIR}
    elif [ "$1" == "zip" ]; then
    unzip "$2"."$1" -d ${UNCOMPRESS_DIR}
    fi
    }

    layers_prep(){
    rm -rf ${BUILD_DIR}
    mkdir -p ${BUILD_DIR}
    src_uncompress ${ZEROMQ_TYPE} ${ZEROMQ_SRC_DIR}
    src_uncompress ${ORTE_TYPE} ${ORTE_SRC_DIR}
    src_uncompress ${OPENDDS_TYPE} ${OPENDDS_SRC_DIR}
    }

    zeromq_compile(){
    fetch_layer_name ${ZEROMQ_SRC_DIR}
    cd ${BUILD_DIR}${LAYER_NAME}
    ./configure --host=${TARGET} --prefix=${OUTPUT_DIR}
    make clean
    xmake
    make install
    }

    orte_compile(){
    cd ${BUILD_DIR}"orte-0.3.3"
    ./configure --host=${TARGET} --prefix=${OUTPUT_DIR}
    make clean
    xmake
    make install
    }

    ace_tao_native(){

    mkdir -p ${ACE_NATIVE_INSTALL_DIR}
    mkdir -p ${ACE_NATIVE_INSTALL_DIR}"/bin"
    if [ ! -f ${ACE_SRC_DIR}.${ACE_TYPE} ]; then
    wget ${ACE_LINK} -O ${ACE_SRC_DIR}.${ACE_TYPE}
    else
    echo ${ACE_SRC_DIR}.${ACE_TYPE}" already exists...skipping"
    fi
    rm -rf ${ACE_NATIVE_INSTALL_DIR}"/ACE_wrappers"
    src_uncompress ${ACE_TYPE} ${ACE_SRC_DIR} ${ACE_NATIVE_INSTALL_DIR}
    export ACE_ROOT=${ACE_NATIVE_INSTALL_DIR}"/ACE_wrappers"
    export TAO_ROOT=${ACE_ROOT}"/TAO"
    echo "#include \"config-linux.h\" " > ${ACE_ROOT}/ace/config.h
    echo "include ${ACE_ROOT}/include/makeinclude/platform_linux.GNU" >> ${ACE_ROOT}/include/makeinclude/platform_macros.GNU
    echo "INSTALL_PREFIX = ${ACE_NATIVE_INSTALL_DIR}/Ace_wrappers/bin" >> ${ACE_ROOT}/include/makeinclude/platform_macros.GNU
    export LD_LIBRARY_PATH=$ACE_ROOT/lib
    cd $ACE_ROOT/ace
    # make -j7 #CPP_FLAGS+=-DACE_USES_STD_NAMESPACE_FOR_STDCPP_LIB
    xmake
    cd $ACE_ROOT/apps/gperf
    xmake || return 1
    cd $TAO_ROOT
    xmake || return 1
    cd $ACE_ROOT/ace
    make install || return 1
    export TAO_ROOT_NATIVE=$TAO_ROOT
    export ACE_ROOT_NATIVE=$ACE_ROOT
    }

    ace_tao_target(){
    if [ ! -f ${ACE_SRC_DIR}.${ACE_TYPE} ]; then
    wget ${ACE_LINK} -O ${ACE_SRC_DIR}.${ACE_TYPE}
    else
    echo ${ACE_SRC_DIR}.${ACE_TYPE}" already exists...skipping"
    fi
    src_uncompress ${ACE_TYPE} ${ACE_SRC_DIR}
    cd ${BUILD_DIR}"ACE_wrappers"
    rm -rf build/linux-arm
    mkdir -p build/linux-arm
    ./bin/create_ace_build build/linux-arm
    cd build/linux-arm
    export ACE_ROOT=`pwd`
    export TAO_ROOT=${ACE_ROOT}"/TAO"
    echo "#include \"ace/config-linux.h\"" > ace/config.h
    #rm -f ./include/makeinclude/platform_macros.GNU
    echo "cross_compile=1" > ./include/makeinclude/platform_macros.GNU
    echo "shared_libs=0" >> ./include/makeinclude/platform_macros.GNU
    echo "static_libs=1" >> ./include/makeinclude/platform_macros.GNU
    echo "inline=0" >> ./include/makeinclude/platform_macros.GNU
    echo "ssl=0" >> ./include/makeinclude/platform_macros.GNU
    echo "boost=0" >> ./include/makeinclude/platform_macros.GNU
    echo "zlib=1" >> ./include/makeinclude/platform_macros.GNU
    echo "no_hidden_visibility=1" >> ./include/makeinclude/platform_macros.GNU
    echo "TAO_IDL:=${ACE_ROOT_NATIVE}/bin/tao_idl" >> ./include/makeinclude/platform_macros.GNU
    echo "TAO_IDLFLAGS += -g ${ACE_ROOT_NATIVE}/bin/ace_gperf" >> ./include/makeinclude/platform_macros.GNU
    echo "CROSS_COMPILE=${TARGET}-" >> ./include/makeinclude/platform_macros.GNU
    echo "include ${ACE_ROOT}/include/makeinclude/platform_linux.GNU" >> ./include/makeinclude/platform_macros.GNU
    echo "INSTALL_PREFIX=${OUTPUT_DIR}" >> ./include/makeinclude/platform_macros.GNU
    cd ${TAO_ROOT}
    #export LD_LIBRARY_PATH=$ACE_ROOT_NATIVE/ace:i$LD_LIBRARY_PATH
    #export LD_LIBRARY_PATH=$TAO_ROOT_NATIVE/TAO_IDL:$LD_LIBRARY_PATH
    ../bin/mwc.pl TAO_ACE.mwc -type gnuace
    xmake || return 1
    }

    opendds_compile(){
    ace_tao_native || return 1
    export DDS_ROOT=${BUILD_DIR}"DDS"
    export PATH=$DDS_ROOT/bin:$PATH
    export LD_LIBRARY_PATH=$DDS_ROOT/lib:$LD_LIBRARY_PATH
    cd ${BUILD_DIR}"DDS"
    make clean
    xmake -C dds/idl || return 1
    ace_tao_target || return 1
    rm -rf ${BUILD_DIR}"DDS-target"
    mkdir -p ${BUILD_DIR}"DDS-target"
    src_uncompress ${OPENDDS_TYPE} ${OPENDDS_SRC_DIR} ${BUILD_DIR}"DDS-target"
    cp $DDS_ROOT/bin/opendds_idl ${BUILD_DIR}"DDS-target/DDS/bin"
    export DDS_ROOT=${BUILD_DIR}"DDS-target/DDS"
    export PATH=$DDS_ROOT/bin:$T_PATH
    export LD_LIBRARY_PATH=$DDS_ROOT/lib:$T_LD_LIB
    cd ${DDS_ROOT}
    xmake -C dds/idl || return 1
    xmake || return 1
    echo " OpenDDS installation complete!!!"
    }

    layers_compile(){
    export T_LD_LIB=$LD_LIBRARY_PATH
    export PATH=$PATH:$CC_PATH
    export T_PATH=$PATH
    export CPLUS_INCLUDE_PATH=$CC_PATH/../arm-none-linux-gnueabi/include
    mkdir -p ${OUTPUT_DIR}
    zeromq_compile || return 1
    orte_compile || return 1
    opendds_compile || return 1
    }

    main(){
    src_download
    build_prep
    layers_prep
    layers_compile
    # tests_compile
    }

    main