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