-
Notifications
You must be signed in to change notification settings - Fork 30
/
Makefile
366 lines (332 loc) · 13.9 KB
/
Makefile
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
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
# -------------------- VALUES TO CONFIGURE --------------------
# Path to Android NDK
# NDK version must match ndkVersion in app/build.gradle
NDK_PATH := /opt/Android/ndk/$(shell sed -n '/ndkVersion/p' /usr/src/baresip-studio/app/build.gradle | sed 's/[^0-9.]*//g')
# Android API level
API_LEVEL := 28
# Set default from following values: [armeabi-v7a, arm64-v8a, x86_64]
ANDROID_TARGET_ARCH := arm64-v8a
# Directory where libraries and include files are instelled
OUTPUT_DIR := /usr/src/baresip-studio/distribution
# -------------------- GENERATED VALUES --------------------
CPU_COUNT := $(shell nproc)
PWD := $(shell pwd)
ifeq ($(ANDROID_TARGET_ARCH), armeabi-v7a)
TARGET := arm-linux-androideabi
CLANG_TARGET := armv7a-linux-androideabi
ARCH := arm
OPENSSL_ARCH := android-arm
MARCH := armv7-a
else
ifeq ($(ANDROID_TARGET_ARCH), arm64-v8a)
TARGET := aarch64-linux-android
CLANG_TARGET := $(TARGET)
ARCH := arm
OPENSSL_ARCH := android-arm64
MARCH := armv8-a
else
ifeq ($(ANDROID_TARGET_ARCH), x86_64)
TARGET := x86_64-linux-android
CLANG_TARGET := $(TARGET)
ARCH := x86
OPENSSL_ARCH := android-x86_64
MARCH := x86-64
else
exit 1
endif
endif
endif
PLATFORM := android-$(API_LEVEL)
OS := $(shell uname -s | tr "[A-Z]" "[a-z]")
ifeq ($(OS),linux)
HOST_OS := linux-x86_64
endif
ifeq ($(OS),darwin)
HOST_OS := darwin-x86_64
endif
# Toolchain and sysroot
TOOLCHAIN := $(NDK_PATH)/toolchains/llvm/prebuilt/$(HOST_OS)
CMAKE_TOOLCHAIN_FILE := $(NDK_PATH)/build/cmake/android.toolchain.cmake
SYSROOT := $(TOOLCHAIN)/sysroot
PKG_CONFIG_LIBDIR := $(NDK_PATH)/prebuilt/$(HOST_OS)/lib/pkgconfig
# Toolchain tools
PATH := $(TOOLCHAIN)/bin:/usr/bin:/bin
AR := llvm-ar
AS := $(CLANG_TARGET)$(API_LEVEL)-clang
CC := $(CLANG_TARGET)$(API_LEVEL)-clang
CXX := $(CLANG_TARGET)$(API_LEVEL)-clang++
LD := ld.lld
RANLIB := llvm-ranlib
STRIP := llvm-strip
# Compiler and Linker Flags for re and baresip
#
# NOTE: use -isystem to avoid warnings in system header files
COMMON_CFLAGS := -isystem $(SYSROOT)/usr/include -fPIE -fPIC -march=$(MARCH)
LFLAGS := -fPIE -pie
COMMON_FLAGS := \
EXTRA_CFLAGS="$(COMMON_CFLAGS) -DANDROID" \
EXTRA_CXXFLAGS="$(COMMON_CFLAGS) -DANDROID -DHAVE_PTHREAD" \
EXTRA_LFLAGS="$(LFLAGS)" \
SYSROOT=$(SYSROOT)/usr \
HAVE_INTTYPES_H=1 \
HAVE_GETOPT=1 \
HAVE_LIBRESOLV= \
HAVE_RESOLV= \
HAVE_PTHREAD=1 \
HAVE_PTHREAD_RWLOCK=1 \
HAVE_LIBPTHREAD= \
HAVE_INET_PTON=1 \
HAVE_INET6=1 \
HAVE_GETIFADDRS= \
PEDANTIC= \
OS=$(OS) \
ARCH=$(ARCH) \
USE_OPENSSL=yes \
USE_OPENSSL_DTLS=yes \
USE_OPENSSL_SRTP=yes
CMAKE_ANDROID_FLAGS := \
-DANDROID=ON \
-DANDROID_PLATFORM=$(API_LEVEL) \
-DCMAKE_SYSTEM_NAME=Android \
-DCMAKE_SYSTEM_VERSION=$(API_LEVEL) \
-DCMAKE_TOOLCHAIN_FILE=$(CMAKE_TOOLCHAIN_FILE) \
-DANDROID_ABI=$(ANDROID_TARGET_ARCH) \
-DCMAKE_ANDROID_ARCH_ABI=$(ANDROID_TARGET_ARCH) \
-DCMAKE_SKIP_INSTALL_RPATH=ON \
-DCMAKE_C_COMPILER=$(CC) \
-DCMAKE_CXX_COMPILER=$(CXX) \
-DCMAKE_POSITION_INDEPENDENT_CODE=ON \
-DCMAKE_BUILD_TYPE=Release
MODULES := "webrtc_aecm;augain;aaudio;dtls_srtp;opus;g711;g722;g7221;g726;codec2;amr;gzrtp;stun;turn;ice;presence;mwi;account;natpmp;srtp;uuid;sndfile;debug_cmd"
APP_MODULES := "g729"
default: all
.PHONY: amr
amr:
cd amr && \
rm -rf lib include && \
autoreconf --install && \
CC="$(CC) --sysroot $(SYSROOT)" CXX=$(CXX) RANLIB=$(RANLIB) AR=$(AR) PATH=$(PATH) ./configure --host=$(TARGET) --disable-shared CXXFLAGS=-fPIC --prefix=$(PWD)/amr && \
make clean && \
CC="$(CC) --sysroot $(SYSROOT)" CXX=$(CXX) RANLIB=$(RANLIB) AR=$(AR) PATH=$(PATH) make && \
make install
cd vo-amrwbenc && \
rm -rf include && \
autoreconf --install && \
CC="$(CC) --sysroot $(SYSROOT)" CXX=$(CXX) CC=$(CC) RANLIB=$(RANLIB) AR=$(AR) PATH=$(PATH) ./configure --host=$(TARGET) --disable-shared CFLAGS=-fPIC CXXFLAGS=-fPIC --prefix=$(PWD)/vo-amrwbenc && \
make clean && \
CC="$(CC) --sysroot $(SYSROOT)" CXX=$(CXX) RANLIB=$(RANLIB) AR=$(AR) PATH=$(PATH) make && \
make install
rm -rf $(OUTPUT_DIR)/amr/lib/$(ANDROID_TARGET_ARCH)
mkdir -p $(OUTPUT_DIR)/amr/lib/$(ANDROID_TARGET_ARCH)
cp amr/amrnb/.libs/libopencore-amrnb.a $(OUTPUT_DIR)/amr/lib/$(ANDROID_TARGET_ARCH)/libamrnb.a
cp amr/amrwb/.libs/libopencore-amrwb.a $(OUTPUT_DIR)/amr/lib/$(ANDROID_TARGET_ARCH)/libamrwb.a
cp vo-amrwbenc/.libs/libvo-amrwbenc.a $(OUTPUT_DIR)/amr/lib/$(ANDROID_TARGET_ARCH)/libamrwbenc.a
.PHONY: codec2
codec2:
cd codec2 && \
rm -rf build && rm -rf .cache && mkdir build && cd build && \
cmake .. -DBUILD_SHARED_LIBS=OFF $(CMAKE_ANDROID_FLAGS) && \
cmake --build . --target codec2 -j$(CPU_COUNT) && \
cp ../src/codec2.h codec2
rm -rf $(OUTPUT_DIR)/codec2/lib/$(ANDROID_TARGET_ARCH)
mkdir -p $(OUTPUT_DIR)/codec2/lib/$(ANDROID_TARGET_ARCH)
cp codec2/build/src/libcodec2.a $(OUTPUT_DIR)/codec2/lib/$(ANDROID_TARGET_ARCH)
.PHONY: g729
g729:
-make clean -C bcg729
cd bcg729/build && \
find . -maxdepth 1 ! -name CMakeLists.txt -type f -delete && \
rm -rf build CMakeFiles include src && \
cmake .. $(CMAKE_ANDROID_FLAGS) && \
cmake --build . --target bcg729-static -j$(CPU_COUNT)
rm -rf $(OUTPUT_DIR)/g729/lib/$(ANDROID_TARGET_ARCH)
mkdir -p $(OUTPUT_DIR)/g729/lib/$(ANDROID_TARGET_ARCH)
cp bcg729/build/src/libbcg729.a $(OUTPUT_DIR)/g729/lib/$(ANDROID_TARGET_ARCH)
.PHONY: g7221
g7221:
-make distclean -C g7221
cd g7221 && \
libtoolize --force && \
autoreconf --install && \
autoconf && \
CC="$(CC) --sysroot $(SYSROOT)" \
RANLIB=$(RANLIB) AR=$(AR) PATH=$(BIN):$(PATH) \
ac_cv_func_malloc_0_nonnull=yes \
./configure --host=$(TARGET) --disable-shared CFLAGS="-fPIC" && \
CC="$(CC) --sysroot $(SYSROOT)" \
RANLIB=$(RANLIB) AR=$(AR) PATH=$(BIN):$(PATH) \
make
rm -rf $(OUTPUT_DIR)/g7221/lib/$(ANDROID_TARGET_ARCH)
mkdir -p $(OUTPUT_DIR)/g7221/lib/$(ANDROID_TARGET_ARCH)
cp g7221/src/.libs/libg722_1.a $(OUTPUT_DIR)/g7221/lib/$(ANDROID_TARGET_ARCH)
.PHONY: gzrtp
gzrtp:
cd zrtpcpp && \
rm -rf build && \
mkdir build && \
cd build && \
cmake .. $(CMAKE_ANDROID_FLAGS) && \
sed -i -e 's/;-lpthread//' CMakeCache.txt && \
cmake .. $(CMAKE_ANDROID_FLAGS) && \
cmake --build . -j$(CPU_COUNT)
rm -rf $(OUTPUT_DIR)/gzrtp/lib/$(ANDROID_TARGET_ARCH)
mkdir -p $(OUTPUT_DIR)/gzrtp/lib/$(ANDROID_TARGET_ARCH)
cp zrtpcpp/build/clients/no_client/libzrtpcppcore.a $(OUTPUT_DIR)/gzrtp/lib/$(ANDROID_TARGET_ARCH)
.PHONY: openssl
openssl:
-make distclean -C openssl
cd openssl && \
ANDROID_NDK_ROOT=$(NDK_PATH) PATH=$(PATH) ./Configure $(OPENSSL_ARCH) no-shared no-tests -U__ANDROID_API__ -D__ANDROID_API__=$(API_LEVEL) && \
sed -e '/[.]hidden.*OPENSSL_armcap_P/d; /[.]extern.*OPENSSL_armcap_P/ {p; s/extern/hidden/ }' -i -- crypto/*arm*pl crypto/*/asm/*arm*pl && \
make build_libs && \
git stash
rm -rf $(OUTPUT_DIR)/openssl/lib/$(ANDROID_TARGET_ARCH)
mkdir -p $(OUTPUT_DIR)/openssl/lib/$(ANDROID_TARGET_ARCH)
cp openssl/libcrypto.a \
$(OUTPUT_DIR)/openssl/lib/$(ANDROID_TARGET_ARCH)
cp openssl/libssl.a \
$(OUTPUT_DIR)/openssl/lib/$(ANDROID_TARGET_ARCH)
.PHONY: opus
opus:
-make distclean -C opus
cd opus && \
rm -rf include_opus && \
./autogen.sh && \
CC="$(CC) --sysroot $(SYSROOT)" RANLIB=$(RANLIB) AR=$(AR) PATH=$(PATH) ./configure --host=$(TARGET) --disable-shared --disable-doc --disable-extra-programs CFLAGS="$(COMMON_CFLAGS)" && \
CC="$(CC) --sysroot $(SYSROOT)" RANLIB=$(RANLIB) AR=$(AR) PATH=$(PATH) make && \
mkdir -p include_opus/opus && \
cp include/* include_opus/opus
rm -rf $(OUTPUT_DIR)/opus/lib/$(ANDROID_TARGET_ARCH)
mkdir -p $(OUTPUT_DIR)/opus/lib/$(ANDROID_TARGET_ARCH)
cp opus/.libs/libopus.a $(OUTPUT_DIR)/opus/lib/$(ANDROID_TARGET_ARCH)
.PHONY: sndfile
sndfile:
cd sndfile && \
rm -rf build && rm -rf .cache && mkdir build && cd build && \
cmake .. $(CMAKE_ANDROID_FLAGS) && \
cmake --build . --target sndfile -j$(CPU_COUNT)
rm -rf $(OUTPUT_DIR)/sndfile/lib/$(ANDROID_TARGET_ARCH)
mkdir -p $(OUTPUT_DIR)/sndfile/lib/$(ANDROID_TARGET_ARCH)
cp sndfile/build/libsndfile.a $(OUTPUT_DIR)/sndfile/lib/$(ANDROID_TARGET_ARCH)
.PHONY: spandsp
spandsp: tiff
-make distclean -C spandsp
cd spandsp && \
touch configure.ac aclocal.m4 configure Makefile.am Makefile.in && \
CC="$(CC) --sysroot $(SYSROOT)" RANLIB=$(RANLIB) AR=$(AR) PATH=$(PATH) ac_cv_func_malloc_0_nonnull=yes ac_cv_func_realloc_0_nonnull=yes ./configure --host=arm-linux --enable-builtin-tiff --disable-shared CFLAGS="$(COMMON_CFLAGS)" && \
CC="$(CC) --sysroot $(SYSROOT)" RANLIB=$(RANLIB) AR=$(AR) PATH=$(PATH) make
rm -rf $(OUTPUT_DIR)/spandsp/lib/$(ANDROID_TARGET_ARCH)
mkdir -p $(OUTPUT_DIR)/spandsp/lib/$(ANDROID_TARGET_ARCH)
cp spandsp/src/.libs/libspandsp.a $(OUTPUT_DIR)/spandsp/lib/$(ANDROID_TARGET_ARCH)
.PHONY: tiff
tiff:
-make distclean -C tiff
cd tiff && \
./autogen.sh && \
CC="$(CC) --sysroot $(SYSROOT)" CXX=$(CXX) RANLIB=$(RANLIB) AR=$(AR) PATH=$(PATH) ac_cv_func_malloc_0_nonnull=yes ac_cv_func_realloc_0_nonnull=yes ./configure --host=arm-linux --disable-shared CFLAGS="$(COMMON_CFLAGS)" && \
CC="$(CC) --sysroot $(SYSROOT)" CXX=$(CXX) RANLIB=$(RANLIB) AR=$(AR) PATH=$(PATH) make
.PHONY: webrtc
webrtc:
cd webrtc && \
rm -rf obj && \
$(NDK_PATH)/ndk-build -j$(CPU_COUNT) APP_PLATFORM=android-$(API_LEVEL)
rm -rf $(OUTPUT_DIR)/webrtc/lib/$(ANDROID_TARGET_ARCH)
mkdir -p $(OUTPUT_DIR)/webrtc/lib/$(ANDROID_TARGET_ARCH)
cp webrtc/obj/local/$(ANDROID_TARGET_ARCH)/libwebrtc.a $(OUTPUT_DIR)/webrtc/lib/$(ANDROID_TARGET_ARCH)
libre.a: Makefile
cd re && \
rm -rf build && rm -rf .cache && mkdir build && cd build && \
cmake .. \
$(CMAKE_ANDROID_FLAGS) \
-DCMAKE_FIND_ROOT_PATH="$(NDK_PATH);$(PWD)/openssl" \
-DOPENSSL_VERSION_MAJOR=3 \
-DOPENSSL_ROOT_DIR=$(PWD)/openssl && \
cmake --build . --target re -j$(CPU_COUNT)
libbaresip: Makefile amr g729 codec2 g7221 gzrtp openssl opus sndfile spandsp webrtc libre.a
cd baresip && \
rm -rf build && rm -rf .cache && mkdir build && cd build && \
cmake .. \
$(CMAKE_ANDROID_FLAGS) \
-DCMAKE_FIND_ROOT_PATH="$(PWD)/amr;$(PWD)/vo-amrwbenc;$(PWD)/openssl" \
-DSTATIC=ON -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON \
-DAAUDIO_INCLUDE_DIR=${TOOLCHAIN}/sysroot/usr/include \
-DAAUDIO_LIBRARY=${TOOLCHAIN}/sysroot/usr/lib/$(TARGET)/$(API_LEVEL)/libaaudio.so \
-Dre_DIR=$(PWD)/re/cmake \
-DRE_LIBRARY=$(PWD)/re/build/libre.a \
-DRE_INCLUDE_DIR=$(PWD)/re/include \
-DOPENSSL_ROOT_DIR=$(PWD)/openssl \
-DG729_INCLUDE_DIR=$(PWD)/bcg729/include \
-DOPUS_INCLUDE_DIR=$(PWD)/opus/include_opus \
-DOPUS_LIBRARY=$(OUTPUT_DIR)/opus/lib/$(ANDROID_TARGET_ARCH)/libopus.a \
-DCODEC2_INCLUDE_DIR=$(PWD)/codec2/build \
-DCODEC2_LIBRARY=$(OUTPUT_DIR)/codec2/lib/$(ANDROID_TARGET_ARCH)/libcodec2.a \
-DSPANDSP_INCLUDE_DIR="$(PWD)/spandsp/src;$(PWD)/tiff/libtiff" \
-DSPANDSP_LIBRARY=$(OUTPUT_DIR)/spandsp/lib/$(ANDROID_TARGET_ARCH)/libspandsp.a \
-DWEBRTC_AECM_INCLUDE_DIR=$(PWD)/webrtc/include \
-DWEBRTC_AECM_LIBRARY=$(OUTPUT_DIR)/webrtc/lib/$(ANDROID_TARGET_ARCH)/libwebrtc.a \
-DG7221_INCLUDE_DIR=$(PWD)/g7221/src \
-DG7221_LIBRARY=$(OUTPUT_DIR)/g7221/lib/$(ANDROID_TARGET_ARCH)/libg722_1.a \
-DGZRTP_INCLUDE_DIR=$(PWD)/zrtpcpp \
-DGZRTP_LIBRARY="$(OUTPUT_DIR)/gzrtp/lib/$(ANDROID_TARGET_ARCH)/libzrtpcppcore.a" \
-DSNDFILE_INCLUDE_DIR="$(PWD)/sndfile/include" \
-DSNDFILE_LIBRARIES="$(OUTPUT_DIR)/sndfile/lib/$(ANDROID_TARGET_ARCH)/libsndfile.a" \
-DCMAKE_C_COMPILER="clang" \
-DCMAKE_CXX_COMPILER="clang++" \
-DAPP_MODULES_DIR=$(PWD)/baresip-app-modules \
-DAPP_MODULES=$(APP_MODULES) \
-DMODULES=$(MODULES) && \
cmake --build . --target baresip -j$(CPU_COUNT)
rm -rf $(OUTPUT_DIR)/re/lib/$(ANDROID_TARGET_ARCH)
mkdir -p $(OUTPUT_DIR)/re/lib/$(ANDROID_TARGET_ARCH)
cp re/build/libre.a $(OUTPUT_DIR)/re/lib/$(ANDROID_TARGET_ARCH)
rm -rf $(OUTPUT_DIR)/baresip/lib/$(ANDROID_TARGET_ARCH)
mkdir -p $(OUTPUT_DIR)/baresip/lib/$(ANDROID_TARGET_ARCH)
cp baresip/build/libbaresip.a $(OUTPUT_DIR)/baresip/lib/$(ANDROID_TARGET_ARCH)
rm -rf $(OUTPUT_DIR)/re/include
mkdir -p $(OUTPUT_DIR)/re/include
cp re/include/* $(OUTPUT_DIR)/re/include
rm -rf $(OUTPUT_DIR)/re/cmake
mkdir -p $(OUTPUT_DIR)/re/cmake
cp re/cmake/re-config.cmake $(OUTPUT_DIR)/re/cmake
rm -rf $(OUTPUT_DIR)/baresip/include
mkdir $(OUTPUT_DIR)/baresip/include
cp baresip/include/baresip.h $(OUTPUT_DIR)/baresip/include
all:
make libbaresip ANDROID_TARGET_ARCH=armeabi-v7a
make libbaresip ANDROID_TARGET_ARCH=arm64-v8a
# make libbaresip ANDROID_TARGET_ARCH=x86_64
.PHONY: download-sources
download-sources:
rm -fr abseil-cpp amr baresip bcg729 codec2 g7221 openssl opus \
re sndfile spandsp tiff vo-amrwbenc webrtc zrtpcpp
git clone https://github.com/abseil/abseil-cpp.git -b lts_2024_01_16 --single-branch
git clone https://git.code.sf.net/p/opencore-amr/code -b v0.1.6 --single-branch amr
git clone https://github.com/baresip/baresip.git
git clone https://github.com/BelledonneCommunications/bcg729.git -b release/1.1.1 --single-branch
git clone https://github.com/drowe67/codec2.git -b 1.2.0 --single-branch
git clone https://github.com/juha-h/libg7221.git -b master --single-branch g7221
git clone https://github.com/openssl/openssl.git -b openssl-3.4 --single-branch openssl
git clone https://github.com/xiph/opus.git -b v1.4 --single-branch
git clone https://github.com/baresip/re.git
git clone https://github.com/juha-h/libsndfile.git -b master --single-branch sndfile
git clone https://github.com/juha-h/spandsp.git -b 1.0 --single-branch spandsp
git clone https://gitlab.com/libtiff/libtiff.git -b v4.7.0 --single-branch tiff
git clone https://github.com/juha-h/libwebrtc.git -b mobile --single-branch webrtc
git clone https://git.code.sf.net/p/opencore-amr/vo-amrwbenc --single-branch vo-amrwbenc
cp -r abseil-cpp/absl webrtc/jni/src/webrtc
git clone https://github.com/juha-h/ZRTPCPP.git -b master --single-branch zrtpcpp
patch -d re -p1 < re-patch
clean:
-make distclean -C amr
make distclean -C baresip
rm -rf codec2/build
-make distclean -C g7221
-make clean -C bcg729
-make distclean -C openssl
-make distclean -C opus
make distclean -C re
rm -rf sndfile/build
-make distclean -C spandsp
-make distclean -C tiff
rm -rf webrtc/obj
rm -rf zrtpcpp/build