Skip to content

Commit 94c5114

Browse files
authored
Add rpath fixups to Mac non-GPL FFmpeg build (#211)
1 parent ec24944 commit 94c5114

File tree

1 file changed

+93
-0
lines changed

1 file changed

+93
-0
lines changed

packaging/build_ffmpeg.sh

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,96 @@ tar -xf ffmpeg.tar.gz --strip-components 1
6464

6565
make -j install
6666
ls ${prefix}/*
67+
68+
# macos: Fix rpath so that the libraries are searched dynamically in user environment.
69+
# In Linux, this is handled by `--enable-rpath` flag.
70+
if [[ "$(uname)" == Darwin ]]; then
71+
ffmpeg_version="${FFMPEG_VERSION:-4.1.8}"
72+
major_ver=${ffmpeg_version:0:1}
73+
if [[ ${major_ver} == 4 ]]; then
74+
avutil=libavutil.56
75+
avcodec=libavcodec.58
76+
avformat=libavformat.58
77+
avdevice=libavdevice.58
78+
avfilter=libavfilter.7
79+
elif [[ ${major_ver} == 5 ]]; then
80+
avutil=libavutil.57
81+
avcodec=libavcodec.59
82+
avformat=libavformat.59
83+
avdevice=libavdevice.59
84+
avfilter=libavfilter.8
85+
elif [[ ${major_ver} == 6 ]]; then
86+
avutil=libavutil.58
87+
avcodec=libavcodec.60
88+
avformat=libavformat.60
89+
avdevice=libavdevice.60
90+
avfilter=libavfilter.9
91+
elif [[ ${major_ver} == 7 ]]; then
92+
avutil=libavutil.59
93+
avcodec=libavcodec.61
94+
avformat=libavformat.61
95+
avdevice=libavdevice.61
96+
avfilter=libavfilter.10
97+
else
98+
printf "Error: unexpected FFmpeg major version: %s\n" ${major_ver}
99+
exit 1;
100+
fi
101+
102+
otool="/usr/bin/otool"
103+
# NOTE: miniconda has a version of otool and install_name_tool installed and we want
104+
# to use the default sytem version instead of the miniconda version since the miniconda
105+
# version can produce inconsistent results
106+
107+
# Attempt to use /usr/bin/otool as our default otool
108+
if [[ ! -e ${otool} ]]; then
109+
otool="$(which otool)"
110+
fi
111+
install_name_tool="/usr/bin/install_name_tool"
112+
# Attempt to use /usr/bin/install_name_tool as our default install_name_tool
113+
if [[ ! -e ${install_name_tool} ]]; then
114+
install_name_tool="$(which install_name_tool)"
115+
fi
116+
117+
# list up the paths to fix
118+
for lib in ${avcodec} ${avdevice} ${avfilter} ${avformat} ${avutil}; do
119+
${otool} -l ${prefix}/lib/${lib}.dylib | grep -B2 ${prefix}
120+
done
121+
122+
# Replace the hardcoded paths to @rpath
123+
${install_name_tool} \
124+
-change ${prefix}/lib/${avutil}.dylib @rpath/${avutil}.dylib \
125+
-delete_rpath ${prefix}/lib \
126+
-id @rpath/${avcodec}.dylib \
127+
${prefix}/lib/${avcodec}.dylib
128+
${otool} -l ${prefix}/lib/${avcodec}.dylib | grep -B2 ${prefix}
129+
130+
${install_name_tool} \
131+
-change ${prefix}/lib/${avformat}.dylib @rpath/${avformat}.dylib \
132+
-change ${prefix}/lib/${avcodec}.dylib @rpath/${avcodec}.dylib \
133+
-change ${prefix}/lib/${avutil}.dylib @rpath/${avutil}.dylib \
134+
-delete_rpath ${prefix}/lib \
135+
-id @rpath/${avdevice}.dylib \
136+
${prefix}/lib/${avdevice}.dylib
137+
${otool} -l ${prefix}/lib/${avdevice}.dylib | grep -B2 ${prefix}
138+
139+
${install_name_tool} \
140+
-change ${prefix}/lib/${avutil}.dylib @rpath/${avutil}.dylib \
141+
-delete_rpath ${prefix}/lib \
142+
-id @rpath/${avfilter}.dylib \
143+
${prefix}/lib/${avfilter}.dylib
144+
${otool} -l ${prefix}/lib/${avfilter}.dylib | grep -B2 ${prefix}
145+
146+
${install_name_tool} \
147+
-change ${prefix}/lib/${avcodec}.dylib @rpath/${avcodec}.dylib \
148+
-change ${prefix}/lib/${avutil}.dylib @rpath/${avutil}.dylib \
149+
-delete_rpath ${prefix}/lib \
150+
-id @rpath/${avformat}.dylib \
151+
${prefix}/lib/${avformat}.dylib
152+
${otool} -l ${prefix}/lib/${avformat}.dylib | grep -B2 ${prefix}
153+
154+
${install_name_tool} \
155+
-delete_rpath ${prefix}/lib \
156+
-id @rpath/${avutil}.dylib \
157+
${prefix}/lib/${avutil}.dylib
158+
${otool} -l ${prefix}/lib/${avutil}.dylib | grep -B2 ${prefix}
159+
fi

0 commit comments

Comments
 (0)