blob: e620f66659fb78146c20c8e5b712805a0c2c664a [file] [log] [blame]
agsantosc9181b42020-11-26 12:03:04 -05001#! /bin/bash
2# Build the plugin for the project
agsantos82678f32020-12-09 15:03:24 -05003set -e
agsantosc9181b42020-11-26 12:03:04 -05004export OSTYPE
agsantos1bbc7cc2021-05-20 16:43:35 -04005ARCH=$(uname -m)
agsantosc9181b42020-11-26 12:03:04 -05006EXTRAPATH=''
7# Flags:
8
Aline Gondim Santos9bd153e2022-08-25 10:49:23 -03009# -p: number of processors to use.
agsantosc9181b42020-11-26 12:03:04 -050010# -c: Runtime plugin cpu/gpu setting.
11# -t: target platform.
Aline Gondim Santos9bd153e2022-08-25 10:49:23 -030012# -d: debug program.
agsantosc9181b42020-11-26 12:03:04 -050013
14
15if [ -z "${DAEMON}" ]; then
16 DAEMON="./../../daemon"
17 echo "DAEMON not provided, building with ${DAEMON}"
18fi
19
20PLUGIN_NAME="AudioFilter"
21JPL_FILE_NAME="${PLUGIN_NAME}.jpl"
22SO_FILE_NAME="lib${PLUGIN_NAME}.so"
23DAEMON_SRC="${DAEMON}/src"
24CONTRIB_PATH="${DAEMON}/contrib"
agsantos1bbc7cc2021-05-20 16:43:35 -040025PLUGINS_LIB="./../lib"
agsantosc9181b42020-11-26 12:03:04 -050026LIBS_DIR="./../contrib/Libs"
agsantos1bbc7cc2021-05-20 16:43:35 -040027PLATFORM=$(uname)
agsantosc9181b42020-11-26 12:03:04 -050028
agsantos1bbc7cc2021-05-20 16:43:35 -040029if [ "${PLATFORM}" = "Linux" ]; then
agsantosc9181b42020-11-26 12:03:04 -050030 PLATFORM="linux-gnu"
agsantos1bbc7cc2021-05-20 16:43:35 -040031 CONTRIB_PLATFORM_CURT=${ARCH}
32 echo "Building with ${PLATFORM}"
33elif [ "${PLATFORM}" = "Darwin" ]; then
34 PLATFORM="darwin"
35 SO_FILE_NAME="lib${PLUGIN_NAME}.dylib"
36 alias nproc='sysctl -n hw.logicalcpu'
37 CONTRIB_PLATFORM_CURT=${ARCH}-apple
38 CONTRIB_PLATFORM_EXTRA=$(uname -r)
39 echo "Building with ${PLATFORM}"
agsantosc9181b42020-11-26 12:03:04 -050040fi
41
Aline Gondim Santos9bd153e2022-08-25 10:49:23 -030042while getopts t:c:p:d OPT; do
agsantosc9181b42020-11-26 12:03:04 -050043 case "$OPT" in
Aline Gondim Santos9bd153e2022-08-25 10:49:23 -030044 d)
45 DEBUG=true
46 export __DEBUG__=true
47 ;;
agsantosc9181b42020-11-26 12:03:04 -050048 t)
49 PLATFORM="${OPTARG}"
50 ;;
51 c)
52 PROCESSOR="${OPTARG}"
53 ;;
54 p)
55 ;;
56 \?)
57 exit 1
58 ;;
59 esac
60done
61
agsantos7ad7a3a2021-01-19 12:57:54 -050062cp -r ffmpeg ${CONTRIB_PATH}/src/
Aline Gondim Santos9bd153e2022-08-25 10:49:23 -030063cp -r ../contrib/mp3lame ${CONTRIB_PATH}/src/
agsantos7ad7a3a2021-01-19 12:57:54 -050064
agsantosc9181b42020-11-26 12:03:04 -050065if [ "${PLATFORM}" = "linux-gnu" ] || [ "${PLATFORM}" = "redhat-linux" ]
66then
agsantos7ad7a3a2021-01-19 12:57:54 -050067 if [ -f "${CONTRIB_PATH}/native/.ffmpeg" ]; then
68 rm "${CONTRIB_PATH}/native/.ffmpeg"
69 fi
70 WORKPATH=$(pwd)
71 cd "${CONTRIB_PATH}/native/"
agsantosdd6a62a2021-03-29 17:13:27 -040072 make .ffmpeg -j$(nproc)
agsantos7ad7a3a2021-01-19 12:57:54 -050073 rm .ffmpeg
74 cd ${WORKPATH}
75
agsantosc9181b42020-11-26 12:03:04 -050076 CONTRIB_PLATFORM=${CONTRIB_PLATFORM_CURT}-${PLATFORM}
77
Aline Gondim Santos9bd153e2022-08-25 10:49:23 -030078 if [ ${DEBUG} ]; then
79 OUTPUT="${PLUGIN_NAME}"
80 CLANG_OPTS="-g -fsanitize=address"
81 EXTRA_DEBUG_LIBRARIES="-lyaml-cpp -lvdpau -lX11 -lva-drm -lva-x11 -lmp3lame"
82 EXTRA_DEFINES="-D__DEBUG__"
83 else
84 python3 ./../SDK/jplManipulation.py --preassemble --plugin=${PLUGIN_NAME}
85 CLANG_OPTS="-O3 -shared"
86 OUTPUT="build-local/jpl/lib/${CONTRIB_PLATFORM}/${SO_FILE_NAME}"
87 fi
88
agsantosc9181b42020-11-26 12:03:04 -050089 # Compile
Aline Gondim Santos9bd153e2022-08-25 10:49:23 -030090 clang++ -std=c++17 -fPIC ${CLANG_OPTS} \
agsantosc9181b42020-11-26 12:03:04 -050091 -Wl,-Bsymbolic,-rpath,"\${ORIGIN}" \
92 -Wall -Wextra \
agsantosc9181b42020-11-26 12:03:04 -050093 -Wno-unused-parameter \
Aline Gondim Santos9bd153e2022-08-25 10:49:23 -030094 ${EXTRA_DEFINES} \
agsantosc9181b42020-11-26 12:03:04 -050095 -I"." \
96 -I"${DAEMON_SRC}" \
97 -I"${CONTRIB_PATH}/${CONTRIB_PLATFORM}/include" \
98 -I"${PLUGINS_LIB}" \
Aline Gondim Santos9bd153e2022-08-25 10:49:23 -030099 ./../lib/common.cpp \
agsantosc9181b42020-11-26 12:03:04 -0500100 ./../lib/frameFilter.cpp \
101 ./../lib/frameUtils.cpp \
agsantos82678f32020-12-09 15:03:24 -0500102 FilterMediaHandler.cpp \
103 FilterAudioSubscriber.cpp \
agsantosc9181b42020-11-26 12:03:04 -0500104 main.cpp \
105 -L"${CONTRIB_PATH}/${CONTRIB_PLATFORM}/lib/" \
106 -l:libavfilter.a \
107 -l:libswscale.a \
108 -l:libswresample.a \
109 -l:libavformat.a \
110 -l:libavcodec.a \
111 -l:libavutil.a \
Aline Gondim Santos9bd153e2022-08-25 10:49:23 -0300112 -lvpx \
113 -lx264 \
114 -lspeex \
115 -lopus \
116 -lz \
agsantosc9181b42020-11-26 12:03:04 -0500117 -lva \
Aline Gondim Santos9bd153e2022-08-25 10:49:23 -0300118 ${EXTRA_DEBUG_LIBRARIES} \
119 -o "${OUTPUT}"
agsantos1bbc7cc2021-05-20 16:43:35 -0400120
121elif [ "${PLATFORM}" = "darwin" ]
122then
123 if [ -f "${CONTRIB_PATH}/native/.ffmpeg" ]; then
124 rm "${CONTRIB_PATH}/native/.ffmpeg"
125 fi
126 WORKPATH=$(pwd)
127 cd "${CONTRIB_PATH}/native/"
128 make .ffmpeg -j$(nproc)
129 rm .ffmpeg
130 cd ${WORKPATH}
131
agsantos1bbc7cc2021-05-20 16:43:35 -0400132 CONTRIB_PLATFORM=${CONTRIB_PLATFORM_CURT}-${PLATFORM}
133
Aline Gondim Santos9bd153e2022-08-25 10:49:23 -0300134 if [ ${DEBUG} ]; then
135 OUTPUT="${PLUGIN_NAME}"
136 CLANG_OPTS="-g -fsanitize=address"
137 EXTRA_DEBUG_LIBRARIES="-lyaml-cpp -lmp3lame"
138 EXTRA_DEFINES="-D__DEBUG__"
139 else
140 python3 ./../SDK/jplManipulation.py --preassemble --plugin=${PLUGIN_NAME}
141 CLANG_OPTS="-O3 -shared"
142 OUTPUT="build-local/jpl/lib/${CONTRIB_PLATFORM}/${SO_FILE_NAME}"
143 fi
144
agsantos1bbc7cc2021-05-20 16:43:35 -0400145 # Compile
Aline Gondim Santos9bd153e2022-08-25 10:49:23 -0300146 clang++ -std=c++17 -fPIC ${CLANG_OPTS} \
agsantos1bbc7cc2021-05-20 16:43:35 -0400147 -Wl,-no_compact_unwind -Wl,-framework,CoreFoundation \
148 -Wl,-framework,Security -Wl,-framework,VideoToolbox \
149 -Wl,-framework,CoreMedia -Wl,-framework,CoreVideo \
150 -Wl,-rpath,"\${ORIGIN}" \
151 -Wall -Wextra \
agsantos1bbc7cc2021-05-20 16:43:35 -0400152 -Wno-unused-parameter \
Aline Gondim Santos9bd153e2022-08-25 10:49:23 -0300153 ${EXTRA_DEFINES} \
agsantos1bbc7cc2021-05-20 16:43:35 -0400154 -I"." \
155 -I"${DAEMON_SRC}" \
156 -I"${CONTRIB_PATH}/${CONTRIB_PLATFORM}${CONTRIB_PLATFORM_EXTRA}/include" \
157 -I"${PLUGINS_LIB}" \
Aline Gondim Santos9bd153e2022-08-25 10:49:23 -0300158 ./../lib/common.cpp \
agsantos1bbc7cc2021-05-20 16:43:35 -0400159 ./../lib/frameFilter.cpp \
160 ./../lib/frameUtils.cpp \
161 FilterMediaHandler.cpp \
162 FilterAudioSubscriber.cpp \
163 main.cpp \
164 -L"${CONTRIB_PATH}/${CONTRIB_PLATFORM}${CONTRIB_PLATFORM_EXTRA}/lib/" \
165 -lavfilter \
166 -lswscale \
167 -lswresample \
168 -lavformat \
169 -lavcodec \
170 -lavutil \
171 -lvpx -lx264 -lbz2 -liconv -lz \
Aline Gondim Santos9bd153e2022-08-25 10:49:23 -0300172 -lspeex \
173 -lopus \
174 ${EXTRA_DEBUG_LIBRARIES} \
175 -o "${OUTPUT}"
agsantos1bbc7cc2021-05-20 16:43:35 -0400176
Aline Gondim Santos9bd153e2022-08-25 10:49:23 -0300177 if [ ! ${DEBUG} ]; then
178 install_name_tool -id "@loader_path/${PLUGIN_NAME}" "${OUTPUT}"
179 else
180 install_name_tool -id "@loader_path/${SO_FILE_NAME}" "${OUTPUT}"
181 fi
agsantos1bbc7cc2021-05-20 16:43:35 -0400182
183 if [ -n "${APPLE_SIGN_CERTIFICATE}" ]; then
184 codesign --force --verify --timestamp -o runtime --sign "${APPLE_SIGN_CERTIFICATE}" "build-local/jpl/lib/${CONTRIB_PLATFORM}/${SO_FILE_NAME}"
185 ditto -c -k --rsrc "build-local/jpl/lib/${CONTRIB_PLATFORM}/${SO_FILE_NAME}" "build-local/${SO_FILE_NAME}.zip"
186 LIBRARYNAME=${SO_FILE_NAME} sh ./../notarize.sh
187 ditto -x -k "build-local/${SO_FILE_NAME}.zip" "build-local/notarized"
188 cp "build-local/notarized/${SO_FILE_NAME}" "build-local/jpl/lib/${CONTRIB_PLATFORM}/${SO_FILE_NAME}"
189 fi
agsantosc9181b42020-11-26 12:03:04 -0500190
191elif [ "${PLATFORM}" = "android" ]
192then
193 python3 ./../SDK/jplManipulation.py --preassemble --plugin=${PLUGIN_NAME} --distribution=${PLATFORM}
194
195 if [ -z "$ANDROID_NDK" ]; then
196 ANDROID_NDK="/home/${USER}/Android/Sdk/ndk/21.1.6352462"
197 echo "ANDROID_NDK not provided, building with ${ANDROID_NDK}"
198 fi
199
200 #=========================================================
201 # Check if the ANDROID_ABI was provided
202 # if not, set default
203 #=========================================================
204 if [ -z "$ANDROID_ABI" ]; then
205 ANDROID_ABI="armeabi-v7a arm64-v8a x86_64"
206 echo "ANDROID_ABI not provided, building for ${ANDROID_ABI}"
207 fi
208
209 buildlib() {
210 echo "$CURRENT_ABI"
211
212 #=========================================================
213 # ANDROID TOOLS
214 #=========================================================
215 export HOST_TAG=linux-x86_64
216 export TOOLCHAIN=$ANDROID_NDK/toolchains/llvm/prebuilt/$HOST_TAG
Aline Gondim Santos4c3f0662022-10-12 13:11:34 -0300217 export AR=$TOOLCHAIN/bin/llvm-ar
218 export AS=$TOOLCHAIN/bin/llvm-as
219 export LD=$TOOLCHAIN/bin/ld
220 export RANLIB=$TOOLCHAIN/bin/llvm-ranlib
221 export STRIP=$TOOLCHAIN/bin/llvm-strip
222 export ANDROID_SYSROOT=$TOOLCHAIN/sysroot
agsantosc9181b42020-11-26 12:03:04 -0500223
224 if [ "$CURRENT_ABI" = armeabi-v7a ]
225 then
agsantosc9181b42020-11-26 12:03:04 -0500226 export CC=$TOOLCHAIN/bin/armv7a-linux-androideabi21-clang
227 export CXX=$TOOLCHAIN/bin/armv7a-linux-androideabi21-clang++
agsantosc9181b42020-11-26 12:03:04 -0500228
229 elif [ "$CURRENT_ABI" = arm64-v8a ]
230 then
agsantosc9181b42020-11-26 12:03:04 -0500231 export CC=$TOOLCHAIN/bin/aarch64-linux-android21-clang
232 export CXX=$TOOLCHAIN/bin/aarch64-linux-android21-clang++
agsantosc9181b42020-11-26 12:03:04 -0500233
234 elif [ "$CURRENT_ABI" = x86_64 ]
235 then
agsantosc9181b42020-11-26 12:03:04 -0500236 export CC=$TOOLCHAIN/bin/x86_64-linux-android21-clang
237 export CXX=$TOOLCHAIN/bin/x86_64-linux-android21-clang++
agsantosc9181b42020-11-26 12:03:04 -0500238
239 else
240 echo "ABI NOT OK" >&2
241 exit 1
242 fi
243
244 #=========================================================
245 # CONTRIBS
246 #=========================================================
247 if [ "$CURRENT_ABI" = armeabi-v7a ]
248 then
249 CONTRIB_PLATFORM=arm-linux-androideabi
250
251 elif [ "$CURRENT_ABI" = arm64-v8a ]
252 then
253 CONTRIB_PLATFORM=aarch64-linux-android
254
255 elif [ "$CURRENT_ABI" = x86_64 ]
256 then
257 CONTRIB_PLATFORM=x86_64-linux-android
258 fi
259
260 #NDK SOURCES FOR cpufeatures
261 NDK_SOURCES=${ANDROID_NDK}/sources/android
262
agsantos7ad7a3a2021-01-19 12:57:54 -0500263 if [ -f "${CONTRIB_PATH}/native-${CONTRIB_PLATFORM}/.ffmpeg" ]; then
264 rm "${CONTRIB_PATH}/native-${CONTRIB_PLATFORM}/.ffmpeg"
265 fi
266 WORKPATH=$(pwd)
267 cd "${CONTRIB_PATH}/native-${CONTRIB_PLATFORM}/"
agsantosdd6a62a2021-03-29 17:13:27 -0400268 make .ffmpeg -j$(nproc)
agsantos7ad7a3a2021-01-19 12:57:54 -0500269 rm .ffmpeg
270 cd ${WORKPATH}
271
agsantosc9181b42020-11-26 12:03:04 -0500272 #=========================================================
273 # Compile the plugin
274 #=========================================================
275
276 # Create so destination folder
Aline Gondim Santos4c3f0662022-10-12 13:11:34 -0300277 $CXX --std=c++17 -O3 -fPIC \
agsantosc9181b42020-11-26 12:03:04 -0500278 -Wl,-Bsymbolic,-rpath,"\${ORIGIN}" \
279 -shared \
280 -Wall -Wextra \
agsantosc9181b42020-11-26 12:03:04 -0500281 -Wno-unused-parameter \
282 -I"." \
283 -I"${DAEMON_SRC}" \
284 -I"${CONTRIB_PATH}/${CONTRIB_PLATFORM}/include" \
285 -I"${PLUGINS_LIB}" \
286 ./../lib/frameFilter.cpp \
287 ./../lib/frameUtils.cpp \
agsantos82678f32020-12-09 15:03:24 -0500288 FilterMediaHandler.cpp \
289 FilterAudioSubscriber.cpp \
agsantosc9181b42020-11-26 12:03:04 -0500290 main.cpp \
291 -L"${CONTRIB_PATH}/${CONTRIB_PLATFORM}/lib/" \
292 -lavfilter \
293 -lswscale \
294 -lswresample \
295 -lavformat \
296 -lavcodec \
297 -lavutil \
298 -lvpx \
299 -lx264 \
300 -lspeex \
301 -lopus \
302 -liconv \
303 -llog -lz \
304 --sysroot=$ANDROID_SYSROOT \
305 -o "build-local/jpl/lib/$CURRENT_ABI/${SO_FILE_NAME}"
306 }
307
308 # Build the so
309 for i in ${ANDROID_ABI}; do
310 CURRENT_ABI=$i
311 buildlib
312 done
313fi
314
Aline Gondim Santos9bd153e2022-08-25 10:49:23 -0300315if [ ! ${DEBUG} ]; then
316 python3 ./../SDK/jplManipulation.py --assemble --plugin=${PLUGIN_NAME} --distribution=${PLATFORM} --extraPath=${EXTRAPATH}
317fi
agsantos7ad7a3a2021-01-19 12:57:54 -0500318cd ${CONTRIB_PATH}/src/ffmpeg/
319# ffmpeg build configuration files were changed during plugin build
320# this git checkout will remove these changes
321git checkout -- .