-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathbuild
executable file
·126 lines (112 loc) · 3.09 KB
/
build
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#!/bin/bash
#
# Audioneex bootstrap build script
# --------------------------------
#
# Usage:
#
# $ ./build [options]
#
# where [options] is one or more of the following
#
# TARGET = linux | android
# ARCH = x32 | x64 (Linux)
# armeabi-v7a | arm64-v8a | x86 | x86_64 (Android)
# API = API version number (Android only)
# BINARY_TYPE = dynamic | static
# BUILD_MODE = debug | release
# DATASTORE_T = TCDataStore | CBDataStore
# WITH_EXAMPLES = ON | OFF
# WITH_ID3 = ON | OFF (for the examples only)
# WITH_TESTS = ON | OFF (for project developers only)
#
# The paramaters are all optional and if none is specified the target and
# architecture will be automatically detected from the environment, while
# the others will be set to default values (dynamic binary, release mode,
# TCDataStore and no WITH_* options).
#
#
# Paramaters:
# $1 - Error message
# Returns:
# null
function error()
{
echo "ERROR: [$(basename $0)] $1"
exit 1
}
# Paramaters:
# $1 - Param name
# Returns:
# The param value
function get_param_value()
{
local PARAM=$1
for p in "${PARAMS[@]}"; do
if [[ "$p" =~ ^${PARAM}= ]]; then
echo "${p/${PARAM}=}"
break
fi
done
}
# Paramaters:
# Returns:
# The path to the NDK root
function get_ndk_home()
{
local NDKHOME=$ANDROID_NDK_HOME
if [ ! $NDKHOME ]; then
NDKHOME=$ANDROID_NDK_ROOT
if [ ! $NDKHOME ]; then
local MSG=(
"Could not find the NDK. Please set either the"
"ANDROID_NDK_HOME or ANDROID_NDK_ROOT environment"
"variable with the path to your NDK installation"
"directory."
)
error "${MSG[*]}"
fi
fi
echo "$NDKHOME"
}
function bootstrap_linux()
{
echo ""
echo "-- Building for Linux"
echo ""
MAKE_CMD="cmake ${DPARAMS[@]} .."
}
function bootstrap_android()
{
echo ""
echo "-- Building for Android"
echo ""
NDK_HOME=$(get_ndk_home)
__TOOLCHAIN_FILE=${NDK_HOME}/build/cmake/android.toolchain.cmake
__ARCH=$(get_param_value "ARCH")
__API=$(get_param_value "API")
if [ ! $__API ]; then __API=latest; fi
MAKE_CMD="cmake -DCMAKE_TOOLCHAIN_FILE=${__TOOLCHAIN_FILE}"
MAKE_CMD="$MAKE_CMD -DANDROID_NDK=${NDK_HOME}"
MAKE_CMD="$MAKE_CMD -DANDROID_ABI=${__ARCH}"
MAKE_CMD="$MAKE_CMD -DANDROID_PLATFORM=${__API}"
MAKE_CMD="$MAKE_CMD -DANDROID_TOOLCHAIN=clang"
MAKE_CMD="$MAKE_CMD ${DPARAMS[@]} .."
}
# ---
BUILD_CMD="cmake --build ."
INSTA_CMD="cmake --build . --target install"
TEST_CMD="cmake --build . --target test -- CTEST_OUTPUT_ON_FAILURE=1"
DPARAMS=()
read -ra PARAMS <<< "${*}"
for p in "${PARAMS[@]}"; do
DPARAMS+=("-DAX_$p")
done
TARGET_PLATFORM=$(get_param_value "TARGET")
if [ ! $TARGET_PLATFORM ]; then TARGET_PLATFORM=linux; fi
bootstrap_$TARGET_PLATFORM
__WITH_TESTS=$(get_param_value "WITH_TESTS")
if [ ! $__WITH_TESTS ]; then TEST_CMD=:; fi
if [ -d "_build" ]; then rm -rf _build; fi
mkdir -p _build && cd _build
$MAKE_CMD && $BUILD_CMD && $INSTA_CMD && $TEST_CMD && cd ..