Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / third_party / ffmpeg / chromium / scripts / build_ffmpeg.sh
1 #!/bin/bash -e
2
3 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
4 # Use of this source code is governed by a BSD-style license that can be
5 # found in the LICENSE file.
6
7 # Builds Chromium, Google Chrome and *OS FFmpeg binaries.
8 #
9 # For Windows it the script must be run from either a x64 or ia32 Visual Studio
10 # environment (i.e., cl.exe, lib.exe and editbin.exe are in $PATH).  Using the
11 # x64 environment will build the x64 version and vice versa.
12 #
13 # For MIPS it assumes that cross-toolchain bin directory is in $PATH.
14 #
15 # Instructions for setting up a MinGW/MSYS shell can be found here:
16 # http://src.chromium.org/viewvc/chrome/trunk/deps/third_party/mingw/README.chromium
17
18 if [ "$3" = "" ]; then
19   echo "Usage:"
20   echo "  $0 [TARGET_OS] [TARGET_ARCH] [path/to/ffmpeg] [config-only]"
21   echo
22   echo "Valid combinations are linux       [ia32|x64|mipsel|arm|arm-neon]"
23   echo "                       linux-noasm x64"
24   echo "                       win         [ia32|x64]"
25   echo "                       win-vs2013  [ia32|x64]"
26   echo "                       mac         [ia32|x64]"
27   echo
28   echo " linux ia32/x64 - script can be run on a normal Ubuntu box."
29   echo " linux mipsel - script can be run on a normal Ubuntu box with MIPS"
30   echo " cross-toolchain in \$PATH."
31   echo " linux arm/arm-neon should be run inside of CrOS chroot."
32   echo " mac and win have to be run on Mac and Windows 7 (under mingw)."
33   echo
34   echo " mac - ensure the Chromium (not Apple) version of clang is in the path,"
35   echo " usually found under src/third_party/llvm-build/Release+Asserts/bin"
36   echo
37   echo "Specifying 'config-only' will skip the build step.  Useful when a"
38   echo "given platform is not necessary for generate_gyp.py."
39   echo
40   echo "The path should be absolute and point at Chromium's copy of FFmpeg."
41   echo "This corresponds to:"
42   echo "  chrome/trunk/deps/third_party/ffmpeg"
43   echo
44   echo "Resulting binaries will be placed in:"
45   echo "  build.TARGET_ARCH.TARGET_OS/Chromium/out/"
46   echo "  build.TARGET_ARCH.TARGET_OS/Chrome/out/"
47   echo "  build.TARGET_ARCH.TARGET_OS/ChromiumOS/out/"
48   echo "  build.TARGET_ARCH.TARGET_OS/ChromeOS/out/"
49   exit 1
50 fi
51
52 TARGET_OS=$1
53 TARGET_ARCH=$2
54 FFMPEG_PATH=$3
55 CONFIG_ONLY=$4
56
57 # Check TARGET_OS (TARGET_ARCH is checked during configuration).
58 if [[ "$TARGET_OS" != "linux" &&
59       "$TARGET_OS" != "linux-noasm" &&
60       "$TARGET_OS" != "mac" &&
61       "$TARGET_OS" != "win" &&
62       "$TARGET_OS" != "win-vs2013" ]]; then
63   echo "Valid target OSes are: linux, linux-noasm, mac, win, win-vs2013"
64   exit 1
65 fi
66
67 # Check FFMPEG_PATH to contain this script.
68 if [ ! -f "$FFMPEG_PATH/chromium/scripts/$(basename $0)" ]; then
69   echo "$FFMPEG_PATH doesn't appear to contain FFmpeg"
70   exit 1
71 fi
72
73 # If configure & make works but this script doesn't, make sure to grep for
74 # these.
75 LIBAVCODEC_VERSION_MAJOR=55
76 LIBAVFORMAT_VERSION_MAJOR=55
77 LIBAVUTIL_VERSION_MAJOR=52
78
79 case $(uname -sm) in
80   Linux\ i?86)
81     HOST_OS=linux
82     HOST_ARCH=ia32
83     JOBS=$(grep processor /proc/cpuinfo | wc -l)
84     ;;
85   Linux\ x86_64)
86     HOST_OS=linux
87     HOST_ARCH=x64
88     JOBS=$(grep processor /proc/cpuinfo | wc -l)
89     ;;
90   Linux\ arm*)
91     HOST_OS=linux
92     HOST_ARCH=arm
93     JOBS=$(grep processor /proc/cpuinfo | wc -l)
94     ;;
95   Darwin\ i386)
96     HOST_OS=mac
97     HOST_ARCH=ia32
98     JOBS=$(sysctl -n hw.ncpu)
99     ;;
100   Darwin\ x86_64)
101     HOST_OS=mac
102     HOST_ARCH=x64
103     JOBS=$(sysctl -n hw.ncpu)
104     ;;
105   MINGW*)
106     HOST_OS=win
107     HOST_ARCH=ia32
108     JOBS=$NUMBER_OF_PROCESSORS
109     ;;
110   *)
111     echo "Unrecognized HOST_OS: $(uname)"
112     echo "Patches welcome!"
113     exit 1
114     ;;
115 esac
116
117 # Print out system information.
118 echo "System information:"
119 echo "HOST_OS     = $HOST_OS"
120 echo "TARGET_OS   = $TARGET_OS"
121 echo "HOST_ARCH   = $HOST_ARCH"
122 echo "TARGET_ARCH = $TARGET_ARCH"
123 echo "JOBS        = $JOBS"
124 echo "LD          = $(ld --version | head -n1)"
125 echo
126
127 # We want to use a sufficiently recent version of yasm on Windows.
128 if [[ "$TARGET_OS" == "win" || "$TARGET_OS" == "win-vs2013" ]]; then
129   if !(which yasm 2>&1 > /dev/null); then
130     echo "Could not find yasm in \$PATH"
131     exit 1
132   fi
133
134   if (yasm --version | head -1 | grep -q "^yasm 0\."); then
135     echo "Must have yasm 1.0 or higher installed"
136     exit 1
137   fi
138 fi
139
140 # Returns the Dynamic Shared Object name given the module name and version.
141 function dso_name { dso_name_${TARGET_OS} $1 $2; }
142 function dso_name_win { echo "${1}-${2}.dll"; }
143 function dso_name_linux { echo "lib${1}.so.${2}"; }
144 function dso_name_mac { echo "lib${1}.${2}.dylib"; }
145
146 # Appends configure flags.
147 FLAGS_COMMON=
148 FLAGS_CHROMIUM=
149 FLAGS_CHROME=
150 FLAGS_CHROMIUMOS=
151 FLAGS_CHROMEOS=
152
153 # Flags that are used in all of Chrome/Chromium + OS.
154 function add_flag_common {
155   FLAGS_COMMON="$FLAGS_COMMON $*"
156 }
157 # Flags that are used in Chromium and ChromiumOS.
158 function add_flag_chromium {
159   FLAGS_CHROMIUM="$FLAGS_CHROMIUM $*"
160 }
161 # Flags that are used in Chrome and ChromeOS.
162 function add_flag_chrome {
163   FLAGS_CHROME="$FLAGS_CHROME $*"
164 }
165 # Flags that are used only in ChromiumOS (but not Chromium).
166 function add_flag_chromiumos {
167   FLAGS_CHROMIUMOS="$FLAGS_CHROMIUMOS $*"
168 }
169 # Flags that are used only in ChromeOS (but not Chrome).
170 function add_flag_chromeos {
171   FLAGS_CHROMEOS="$FLAGS_CHROMEOS $*"
172 }
173
174 # Builds using $1 as the output directory and all following arguments as
175 # configure script arguments.
176 function build {
177   CONFIG=$1
178   CONFIG_DIR="build.$TARGET_ARCH.$TARGET_OS/$CONFIG"
179   shift
180
181   # Create our working directory.
182   echo "Creating build directory..."
183   rm -rf $CONFIG_DIR
184   mkdir -p $CONFIG_DIR
185   pushd $CONFIG_DIR
186   mkdir out
187
188   # Configure and check for exit status.
189   echo "Configuring $CONFIG..."
190   CMD="$FFMPEG_PATH/configure $*"
191   echo $CMD
192   eval $CMD
193
194   if [ ! -f config.h ]; then
195     echo "Configure failed!"
196     exit 1
197   fi
198
199   if [ $TARGET_OS = "mac" ]; then
200     # Required to get Mac ia32 builds compiling with -fno-omit-frame-pointer,
201     # which is required for accurate stack traces.  See http://crbug.com/115170.
202     if [ $TARGET_ARCH = "ia32" ]; then
203       echo "Forcing HAVE_EBP_AVAILABLE to 0 in config.h and config.asm"
204       $FFMPEG_PATH/chromium/scripts/munge_config_optimizations.sh config.h
205       $FFMPEG_PATH/chromium/scripts/munge_config_optimizations.sh config.asm
206     fi
207   fi
208
209   if [[ "$HOST_OS" = "$TARGET_OS" && "$CONFIG_ONLY" = "" ]]; then
210     # Build!
211     LIBS="libavcodec/$(dso_name avcodec $LIBAVCODEC_VERSION_MAJOR)"
212     LIBS="libavformat/$(dso_name avformat $LIBAVFORMAT_VERSION_MAJOR) $LIBS"
213     LIBS="libavutil/$(dso_name avutil $LIBAVUTIL_VERSION_MAJOR) $LIBS"
214     for lib in $LIBS; do
215       echo "Building $lib for $CONFIG..."
216       echo "make -j$JOBS $lib"
217       make -j$JOBS $lib
218       if [ -f $lib ]; then
219         cp $lib out
220       else
221         echo "Build failed!"
222         exit 1
223       fi
224     done
225   elif [ ! "$CONFIG_ONLY" = "" ]; then
226     echo "Skipping build step as requested."
227   else
228     echo "Skipping compile as host configuration differs from target."
229     echo "Please compare the generated config.h with the previous version."
230     echo "You may also patch the script to properly cross-compile."
231     echo "host   OS  = $HOST_OS"
232     echo "target OS  = $TARGET_OS"
233     echo "host   ARCH= $HOST_ARCH"
234     echo "target ARCH= $TARGET_ARCH"
235   fi
236
237   if [ "$TARGET_ARCH" = "arm" -o "$TARGET_ARCH" = "arm-neon" ]; then
238     sed -i 's/^\(#define HAVE_VFP_ARGS [01]\)$/\/* \1 -- Disabled to allow softfp\/hardfp selection at gyp time *\//' config.h
239   fi
240
241   popd
242 }
243
244 # Common configuration.  Note: --disable-everything does not in fact disable
245 # everything, just non-library components such as decoders and demuxers.
246 add_flag_common --disable-everything
247 add_flag_common --disable-avdevice
248 add_flag_common --disable-avfilter
249 add_flag_common --disable-bzlib
250 add_flag_common --disable-doc
251 add_flag_common --disable-ffprobe
252 add_flag_common --disable-lzo
253 add_flag_common --disable-network
254 add_flag_common --disable-postproc
255 add_flag_common --disable-swresample
256 add_flag_common --disable-swscale
257 add_flag_common --disable-zlib
258 add_flag_common --enable-fft
259 add_flag_common --enable-rdft
260 add_flag_common --enable-shared
261 add_flag_common --disable-iconv
262
263 # Disable hardware decoding options which will sometimes turn on via autodetect.
264 add_flag_common --disable-dxva2
265 add_flag_common --disable-vaapi
266 add_flag_common --disable-vda
267 add_flag_common --disable-vdpau
268
269 # --optflags doesn't append multiple entries, so set all at once.
270 if [[ "$TARGET_OS" = "mac" && "$TARGET_ARCH" = "ia32" ]]; then
271   add_flag_common --optflags="\"-fno-omit-frame-pointer -O2\""
272 else
273   add_flag_common --optflags=-O2
274 fi
275
276 # Common codecs.
277 add_flag_common --enable-decoder=theora,vorbis,vp8
278 add_flag_common --enable-decoder=pcm_u8,pcm_s16le,pcm_s24le,pcm_f32le
279 add_flag_common --enable-decoder=pcm_s16be,pcm_s24be,pcm_mulaw,pcm_alaw
280 add_flag_common --enable-demuxer=ogg,matroska,wav
281 add_flag_common --enable-parser=vp3,vorbis,vp8
282
283 # Linux only.
284 if [[ "$TARGET_OS" = "linux" || "$TARGET_OS" = "linux-noasm" ]]; then
285   if [ "$TARGET_ARCH" = "x64" ]; then
286     # Nothing to add for now.
287     add_flag_common ""
288   elif [ "$TARGET_ARCH" = "ia32" ]; then
289     add_flag_common --arch=i686
290     add_flag_common --enable-yasm
291     add_flag_common --extra-cflags=-m32
292     add_flag_common --extra-ldflags=-m32
293   elif [ "$TARGET_ARCH" = "arm" ]; then
294     if [ "$HOST_ARCH" != "arm" ]; then
295       # This if-statement essentially is for chroot tegra2.
296       add_flag_common --enable-cross-compile
297
298       # Location is for CrOS chroot. If you want to use this, enter chroot
299       # and copy ffmpeg to a location that is reachable.
300       add_flag_common --cross-prefix=/usr/bin/armv7a-cros-linux-gnueabi-
301       add_flag_common --target-os=linux
302       add_flag_common --arch=arm
303     fi
304
305     # TODO(ihf): ARM compile flags are tricky. The final options
306     # overriding everything live in chroot /build/*/etc/make.conf
307     # (some of them coming from src/overlays/overlay-<BOARD>/make.conf).
308     # We try to follow these here closely. In particular we need to
309     # set ffmpeg internal #defines to conform to make.conf.
310     # TODO(ihf): For now it is not clear if thumb or arm settings would be
311     # faster. I ran experiments in other contexts and performance seemed
312     # to be close and compiler version dependent. In practice thumb builds are
313     # much smaller than optimized arm builds, hence we go with the global
314     # CrOS settings.
315     add_flag_common --enable-armv6
316     add_flag_common --enable-armv6t2
317     add_flag_common --enable-vfp
318     add_flag_common --enable-thumb
319     add_flag_common --disable-neon
320     add_flag_common --extra-cflags=-march=armv7-a
321     add_flag_common --extra-cflags=-mtune=cortex-a8
322     add_flag_common --extra-cflags=-mfpu=vfpv3-d16
323     # NOTE: softfp/hardfp selected at gyp time.
324     add_flag_common --extra-cflags=-mfloat-abi=hard
325   elif [ "$TARGET_ARCH" = "arm-neon" ]; then
326     if [ "$HOST_ARCH" != "arm" ]; then
327       # This if-statement is for chroot arm-generic.
328       add_flag_common --enable-cross-compile
329       add_flag_common --cross-prefix=/usr/bin/armv7a-cros-linux-gnueabi-
330       add_flag_common --target-os=linux
331       add_flag_common --arch=arm
332     fi
333     add_flag_common --enable-armv6
334     add_flag_common --enable-armv6t2
335     add_flag_common --enable-vfp
336     add_flag_common --enable-thumb
337     add_flag_common --enable-neon
338     add_flag_common --extra-cflags=-march=armv7-a
339     add_flag_common --extra-cflags=-mtune=cortex-a8
340     add_flag_common --extra-cflags=-mfpu=neon
341     # NOTE: softfp/hardfp selected at gyp time.
342     add_flag_common --extra-cflags=-mfloat-abi=hard
343   elif [ "$TARGET_ARCH" = "mipsel" ]; then
344     add_flag_common --enable-cross-compile
345     add_flag_common --cross-prefix=mips-linux-gnu-
346     add_flag_common --target-os=linux
347     add_flag_common --arch=mips
348     add_flag_common --extra-cflags=-mips32
349     add_flag_common --extra-cflags=-EL
350     add_flag_common --extra-ldflags=-mips32
351     add_flag_common --extra-ldflags=-EL
352     add_flag_common --disable-mipsfpu
353     add_flag_common --disable-mipsdspr1
354     add_flag_common --disable-mipsdspr2
355   else
356     echo "Error: Unknown TARGET_ARCH=$TARGET_ARCH for TARGET_OS=$TARGET_OS!"
357     exit 1
358   fi
359 fi
360
361 if [ "$TARGET_OS" = "linux-noasm" ]; then
362   if [ "$TARGET_ARCH" = "x64" ]; then
363     add_flag_common --disable-asm
364     add_flag_common --disable-inline-asm
365   else
366     echo "Error: Unknown TARGET_ARCH=$TARGET_ARCH for TARGET_OS=$TARGET_OS!"
367     exit 1
368   fi
369 fi
370
371 # Should be run on Windows.
372 if [ "$TARGET_OS" = "win" ]; then
373   if [ "$HOST_OS" = "win" ]; then
374     add_flag_common --toolchain=msvc
375     add_flag_common --enable-yasm
376     add_flag_common --extra-cflags=-I$FFMPEG_PATH/chromium/include/win
377   else
378     echo "Script should be run on Windows host. If this is not possible try a "
379     echo "merge of config files with new linux ia32 config.h by hand."
380     exit 1
381   fi
382 elif [ "$TARGET_OS" = "win-vs2013" ]; then
383   if [ "$HOST_OS" = "win" ]; then
384     add_flag_common --toolchain=msvc2013
385     add_flag_common --enable-yasm
386     add_flag_common --extra-cflags=-I$FFMPEG_PATH/chromium/include/win
387   else
388     echo "Script should be run on Windows host. If this is not possible try a "
389     echo "merge of config files with new linux ia32 config.h by hand."
390     exit 1
391   fi
392 else
393   add_flag_common --enable-pic
394 fi
395
396 # Should be run on Mac.
397 if [ "$TARGET_OS" = "mac" ]; then
398   if [ "$HOST_OS" = "mac" ]; then
399     add_flag_common --enable-yasm
400     add_flag_common --cc=clang
401     add_flag_common --cxx=clang++
402     if [ "$TARGET_ARCH" = "ia32" ]; then
403       add_flag_common --arch=i686
404       add_flag_common --extra-cflags=-m32
405       add_flag_common --extra-ldflags=-m32
406     elif [ "$TARGET_ARCH" = "x64" ]; then
407       add_flag_common --arch=x86_64
408       add_flag_common --extra-cflags=-m64
409       add_flag_common --extra-ldflags=-m64
410     else
411       echo "Error: Unknown TARGET_ARCH=$TARGET_ARCH for TARGET_OS=$TARGET_OS!"
412       exit 1
413     fi
414   else
415     echo "Script should be run on a Mac host. If this is not possible try a "
416     echo "merge of config files with new linux ia32 config.h by hand."
417     exit 1
418   fi
419 fi
420
421 # Chromium & ChromiumOS specific configuration.
422 # Though CONFIG_ERROR_RESILIENCE should already be disabled for Chromium[OS],
423 # forcing disable here to help ensure it remains this way.
424 add_flag_chromium --disable-error-resilience
425
426 # Google Chrome & ChromeOS specific configuration.
427 add_flag_chrome --enable-decoder=aac,h264,mp3
428 add_flag_chrome --enable-demuxer=mp3,mov
429 add_flag_chrome --enable-parser=aac,h264,mpegaudio
430
431 # ChromiumOS specific configuration.
432 # Warning: do *NOT* add avi, aac, h264, mp3, mp4, amr*
433 # Flac support.
434 add_flag_chromiumos --enable-demuxer=flac
435 add_flag_chromiumos --enable-decoder=flac
436 add_flag_chromiumos --enable-parser=flac
437
438 # Google ChromeOS specific configuration.
439 # We want to make sure to play everything Android generates and plays.
440 # http://developer.android.com/guide/appendix/media-formats.html
441 # Enable playing avi files.
442 add_flag_chromeos --enable-decoder=mpeg4
443 add_flag_chromeos --enable-parser=h263,mpeg4video
444 add_flag_chromeos --enable-demuxer=avi
445 # Enable playing Android 3gp files.
446 add_flag_chromeos --enable-demuxer=amr
447 add_flag_chromeos --enable-decoder=amrnb,amrwb
448 # Flac support.
449 add_flag_chromeos --enable-demuxer=flac
450 add_flag_chromeos --enable-decoder=flac
451 add_flag_chromeos --enable-parser=flac
452 # Wav files for playing phone messages.
453 add_flag_chromeos --enable-decoder=gsm_ms
454 add_flag_chromeos --enable-demuxer=gsm
455 add_flag_chromeos --enable-parser=gsm
456
457 echo "Chromium configure/build:"
458 build Chromium $FLAGS_COMMON $FLAGS_CHROMIUM
459 echo "Chrome configure/build:"
460 build Chrome $FLAGS_COMMON $FLAGS_CHROME
461
462 if [ "$TARGET_OS" = "linux" ]; then
463   echo "ChromiumOS configure/build:"
464   build ChromiumOS $FLAGS_COMMON $FLAGS_CHROMIUM $FLAGS_CHROMIUMOS
465   echo "ChromeOS configure/build:"
466   build ChromeOS $FLAGS_COMMON $FLAGS_CHROME $FLAGS_CHROMEOS
467 fi
468
469 echo "Done. If desired you may copy config.h/config.asm into the" \
470      "source/config tree using copy_config.sh."