-
-
Notifications
You must be signed in to change notification settings - Fork 44
/
build.sh
executable file
·185 lines (168 loc) · 6.75 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
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
#!/bin/bash
set -ex
# unset the SUBDIR variable since it changes the behavior of make here
unset SUBDIR
extra_args=""
if [[ "$CONDA_BUILD_CROSS_COMPILATION" == "1" ]]; then
if [[ "$ARCH" == "64" ]]; then
ARCH=x86_64
fi
case "$target_platform" in
linux-*)
OS=linux
;;
osx-*)
OS=darwin
;;
*)
echo "unknown OS for cross compile"
exit 1
;;
esac
extra_args="${extra_args} --enable-cross-compile --arch=$ARCH --target-os=$OS --cross-prefix=$HOST- --host-cc=$CC_FOR_BUILD"
fi
if [[ "${target_platform}" == "win-64" ]]; then
# 2022/07 hmaarrfk
# Specifying these extra flags for osx and linux
# seems to cause things to fail since FFmpeg
# expects cc to be the ld
# # https://github.com/FFmpeg/FFmpeg/blob/master/configure#L4894
# the LDFLAGs on Unix contain the -Wl, prefix, and thus
# are incompatible with the direct ld command
# Thus we avoid specifying ld for the unix platforms
extra_args="${extra_args} --ld=${LD}"
extra_args="${extra_args} --target-os=win64"
extra_args="${extra_args} --enable-cross-compile"
extra_args="${extra_args} --toolchain=msvc"
extra_args="${extra_args} --host-cc=${CC}"
extra_args="${extra_args} --extra-libs=ucrt.lib --extra-libs=vcruntime.lib --extra-libs=oldnames.lib"
extra_args="${extra_args} --strip=llvm-strip"
# Through, locally, I get
# This app can't run on your PC
# and access denied on the terminal
# I cannot even run llvm-strip on the terminal
extra_args="${extra_args} --disable-stripping"
# ffmpeg by default attempts to link to libm
# but that doesn't exist for windows
extra_args="${extra_args} --host-extralibs="
# Delete line that includes unistd.h from zconf. we should patch this
# better for LLVM compatibility
# I submitted a ticket upstream
# https://github.com/madler/zlib/issues/674
# cp ${PREFIX}/include/zconf.h zconf.h.backup
# sed -i "/unistd/d" ${PREFIX}/include/zconf.h
if [[ ! -f "${PREFIX}/include/unistd.h" ]]; then
UNISTD_CREATED=1
touch "${PREFIX}/include/unistd.h"
fi
# Add pkgconfig from the prefix to search through it correctly
export PKG_CONFIG_PATH=${PREFIX}/lib/pkgconfig:${PKG_CONFIG_PATH}
PKG_CONFIG="${BUILD_PREFIX}/Library/bin/pkg-config"
# I'm not sure, but it seems like
# their hacky way of silencing things is messing with the AR command
# Especially as it is called in compat/windows/makedef
# https://github.com/FFmpeg/FFmpeg/blob/master/ffbuild/common.mak#L21
# I think their hacky silence is corrupting later on AR commands invoked
# from shells with a @printf statement
# To avoid hacky patches, I'm just going to make it verbose, always.
# maybe related to https://trac.ffmpeg.org/ticket/6620
export V=1
elif [[ "${target_platform}" == linux-* ]]; then
PKG_CONFIG="${BUILD_PREFIX}/bin/pkg-config"
extra_args="${extra_args} --disable-gnutls"
extra_args="${extra_args} --enable-libmp3lame"
extra_args="${extra_args} --enable-libvpx"
extra_args="${extra_args} --enable-libass"
extra_args="${extra_args} --enable-pthreads"
if [[ "${target_platform}" == "linux-64" ]]; then
extra_args="${extra_args} --enable-vaapi"
fi
elif [[ "${target_platform}" == osx-* ]]; then
if [[ "${target_platform}" == osx-arm64 ]]; then
extra_args="${extra_args} --enable-neon"
else
extra_args="${extra_args} --enable-videotoolbox"
fi
extra_args="${extra_args} --disable-gnutls"
extra_args="${extra_args} --enable-libmp3lame"
extra_args="${extra_args} --enable-libvpx"
extra_args="${extra_args} --enable-libass"
extra_args="${extra_args} --enable-pthreads"
# See https://github.com/conda-forge/ffmpeg-feedstock/pull/115
# why this flag needs to be removed.
sed -i.bak s/-Wl,-single_module// configure
PKG_CONFIG="${BUILD_PREFIX}/bin/pkg-config"
fi
# enable OpenVINO to optimize AI tasks of avfilter component
if [[ "${target_platform}" == linux-ppc64le ]] || [[ "${target_platform}" == win-64 ]]; then
extra_args="${extra_args} --disable-libopenvino"
else
extra_args="${extra_args} --enable-libopenvino"
fi
if [[ "${license_family}" == "gpl" ]]; then
extra_args="${extra_args} --enable-gpl"
extra_args="${extra_args} --enable-libx264"
extra_args="${extra_args} --enable-libx265"
if [[ "${target_platform}" == "win-64" ]]; then
# seems like we don't use the same organization as
# others for x264.
# This may not be necessary with version 164
# https://github.com/conda-forge/x264-feedstock/pull/28#issuecomment-1178402181
if [[ ! -f "${PREFIX}/lib/libx264.lib" ]]; then
cp ${PREFIX}/lib/x264.lib ${PREFIX}/lib/libx264.lib
LIBX264_LIB_CREATED=1
fi
fi
else
extra_args="${extra_args} --disable-gpl"
fi
./configure \
--prefix="${PREFIX}" \
--cc=${CC} \
--cxx=${CXX} \
--nm=${NM} \
--ar=${AR} \
--disable-doc \
--enable-openssl \
--enable-demuxer=dash \
--enable-hardcoded-tables \
--enable-libfreetype \
--enable-libharfbuzz \
--enable-libfontconfig \
--enable-libopenh264 \
--enable-libdav1d \
${extra_args} \
--enable-libaom \
--enable-libsvtav1 \
--enable-libxml2 \
--enable-pic \
--enable-shared \
--disable-static \
--enable-version3 \
--enable-zlib \
--enable-libopus \
--pkg-config=${PKG_CONFIG} \
|| { if [[ ${CI} != "" ]]; then cat ffbuild/config.log; fi; exit 1; }
if [[ "${target_platform}" == win-* ]]; then
# Don't install the def files, but intall the lib files instead
sed -i 's/SLIB_INSTALL_EXTRA_LIB=$(SLIBNAME_WITH_MAJOR:$(SLIBSUF)=.def)/SLIB_INSTALL_EXTRA_LIB=$(SLIBNAME:$(SLIBSUF)=.lib)/' ffbuild/config.mak
# install the lib files in the lib directory, not bin
sed -i 's/SLIB_INSTALL_EXTRA_SHLIB=$(SLIBNAME:$(SLIBSUF)=.lib)/SLIB_INSTALL_EXTRA_SHLIB=/' ffbuild/config.mak
# Their default DLLs include the version in the dll name
# If we want to, we can uncomment the lines below to remove the version from the dll name
# we don't need those version numbers because conda is our package manager
# sed -i 's/SLIB_INSTALL_NAME=$(SLIBNAME_WITH_MAJOR)/SLIB_INSTALL_NAME=$(SLIBNAME)/' ffbuild/config.mak
# sed -i 's/SLIBNAME_WITH_VERSION=$(SLIBPREF)$(FULLNAME)-$(LIBVERSION)$(SLIBSUF)/SLIBNAME_WITH_VERSION=$(SLIBNAME)/' ffbuild/config.mak
# sed -i 's/SLIBNAME_WITH_MAJOR=$(SLIBPREF)$(FULLNAME)-$(LIBMAJOR)$(SLIBSUF)/SLIBNAME_WITH_MAJOR=$(SLIBNAME)/' ffbuild/config.mak
fi
if [[ ${CI} != "" ]]; then cat ffbuild/config.mak; fi
make -j${CPU_COUNT}
make install
if [[ "${target_platform}" == win-* ]]; then
if [[ "${UNISTD_CREATED}" == "1" ]]; then
rm -f "${PREFIX}/include/unistd.h"
fi
if [[ "${LIBX264_LIB_CREATED}" == "1" ]]; then
rm -f ${PREFIX}/lib/libx264.lib
fi
fi