buildcommon 4.88 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
#############
#  DEFINES  #
#############

GCCVER=4.8
GCCVERFULL=4.8.3

#############
# FUNCTIONS #
#############

checkfail()
{
    if [ ! $? -eq 0 ];then
        echo -e "\e[1m\e[31m$1\e[0m"
        exit 1
    fi
}

#############
# ARGUMENTS #
#############

RELEASE=0
25
STRIP=0
26 27 28 29 30 31 32 33
while [ $# -gt 0 ]; do
    case $1 in
        help|--help)
            echo "Use -a to set the ARCH"
            echo "Use --release to build in release mode"
            exit 1
            ;;
        a|-a)
34
            export TIZEN_ABI=$2
35 36
            shift
            ;;
37 38 39
        s|-s)
            export STRIP=1
            ;;
40
        release|--release)
41
            export RELEASE=1
42 43 44 45 46 47 48 49 50 51 52 53 54 55
            ;;
    esac
    shift
done

if [ -z "$TIZEN_SDK" ]; then
    echo "Please set the TIZEN_SDK environment variable with its path."
    exit 1
fi

if [ -z "$TIZEN_ABI" ]; then
    echo "Please pass the TIZEN_ABI to the correct architecture, using
                ${SCRIPT} -a ARCH
    ARM:     armv7l
56
    X86:     x86"
57 58 59
    exit 1
fi

60
. ${TIZEN_SDK}/sdk.version
61 62

mkdir -p ${PROJECTPATH}/lib
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133

#########
# FLAGS #
#########

# Set up ABI variables
if [ "${TIZEN_ABI}" = "x86" ] ; then
    TARGET_TUPLE="i386-linux-gnueabi"
    PATH_HOST="x86"
    PLATFORM_SHORT_ARCH="x86"
    TIZEN_DEVICE="emulator"
elif [ "${TIZEN_ABI}" = "armv7l" ] ; then
    TARGET_TUPLE="arm-linux-gnueabi"
    PATH_HOST=$TARGET_TUPLE
    HAVE_ARM=1
    PLATFORM_SHORT_ARCH="arm"
    TIZEN_DEVICE="device"
else
    echo -e "\e[1m\e[31mUnknown ABI: '${TIZEN_ABI}'\e[0m"
    exit 2
fi

SYSROOT=${TIZEN_SDK}/tools/${TARGET_TUPLE}-gcc-${GCCVER}
LIBEXEC=${TIZEN_SDK}/tools/${TARGET_TUPLE}-gcc-${GCCVER}/libexec/gcc/${TARGET_TUPLE}/${GCCVERFULL}
TIZEN_TOOLCHAIN_PATH=${SYSROOT}/bin

export PATH=${TIZEN_TOOLCHAIN_PATH}:${LIBEXEC}:${PATH}

###############
# DISPLAY ABI #
###############
echo -e "\e[1m\e[36mABI:        $TIZEN_ABI\e[0m"
echo -e "\e[1m\e[36mTIZEN SDK:  $TIZEN_SDK\e[0m"
echo -e "\e[1m\e[36mSYSROOT:    $SYSROOT\e[0m"
echo -e "\e[1m\e[36mPATH:       $PATH\e[0m"

# Make in //
if [ -z "$MAKEFLAGS" ]; then
    UNAMES=$(uname -s)
    MAKEFLAGS=
    if which nproc >/dev/null; then
        MAKEFLAGS=-j`nproc`
    elif [ "$UNAMES" == "Darwin" ] && which sysctl >/dev/null; then
        MAKEFLAGS=-j`sysctl -n machdep.cpu.thread_count`
    fi
fi

###########
# FIX SDK #
###########

LIBSTDCPP=${TIZEN_SDK}/tools/${TARGET_TUPLE}-gcc-${GCCVER}/${TARGET_TUPLE}/lib/libstdc++.la

if [ -f "${LIBSTDCPP}" ] ; then
    mv -f ${LIBSTDCPP} ${LIBSTDCPP}.bak
fi

##########
# CFLAGS #
##########

CFLAGS="${CFLAGS} -fstrict-aliasing -funsafe-math-optimizations"

EXTRA_CFLAGS="-fPIC"
# Setup CFLAGS per ABI
if [ "${TIZEN_ABI}" = "armv7l" ] ; then
    EXTRA_CFLAGS="${EXTRA_CFLAGS} -march=armv7-a -mtune=cortex-a8 -mfpu=vfpv3-d16 -mthumb -mfloat-abi=softfp"
