merge_libs.sh 3.0 KB
Newer Older
Y
yejianwu 已提交
1 2 3
#!/bin/bash

Usage() {
Y
yejianwu 已提交
4
  echo "Usage: bash tools/merge_libs.sh target_soc libmace_output_dir model_output_dirs"
Y
yejianwu 已提交
5 6
}

Y
yejianwu 已提交
7
if [ $# -lt 3 ]; then
Y
yejianwu 已提交
8 9 10 11 12 13 14
  Usage
  exit 1
fi

CURRENT_DIR=`dirname $0`
source ${CURRENT_DIR}/env.sh

Y
yejianwu 已提交
15 16 17
TARGET_SOC=$1
LIBMACE_BUILD_DIR=$2
MODEL_OUTPUT_DIRS=$3
Y
yejianwu 已提交
18
MODEL_OUTPUT_DIRS_ARR=(${MODEL_OUTPUT_DIRS//,/ })
Y
yejianwu 已提交
19 20
MODEL_HEADER_DIR=${LIBMACE_BUILD_DIR}/include/mace/public
MODEL_DATA_DIR=${LIBMACE_BUILD_DIR}/data
Y
yejianwu 已提交
21

Y
yejianwu 已提交
22 23 24
if [ ! -d "${MODEL_HEADER_DIR}" ]; then
  mkdir -p ${MODEL_HEADER_DIR}
fi
Y
yejianwu 已提交
25 26
cp -rf ${MACE_SOURCE_DIR}/mace/public/*.h ${LIBMACE_BUILD_DIR}/include/mace/public/

Y
yejianwu 已提交
27 28 29 30 31 32 33
if [ ! -d "${LIBMACE_BUILD_DIR}/${TARGET_ABI}" ]; then
  mkdir -p ${LIBMACE_BUILD_DIR}/${TARGET_ABI}
fi
if [ ! -d "${MODEL_DATA_DIR}" ]; then
  mkdir -p ${MODEL_DATA_DIR}
fi

Y
yejianwu 已提交
34 35 36
if [ x"${TARGET_ABI}" = x"armeabi-v7a" ]; then
  cp ${MACE_SOURCE_DIR}/mace/core/runtime/hexagon/libhexagon_controller.so ${LIBMACE_BUILD_DIR}/${TARGET_ABI}/
fi
Y
yejianwu 已提交
37 38 39

LIBMACE_TEMP_DIR=`mktemp -d -t libmace.XXXX`

40
# Merge all libraries in to one
Y
yejianwu 已提交
41
echo "create ${LIBMACE_BUILD_DIR}/${TARGET_ABI}/libmace_${PROJECT_NAME}.${TARGET_SOC}.a" > ${LIBMACE_TEMP_DIR}/libmace_${PROJECT_NAME}.mri
Y
yejianwu 已提交
42 43

if [ x"$TARGET_ABI" = x"host" ]; then
L
liuqi 已提交
44
  echo "addlib bazel-bin/mace/codegen/libgenerated_opencl.pic.a" >> ${LIBMACE_TEMP_DIR}/libmace_${PROJECT_NAME}.mri
Y
yejianwu 已提交
45
  echo "addlib bazel-bin/mace/codegen/libgenerated_tuning_params.pic.a" >> ${LIBMACE_TEMP_DIR}/libmace_${PROJECT_NAME}.mri
Y
yejianwu 已提交
46
else
L
liuqi 已提交
47
  echo "addlib bazel-bin/mace/codegen/libgenerated_opencl.a" >> ${LIBMACE_TEMP_DIR}/libmace_${PROJECT_NAME}.mri
Y
yejianwu 已提交
48 49 50 51 52 53
  echo "addlib bazel-bin/mace/codegen/libgenerated_tuning_params.a" >> ${LIBMACE_TEMP_DIR}/libmace_${PROJECT_NAME}.mri
  echo "addlib bazel-bin/mace/codegen/libgenerated_version.a" >> ${LIBMACE_TEMP_DIR}/libmace_${PROJECT_NAME}.mri
  echo "addlib bazel-bin/mace/core/libcore.a" >> ${LIBMACE_TEMP_DIR}/libmace_${PROJECT_NAME}.mri
  echo "addlib bazel-bin/mace/kernels/libkernels.a" >> ${LIBMACE_TEMP_DIR}/libmace_${PROJECT_NAME}.mri
  echo "addlib bazel-bin/mace/utils/libutils.a" >> ${LIBMACE_TEMP_DIR}/libmace_${PROJECT_NAME}.mri
  echo "addlib bazel-bin/mace/utils/libutils_prod.a" >> ${LIBMACE_TEMP_DIR}/libmace_${PROJECT_NAME}.mri
54
  echo "addlib bazel-bin/mace/ops/libops.lo" >> ${LIBMACE_TEMP_DIR}/libmace_${PROJECT_NAME}.mri
Y
yejianwu 已提交
55
fi
Y
yejianwu 已提交
56

57 58
for model_output_dir in ${MODEL_OUTPUT_DIRS_ARR[@]}; do
  for lib in ${model_output_dir}/*.a; do
Y
yejianwu 已提交
59
    echo "addlib ${lib}" >> ${LIBMACE_TEMP_DIR}/libmace_${PROJECT_NAME}.mri
60
  done
61 62 63 64 65
  if [ "${EMBED_MODEL_DATA}" == "0" ];then
    for data_file in ${model_output_dir}/*.data; do
      cp ${data_file} ${MODEL_DATA_DIR}
    done
  fi
66 67 68
  for header_file in ${model_output_dir}/*.h; do
    cp ${header_file} ${MODEL_HEADER_DIR}
  done
69
done
Y
yejianwu 已提交
70 71
echo "save" >> ${LIBMACE_TEMP_DIR}/libmace_${PROJECT_NAME}.mri
echo "end" >> ${LIBMACE_TEMP_DIR}/libmace_${PROJECT_NAME}.mri
Y
yejianwu 已提交
72
$ANDROID_NDK_HOME/toolchains/aarch64-linux-android-4.9/prebuilt/linux-x86_64/bin/aarch64-linux-android-ar \
Y
yejianwu 已提交
73
    -M < ${LIBMACE_TEMP_DIR}/libmace_${PROJECT_NAME}.mri || exit 1
Y
yejianwu 已提交
74 75 76 77

rm -rf ${LIBMACE_TEMP_DIR}

echo "Libs merged!"