forked from videolan/vlc-unity
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild-libvlc.sh
More file actions
executable file
·189 lines (166 loc) · 6.6 KB
/
Copy pathbuild-libvlc.sh
File metadata and controls
executable file
·189 lines (166 loc) · 6.6 KB
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
#!/bin/bash
# Build libvlc from source.
# Runs inside the VLC build container (locally via Docker, or natively in CI).
#
# Usage:
# ./build-libvlc.sh <TRIPLET> <ARCH>
# e.g. ./build-libvlc.sh x86_64-linux-gnu x86_64
#
# Output: ./linux-install/ (relative to the working directory)
set -ex
TRIPLET="${1:?Usage: $0 <TRIPLET> <ARCH>}"
ARCH="${2:?Usage: $0 <TRIPLET> <ARCH>}"
export NCPU=$(getconf _NPROCESSORS_ONLN)
set_runpath_to_origin() {
local path="$1"
[ -f "$path" ] || return 0
if command -v patchelf >/dev/null 2>&1; then
patchelf --set-rpath '$ORIGIN' "$path"
return 0
fi
python3 - "$path" <<'PY'
import pathlib
import re
import subprocess
import sys
path = pathlib.Path(sys.argv[1])
out = subprocess.check_output(["readelf", "-d", str(path)], text=True, stderr=subprocess.DEVNULL)
match = re.search(r"RUNPATH.*\[(.+)\]", out)
if not match:
sys.exit(0)
old = match.group(1).encode()
new = b"$ORIGIN"
if old == new:
sys.exit(0)
if len(old) < len(new):
raise SystemExit(f"RUNPATH too short to patch in-place for {path}")
data = path.read_bytes()
data = data.replace(old, new + b"\x00" * (len(old) - len(new)), 1)
path.write_bytes(data)
PY
}
# Clone VLC if not already present
if [ ! -d vlc ]; then
git clone --depth 1 https://code.videolan.org/videolan/vlc
fi
cd vlc
# Build extras/tools if not already built
if [ ! -f extras/tools/.buildmeson ]; then
cd extras/tools && ./bootstrap && make -j$NCPU --output-sync=recurse
cd ../..
fi
export PATH="$(pwd)/extras/tools/build/bin:$PATH"
# Build contribs from source — ignore system packages so all deps are
# built as static libs, making VLC plugins self-contained.
export PKG_CONFIG_LIBDIR=""
export PKG_CONFIG_PATH=""
export PKG_CONFIG_SYSROOT_DIR=""
# Expose selected system pkg-config files that contrib-built dependencies rely on
# during their own configure/build steps (for example Vulkan-Loader needs X11/XCB).
mkdir -p contrib/${TRIPLET}/lib/pkgconfig
src="/usr/lib/${TRIPLET}/pkgconfig/x11.pc"
if [ -f "$src" ]; then
cp "$src" "contrib/${TRIPLET}/lib/pkgconfig/x11.pc"
sed -i '/^Requires:/d' "contrib/${TRIPLET}/lib/pkgconfig/x11.pc"
fi
for pc in gl egl glesv2 libunwind libunwind-generic lcms2 libpulse \
x11-xcb xau xdmcp xcb xext xfixes xrender xrandr; do
src="/usr/lib/${TRIPLET}/pkgconfig/${pc}.pc"
[ -f "$src" ] || src="/usr/share/pkgconfig/${pc}.pc"
[ -f "$src" ] && ln -sf "$src" "contrib/${TRIPLET}/lib/pkgconfig/" || true
done
for pc in xproto kbproto; do
src="/usr/share/pkgconfig/${pc}.pc"
[ -f "$src" ] && ln -sf "$src" "contrib/${TRIPLET}/lib/pkgconfig/" || true
done
mkdir -p contrib/contrib-${TRIPLET} && cd contrib/contrib-${TRIPLET}
if [ ! -f Makefile ]; then
../bootstrap --disable-x264 --disable-x265 --disable-dvdread --disable-dvdnav \
--enable-glslang --enable-libplacebo \
--enable-vulkan-headers --enable-vulkan-loader
fi
make list 2>&1 | grep -A5 "Distribution-provided\|Automatically selected" || true
make -j$NCPU --output-sync=recurse fetch
# Force-build libplacebo before the main parallel build.
# The contrib "all" target may finish with unrelated errors before this path
# completes, leaving libplacebo absent even though it is otherwise buildable.
# Build matching contrib Vulkan headers first so vulkan-loader does not pick
# newer system headers with incompatible generated entrypoint signatures.
# Building it up front also guarantees that we use the contrib
# glslang static libraries instead of whatever the container happens to expose.
make .vulkan-headers || true
make .glslang || true
make .libplacebo || true
make -j$NCPU --output-sync=recurse -k || true
# Verify critical contribs were built as static libs
ls ../${TRIPLET}/lib/libavcodec.a || { echo "ERROR: FFmpeg static libs missing"; exit 1; }
ls ../${TRIPLET}/lib/libplacebo.a || { echo "ERROR: libplacebo static lib missing"; exit 1; }
mkdir -p ../${TRIPLET}/lib/pkgconfig
# Replace system xau/xcb pkg-config metadata with contrib versions so VLC
# links against the matching static libraries and their dependencies.
src=$(find . -path "*/libxau/vlc_build/xau.pc" 2>/dev/null | head -1)
[ -n "$src" ] && rm -f "../${TRIPLET}/lib/pkgconfig/xau.pc" && cp "$src" "../${TRIPLET}/lib/pkgconfig/xau.pc" || true
for pkg in xcb xcb-composite xcb-dbe xcb-dri3 xcb-keysyms xcb-present \
xcb-randr xcb-record xcb-render xcb-shape xcb-shm xcb-xfixes xcb-xkb; do
src=$(find . -path "*/libxcb/vlc_build/${pkg}.pc" 2>/dev/null | head -1)
dest="../${TRIPLET}/lib/pkgconfig/${pkg}.pc"
[ -n "$src" ] && [ -f "$src" ] && rm -f "$dest" && cp "$src" "$dest" || true
done
cd ../..
# Bootstrap and configure VLC
if [ ! -f configure ]; then
./bootstrap
fi
./configure \
--prefix=$(pwd)/linux-install \
--disable-vlc \
--disable-x264 \
--disable-x26410b \
--disable-x265 \
--disable-dvdread \
--disable-dvdnav \
--disable-qt \
--disable-skins2 \
--disable-ncurses \
--disable-lirc \
--disable-lua \
--disable-dbus \
--disable-avahi \
--disable-mtp \
--disable-notify \
--enable-pulse \
--disable-sout
# Build and install
make -j$NCPU
make install
# libtool bakes the install prefix into libvlc's RUNPATH. Replace it at build
# time so deployed libraries resolve their sibling SONAMEs from the final
# package location instead of the original build path.
for f in linux-install/lib/libvlc.so*; do
[ -f "$f" ] || continue
set_runpath_to_origin "$f"
done
# Flatten only the top-level libvlc/libvlccore runtime libs and create SONAME
# symlinks for them. Keep the lib/vlc helper libraries versioned: some VLC
# modules depend on their real filename targets (for example
# libvlc_xcb_events.so.0.0.0).
cd linux-install/lib
for f in libvlc.so.*.*.* libvlccore.so.*.*.*; do
[ -f "$f" ] || continue
base=$(echo "$f" | sed 's/\.so\..*/.so/')
soname=$(objdump -p "$f" 2>/dev/null | awk '/SONAME/{print $2}')
mv "$f" "$base"
[ -n "$soname" ] && [ "$soname" != "$base" ] && ln -sf "$base" "$soname"
done
find . -maxdepth 1 -type f \( -name "libvlc.so.*" -o -name "libvlccore.so.*" \) -delete 2>/dev/null || true
cd ../..
# Strip the lib/vlc/ tree down to what's actually used at runtime.
# libtool installs a lot of link-time-only artifacts (.la descriptors,
# .a static archives). Keep the versioned .so files there: VLC modules may
# reference them by exact SONAME at runtime.
find linux-install/lib/vlc \( -name "*.la" -o -name "*.a" \) -delete
find linux-install/lib -type f \( -name "*.so" -o -name "*.so.*" \) -exec strip --strip-unneeded {} +
echo "=== Build complete ==="
ls -la linux-install/lib/libvlc* 2>/dev/null || true
echo "--- lib/vlc/ ---"
ls linux-install/lib/vlc/ 2>/dev/null || true