compile-ffmpeg.sh 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. #! /usr/bin/env bash
  2. #
  3. # Copyright (C) 2013-2014 Bilibili
  4. # Copyright (C) 2013-2014 Zhang Rui <bbcallen@gmail.com>
  5. #
  6. # Licensed under the Apache License, Version 2.0 (the "License");
  7. # you may not use this file except in compliance with the License.
  8. # You may obtain a copy of the License at
  9. #
  10. # http://www.apache.org/licenses/LICENSE-2.0
  11. #
  12. # Unless required by applicable law or agreed to in writing, software
  13. # distributed under the License is distributed on an "AS IS" BASIS,
  14. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. # See the License for the specific language governing permissions and
  16. # limitations under the License.
  17. #
  18. #----------
  19. # modify for your build tool
  20. FF_ALL_ARCHS_IOS6_SDK="armv7 armv7s i386"
  21. FF_ALL_ARCHS_IOS7_SDK="armv7 armv7s arm64 i386 x86_64"
  22. FF_ALL_ARCHS_IOS8_SDK="armv7 arm64 i386 x86_64"
  23. FF_ALL_ARCHS=$FF_ALL_ARCHS_IOS8_SDK
  24. #----------
  25. UNI_BUILD_ROOT=`pwd`
  26. UNI_TMP="$UNI_BUILD_ROOT/tmp"
  27. UNI_TMP_LLVM_VER_FILE="$UNI_TMP/llvm.ver.txt"
  28. FF_TARGET=$1
  29. FF_TARGET_EXTRA=$2
  30. set -e
  31. #----------
  32. echo_archs() {
  33. echo "===================="
  34. echo "[*] check xcode version"
  35. echo "===================="
  36. echo "FF_ALL_ARCHS = $FF_ALL_ARCHS"
  37. }
  38. FF_LIBS="libavcodec libavfilter libavformat libavutil libswscale libswresample"
  39. do_lipo_ffmpeg () {
  40. LIB_FILE=$1
  41. LIPO_FLAGS=
  42. for ARCH in $FF_ALL_ARCHS
  43. do
  44. ARCH_LIB_FILE="$UNI_BUILD_ROOT/build/ffmpeg-$ARCH/output/lib/$LIB_FILE"
  45. if [ -f "$ARCH_LIB_FILE" ]; then
  46. LIPO_FLAGS="$LIPO_FLAGS $ARCH_LIB_FILE"
  47. else
  48. echo "skip $LIB_FILE of $ARCH";
  49. fi
  50. done
  51. xcrun lipo -create $LIPO_FLAGS -output $UNI_BUILD_ROOT/build/universal/lib/$LIB_FILE
  52. xcrun lipo -info $UNI_BUILD_ROOT/build/universal/lib/$LIB_FILE
  53. }
  54. SSL_LIBS="libcrypto libssl"
  55. do_lipo_ssl () {
  56. LIB_FILE=$1
  57. LIPO_FLAGS=
  58. for ARCH in $FF_ALL_ARCHS
  59. do
  60. ARCH_LIB_FILE="$UNI_BUILD_ROOT/build/openssl-$ARCH/output/lib/$LIB_FILE"
  61. if [ -f "$ARCH_LIB_FILE" ]; then
  62. LIPO_FLAGS="$LIPO_FLAGS $ARCH_LIB_FILE"
  63. else
  64. echo "skip $LIB_FILE of $ARCH";
  65. fi
  66. done
  67. if [ "$LIPO_FLAGS" != "" ]; then
  68. xcrun lipo -create $LIPO_FLAGS -output $UNI_BUILD_ROOT/build/universal/lib/$LIB_FILE
  69. xcrun lipo -info $UNI_BUILD_ROOT/build/universal/lib/$LIB_FILE
  70. fi
  71. }
  72. do_lipo_all () {
  73. mkdir -p $UNI_BUILD_ROOT/build/universal/lib
  74. echo "lipo archs: $FF_ALL_ARCHS"
  75. for FF_LIB in $FF_LIBS
  76. do
  77. do_lipo_ffmpeg "$FF_LIB.a";
  78. done
  79. ANY_ARCH=
  80. for ARCH in $FF_ALL_ARCHS
  81. do
  82. ARCH_INC_DIR="$UNI_BUILD_ROOT/build/ffmpeg-$ARCH/output/include"
  83. if [ -d "$ARCH_INC_DIR" ]; then
  84. if [ -z "$ANY_ARCH" ]; then
  85. ANY_ARCH=$ARCH
  86. cp -R "$ARCH_INC_DIR" "$UNI_BUILD_ROOT/build/universal/"
  87. fi
  88. UNI_INC_DIR="$UNI_BUILD_ROOT/build/universal/include"
  89. mkdir -p "$UNI_INC_DIR/libavutil/$ARCH"
  90. cp -f "$ARCH_INC_DIR/libavutil/avconfig.h" "$UNI_INC_DIR/libavutil/$ARCH/avconfig.h"
  91. cp -f tools/avconfig.h "$UNI_INC_DIR/libavutil/avconfig.h"
  92. cp -f "$ARCH_INC_DIR/libavutil/ffversion.h" "$UNI_INC_DIR/libavutil/$ARCH/ffversion.h"
  93. cp -f tools/ffversion.h "$UNI_INC_DIR/libavutil/ffversion.h"
  94. mkdir -p "$UNI_INC_DIR/libffmpeg/$ARCH"
  95. cp -f "$ARCH_INC_DIR/libffmpeg/config.h" "$UNI_INC_DIR/libffmpeg/$ARCH/config.h"
  96. cp -f tools/config.h "$UNI_INC_DIR/libffmpeg/config.h"
  97. fi
  98. done
  99. for SSL_LIB in $SSL_LIBS
  100. do
  101. do_lipo_ssl "$SSL_LIB.a";
  102. done
  103. }
  104. #----------
  105. if [ "$FF_TARGET" = "armv7" -o "$FF_TARGET" = "armv7s" -o "$FF_TARGET" = "arm64" ]; then
  106. echo_archs
  107. sh tools/do-compile-ffmpeg.sh $FF_TARGET $FF_TARGET_EXTRA
  108. do_lipo_all
  109. elif [ "$FF_TARGET" = "i386" -o "$FF_TARGET" = "x86_64" ]; then
  110. echo_archs
  111. sh tools/do-compile-ffmpeg.sh $FF_TARGET $FF_TARGET_EXTRA
  112. do_lipo_all
  113. elif [ "$FF_TARGET" = "lipo" ]; then
  114. echo_archs
  115. do_lipo_all
  116. elif [ "$FF_TARGET" = "all" ]; then
  117. echo_archs
  118. for ARCH in $FF_ALL_ARCHS
  119. do
  120. sh tools/do-compile-ffmpeg.sh $ARCH $FF_TARGET_EXTRA
  121. done
  122. do_lipo_all
  123. elif [ "$FF_TARGET" = "check" ]; then
  124. echo_archs
  125. elif [ "$FF_TARGET" = "clean" ]; then
  126. echo_archs
  127. echo "=================="
  128. for ARCH in $FF_ALL_ARCHS
  129. do
  130. echo "clean ffmpeg-$ARCH"
  131. echo "=================="
  132. cd ffmpeg-$ARCH && git clean -xdf && cd -
  133. done
  134. echo "clean build cache"
  135. echo "================="
  136. rm -rf build/ffmpeg-*
  137. rm -rf build/openssl-*
  138. rm -rf build/universal/include
  139. rm -rf build/universal/lib
  140. echo "clean success"
  141. else
  142. echo "Usage:"
  143. echo " compile-ffmpeg.sh armv7|arm64|i386|x86_64"
  144. echo " compile-ffmpeg.sh armv7s (obselete)"
  145. echo " compile-ffmpeg.sh lipo"
  146. echo " compile-ffmpeg.sh all"
  147. echo " compile-ffmpeg.sh clean"
  148. echo " compile-ffmpeg.sh check"
  149. exit 1
  150. fi