build.sh 18.9 KB
Newer Older
Y
Yan Chunwei 已提交
1
#!/bin/bash
2
set -ex
Y
Yan Chunwei 已提交
3 4 5 6 7 8 9 10 11

readonly CMAKE_COMMON_OPTIONS="-DWITH_GPU=OFF \
                               -DWITH_MKL=OFF \
                               -DWITH_LITE=ON \
                               -DLITE_WITH_CUDA=OFF \
                               -DLITE_WITH_X86=OFF \
                               -DLITE_WITH_ARM=ON \
                               -DLITE_WITH_LIGHT_WEIGHT_FRAMEWORK=ON"

12 13
readonly NUM_PROC=${LITE_BUILD_THREADS:-4}

14 15 16

# global variables
BUILD_EXTRA=OFF
17
BUILD_TRAIN=OFF
18
BUILD_JAVA=ON
19
BUILD_PYTHON=OFF
20
BUILD_DIR=$(pwd)
21 22
OPTMODEL_DIR=""
BUILD_TAILOR=OFF
23
BUILD_CV=OFF
24
WITH_LOG=ON
25
WITH_EXCEPTION=OFF
26
WITH_PROFILE=OFF
27 28 29
BUILD_NPU=OFF
NPU_DDK_ROOT="$(pwd)/ai_ddk_lib/" # Download HiAI DDK from https://developer.huawei.com/consumer/cn/hiai/
BUILD_XPU=OFF
30
BUILD_XTCL=OFF
31
XPU_SDK_ROOT="$(pwd)/xpu_sdk_lib/"
H
hong19860320 已提交
32 33
BUILD_APU=OFF
APU_DDK_ROOT="$(pwd)/apu_sdk_lib/"
34 35
BUILD_RKNPU=OFF
RKNPU_DDK_ROOT="$(pwd)/rknpu/"
36 37 38
WITH_HUAWEI_ASCEND_NPU=OFF # Huawei Ascend Builder/Runtime Libs on X86 host 
# default installation path, ensure acllib/atc/opp directories are all in this root dir
HUAWEI_ASCEND_NPU_DDK_ROOT="/usr/local/Ascend/ascend-toolkit/latest/x86_64-linux_gcc4.8.5"
39
PYTHON_EXECUTABLE_OPTION=""
40
ENABLE_FLATBUFFERS_DESC_VIEW=OFF
41
IOS_DEPLOYMENT_TARGET=9.0
42

43 44 45 46
readonly THIRDPARTY_TAR=https://paddle-inference-dist.bj.bcebos.com/PaddleLite/third-party-05b862.tar.gz

readonly workspace=$PWD

47
# if operating in mac env, we should expand the maximum file num
48 49
os_name=`uname -s`
if [ ${os_name} == "Darwin" ]; then
50 51 52
   ulimit -n 1024
fi

Y
Yan Chunwei 已提交
53 54 55
# for code gen, a source file is generated after a test, but is dependended by some targets in cmake.
# here we fake an empty file to make cmake works.
function prepare_workspace {
56 57
    local root_dir=$1
    local build_dir=$2
Y
Yan Chunwei 已提交
58 59
    # in build directory
    # 1. Prepare gen_code file
60 61 62
    GEN_CODE_PATH_PREFIX=$build_dir/lite/gen_code
    mkdir -p ${GEN_CODE_PATH_PREFIX}
    touch ${GEN_CODE_PATH_PREFIX}/__generated_code__.cc
Y
Yan Chunwei 已提交
63
    # 2.Prepare debug tool
64 65 66
    DEBUG_TOOL_PATH_PREFIX=$build_dir/lite/tools/debug
    mkdir -p ${DEBUG_TOOL_PATH_PREFIX}
    cp $root_dir/lite/tools/debug/analysis_tool.py ${DEBUG_TOOL_PATH_PREFIX}/
Y
Yan Chunwei 已提交
67 68
}

