-
Notifications
You must be signed in to change notification settings - Fork 106
/
build.sh
executable file
·99 lines (81 loc) · 2.55 KB
/
build.sh
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
#!/bin/bash
# use extended globbing features
shopt -s extglob
# import our build functions
source _build_openssl.sh
source _build_librtmp.sh
source _build_ffmpeg.sh
#-- error function
function die {
code=-1
err="Unknown error!"
test "$1" && err=$1
cd ${top_root}
echo "$err"
echo "Check the build log: ${build_log}"
exit -1
}
#-- try to intelligently determine where the Android NDK is installed
function find_ndk {
ndk_name="android-ndk-r10"
top_level_paths_to_search="/Users /Applications /usr"
found_ndk=""
for d in $top_level_paths_to_search; do
test -d "$d" || continue
found_ndk=$(find $d -name $ndk_name -print)
test "$found_ndk" && break
done
echo "$found_ndk"
}
#-- set up environment variables, folder structure, and log files
function initialize {
echo "Setting up build environment ..."
# environment variables
top_root=$PWD
src_root=${top_root}/src
build_root=${top_root}/build
patch_root=${top_root}/patches
dist_root=${top_root}/build/dist
dist_bin_root=${dist_root}/bin
dist_include_root=${dist_root}/include
dist_lib_root=${dist_root}/lib
build_log=${top_root}/build/build.log
config_file=${top_root}/.build-config.sh
# create our folder structure
cd ${top_root}
test -d ${src_root} || mkdir -p ${src_root}
test -d ${build_root} || mkdir -p ${build_root}
test -d ${dist_root} || mkdir -p ${dist_root}
test -d ${dist_bin_root} || mkdir -p ${dist_bin_root}
test -d ${dist_include_root} || mkdir -p ${dist_include_root}
test -d ${dist_lib_root} || mkdir -p ${dist_lib_root}
touch ${build_log}
rm -f ${build_log}
# create our configuration file if it doesn't yet exist
if [ ! -f "${config_file}" ]; then
# determine OS and architecture
OS_ARCH=$(uname -sm | tr 'A-Z' 'a-z' | sed "s/\ /\-/g")
# find / ask for the NDK
echo "Looking for the NDK ..."
NDK=$(find_ndk)
echo -n "Path to NDK [$NDK]: "
read typed_ndk_root
test "$typed_ndk_root" && NDK="$typed_ndk_root"
# save our configuration
echo "Saving configuration into ${config_file} ..."
echo "OS_ARCH=$OS_ARCH" > ${config_file}
echo "NDK=$NDK" >> ${config_file}
echo "SYSROOT=${NDK}/platforms/android-19/arch-arm" >> ${config_file}
echo "TOOLCHAIN=${NDK}/toolchains/arm-linux-androideabi-4.8/prebuilt/${OS_ARCH}" >> ${config_file}
fi
# show the user our configuration, then import it
cat ${config_file}
source ${config_file}
}
#-- main
set -e # fail hard on any error
initialize
build_openssl
build_librtmp
build_ffmpeg
echo "Look in ${dist_root} for libraries and executables."