dist: support armv7hl
[platform/upstream/dldt.git] / inference-engine / samples / build_samples.sh
1 #!/usr/bin/env bash
2
3 # Copyright (C) 2018-2019 Intel Corporation
4 #
5 #  Licensed under the Apache License, Version 2.0 (the "License");
6 #  you may not use this file except in compliance with the License.
7 #  You may obtain a copy of the License at
8 #
9 #       http://www.apache.org/licenses/LICENSE-2.0
10 #
11 #  Unless required by applicable law or agreed to in writing, software
12 #  distributed under the License is distributed on an "AS IS" BASIS,
13 #  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 #  See the License for the specific language governing permissions and
15 #  limitations under the License.
16
17 error() {
18     local code="${3:-1}"
19     if [[ -n "$2" ]];then
20         echo "Error on or near line $1: $2; exiting with status ${code}"
21     else
22         echo "Error on or near line $1; exiting with status ${code}"
23     fi
24     exit "${code}"
25 }
26 trap 'error ${LINENO}' ERR
27
28 SAMPLES_PATH="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
29
30 printf "\nSetting environment variables for building samples...\n"
31
32 if [ -z "$INTEL_OPENVINO_DIR" ]; then
33     if [ -e "$SAMPLES_PATH/../../bin/setupvars.sh" ]; then
34         setvars_path="$SAMPLES_PATH/../../bin/setupvars.sh"
35     elif [ -e "$SAMPLES_PATH/../../../bin/setupvars.sh" ]; then
36         setvars_path="$SAMPLES_PATH/../../../bin/setupvars.sh"
37     else
38         printf "Error: Failed to set the environment variables automatically. To fix, run the following command:\n source <INSTALL_DIR>/bin/setupvars.sh\n where INSTALL_DIR is the OpenVINO installation directory.\n\n"
39         exit 1
40     fi
41     if ! source $setvars_path ; then
42         printf "Unable to run ./setupvars.sh. Please check its presence. \n\n"
43         exit 1
44     fi
45 else
46     # case for run with `sudo -E` 
47     source "$INTEL_OPENVINO_DIR/bin/setupvars.sh"
48 fi
49
50 if ! command -v cmake &>/dev/null; then
51     printf "\n\nCMAKE is not installed. It is required to build Inference Engine samples. Please install it. \n\n"
52     exit 1
53 fi
54
55 build_dir=$HOME/inference_engine_samples_build
56
57 OS_PATH=$(uname -m)
58 NUM_THREADS="-j2"
59
60 if [ $OS_PATH == "x86_64" ]; then
61   OS_PATH="intel64"
62   NUM_THREADS="-j8"
63 fi
64
65 if [ -e $build_dir/CMakeCache.txt ]; then
66     rm -rf $build_dir/CMakeCache.txt
67 fi
68 mkdir -p $build_dir
69 cd $build_dir
70 cmake -DCMAKE_BUILD_TYPE=Release $SAMPLES_PATH
71 make $NUM_THREADS
72
73 printf "\nBuild completed, you can find binaries for all samples in the $build_dir/${OS_PATH}/Release subfolder.\n\n"