69 70 71 72 73 74 75 76 77 78 79 80 81 82

function prepare_opencl_source_code {
    local root_dir=$1
    local build_dir=$2
    # in build directory
    # Prepare opencl_kernels_source.cc file
    GEN_CODE_PATH_OPENCL=$root_dir/lite/backends/opencl
    rm -f GEN_CODE_PATH_OPENCL/opencl_kernels_source.cc
    OPENCL_KERNELS_PATH=$root_dir/lite/backends/opencl/cl_kernel
    mkdir -p ${GEN_CODE_PATH_OPENCL}
    touch $GEN_CODE_PATH_OPENCL/opencl_kernels_source.cc
    python $root_dir/lite/tools/cmake_tools/gen_opencl_code.py $OPENCL_KERNELS_PATH $GEN_CODE_PATH_OPENCL/opencl_kernels_source.cc 
}

83 84 85 86 87 88 89 90 91 92 93 94 95
function prepare_thirdparty {
    if [ ! -d $workspace/third-party -o -f $workspace/third-party-05b862.tar.gz ]; then
        rm -rf $workspace/third-party

        if [ ! -f $workspace/third-party-05b862.tar.gz ]; then
            wget $THIRDPARTY_TAR
        fi
        tar xzf third-party-05b862.tar.gz
    else
        git submodule update --init --recursive
    fi
}

96
function build_opt {
97
    cd $workspace
98
    prepare_thirdparty
99 100
    mkdir -p build.opt
    cd build.opt
101 102 103 104 105
    cmake .. -DWITH_LITE=ON \
      -DLITE_ON_MODEL_OPTIMIZE_TOOL=ON \
      -DWITH_TESTING=OFF \
      -DLITE_BUILD_EXTRA=ON \
      -DWITH_MKL=OFF
106
    make opt -j$NUM_PROC
107 108
}

Y
Yan Chunwei 已提交
109 110 111 112 113 114 115 116
function make_tiny_publish_so {
  local os=$1
  local abi=$2
  local lang=$3
  local android_stl=$4

  cur_dir=$(pwd)
  build_dir=$cur_dir/build.lite.${os}.${abi}.${lang}
S
sangoly 已提交
117 118 119 120
  if [ -d $build_dir ]
  then
    rm -rf $build_dir
  fi
Y
Yan Chunwei 已提交
121 122 123
  mkdir -p $build_dir
  cd $build_dir

124 125 126
  if [ ${os} == "armlinux" ]; then
    BUILD_JAVA=OFF
  fi
H
HappyAngel 已提交
127
  
Y
Yan Chunwei 已提交
128
  cmake .. \
129
      ${PYTHON_FLAGS} \
Y
Yan Chunwei 已提交
130 131
      ${CMAKE_COMMON_OPTIONS} \
      -DWITH_TESTING=OFF \
132
      -DLITE_WITH_JAVA=$BUILD_JAVA \
133
      -DLITE_WITH_PYTHON=$BUILD_PYTHON \
134
      -DLITE_WITH_LOG=$WITH_LOG \
135
      -DLITE_WITH_EXCEPTION=$WITH_EXCEPTION \
Y
Yan Chunwei 已提交
136 137
      -DLITE_ON_TINY_PUBLISH=ON \
      -DANDROID_STL_TYPE=$android_stl \
138
      -DLITE_BUILD_EXTRA=$BUILD_EXTRA \
139
      -DLITE_WITH_CV=$BUILD_CV \
140 141
      -DLITE_BUILD_TAILOR=$BUILD_TAILOR \
      -DLITE_OPTMODEL_DIR=$OPTMODEL_DIR \
142 143 144
      -DLITE_WITH_NPU=$BUILD_NPU \
      -DNPU_DDK_ROOT=$NPU_DDK_ROOT \
      -DLITE_WITH_XPU=$BUILD_XPU \
145
      -DLITE_WITH_XTCL=$BUILD_XTCL \
146
      -DXPU_SDK_ROOT=$XPU_SDK_ROOT \
H
hong19860320 已提交
147 148
      -DLITE_WITH_APU=$BUILD_APU \
      -DAPU_DDK_ROOT=$APU_DDK_ROOT \
149 150
      -DLITE_WITH_RKNPU=$BUILD_RKNPU \
      -DRKNPU_DDK_ROOT=$RKNPU_DDK_ROOT \
151 152
      -DARM_TARGET_OS=${os} -DARM_TARGET_ARCH_ABI=${abi} -DARM_TARGET_LANG=${lang} \
      -DLITE_ON_FLATBUFFERS_DESC_VIEW=${ENABLE_FLATBUFFERS_DESC_VIEW}
Y
Yan Chunwei 已提交
153

154
  make publish_inference -j$NUM_PROC
Y
Yan Chunwei 已提交
155 156 157
  cd - > /dev/null
}

