#!/bin/bash
#android_build.sh
#ndk的路径,替换为自己的路径
export NDK_PATH=android-ndk-r16b
#将要构建的架构
TARGETS=(arm64-v8a armeabi armeabi-v7a mips mips64 x86 x86_64)
#清除build文件夹下的内容
function clean_build() {
if ([ -d build ]); then
echo "prepare to clean cache"
(rm -rf ./build/*)
echo "complete"
else
echo "build is not a directory"
exit 0
fi
}
function prepare_build() {
# 检测是否有Build文件夹,有的话删除文件夹,没有的话创建文件夹
if ([ -e build ]); then
echo "you already have build dir"
clean_build
else
echo "prepare to create dir build"
mkdir build
fi
}
function prepare_target() {
#检测是否有所有的target文件夹,有则删除,没有则创建
#文件存在且为目录
if ([ -e target ] && [ -d target ]); then
echo "prepare to clean target"
rm -rf ./target/*
echo "clean target complete"
else
echo "you not have target_dir,we will create it"
mkdir target
fi
}
function create_child_dir() {
if ([ -e target ]); then
(
cd target
mkdir $1
)
else
echo "target is not a dir"
fi
}
function create_all_child_dir() {
for dir in ${TARGETS[@]}; do
create_child_dir $dir
echo "$dir created"
done
}
function move_to_target() {
if ([ -e ./build/libbcimgproc.so ]); then
echo "prepare move target to ./target/$1"
mv ./build/libbcimgproc.so ./target/$1
mv ./build/libbcimgproc.so ./target/$1
echo "move to ./target/$1 finished"
else
echo "move error"$()
fi
}
function build_lib() {
clean_build
cd build
#cmake ..
/usr/local/cmake-3.10.3-Linux-x86_64/bin/cmake ..\
-DCMAKE_SYSTEM_NAME=Android\
-DCMAKE_SYSTEM_VERSION=21\
-DCMAKE_ANDROID_ARCH_ABI=$1\
-DCMAKE_ANDROID_NDK=$NDK_PATH\
-DCMAKE_ANDROID_STL_TYPE=gnustl_static
}
function build_armeabi() {
prepare_build
prepare_target
create_child_dir armeabi
(
build_lib armeabi
make
)
move_to_target armeabi
}
function build_armeabi-v7a() {
prepare_build
prepare_target
create_child_dir armeabi-v7a
(
build_lib armeabi_v7a
make
)
move_to_target armeabi-v7a
}
function build_arm64-v8a() {
prepare_build
prepare_target
create_child_dir arm64-8a
(
build_lib arm64-v8a
make
)
move_to_target arm64-8a
}
function build_mips() {
prepare_build
prepare_target
create_child_dir mips
(
build_lib mips
make
)
move_to_target mips
}
function build_mips64() {
prepare_build
prepare_target
create_child_dir mips64
(
build_lib mips64
make
)
move_to_target mips64
}
function build_x86() {
prepare_build
prepare_target
create_child_dir x86
(
build_lib x86
make
)
move_to_target x86
}
function build_x86_64() {
prepare_build
prepare_target
create_child_dir x86_64
(
build_lib x86_64
make
)
move_to_target x86_64
}
function create_all_target() {
prepare_build
prepare_target
create_all_child_dir
for target in ${TARGETS[@]}; do
(
build_lib $target
make
)
move_to_target $target
done
}
#call build function
create_all_target
Android 多平台编译脚本
猜你喜欢
转载自blog.csdn.net/xxboy61/article/details/80992437
今日推荐
周排行