-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild-linux.sh
More file actions
executable file
·108 lines (88 loc) · 2.83 KB
/
build-linux.sh
File metadata and controls
executable file
·108 lines (88 loc) · 2.83 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
#!/usr/bin/env bash
set -eu
source "$(dirname "$0")/build-common.sh"
init_build_env
download_ffmpeg_tarball
read_configure_flags
apply_optional_feature_filters
set_lib_type
OUTPUT_DIR=outputs/ffmpeg-$FFMPEG_VERSION-$LIB_TYPE-$ARCH-linux-gnu
# Use explicit BUILD_DIR if provided, otherwise derive from ENABLE_SHARED
if [ -z "${BUILD_DIR:-}" ]; then
BUILD_DIR="$BASE_DIR/build-${LIB_TYPE}-linux"
fi
mkdir -p "$BUILD_DIR"
if [ "$LIB_TYPE" = "shared" ]; then
FFMPEG_CONFIGURE_FLAGS+=(
--enable-shared
--disable-static
)
else
FFMPEG_CONFIGURE_FLAGS+=(
--enable-static
--disable-shared
--pkg-config-flags=--static
)
fi
FFMPEG_CONFIGURE_FLAGS+=(
--enable-ffmpeg
--disable-ffprobe
)
FFMPEG_CONFIGURE_FLAGS+=(
--extra-cflags="$(linux_extra_cflags)"
--extra-ldflags="-Wl,--gc-sections"
)
cd "$BUILD_DIR"
tar --strip-components=1 -xf "$BASE_DIR/$FFMPEG_TARBALL"
FFMPEG_CONFIGURE_FLAGS+=(
--prefix="$BASE_DIR/$OUTPUT_DIR"
)
echo "Configuring FFmpeg..."
./configure "${FFMPEG_CONFIGURE_FLAGS[@]}" || (cat ffbuild/config.log && exit 1)
echo "Building..."
make -j$(nproc)
make install
if [ "$LIB_TYPE" = "shared" ]; then
echo "Post-processing shared libraries..."
LIB_DIR="$BASE_DIR/$OUTPUT_DIR/lib"
cd "$LIB_DIR"
# Remove symlinks, keep real files
for link in *.so *.so.[0-9]*; do
if [ -L "$link" ]; then
rm -f "$link"
fi
done
# Fix SONAME and dependencies
if command -v patchelf > /dev/null; then
for so_file in *.so.*.*.*; do
if [ -f "$so_file" ] && [ ! -L "$so_file" ]; then
echo " Processing $so_file..."
patchelf --set-soname "$so_file" "$so_file"
for dep in $(patchelf --print-needed "$so_file"); do
case $dep in
libav*|libsw*|libpostproc*)
prefix=$(echo "$dep" | cut -d. -f1)
actual_dep=$(ls ${prefix}.so.*.*.* 2>/dev/null | head -n 1)
if [ -n "$actual_dep" ] && [ "$dep" != "$actual_dep" ]; then
patchelf --replace-needed "$dep" "$actual_dep" "$so_file"
fi
;;
esac
done
patchelf --set-rpath '$ORIGIN' "$so_file"
fi
done
else
echo "Warning: patchelf not found. SONAME/Dependencies not updated."
fi
fi
cd "$BASE_DIR"
TAR_NAME="${OUTPUT_DIR}.tar.gz"
echo "Packaging to $TAR_NAME ..."
tar czf "$TAR_NAME" -C outputs "$(basename "$OUTPUT_DIR")"
# Only chown if running as root
if [ "$(id -u)" -eq 0 ]; then
chown "$(stat -c '%u:%g' "$BASE_DIR")" "$TAR_NAME"
chown "$(stat -c '%u:%g' "$BASE_DIR")" -R "$OUTPUT_DIR"
fi
echo "Linux build complete. Output: $OUTPUT_DIR"