158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189
function make_opencl {
  local os=$1
  local abi=$2
  local lang=$3
  #git submodule update --init --recursive
  prepare_thirdparty

  root_dir=$(pwd)
  build_dir=$root_dir/build.lite.${os}.${abi}.${lang}.opencl
  if [ -d $build_directory ]
  then
  rm -rf $build_directory
  fi
  mkdir -p $build_dir
  cd $build_dir
  prepare_workspace $root_dir $build_dir
  prepare_opencl_source_code $root_dir $build_dir
  # $1: ARM_TARGET_OS in "android" , "armlinux"
  # $2: ARM_TARGET_ARCH_ABI in "armv8", "armv7" ,"armv7hf"
  # $3: ARM_TARGET_LANG in "gcc" "clang"
  cmake .. \
      -DLITE_WITH_OPENCL=ON \
      -DWITH_GPU=OFF \
      -DWITH_MKL=OFF \
      -DWITH_LITE=ON \
      -DLITE_WITH_CUDA=OFF \
      -DLITE_WITH_X86=OFF \
      -DLITE_WITH_ARM=ON \
      -DWITH_ARM_DOTPROD=ON   \
      -DLITE_ON_TINY_PUBLISH=ON \
      -DLITE_WITH_LIGHT_WEIGHT_FRAMEWORK=ON \
      -DWITH_TESTING=OFF \
190
      -DLITE_BUILD_EXTRA=$BUILD_EXTRA \
191
      -DLITE_WITH_LOG=$WITH_LOG \
192
      -DLITE_WITH_EXCEPTION=$WITH_EXCEPTION \
193
      -DLITE_WITH_CV=$BUILD_CV \
194 195
      -DARM_TARGET_OS=$1 -DARM_TARGET_ARCH_ABI=$2 -DARM_TARGET_LANG=$3

196 197
    make opencl_clhpp -j$NUM_PROC
    make publish_inference -j$NUM_PROC
198 199
}

