move all function definitions into the common-def script

This change moves all function definitions into the common-def script,
which now acts as a script header, and tf-cov-make just taking care of
make calls.

Also, a new function is defined (set_armclang_toolchain) which sets
correctly the armclang toolchain based on the (jenkins) environment.

Signed-off-by: Leonardo Sandoval <leonardo.sandoval@linaro.org>
Change-Id: I8ebe4f8068ee77e9d0b6f17f0263faac08c69595
diff --git a/script/tf-coverity/common-def.sh b/script/tf-coverity/common-def.sh
index 90d0152..220d503 100644
--- a/script/tf-coverity/common-def.sh
+++ b/script/tf-coverity/common-def.sh
@@ -5,6 +5,65 @@
 # SPDX-License-Identifier: BSD-3-Clause
 #
 
+export CROSS_COMPILE=aarch64-none-elf-
+
+# We need to clean the platform build between each configuration because Trusted
+# Firmware's build system doesn't track build options dependencies and won't
+# rebuild the files affected by build options changes.
+clean_build()
+{
+    local flags="$*"
+    echo "Building TF with the following build flags:"
+    echo "  $flags"
+    make $flags clean
+    make $flags all
+    echo "Build config complete."
+    echo
+}
+
+# Defines common flags between platforms
+common_flags() {
+    local release="${1:-}"
+    local num_cpus="$(/usr/bin/getconf _NPROCESSORS_ONLN)"
+    local parallel_make="-j $num_cpus"
+
+    # default to debug mode, unless a parameter is passed to the function
+    debug="DEBUG=1"
+    [ -n "$release" ] && debug=""
+
+    echo " $parallel_make $debug -s "
+}
+
+# Check if execution environment is ARM's jenkins (Jenkins running under ARM
+# infraestructure)
+is_arm_jenkins_env() {
+    if [ "$JENKINS_HOME" ]; then
+	if echo "$JENKINS_URL" | grep -q "arm.com"; then
+	    return 0;
+	fi
+    fi
+    return 1
+}
+
+# Provide correct linaro cross toolchain based on environment
+set_cross_compile_gcc_linaro_toolchain() {
+    local cross_compile_path="/home/buildslave/tools"
+
+    # if under arm enviroment, overide cross-compilation path
+    is_arm_jenkins_env && cross_compile_path="/arm/pdsw/tools"
+
+    echo "${cross_compile_path}/gcc-linaro-6.2.1-2016.11-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu-"
+}
+
+# Provide correct armclang toolchain based on environment
+set_armclang_toolchain() {
+    local armclang_path="/home/buildslave/tools/armclang-6.8/bin"
+
+    # if under arm enviroment, overide cross-compilation path
+    is_arm_jenkins_env && armclang_path="/arm/warehouse/Distributions/FA/ARMCompiler/6.8/25/standalone-linux-x86_64-rel/bin"
+
+    echo "${armclang_path}/armclang"
+}
 
 # mbed TLS variables
 MBED_TLS_DIR=mbedtls
@@ -14,5 +73,9 @@
 # Board Boot support.
 MBED_TLS_SOURCES_TAG="mbedtls-2.24.0"
 
-ARMCLANG_PATH=/arm/warehouse/Distributions/FA/ARMCompiler/6.8/25/standalone-linux-x86_64-rel/bin/armclang
+ARMCLANG_PATH="$(set_armclang_toolchain)"
+
 CRYPTOCELL_LIB_PATH=/arm/projectscratch/ssg/trusted-fw/dummy-crypto-lib
+
+TBB_OPTIONS="TRUSTED_BOARD_BOOT=1 GENERATE_COT=1 MBEDTLS_DIR=$(pwd)/mbedtls"
+ARM_TBB_OPTIONS="$TBB_OPTIONS ARM_ROTPK_LOCATION=devel_rsa"