build.sh.in 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. #!/usr/bin/env bash
  2. set -e
  3. export PATH="$PATH:/usr/bin"
  4. command -v cygpath >/dev/null && have_cygpath=1
  5. cygpath() {
  6. if [ -n "$have_cygpath" ]; then
  7. command cygpath "$@"
  8. else
  9. eval _p='$'$#
  10. printf '%s\n' "$_p"
  11. fi
  12. }
  13. move_binary() {
  14. SOURCE=$1
  15. TARGET=$2
  16. BINARY=$3
  17. # run lipo over the command to check whether it really
  18. # is a binary that we need to merge architectures
  19. lipo $SOURCE/$BINARY -info &> /dev/null || return 0
  20. # get the directory name the file is in
  21. DIRNAME=$(dirname $BINARY)
  22. # ensure the directory to move the binary to exists
  23. mkdir -p $TARGET/$DIRNAME
  24. # now finally move the binary
  25. mv $SOURCE/$BINARY $TARGET/$BINARY
  26. }
  27. move_binaries() {
  28. SOURCE=$1
  29. TARGET=$2
  30. [ ! -d $SOURCE ] && return 0
  31. pushd $SOURCE
  32. for BINARY in $(find . -type f); do
  33. move_binary $SOURCE $TARGET $BINARY
  34. done
  35. popd
  36. }
  37. merge_binaries() {
  38. TARGET=$1
  39. SOURCE=$2
  40. shift
  41. shift
  42. pushd $SOURCE/$1
  43. BINARIES=$(find . -type f)
  44. popd
  45. for BINARY in $BINARIES; do
  46. COMMAND="lipo -create -output $TARGET/$BINARY"
  47. for ARCH in $@; do
  48. COMMAND="$COMMAND -arch $ARCH $SOURCE/$ARCH/$BINARY"
  49. done
  50. $($COMMAND)
  51. done
  52. }
  53. export PKG_CONFIG_PATH="$(cygpath -p "${PKG_CONFIG_PATH}")"
  54. # Export HTTP(S)_PROXY as http(s)_proxy:
  55. [ -n "$HTTP_PROXY" ] && export http_proxy="$HTTP_PROXY"
  56. [ -n "$HTTPS_PROXY" ] && export https_proxy="$HTTPS_PROXY"
  57. PATH_TO_BUILD_DIR=$( cygpath "@BUILD_DIR@")
  58. PATH_TO_SRC_DIR=$( cygpath "@SOURCE_PATH@")
  59. PATH_TO_PACKAGE_DIR=$(cygpath "@INST_PREFIX@")
  60. JOBS=@VCPKG_CONCURRENCY@
  61. OSX_ARCHS="@OSX_ARCHS@"
  62. OSX_ARCH_COUNT=0@OSX_ARCH_COUNT@
  63. # Default to hardware concurrency if unset.
  64. : ${JOBS:=$(nproc)}
  65. # Disable asm and x86asm on all android targets because they trigger build failures:
  66. # arm64 Android build fails with 'relocation R_AARCH64_ADR_PREL_PG_HI21 cannot be used against symbol ff_cos_32; recompile with -fPIC'
  67. # x86 Android build fails with 'error: inline assembly requires more registers than available'.
  68. # x64 Android build fails with 'relocation R_X86_64_PC32 cannot be used against symbol ff_h264_cabac_tables; recompile with -fPIC'
  69. if [ "@VCPKG_CMAKE_SYSTEM_NAME@" = "Android" ]; then
  70. OPTIONS_arm=" --disable-asm --disable-x86asm"
  71. OPTIONS_arm64=" --disable-asm --disable-x86asm"
  72. OPTIONS_x86=" --disable-asm --disable-x86asm"
  73. OPTIONS_x86_64="${OPTIONS_x86}"
  74. else
  75. OPTIONS_arm=" --disable-asm --disable-x86asm"
  76. OPTIONS_arm64=" --enable-asm --disable-x86asm"
  77. OPTIONS_x86=" --enable-asm --enable-x86asm"
  78. OPTIONS_x86_64="${OPTIONS_x86}"
  79. fi
  80. build_ffmpeg() {
  81. # extract build architecture
  82. BUILD_ARCH=$1
  83. shift
  84. echo "BUILD_ARCH=${BUILD_ARCH}"
  85. # get architecture-specific options
  86. OPTION_VARIABLE="OPTIONS_${BUILD_ARCH}"
  87. echo "OPTION_VARIABLE=${OPTION_VARIABLE}"
  88. echo "=== CONFIGURING ==="
  89. sh "$PATH_TO_SRC_DIR/configure" "--prefix=$PATH_TO_PACKAGE_DIR" @CONFIGURE_OPTIONS@ --arch=${BUILD_ARCH} ${!OPTION_VARIABLE} $@
  90. echo "=== BUILDING ==="
  91. make -j${JOBS} V=1
  92. echo "=== INSTALLING ==="
  93. make install
  94. }
  95. cd "$PATH_TO_BUILD_DIR"
  96. if [ $OSX_ARCH_COUNT -gt 0 ]; then
  97. for ARCH in $OSX_ARCHS; do
  98. echo "=== CLEANING FOR $ARCH ==="
  99. make clean && make distclean
  100. build_ffmpeg $ARCH --extra-cflags=-arch --extra-cflags=$ARCH --extra-ldflags=-arch --extra-ldflags=$ARCH
  101. echo "=== COLLECTING BINARIES FOR $ARCH ==="
  102. move_binaries $PATH_TO_PACKAGE_DIR/lib $PATH_TO_BUILD_DIR/stage/$ARCH/lib
  103. move_binaries $PATH_TO_PACKAGE_DIR/bin $PATH_TO_BUILD_DIR/stage/$ARCH/bin
  104. done
  105. echo "=== MERGING ARCHITECTURES ==="
  106. merge_binaries $PATH_TO_PACKAGE_DIR $PATH_TO_BUILD_DIR/stage $OSX_ARCHS
  107. else
  108. build_ffmpeg @BUILD_ARCH@
  109. fi