Y
Yan Chunwei 已提交
200 201 202 203 204 205
function make_full_publish_so {
  local os=$1
  local abi=$2
  local lang=$3
  local android_stl=$4

206 207
  #git submodule update --init --recursive
  prepare_thirdparty
208

209 210 211 212
  root_dir=$(pwd)
  build_directory=$BUILD_DIR/build.lite.${os}.${abi}.${lang}

  if [ -d $build_directory ]
S
sangoly 已提交
213
  then
214
    rm -rf $build_directory
S
sangoly 已提交
215
  fi
216 217
  mkdir -p $build_directory
  cd $build_directory
218

219 220 221
  if [ ${os} == "armlinux" ]; then
    BUILD_JAVA=OFF
  fi
Y
Yan Chunwei 已提交
222

223 224
  prepare_workspace $root_dir $build_directory
  cmake $root_dir \
225
      ${PYTHON_FLAGS} \
Y
Yan Chunwei 已提交
226 227
      ${CMAKE_COMMON_OPTIONS} \
      -DWITH_TESTING=OFF \
228
      -DLITE_WITH_JAVA=$BUILD_JAVA \
229
      -DLITE_WITH_PYTHON=$BUILD_PYTHON \
230
      -DLITE_WITH_LOG=$WITH_LOG \
231
      -DLITE_WITH_EXCEPTION=$WITH_EXCEPTION \
232
      -DLITE_WITH_PROFILE=${WITH_PROFILE} \
Y
Yan Chunwei 已提交
233
      -DANDROID_STL_TYPE=$android_stl \
234
      -DLITE_BUILD_EXTRA=$BUILD_EXTRA \
235
      -DLITE_WITH_CV=$BUILD_CV \
236 237
      -DLITE_BUILD_TAILOR=$BUILD_TAILOR \
      -DLITE_OPTMODEL_DIR=$OPTMODEL_DIR \
238 239 240
      -DLITE_WITH_NPU=$BUILD_NPU \
      -DNPU_DDK_ROOT=$NPU_DDK_ROOT \
      -DLITE_WITH_XPU=$BUILD_XPU \
241
      -DLITE_WITH_XTCL=$BUILD_XTCL \
242
      -DXPU_SDK_ROOT=$XPU_SDK_ROOT \
243 244
      -DLITE_WITH_RKNPU=$BUILD_RKNPU \
      -DRKNPU_DDK_ROOT=$RKNPU_DDK_ROOT \
245
      -DLITE_WITH_TRAIN=$BUILD_TRAIN \
H
hong19860320 已提交
246 247
      -DLITE_WITH_APU=$BUILD_APU \
      -DAPU_DDK_ROOT=$APU_DDK_ROOT \
Y
Yan Chunwei 已提交
248 249
      -DARM_TARGET_OS=${os} -DARM_TARGET_ARCH_ABI=${abi} -DARM_TARGET_LANG=${lang}

250
  make publish_inference -j$NUM_PROC
Y
Yan Chunwei 已提交
251 252 253 254 255 256 257 258
  cd - > /dev/null
}

function make_all_tests {
  local os=$1
  local abi=$2
  local lang=$3

259 260
  #git submodule update --init --recursive
  prepare_thirdparty
261 262
  root_dir=$(pwd)
  build_directory=$BUILD_DIR/build.lite.${os}.${abi}.${lang}
S
sangoly 已提交
263 264 265 266
  if [ -d $build_dir ]
  then
    rm -rf $build_dir
  fi
267 268
  mkdir -p $build_directory
  cd $build_directory
H
HappyAngel 已提交
269
 
270 271
  prepare_workspace $root_dir $build_directory
  cmake $root_dir \
Y
Yan Chunwei 已提交
272 273
      ${CMAKE_COMMON_OPTIONS} \
      -DWITH_TESTING=ON \
H
HappyAngel 已提交
274 275
      -DLITE_WITH_PROFILE=OFF \
      -DLITE_WITH_PRECISION_PROFILE=OFF \
276
      -DLITE_BUILD_EXTRA=$BUILD_EXTRA \
277
      -DLITE_WITH_CV=$BUILD_CV \
278 279 280
      -DLITE_WITH_NPU=$BUILD_NPU \
      -DNPU_DDK_ROOT=$NPU_DDK_ROOT \
      -DLITE_WITH_XPU=$BUILD_XPU \
281
      -DLITE_WITH_XTCL=$BUILD_XTCL \
282
      -DXPU_SDK_ROOT=$XPU_SDK_ROOT \
H
hong19860320 已提交
283 284
      -DLITE_WITH_APU=$BUILD_APU \
      -DAPU_DDK_ROOT=$APU_DDK_ROOT \
285 286
      -DLITE_WITH_RKNPU=$BUILD_RKNPU \
      -DRKNPU_DDK_ROOT=$RKNPU_DDK_ROOT \
Y
Yan Chunwei 已提交
287 288
      -DARM_TARGET_OS=${os} -DARM_TARGET_ARCH_ABI=${abi} -DARM_TARGET_LANG=${lang}

289
  make lite_compile_deps -j$NUM_PROC
Y
Yan Chunwei 已提交
290 291 292
  cd - > /dev/null
}

