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