forked from nesterenkodm/pjsip
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pjsip.sh
executable file
·219 lines (189 loc) · 5.94 KB
/
pjsip.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
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
#!/bin/sh
# see http://stackoverflow.com/a/3915420/318790
function realpath { echo $(cd $(dirname "$1"); pwd)/$(basename "$1"); }
__FILE__=`realpath "$0"`
__DIR__=`dirname "${__FILE__}"`
# download
function download() {
"${__DIR__}/download.sh" "$1" "$2" #--no-cache
}
BASE_DIR="$1"
PJSIP_URL="http://www.pjsip.org/release/2.5.5/pjproject-2.5.5.tar.bz2"
PJSIP_DIR="$1/src"
LIB_PATHS=("pjlib/lib" \
"pjlib-util/lib" \
"pjmedia/lib" \
"pjnath/lib" \
"third_party/lib")
OPENSSL_PREFIX=
OPENH264_PREFIX=
while [ "$#" -gt 0 ]; do
case $1 in
--with-openssl)
if [ "$#" -gt 1 ]; then
OPENSSL_PREFIX=$2
shift 2
continue
else
echo 'ERROR: Must specify a non-empty "--with-openssl PREFIX" argument.' >&2
exit 1
fi
;;
--with-openh264)
if [ "$#" -gt 1 ]; then
OPENH264_PREFIX=$2
shift 2
continue
else
echo 'ERROR: Must specify a non-empty "--with-openh264 PREFIX" argument.' >&2
exit 1
fi
;;
esac
shift
done
function config_site() {
SOURCE_DIR=$1
PJSIP_CONFIG_PATH="${SOURCE_DIR}/pjlib/include/pj/config_site.h"
HAS_VIDEO=
echo "Creating config_site.h ..."
if [ -f "${PJSIP_CONFIG_PATH}" ]; then
rm "${PJSIP_CONFIG_PATH}"
fi
echo "#define PJ_CONFIG_IPHONE 1" >> "${PJSIP_CONFIG_PATH}"
echo "#define PJ_HAS_IPV6 1" >> "${PJSIP_CONFIG_PATH}" # Enable IPV6
if [[ ${OPENH264_PREFIX} ]]; then
echo "#define PJMEDIA_HAS_OPENH264_CODEC 1" >> "${PJSIP_CONFIG_PATH}"
HAS_VIDEO=1
fi
if [[ ${HAS_VIDEO} ]]; then
echo "#define PJMEDIA_HAS_VIDEO 1" >> "${PJSIP_CONFIG_PATH}"
echo "#define PJMEDIA_VIDEO_DEV_HAS_OPENGL 1" >> "${PJSIP_CONFIG_PATH}"
echo "#define PJMEDIA_VIDEO_DEV_HAS_OPENGL_ES 1" >> "${PJSIP_CONFIG_PATH}"
echo "#define PJMEDIA_VIDEO_DEV_HAS_IOS_OPENGL 1" >> "${PJSIP_CONFIG_PATH}"
echo "#include <OpenGLES/ES3/glext.h>" >> "${PJSIP_CONFIG_PATH}"
fi
echo "#include <pj/config_site_sample.h>" >> "${PJSIP_CONFIG_PATH}"
}
function clean_libs () {
ARCH=${1}
for SRC_DIR in ${LIB_PATHS[*]}; do
DIR="${PJSIP_DIR}/${SRC_DIR}"
if [ -d "${DIR}" ]; then
rm -rf "${DIR}"/*
fi
DIR="${PJSIP_DIR}/${SRC_DIR}-${ARCH}"
if [ -d "${DIR}" ]; then
rm -rf "${DIR}"
fi
done
}
function copy_libs () {
ARCH=${1}
for SRC_DIR in ${LIB_PATHS[*]}; do
SRC_DIR="${PJSIP_DIR}/${SRC_DIR}"
DST_DIR="${SRC_DIR}-${ARCH}"
if [ -d "${DST_DIR}" ]; then
rm -rf "${DST_DIR}"
fi
cp -R "${SRC_DIR}" "${DST_DIR}"
rm -rf "${SRC_DIR}"/* # delete files because this directory will be used for the final lipo output
done
}
function _build() {
pushd . > /dev/null
cd ${PJSIP_DIR}
ARCH=$1
LOG=${BASE_DIR}/${ARCH}.log
# configure
CONFIGURE="./configure-iphone"
if [[ ${OPENSSL_PREFIX} ]]; then
CONFIGURE="${CONFIGURE} --with-ssl=${OPENSSL_PREFIX}"
fi
if [[ ${OPENH264_PREFIX} ]]; then
CONFIGURE="${CONFIGURE} --with-openh264=${OPENH264_PREFIX}"
fi
# flags
if [[ ! ${CFLAGS} ]]; then
export CFLAGS=
fi
if [[ ! ${LDFLAGS} ]]; then
export LDFLAGS=
fi
if [[ ${OPENSSL_PREFIX} ]]; then
export CFLAGS="${CFLAGS} -I${OPENSSL_PREFIX}/include"
export LDFLAGS="${LDFLAGS} -L${OPENSSL_PREFIX}/lib"
fi
if [[ ${OPENH264_PREFIX} ]]; then
export CFLAGS="${CFLAGS} -I${OPENH264_PREFIX}/include"
export LDFLAGS="${LDFLAGS} -L${OPENH264_PREFIX}/lib"
fi
export LDFLAGS="${LDFLAGS} -lstdc++"
echo "Building for ${ARCH}..."
clean_libs ${ARCH}
make distclean > ${LOG} 2>&1
ARCH="-arch ${ARCH}" ${CONFIGURE} >> ${LOG} 2>&1
make dep >> ${LOG} 2>&1
make clean >> ${LOG}
make >> ${LOG} 2>&1
copy_libs ${ARCH}
}
function armv7() {
export CFLAGS=
export LDFLAGS=
_build "armv7"
}
function armv7s() {
export CFLAGS=
export LDFLAGS=
_build "armv7s"
}
function arm64() {
export CFLAGS=
export LDFLAGS=
_build "arm64"
}
function i386() {
export DEVPATH="`xcrun -sdk iphonesimulator --show-sdk-platform-path`/Developer"
export CFLAGS="-O2 -m32 -mios-simulator-version-min=7.0"
export LDFLAGS="-O2 -m32 -mios-simulator-version-min=7.0"
_build "i386"
}
function x86_64() {
export DEVPATH="`xcrun -sdk iphonesimulator --show-sdk-platform-path`/Developer"
export CFLAGS="-O2 -m32 -mios-simulator-version-min=7.0"
export LDFLAGS="-O2 -m32 -mios-simulator-version-min=7.0"
_build "x86_64"
}
function lipo() {
TMP=`mktemp -t lipo`
echo "Lipo libs... (${TMP})"
for LIB_DIR in ${LIB_PATHS[*]}; do # loop over libs
DST_DIR="${PJSIP_DIR}/${LIB_DIR}"
# use the first architecture to find all libraries
PATTERN_DIR="${DST_DIR}-$1"
for PATTERN_FILE in `ls -l1 "${PATTERN_DIR}"`; do
OPTIONS=""
# loop over all architectures and collect the current library
for ARCH in "$@"; do
FILE="${DST_DIR}-${ARCH}/${PATTERN_FILE/-$1-/-${ARCH}-}"
if [ -e "${FILE}" ]; then
OPTIONS="$OPTIONS -arch ${ARCH} ${FILE}"
fi
done
if [ "$OPTIONS" != "" ]; then
OUTPUT_PREFIX=$(dirname "${DST_DIR}")
OUTPUT="${OUTPUT_PREFIX}/lib/${PATTERN_FILE/-$1-/-}"
OPTIONS="${OPTIONS} -create -output ${OUTPUT}"
echo "$OPTIONS" >> "${TMP}"
fi
done
done
while read LINE; do
xcrun -sdk iphoneos lipo ${LINE}
done < "${TMP}"
}
download "${PJSIP_URL}" "${PJSIP_DIR}"
config_site "${PJSIP_DIR}"
armv7 && armv7s && arm64 && i386 && x86_64
lipo armv7 armv7s arm64 i386 x86_64