X
Xiaoyang LI 已提交
293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314
function make_ios {
    local os=$1
    local abi=$2
    build_dir=build.ios.${os}.${abi}
    echo "building ios target into $build_dir"
    echo "target os: $os"
    echo "target abi: $abi"
    mkdir -p ${build_dir}
    cd ${build_dir}
    GEN_CODE_PATH_PREFIX=lite/gen_code
    mkdir -p ./${GEN_CODE_PATH_PREFIX}
    touch ./${GEN_CODE_PATH_PREFIX}/__generated_code__.cc

    cmake .. \
            -DWITH_GPU=OFF \
            -DWITH_MKL=OFF \
            -DWITH_LITE=ON \
            -DLITE_WITH_CUDA=OFF \
            -DLITE_WITH_X86=OFF \
            -DLITE_WITH_ARM=ON \
            -DWITH_TESTING=OFF \
            -DLITE_WITH_JAVA=OFF \
315
            -DLITE_WITH_LOG=ON \
X
Xiaoyang LI 已提交
316 317 318
            -DLITE_ON_TINY_PUBLISH=ON \
            -DLITE_WITH_OPENMP=OFF \
            -DWITH_ARM_DOTPROD=OFF \
319 320
            -DLITE_BUILD_TAILOR=$BUILD_TAILOR \
            -DLITE_OPTMODEL_DIR=$OPTMODEL_DIR \
X
Xiaoyang LI 已提交
321 322 323
            -DLITE_WITH_LIGHT_WEIGHT_FRAMEWORK=ON \
            -DARM_TARGET_ARCH_ABI=$abi \
            -DLITE_BUILD_EXTRA=$BUILD_EXTRA \
324
            -DLITE_WITH_CV=$BUILD_CV \
325
            -DDEPLOYMENT_TARGET=${IOS_DEPLOYMENT_TARGET} \
X
Xiaoyang LI 已提交
326 327
            -DARM_TARGET_OS=$os

328
    make publish_inference -j$NUM_PROC
X
Xiaoyang LI 已提交
329 330 331
    cd -
}

332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355
function make_cuda {
  prepare_thirdparty

  root_dir=$(pwd)
  build_directory=$BUILD_DIR/build_cuda

  if [ -d $build_directory ]
  then
    rm -rf $build_directory
  fi
  mkdir -p $build_directory
  cd $build_directory

  prepare_workspace $root_dir $build_directory

  cmake ..  -DWITH_MKL=OFF       \
            -DLITE_WITH_CUDA=ON  \
            -DWITH_MKLDNN=OFF    \
            -DLITE_WITH_X86=OFF  \
            -DLITE_WITH_PROFILE=OFF \
            -DWITH_LITE=ON \
            -DLITE_WITH_LIGHT_WEIGHT_FRAMEWORK=OFF \
            -DWITH_TESTING=OFF \
            -DLITE_WITH_ARM=OFF \
356
            -DLITE_WITH_STATIC_CUDA=OFF \
357
            -DLITE_WITH_PYTHON=${BUILD_PYTHON} \
358
            -DLITE_BUILD_EXTRA=ON \
359 360
            -DLITE_WITH_LOG=${WITH_LOG} \
            -DLITE_WITH_EXCEPTION=$WITH_EXCEPTION \
361 362 363
            -DLITE_WITH_XPU=$BUILD_XPU \
            -DLITE_WITH_XTCL=$BUILD_XTCL \
            -DXPU_SDK_ROOT=$XPU_SDK_ROOT
364
 
365
  make -j$NUM_PROC
366
  make publish_inference -j$NUM_PROC
367 368
  cd -
}
Y
Yan Chunwei 已提交
369

