Introduce configure script (#3180)
author오형석/동작제어Lab(SR)/Staff Engineer/삼성전자 <hseok82.oh@samsung.com>
Thu, 18 Oct 2018 06:17:21 +0000 (15:17 +0900)
committerGitHub Enterprise <noreply-CODE@samsung.com>
Thu, 18 Oct 2018 06:17:21 +0000 (15:17 +0900)
* Introduce configure script

Introduce configure script
- prepare to use this script instead of Makefile
- Howto: On project root, "./run configure" with environment variable setting

Signed-off-by: Hyeongseok Oh <hseok82.oh@samsung.com>
* Fix

- Generate install path and alias
- Change variable name for build/install path alias

Signed-off-by: Hyeongseok Oh <hseok82.oh@samsung.com>
* Fix and remove unused variable

- Remove unused variable
- Fix bug: string compare to substring

* Change all tab to space

scripts/build.configuration [new file with mode: 0644]
scripts/command/configure [new file with mode: 0644]

diff --git a/scripts/build.configuration b/scripts/build.configuration
new file mode 100644 (file)
index 0000000..cdbf3bf
--- /dev/null
@@ -0,0 +1,5 @@
+WORKSPACE_RPATH=${NNFW_WORKSPACE:-Product}
+
+# Soft link path to build and install directory
+BUILD_ALIAS=${NNFW_PROJECT_PATH}/${WORKSPACE_RPATH}/obj
+INSTALL_ALIAS=${NNFW_PROJECT_PATH}/${WORKSPACE_RPATH}/out
diff --git a/scripts/command/configure b/scripts/command/configure
new file mode 100644 (file)
index 0000000..4e4ae8c
--- /dev/null
@@ -0,0 +1,84 @@
+#!/bin/bash
+
+source "${NNFW_SCRIPT_PATH}/build.configuration"
+
+# Set target platform using environment variable
+# TODO: use argument instead of environment variable
+TARGET_ARCH=${TARGET_ARCH:-$(uname -p)}
+BUILD_TYPE=${BUILD_TYPE:-Debug}
+CROSS_BUILD=${CROSS_BUILD:-0}
+HOST_OS=${HOST_OS:-linux}
+TARGET_OS=${TARGET_OS:-linux}
+## TODO: fix obs build break
+OBS_BUILD=${OBS_BUILD:-OFF}
+COVERAGE_BUILD=${COVERAGE_BUILD:-0}
+BENCHMARK_ACL_BUILD=${BENCHMARK_ACL_BUILD:-0}
+OPTIONS=${OPTIONS:-}
+
+# make TARGET and TYPE to lowercase
+TARGET_ARCH_LC="$(echo ${TARGET_ARCH} | tr A-Z a-z)"
+BUILD_TYPE_LC="$(echo ${BUILD_TYPE} | tr A-Z a-z)"
+
+if [ "${TARGET_ARCH_LC}" == *"arm64"* ]; then
+  # arm64 as target-arch comes from Android
+  if [ ! -z ${ROOTFS_DIR} ]; then
+    ROOTFS_ARM64="${ROOTFS_DIR}"
+    export ROOTFS_ARM64
+  fi
+  # For now Android is the only option for arm64
+  TARGET_OS=android
+elif [ "${TARGET_ARCH_LC}" == *"arm"* ]; then
+  if [ ! -z ${ROOTFS_DIR} ] ; then
+    ROOTFS_ARM="${ROOTFS_DIR}"
+    export ROOTFS_ARM
+  fi
+elif [ "${TARGET_ARCH_LC}" == *"aarch64"* ]; then
+  # aarch64 as target-arch comes from all except for Android
+  if [ ! -z ${ROOTFS_DIR} ] ; then
+    ROOTFS_ARM64="${ROOTFS_DIR}"
+    export ROOTFS_ARM64
+  fi
+fi
+
+# Todo: we may set CROSS_BUILD=1 when ROOTFS_DIR is given
+# the toolchain file, only for cross build
+if [ "${CROSS_BUILD}" == "1" ]; then
+  TOOLCHAIN_FILE="cmake/config/config_${TARGET_ARCH_LC}-${TARGET_OS}.cmake"
+  OPTION_TOOLCHAIN="-DCMAKE_TOOLCHAIN_FILE=${TOOLCHAIN_FILE}"
+else
+  OPTION_TOOLCHAIN=
+fi
+
+if [ "${COVERAGE_BUILD}" == "1" ]; then
+  OPTIONS+=" -DCOVERAGE_BUILD=1"
+else
+  OPTIONS+=" -DCOVERAGE_BUILD=0"
+fi
+
+if [ "${BENCHMARK_ACL_BUILD}" ==  "1" ]; then
+  OPTIONS+=" -DBUILD_BENCHMARK_ACL=1"
+fi
+
+WORK_FOLDER=${TARGET_ARCH_LC}-${TARGET_OS}.${BUILD_TYPE_LC}
+WORK_PATH=${NNFW_PROJECT_PATH}/${WORKSPACE_RPATH}/${WORK_FOLDER}
+BUILD_PATH=${WORK_PATH}/obj
+INSTALL_PATH=${NNFW_INSTALL_PATH:-${WORK_PATH}/out}
+
+mkdir -vp ${BUILD_PATH}
+mkdir -vp ${INSTALL_PATH}
+rm -rf ${BUILD_ALIAS}
+rm -rf ${INSTALL_ALIAS}
+ln -s ${BUILD_PATH} ${BUILD_ALIAS}
+ln -s ${INSTALL_PATH} ${INSTALL_ALIAS}
+
+cd "${BUILD_PATH}"
+
+cmake \
+  -DCMAKE_INSTALL_PREFIX=${INSTALL_PATH} \
+  -DCMAKE_BUILD_TYPE=${BUILD_TYPE_LC} -DTARGET_ARCH=${TARGET_ARCH_LC} \
+  -DHOST_OS=${HOST_OS} \
+  -DTARGET_OS=${TARGET_OS} \
+  -DOBS_BUILD=${OBS_BUILD} \
+  ${OPTION_TOOLCHAIN} \
+  ${OPTIONS} \
+  "${NNFW_PROJECT_PATH}" "$@"