elif [ "${TIZEN_ABI}" = "x86" ] ; then
    EXTRA_CFLAGS="${EXTRA_CFLAGS} -mtune=atom -msse3 -mfpmath=sse -m32"
fi

134 135 136 137
TIZEN_SDK_MAJOR=`echo "${TIZEN_SDK_VERSION}" | cut -d. -f1`
TIZEN_SDK_MINOR=`echo "${TIZEN_SDK_VERSION}" | cut -d. -f2`
TIZEN_SDK_REV=`echo "${TIZEN_SDK_VERSION}" | cut -d. -f3`

138 139 140
if [ ${TIZEN_SDK_VERSION} = "2.3.1" ];then
    TIZEN_CORE="${TIZEN_SDK}/platforms/mobile-${TIZEN_SDK_VERSION}/rootstraps/mobile-${TIZEN_SDK_VERSION}-${TIZEN_DEVICE}.core"
else
141
    TIZEN_SDK_SHORT_VERSION="${TIZEN_SDK_MAJOR}.${TIZEN_SDK_MINOR}"
142 143
    TIZEN_CORE="${TIZEN_SDK}/platforms/tizen-${TIZEN_SDK_SHORT_VERSION}/mobile/rootstraps/mobile-${TIZEN_SDK_SHORT_VERSION}-${TIZEN_DEVICE}.core"
fi
144 145
TIZEN_INCLUDES="${TIZEN_CORE}/usr/include"
TIZEN_LIBS="${TIZEN_CORE}/usr/lib"
146 147
EXTRA_CFLAGS="${EXTRA_CFLAGS} -I${SYSROOT}/include/c++/${GCCVERFULL}"
EXTRA_CFLAGS="${EXTRA_CFLAGS} -I${SYSROOT}/include/c++/${GCCVERFULL}/${TARGET_TUPLE}"
148
EXTRA_CFLAGS="${EXTRA_CFLAGS} -I${TIZEN_INCLUDES} -I${TIZEN_INCLUDES}/media"
149
EXTRA_CFLAGS="${EXTRA_CFLAGS} -DTIZEN_SDK_MAJOR=${TIZEN_SDK_MAJOR} -DTIZEN_SDK_MINOR=${TIZEN_SDK_MINOR}"
150

151
EXTRA_CXXFLAGS="${EXTRA_CFLAGS} -D__STDC_FORMAT_MACROS=1 -D__STDC_CONSTANT_MACROS=1 -D__STDC_LIMIT_MACROS=1"
152

153
CPPFLAGS="-I${SYSROOT}/include/c++/${GCCVERFULL} -I${SYSROOT}/include/c++/${GCCVERFULL}/${TARGET_TUPLE} -I${TIZEN_INCLUDES} -I${TIZEN_INCLUDES}/media"
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184

#################
# Setup LDFLAGS #
#################

TIZEN_TOOLS=${TIZEN_SDK}/tools/${TARGET_TUPLE}-gcc-${GCCVER}/bin/${TARGET_TUPLE}-
CROSS_COMPILE=${TIZEN_TOOLS}
TIZEN_FLAGS="--sysroot=${TIZEN_CORE}"
export CC="${TIZEN_TOOLS}gcc ${TIZEN_FLAGS}"
export CXX="${TIZEN_TOOLS}g++ ${TIZEN_FLAGS}"
export AR="${TIZEN_TOOLS}ar"
export LD="${TIZEN_TOOLS}ld ${TIZEN_FLAGS}"

EXTRA_LDFLAGS="-L${TIZEN_CORE}/usr/lib"

LDFLAGS="${TIZEN_FLAGS} -Wl,-Bdynamic -Wl,--no-undefined -lrt"

if [ -n "$HAVE_ARM" ]; then
        EXTRA_PARAMS=" --enable-neon"
        LDFLAGS="${LDFLAGS} -Wl,--fix-cortex-a8"
fi

LDFLAGS="${LDFLAGS} -L${SYSROOT}/lib"

# Release or not?
if [ "$RELEASE" = 1 ]; then
    EXTRA_CFLAGS="${EXTRA_CFLAGS} -DNDEBUG "
fi

echo -e "\e[1m\e[36mCFLAGS:            ${CFLAGS}\e[0m"
echo -e "\e[1m\e[36mEXTRA_CFLAGS:      ${EXTRA_CFLAGS}\e[0m"