H
huzhiqiang 已提交
370 371 372 373
function make_x86 {
  prepare_thirdparty

  root_dir=$(pwd)
374
  build_directory=$BUILD_DIR/build.lite.x86
H
huzhiqiang 已提交
375

376 377 378 379 380
  if [ ${WITH_HUAWEI_ASCEND_NPU} == "ON" ]; then
    export CXX=/usr/bin/g++ # Ascend need g++ in centos
    build_directory=$BUILD_DIR/build.lite.huawei_ascend_npu
  fi

H
huzhiqiang 已提交
381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397
  if [ -d $build_directory ]
  then
    rm -rf $build_directory
  fi
  mkdir -p $build_directory
  cd $build_directory

  prepare_workspace $root_dir $build_directory

  cmake ..  -DWITH_MKL=ON       \
            -DWITH_MKLDNN=OFF    \
            -DLITE_WITH_X86=ON  \
            -DLITE_WITH_PROFILE=OFF \
            -DWITH_LITE=ON \
            -DLITE_WITH_LIGHT_WEIGHT_FRAMEWORK=OFF \
            -DLITE_WITH_ARM=OFF \
            -DWITH_GPU=OFF \
398
            -DLITE_SHUTDOWN_LOG=ON \
399
            -DLITE_WITH_PYTHON=${BUILD_PYTHON} \
400
            -DLITE_BUILD_EXTRA=ON \
401
            -DLITE_WITH_LOG=${WITH_LOG} \
402
            -DLITE_WITH_EXCEPTION=$WITH_EXCEPTION \
403
            -DLITE_WITH_PROFILE=${WITH_PROFILE} \
404 405 406
            -DLITE_WITH_XPU=$BUILD_XPU \
            -DLITE_WITH_XTCL=$BUILD_XTCL \
            -DXPU_SDK_ROOT=$XPU_SDK_ROOT \
407 408
            -DLITE_WITH_HUAWEI_ASCEND_NPU=$WITH_HUAWEI_ASCEND_NPU \
            -DHUAWEI_ASCEND_NPU_DDK_ROOT=$HUAWEI_ASCEND_NPU_DDK_ROOT \
409
            -DCMAKE_BUILD_TYPE=Release \
410
            -DPY_VERSION=$PY_VERSION \
411
            $PYTHON_EXECUTABLE_OPTION
412
  make publish_inference -j$NUM_PROC
H
huzhiqiang 已提交
413 414 415
  cd -
}

