build.sh 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. #!/bin/bash
  2. set -xe
  3. shopt -s globstar
  4. cd "$(dirname "$0")"
  5. source util/vars.sh
  6. source "variants/${TARGET}-${VARIANT}.sh"
  7. for addin in ${ADDINS[*]}; do
  8. source "addins/${addin}.sh"
  9. done
  10. if docker info -f "{{println .SecurityOptions}}" | grep rootless >/dev/null 2>&1; then
  11. UIDARGS=()
  12. else
  13. UIDARGS=( -u "$(id -u):$(id -g)" )
  14. fi
  15. rm -rf ffbuild
  16. mkdir ffbuild
  17. FFMPEG_REPO="${FFMPEG_REPO:-https://github.com/FFmpeg/FFmpeg.git}"
  18. FFMPEG_REPO="${FFMPEG_REPO_OVERRIDE:-$FFMPEG_REPO}"
  19. GIT_BRANCH="${GIT_BRANCH:-master}"
  20. GIT_BRANCH="${GIT_BRANCH_OVERRIDE:-$GIT_BRANCH}"
  21. BUILD_SCRIPT="$(mktemp)"
  22. trap "rm -f -- '$BUILD_SCRIPT'" EXIT
  23. cat <<EOF >"$BUILD_SCRIPT"
  24. set -xe
  25. shopt -s nullglob
  26. cd /ffbuild
  27. rm -rf ffmpeg prefix
  28. git clone --filter=blob:none --branch='$GIT_BRANCH' '$FFMPEG_REPO' ffmpeg
  29. cd ffmpeg
  30. git config user.email "builder@localhost"
  31. git config user.name "Builder"
  32. PATCHES=('/patches/$GIT_BRANCH'/*.patch)
  33. if [[ "\${#PATCHES[@]}" = 0 ]]; then
  34. echo 'No patches found for $GIT_BRANCH'
  35. fi
  36. for patch in "\${PATCHES[@]}"; do
  37. echo "Applying \$patch"
  38. git apply "\$patch"
  39. done
  40. ./configure --prefix=/ffbuild/prefix --pkg-config-flags="--static" \$FFBUILD_TARGET_FLAGS \$FF_CONFIGURE \
  41. --extra-cflags="\$FF_CFLAGS" --extra-cxxflags="\$FF_CXXFLAGS" --extra-libs="\$FF_LIBS" \
  42. --extra-ldflags="\$FF_LDFLAGS" --extra-ldexeflags="\$FF_LDEXEFLAGS" \
  43. --cc="\$CC" --cxx="\$CXX" --ar="\$AR" --ranlib="\$RANLIB" --nm="\$NM" \
  44. --extra-version="\$(date +%Y%m%d)"
  45. make -j\$(nproc) V=1
  46. make install install-doc
  47. EOF
  48. [[ -t 1 ]] && TTY_ARG="-t" || TTY_ARG=""
  49. docker run --rm -i $TTY_ARG "${UIDARGS[@]}" -v "$PWD/ffbuild":/ffbuild -v "$PWD/patches/ffmpeg/":/patches -v "$BUILD_SCRIPT":/build.sh "$IMAGE" bash /build.sh
  50. mkdir -p artifacts
  51. ARTIFACTS_PATH="$PWD/artifacts"
  52. BUILD_NAME="ffmpeg-$(./ffbuild/ffmpeg/ffbuild/version.sh ffbuild/ffmpeg)-${TARGET}-${VARIANT}${ADDINS_STR:+-}${ADDINS_STR}"
  53. mkdir -p "ffbuild/pkgroot/$BUILD_NAME"
  54. package_variant ffbuild/prefix "ffbuild/pkgroot/$BUILD_NAME"
  55. [[ -n "$LICENSE_FILE" ]] && cp "ffbuild/ffmpeg/$LICENSE_FILE" "ffbuild/pkgroot/$BUILD_NAME/LICENSE.txt"
  56. cd ffbuild/pkgroot
  57. if [[ "${TARGET}" == win* ]]; then
  58. OUTPUT_FNAME="${BUILD_NAME}.zip"
  59. docker run --rm -i $TTY_ARG "${UIDARGS[@]}" -v "${ARTIFACTS_PATH}":/out -v "${PWD}/${BUILD_NAME}":"/${BUILD_NAME}" -w / "$IMAGE" zip -9 -r "/out/${OUTPUT_FNAME}" "$BUILD_NAME"
  60. else
  61. OUTPUT_FNAME="${BUILD_NAME}.tar.xz"
  62. docker run --rm -i $TTY_ARG "${UIDARGS[@]}" -v "${ARTIFACTS_PATH}":/out -v "${PWD}/${BUILD_NAME}":"/${BUILD_NAME}" -w / "$IMAGE" tar cJf "/out/${OUTPUT_FNAME}" "$BUILD_NAME"
  63. fi
  64. cd -
  65. rm -rf ffbuild
  66. if [[ -n "$GITHUB_ACTIONS" ]]; then
  67. echo "build_name=${BUILD_NAME}" >> "$GITHUB_OUTPUT"
  68. echo "${OUTPUT_FNAME}" > "${ARTIFACTS_PATH}/${TARGET}-${VARIANT}${ADDINS_STR:+-}${ADDINS_STR}.txt"
  69. fi