Imported Upstream version 1.8.0
[platform/core/ml/nnfw.git] / infra / packaging / build
1 #!/bin/bash
2
3 SCRIPT_PATH="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
4
5 if [[ -z "${NNAS_PROJECT_PATH}" ]]; then
6   echo "ERROR: NNAS_PROJECT_PATH is not specified"
7   exit 255
8 fi
9
10 # The default preset
11 PRESET="20200630"
12
13 EXTRA_OPTIONS=()
14 while [ "$#" -ne 0 ]; do
15   CUR="$1"
16
17   case $CUR in
18     '--prefix')
19       NNAS_INSTALL_PREFIX="$2"
20       shift 2
21       ;;
22     '--preset')
23       PRESET="$2"
24       shift 2
25       ;;
26     '--')
27       shift
28       while [ "$#" -ne 0 ]; do
29         EXTRA_OPTIONS+=("$1")
30         shift
31       done
32       ;;
33     *)
34       echo "ERROR: '${CUR}' is invalid"
35       exit 255
36       ;;
37   esac
38 done
39
40 # Q. Is it better to have the default value for NNAS_INSTALL_PREFIX?
41 # TODO Show USAGE
42 if [[ -z "${NNAS_INSTALL_PREFIX}" ]]; then
43   echo "ERROR: --prefix is not specified"
44   exit 255
45 fi
46
47 PRESET_PATH="${SCRIPT_PATH}/preset/${PRESET}"
48
49 if [[ ! -f "${PRESET_PATH}" ]]; then
50   echo "ERROR: ${PRESET} is unavailable"
51   # TODO Show available presets
52   exit 255
53 fi
54
55 echo "-- Use '${PRESET}' SDK preset"
56
57 source "${PRESET_PATH}"
58
59 # Normalize to absolute path
60 if [[ "${NNAS_INSTALL_PREFIX}" != /*  ]]; then
61     NNAS_INSTALL_PREFIX=${PWD}/${NNAS_INSTALL_PREFIX}
62 fi
63
64 if [[ -z "${NNAS_BUILD_PREFIX}" ]]; then
65   # Create a temporary directory and use it!
66   NNAS_BUILD_PREFIX=$(mktemp -d)
67   trap "{ rm -rf $NNAS_BUILD_PREFIX; }" EXIT
68 fi
69
70 # Create a release directory
71 mkdir -p "${NNAS_INSTALL_PREFIX}"
72
73 # Build and Install NNCC
74 NNCC_BUILD_PREFIX="${NNAS_BUILD_PREFIX}/nncc"
75 NNCC_INSTALL_PREFIX="${NNAS_INSTALL_PREFIX}"
76
77 mkdir -p "${NNCC_BUILD_PREFIX}"
78 cd "${NNCC_BUILD_PREFIX}"
79
80 function join_by
81 {
82   local IFS="$1"; shift; echo "$*"
83 }
84
85 # Invoke "preset_configure" function that the preset provides
86 preset_configure
87
88 NPROC=${NPROC:-$(cat /proc/cpuinfo | grep -c processor)}
89 echo "[BUILD] \"make\" with -j${NPROC} option. You can specify the number of jobs by defining NPROC"
90 cmake --build . -- -j$((NPROC/2)) all
91 cmake --build . -- install
92 # Install NN Package tools
93 NNPKG_INSTALL_PREFIX="${NNAS_INSTALL_PREFIX}"
94
95 # Invoke "preset_install" function that the preset provides
96 preset_install