merge_libs.sh 2.8 KB
Newer Older
Y
yejianwu 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
#!/bin/bash

Usage() {
  echo "Usage: bash tools/merge_libs.sh libmace_output_dir model_output_dirs"
}

if [ $# -lt 2 ]; then
  Usage
  exit 1
fi

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

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

rm -rf ${LIBMACE_BUILD_DIR}/libmace
Y
yejianwu 已提交
22
mkdir -p ${LIBMACE_BUILD_DIR}/libmace/include/mace/public
Y
yejianwu 已提交
23
mkdir -p ${LIBMACE_BUILD_DIR}/libmace/lib
24
mkdir -p ${MODEL_DATA_DIR}
Y
yejianwu 已提交
25
cp -rf ${MACE_SOURCE_DIR}/mace/public/*.h ${LIBMACE_BUILD_DIR}/libmace/include/mace/public/
Y
yejianwu 已提交
26
cp ${MACE_SOURCE_DIR}/mace/core/runtime/hexagon/libhexagon_controller.so ${LIBMACE_BUILD_DIR}/libmace/lib
Y
yejianwu 已提交
27 28 29

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

30
# Merge all libraries in to one
Y
yejianwu 已提交
31
echo "create ${LIBMACE_BUILD_DIR}/libmace/lib/libmace_${PROJECT_NAME}.a" > ${LIBMACE_TEMP_DIR}/libmace_${PROJECT_NAME}.mri
Y
yejianwu 已提交
32 33 34 35

if [ x"$TARGET_ABI" = x"host" ]; then
  echo "addlib bazel-bin/mace/codegen/libgenerated_opencl_prod.pic.a" >> ${LIBMACE_TEMP_DIR}/libmace_${PROJECT_NAME}.mri
  echo "addlib bazel-bin/mace/codegen/libgenerated_tuning_params.pic.a" >> ${LIBMACE_TEMP_DIR}/libmace_${PROJECT_NAME}.mri
Y
yejianwu 已提交
36
else
Y
yejianwu 已提交
37 38 39 40 41 42 43 44
  echo "addlib bazel-bin/mace/codegen/libgenerated_opencl_prod.a" >> ${LIBMACE_TEMP_DIR}/libmace_${PROJECT_NAME}.mri
  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/core/libopencl_prod.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
Y
yejianwu 已提交
45
fi
Y
yejianwu 已提交
46

47 48
for model_output_dir in ${MODEL_OUTPUT_DIRS_ARR[@]}; do
  for lib in ${model_output_dir}/*.a; do
Y
yejianwu 已提交
49
    echo "addlib ${lib}" >> ${LIBMACE_TEMP_DIR}/libmace_${PROJECT_NAME}.mri
50
  done
51 52 53 54 55 56
  for data_file in ${model_output_dir}/*.data; do
    cp ${data_file} ${MODEL_DATA_DIR}
  done
  for header_file in ${model_output_dir}/*.h; do
    cp ${header_file} ${MODEL_HEADER_DIR}
  done
57
done
Y
yejianwu 已提交
58 59
echo "save" >> ${LIBMACE_TEMP_DIR}/libmace_${PROJECT_NAME}.mri
echo "end" >> ${LIBMACE_TEMP_DIR}/libmace_${PROJECT_NAME}.mri
Y
yejianwu 已提交
60
$ANDROID_NDK_HOME/toolchains/aarch64-linux-android-4.9/prebuilt/linux-x86_64/bin/aarch64-linux-android-ar \
Y
yejianwu 已提交
61
    -M < ${LIBMACE_TEMP_DIR}/libmace_${PROJECT_NAME}.mri || exit 1
Y
yejianwu 已提交
62 63 64 65

rm -rf ${LIBMACE_TEMP_DIR}

echo "Libs merged!"