Y
Yan Chunwei 已提交
416
function print_usage {
417
    set +x
Y
Yan Chunwei 已提交
418 419 420 421
    echo -e "\nUSAGE:"
    echo
    echo "----------------------------------------"
    echo -e "compile tiny publish so lib:"
X
Xiaoyang LI 已提交
422
    echo -e "for android:"
Y
Yan Chunwei 已提交
423
    echo -e "   ./build.sh --arm_os=<os> --arm_abi=<abi> --arm_lang=<lang> --android_stl=<stl> tiny_publish"
X
Xiaoyang LI 已提交
424 425
    echo -e "for ios:"
    echo -e "   ./build.sh --arm_os=<os> --arm_abi=<abi> ios"
Y
Yan Chunwei 已提交
426
    echo
X
Xiaoyang LI 已提交
427
    echo -e "compile full publish so lib (ios not support):"
Y
Yan Chunwei 已提交
428 429
    echo -e "   ./build.sh --arm_os=<os> --arm_abi=<abi> --arm_lang=<lang> --android_stl=<stl> full_publish"
    echo
X
Xiaoyang LI 已提交
430
    echo -e "compile all arm tests (ios not support):"
Y
Yan Chunwei 已提交
431 432
    echo -e "   ./build.sh --arm_os=<os> --arm_abi=<abi> --arm_lang=<lang> test"
    echo
433
    echo -e "optional argument:"
434
    echo -e "--with_log: (OFF|ON); controls whether to print log information, default is ON"
435
    echo -e "--with_exception: (OFF|ON); controls whether to throw the exception when error occurs, default is OFF"
436
    echo -e "--build_extra: (OFF|ON); controls whether to publish extra operators and kernels for (sequence-related model such as OCR or NLP)"
437
    echo -e "--build_train: (OFF|ON); controls whether to publish training operators and kernels, build_train is only for full_publish library now"
438 439
    echo -e "--build_python: (OFF|ON); controls whether to publish python api lib (ANDROID and IOS is not supported)"
    echo -e "--build_java: (OFF|ON); controls whether to publish java api lib (Only ANDROID is supported)"
440
    echo -e "--build_dir: directory for building"
441
    echo -e "--enable_flatbuffers_view: (OFF|ON); Use the flatbuffers read-only view to load the model. If ON, the naive buffer will no longer be supported."
442
    echo -e "--ios_deployment_target: (default: 9.0); Set the minimum compatible system version for ios deployment."
Y
Yan Chunwei 已提交
443
    echo
444
    echo -e "argument choices:"
X
Xiaoyang LI 已提交
445
    echo -e "--arm_os:\t android|ios|ios64"
Y
Yan Chunwei 已提交
446
    echo -e "--arm_abi:\t armv8|armv7"
447
    echo -e "--arm_lang:\t only support gcc now, clang will be supported in future.(for android)"
X
Xiaoyang LI 已提交
448
    echo -e "--android_stl:\t c++_static|c++_shared (for android)"
Y
Yan Chunwei 已提交
449 450 451 452 453 454
    echo
    echo -e "tasks:"
    echo
    echo -e "tiny_publish: a small library for deployment."
    echo -e "full_publish: a full library for debug and test."
    echo -e "test: produce all the unittests."
Y
Yan Chunwei 已提交
455 456 457 458 459
    echo "----------------------------------------"
    echo
}

function main {
Y
Yan Chunwei 已提交
460 461 462 463 464
    if [ -z "$1" ]; then
        print_usage
        exit -1
    fi

Y
Yan Chunwei 已提交
465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483
    # Parse command line.
    for i in "$@"; do
        case $i in
            --arm_os=*)
                ARM_OS="${i#*=}"
                shift
                ;;
            --arm_abi=*)
                ARM_ABI="${i#*=}"
                shift
                ;;
            --arm_lang=*)
                ARM_LANG="${i#*=}"
                shift
                ;;
            --android_stl=*)
                ANDROID_STL="${i#*=}"
                shift
                ;;
484 485 486 487
            --build_extra=*)
                BUILD_EXTRA="${i#*=}"
                shift
                ;;
488 489 490 491
            --build_train=*)
                BUILD_TRAIN="${i#*=}"
                shift
                ;;
Y
Yuan Shuai 已提交
492 493 494 495
            --build_cv=*)
                BUILD_CV="${i#*=}"
                shift
                ;;
496 497 498 499 500 501 502 503
            --build_python=*)
                BUILD_PYTHON="${i#*=}"
                shift
                ;;
            --build_java=*)
                BUILD_JAVA="${i#*=}"
                shift
                ;;
504 505 506
            --build_dir=*)
                BUILD_DIR="${i#*=}"
                shift
507
		;;
508 509 510 511 512 513 514 515
            --opt_model_dir=*)
                OPTMODEL_DIR="${i#*=}"
                shift
                ;;
            --build_tailor=*)
                BUILD_TAILOR="${i#*=}"
                shift
                ;;
516 517
            --with_log=*)
                WITH_LOG="${i#*=}"
518 519
                shift
                ;;
