File: android-build-common.sh

package info (click to toggle)
freerdp2 2.0.0~git20190204.1.2693389a+dfsg1-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 22,772 kB
  • sloc: ansic: 307,908; xml: 1,676; sh: 770; perl: 231; makefile: 158; python: 65
file content (273 lines) | stat: -rw-r--r-- 4,374 bytes parent folder | download | duplicates (2)
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
#!/bin/bash

SCRIPT_PATH=$(dirname "${BASH_SOURCE[0]}")
SCRIPT_PATH=$(realpath "$SCRIPT_PATH")

if [ -z $BUILD_ARCH ]; then
	BUILD_ARCH="armeabi-v7a x86 x86_64 arm64-v8a"
fi

if [ -z $NDK_TARGET ]; then
	NDK_TARGET=21
fi

if [ -z $CCACHE ]; then
	CCACHE=$(which ccache)
fi

if [ -z $ANDROID_NDK ]; then
	ANDROID_NDK="missing"
fi

if [ -z $BUILD_DST ]; then
	BUILD_DST=$(pwd)/libs
fi

if [ -z $BUILD_SRC ]; then
	BUILD_SRC=$(pwd)/src
fi

if [ -z $SCM_URL ]; then
	SCM_URL="missing"
fi

if [ -z $SCM_TAG ]; then
	SCM_TAG=master
fi

CLEAN_BUILD_DIR=0

function common_help {
	echo "$(BASHSOURCE[0]) supports the following arguments:"
	echo "	--ndk	The base directory of your android NDK defa"
	echo "			ANDROID_NDK=$ANDROID_NDK"
	echo "	--arch	A list of architectures to build"
	echo "			BUILD_ARCH=$BUILD_ARCH"
	echo "	--dst	The destination directory for include and library files"
	echo "			BUILD_DST=$BUILD_DST"
	echo "	--src	The source directory for SCM checkout"
	echo "			BUILD_SRC=$BUILD_SRC"
	echo "	--url	The SCM source url"
	echo "			SCM_URL=$SCM_URL"
	echo "	--tag	The SCM branch or tag to check out"
	echo "			SCM_TAG=$SCM_TAG"
	echo "	--clean	Clean the destination before build"
	echo "	--help	Display this help"
	exit 0
}

function common_run {
	echo "[RUN] $@"
	"$@"
	RES=$?
	if [[ $RES -ne 0 ]];
	then
		echo "[ERROR] $@ retured $RES"
		exit 1
	fi
}

function common_parse_arguments {
	while [[ $# > 0 ]]
	do
		key="$1"
		case $key in
		    --conf)
            source "$2"
            shift
            ;;

			--target)
			NDK_TARGET="$2"
			shift
			;;

			--ndk)
			ANDROID_NDK="$2"
			shift
			;;

			--arch)
			BUILD_ARCH="$2"
			shift
			;;

			--dst)
			BUILD_DST="$2"
			shift
			;;

			--src)
			BUILD_SRC="$2"
			shift
			;;

			--url)
			SCM_URL="$2"
			shift
			;;

			--tag)
			SCM_TAG="$2"
			shift
			;;

			--clean)
			CLEAN_BUILD_DIR=1
			shift
			;;

			--help)
			common_help
			shift
			;;

			*) # Unknown
			;;
		esac
		shift
	done
}

function common_check_requirements {
	if [[ ! -d $ANDROID_NDK ]];
	then
		echo "export ANDROID_NDK to point to your NDK location."
		exit 1
	fi

	if [[ -z $BUILD_DST ]];
	then
		echo "Destination directory not valid"
		exit 1
	fi

	if [[ -z $BUILD_SRC ]];
	then
		echo "Source directory not valid"
		exit 1
	fi

	if [[ -z $SCM_URL ]];
	then
		echo "Source URL not defined! Define SCM_URL"
		exit 1
	fi

	if [[ -z $SCM_TAG ]];
	then
		echo "SCM TAG / BRANCH not defined! Define SCM_TAG"
		exit 1
	fi

	if [[ -z $NDK_TARGET ]];
	then
		echo "Android platform NDK_TARGET not defined"
		exit 1
	fi

	if [ -x $ANDROID_NDK/ndk-build ]; then
		NDK_BUILD=$ANDROID_NDK/ndk-build
	else
		echo "ndk-build not found in NDK directory $ANDROID_NDK"
		echo "assuming ndk-build is in path..."
		NDK_BUILD=ndk-build
	fi

	if [[ -z $NDK_BUILD ]];
	then
		echo "Android ndk-build not detected"
		exit 1
	fi

	for CMD in make git cmake $NDK_BUILD
	do
		if ! type $CMD >/dev/null; then
			echo "Command $CMD not found. Install and add it to the PATH."
			exit 1
		fi
	done

	if [ "${BUILD_SRC:0:1}" != "/" ];
	then
		BUILD_SRC=$(pwd)/$BUILD_SRC
	fi
	if [ "${BUILD_DST:0:1}" != "/" ];
	then
		BUILD_DST=$(pwd)/$BUILD_DST
	fi
}

function common_update {
	if [ $# -ne 3 ];
	then
		echo "Invalid arguments to update function $@"
		exit 1
	fi
	SCM_URL=$1
	SCM_TAG=$2
	BUILD_SRC=$3

	echo "Preparing checkout..."
	BASE=$(pwd)
	CACHE=$SCRIPT_PATH/../cache
	common_run mkdir -p $CACHE
	TARFILE="$CACHE/$SCM_TAG.tar.gz"
	
	
	if [[ ! -f "$TARFILE" ]];
	then
		common_run wget -O "$TARFILE" "$SCM_URL/archive/$SCM_TAG.tar.gz"
	fi

	if [[ -d $BUILD_SRC ]];
	then
		common_run rm -rf $BUILD_SRC
	fi
	common_run mkdir -p $BUILD_SRC
	common_run cd $BUILD_SRC
	common_run tar zxf "$TARFILE" --strip 1
	common_run cd $BASE

}

function common_clean {
	if [ $CLEAN_BUILD_DIR -ne 1 ];
	then
		return
	fi

	if [ $# -ne 1 ];
	then
		echo "Invalid arguments to clean function $@"
		exit 1
	fi

	echo "Cleaning up $1..."
	common_run rm -rf $1
}

function common_copy {
	if [ $# -ne 2 ];
	then
		echo "Invalid arguments to copy function $@"
		exit 1
	fi
	if [ ! -d $1 ] || [ ! -d $1/include ] || [ ! -d $1/libs ];
	then
		echo "Invalid source $1"
		exit 1
	fi
	if [ -z $2 ];
	then
		echo "Invalid destination $2"
		exit 1
	fi

	if [ ! -d $2 ];
	then
		common_run mkdir -p $2
	fi
	common_run cp -L -r $1/include $2
	common_run cp -L -r $1/libs/* $2
}