520 521 522 523 524 525 526 527 528 529 530
            --with_exception=*)
                WITH_EXCEPTION="${i#*=}"
                if [[ $WITH_EXCEPTION == "ON" && $ARM_OS=="android" && $ARM_ABI == "armv7" && $ARM_LANG != "clang" ]]; then
                     set +x
                     echo
                     echo -e "error: only clang provide C++ exception handling support for 32-bit ARM."
                     echo
                     exit 1
                fi
                shift
                ;;
531 532 533 534
            --with_profile=*)
                WITH_PROFILE="${i#*=}"
                shift
                ;;
535 536 537 538
            --build_npu=*)
                BUILD_NPU="${i#*=}"
                shift
                ;;
539
            --npu_ddk_root=*)
540 541 542 543 544 545 546
                NPU_DDK_ROOT="${i#*=}"
                shift
                ;;
            --build_xpu=*)
                BUILD_XPU="${i#*=}"
                shift
                ;;
547 548 549 550
            --build_xtcl=*)
                BUILD_XTCL="${i#*=}"
                shift
                ;;
551 552 553 554
            --xpu_sdk_root=*)
                XPU_SDK_ROOT="${i#*=}"
                shift
                ;;
555 556 557 558
            --python_executable=*)
                PYTHON_EXECUTABLE_OPTION="-DPYTHON_EXECUTABLE=${i#*=}"
                shift
                ;;
559 560 561 562
            --python_version=*)
                PY_VERSION="${i#*=}"
                shift
                ;;
H
hong19860320 已提交
563 564 565 566 567 568 569 570
            --build_apu=*)
                BUILD_APU="${i#*=}"
                shift
                ;;
           --apu_ddk_root=*)
                APU_DDK_ROOT="${i#*=}"
                shift
                ;;
571 572 573 574 575 576 577 578
            --build_rknpu=*)
                BUILD_RKNPU="${i#*=}"
                shift
                ;;
            --rknpu_ddk_root=*)
                RKNPU_DDK_ROOT="${i#*=}"
                shift
                ;;
579 580 581 582 583 584 585 586
            --with_huawei_ascend_npu=*)
                WITH_HUAWEI_ASCEND_NPU="${i#*=}"
                shift
                ;;
            --huawei_ascend_npu_ddk_root=*)
                HUAWEI_ASCEND_NPU_DDK_ROOT="${i#*=}"
                shift
                ;;
587 588 589 590
            --enable_flatbuffers_view=*)
                ENABLE_FLATBUFFERS_DESC_VIEW="${i#*=}"
                shift
                ;;
591 592 593 594
            --ios_deployment_target=*)
                IOS_DEPLOYMENT_TARGET="${i#*=}"
                shift
                ;;
Y
Yan Chunwei 已提交
595
            tiny_publish)
596
                make_tiny_publish_so $ARM_OS $ARM_ABI $ARM_LANG $ANDROID_STL 
Y
Yan Chunwei 已提交
597 598 599
                shift
                ;;
            full_publish)
600
                make_full_publish_so $ARM_OS $ARM_ABI $ARM_LANG $ANDROID_STL 
Y
Yan Chunwei 已提交
601 602 603 604 605 606
                shift
                ;;
            test)
                make_all_tests $ARM_OS $ARM_ABI $ARM_LANG
                shift
                ;;
X
Xiaoyang LI 已提交
607 608 609 610
            ios)
                make_ios $ARM_OS $ARM_ABI
                shift
                ;;
611
            build_optimize_tool)
612
                build_opt
613 614
                shift
                ;;
615 616 617 618
            opencl)
                make_opencl $ARM_OS $ARM_ABI $ARM_LANG
                shift
                ;;
619
            cuda)
620
                make_cuda
621 622
                shift
                ;;
H
huzhiqiang 已提交
623 624 625 626
            x86)
               make_x86
               shift
               ;;
Y
Yan Chunwei 已提交
627 628 629 630 631 632 633 634 635 636
            *)
                # unknown option
                print_usage
                exit 1
                ;;
        esac
    done
}

main $@