- add third_party src.
[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\ i386)
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   Darwin\ i386)
89     HOST_OS=mac
90     HOST_ARCH=ia32
91     JOBS=$(sysctl -n hw.ncpu)
92     ;;
93   Darwin\ x86_64)
94     HOST_OS=mac
95     HOST_ARCH=x64
96     JOBS=$(sysctl -n hw.ncpu)
97     ;;
98   MINGW*)
99     HOST_OS=win
100     HOST_ARCH=ia32
101     JOBS=$NUMBER_OF_PROCESSORS
102     ;;
103   *)
104     echo "Unrecognized HOST_OS: $(uname)"
105     echo "Patches welcome!"
106     exit 1
107     ;;
108 esac
109
110 # Print out system information.
111 echo "System information:"
112 echo "HOST_OS     = $HOST_OS"
113 echo "TARGET_OS   = $TARGET_OS"
114 echo "HOST_ARCH   = $HOST_ARCH"
115 echo "TARGET_ARCH = $TARGET_ARCH"
116 echo "JOBS        = $JOBS"
117 echo "LD          = $(ld --version | head -n1)"
118 echo
119
120 # As of this writing gold 2.20.1-system.20100303 is unable to link FFmpeg.
121 if ld --version | grep -q gold; then
122   echo "gold is unable to link FFmpeg"
123   echo
124   echo "Switch /usr/bin/ld to the regular binutils ld and try again"
125   exit 1
126 fi
127
128 # We want to use a sufficiently recent version of yasm on Windows.
129 if [[ "$TARGET_OS" == "win" || "$TARGET_OS" == "win-vs2013" ]]; then
130   if !(which yasm 2>&1 > /dev/null); then
131     echo "Could not find yasm in \$PATH"
132     exit 1
133   fi
134
135   if (yasm --version | head -1 | grep -q "^yasm 0\."); then
136     echo "Must have yasm 1.0 or higher installed"
137     exit 1
138   fi
139 fi
140
141 # Returns the Dynamic Shared Object name given the module name and version.
142 function dso_name { dso_name_${TARGET_OS} $1 $2; }
143 function dso_name_win { echo "${1}-${2}.dll"; }
144 function dso_name_linux { echo "lib${1}.so.${2}"; }
145 function dso_name_mac { echo "lib${1}.${2}.dylib"; }
146
147 # Appends configure flags.
148 FLAGS_COMMON=
149 FLAGS_CHROMIUM=
150 FLAGS_CHROME=
151 FLAGS_CHROMIUMOS=
152 FLAGS_CHROMEOS=
153
154 # Flags that are used in all of Chrome/Chromium + OS.
155 function add_flag_common {
156   FLAGS_COMMON="$FLAGS_COMMON $*"
157 }
158 # Flags that are used in Chromium and ChromiumOS.
159 function add_flag_chromium {
160   FLAGS_CHROMIUM="$FLAGS_CHROMIUM $*"
161 }
162 # Flags that are used in Chrome and ChromeOS.
163 function add_flag_chrome {
164   FLAGS_CHROME="$FLAGS_CHROME $*"
165 }
166 # Flags that are used only in ChromiumOS (but not Chromium).
167 function add_flag_chromiumos {
168   FLAGS_CHROMIUMOS="$FLAGS_CHROMIUMOS $*"
169 }
170 # Flags that are used only in ChromeOS (but not Chrome).
171 function add_flag_chromeos {
172   FLAGS_CHROMEOS="$FLAGS_CHROMEOS $*"
173 }
174
175 # Builds using $1 as the output directory and all following arguments as
176 # configure script arguments.
177 function build {
178   CONFIG=$1
179   CONFIG_DIR="build.$TARGET_ARCH.$TARGET_OS/$CONFIG"
180   shift
181
182   # Create our working directory.
183   echo "Creating build directory..."
184   rm -rf $CONFIG_DIR
185   mkdir -p $CONFIG_DIR
186   pushd $CONFIG_DIR
187   mkdir out
188
189   # Configure and check for exit status.
190   echo "Configuring $CONFIG..."
191   CMD="$FFMPEG_PATH/configure $*"
192   echo $CMD
193   eval $CMD
194
195   if [ ! -f config.h ]; then
196     echo "Configure failed!"
197     exit 1
198   fi
199
200   if [ $TARGET_OS = "mac" ]; then
201     # Required to get Mac ia32 builds compiling with -fno-omit-frame-pointer,
202     # which is required for accurate stack traces.  See http://crbug.com/115170.
203     if [ $TARGET_ARCH = "ia32" ]; then
204       echo "Forcing HAVE_EBP_AVAILABLE to 0 in config.h and config.asm"
205       $FFMPEG_PATH/chromium/scripts/munge_config_optimizations.sh config.h
206       $FFMPEG_PATH/chromium/scripts/munge_config_optimizations.sh config.asm
207     fi
208   fi
209
210   if [[ "$HOST_OS" = "$TARGET_OS" && "$CONFIG_ONLY" = "" ]]; then
211     # Build!
212     LIBS="libavcodec/$(dso_name avcodec $LIBAVCODEC_VERSION_MAJOR)"
213     LIBS="libavformat/$(dso_name avformat $LIBAVFORMAT_VERSION_MAJOR) $LIBS"
214     LIBS="libavutil/$(dso_name avutil $LIBAVUTIL_VERSION_MAJOR) $LIBS"
215     for lib in $LIBS; do
216       echo "Building $lib for $CONFIG..."
217       echo "make -j$JOBS $lib"
218       make -j$JOBS $lib
219       if [ -f $lib ]; then
220         cp $lib out
221       else
222         echo "Build failed!"
223         exit 1
224       fi
225     done
226   elif [ ! "$CONFIG_ONLY" = "" ]; then
227     echo "Skipping build step as requested."
228   else
229     echo "Skipping compile as host configuration differs from target."
230     echo "Please compare the generated config.h with the previous version."
231     echo "You may also patch the script to properly cross-compile."
232     echo "host   OS  = $HOST_OS"
233     echo "target OS  = $TARGET_OS"
234     echo "host   ARCH= $HOST_ARCH"
235     echo "target ARCH= $TARGET_ARCH"
236   fi
237
238   if [ "$TARGET_ARCH" = "arm" -o "$TARGET_ARCH" = "arm-neon" ]; then
239     sed -i 's/^\(#define HAVE_VFP_ARGS [01]\)$/\/* \1 -- Disabled to allow softfp\/hardfp selection at gyp time *\//' config.h
240   fi
241
242   popd
243 }
244
245 # Common configuration.  Note: --disable-everything does not in fact disable
246 # everything, just non-library components such as decoders and demuxers.
247 add_flag_common --disable-everything
248 add_flag_common --disable-avdevice
249 add_flag_common --disable-avfilter
250 add_flag_common --disable-bzlib
251 add_flag_common --disable-doc
252 add_flag_common --disable-ffprobe
253 add_flag_common --disable-lzo
254 add_flag_common --disable-network
255 add_flag_common --disable-postproc
256 add_flag_common --disable-swresample
257 add_flag_common --disable-swscale
258 add_flag_common --disable-zlib
259 add_flag_common --enable-fft
260 add_flag_common --enable-rdft
261 add_flag_common --enable-shared
262 add_flag_common --disable-iconv
263
264 # Disable hardware decoding options which will sometimes turn on via autodetect.
265 add_flag_common --disable-dxva2
266 add_flag_common --disable-vaapi
267 add_flag_common --disable-vda
268 add_flag_common --disable-vdpau
269
270 # --optflags doesn't append multiple entries, so set all at once.
271 if [[ "$TARGET_OS" = "mac" && "$TARGET_ARCH" = "ia32" ]]; then
272   add_flag_common --optflags="\"-fno-omit-frame-pointer -O2\""
273 else
274   add_flag_common --optflags=-O2
275 fi
276
277 # Common codecs.
278 add_flag_common --enable-decoder=theora,vorbis,vp8
279 add_flag_common --enable-decoder=pcm_u8,pcm_s16le,pcm_s24le,pcm_f32le
280 add_flag_common --enable-decoder=pcm_s16be,pcm_s24be,pcm_mulaw,pcm_alaw
281 add_flag_common --enable-demuxer=ogg,matroska,wav
282 add_flag_common --enable-parser=vp3,vorbis,vp8
283
284 # Linux only.
285 if [ "$TARGET_OS" = "linux" ]; then
286   if [ "$TARGET_ARCH" = "x64" ]; then
287     # Nothing to add for now.
288     add_flag_common ""
289   elif [ "$TARGET_ARCH" = "ia32" ]; then
290     add_flag_common --arch=i686
291     add_flag_common --enable-yasm
292     add_flag_common --extra-cflags=-m32
293     add_flag_common --extra-ldflags=-m32
294   elif [ "$TARGET_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
304     # TODO(ihf): ARM compile flags are tricky. The final options
305     # overriding everything live in chroot /build/*/etc/make.conf
306     # (some of them coming from src/overlays/overlay-<BOARD>/make.conf).
307     # We try to follow these here closely. In particular we need to
308     # set ffmpeg internal #defines to conform to make.conf.
309     # TODO(ihf): For now it is not clear if thumb or arm settings would be
310     # faster. I ran experiments in other contexts and performance seemed
311     # to be close and compiler version dependent. In practice thumb builds are
312     # much smaller than optimized arm builds, hence we go with the global
313     # CrOS settings.
314     add_flag_common --enable-armv6
315     add_flag_common --enable-armv6t2
316     add_flag_common --enable-vfp
317     add_flag_common --enable-thumb
318     add_flag_common --disable-neon
319     add_flag_common --extra-cflags=-march=armv7-a
320     add_flag_common --extra-cflags=-mtune=cortex-a8
321     add_flag_common --extra-cflags=-mfpu=vfpv3-d16
322     # NOTE: softfp/hardfp selected at gyp time.
323     add_flag_common --extra-cflags=-mfloat-abi=hard
324   elif [ "$TARGET_ARCH" = "arm-neon" ]; 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     add_flag_common --enable-armv6
331     add_flag_common --enable-armv6t2
332     add_flag_common --enable-vfp
333     add_flag_common --enable-thumb
334     add_flag_common --enable-neon
335     add_flag_common --extra-cflags=-march=armv7-a
336     add_flag_common --extra-cflags=-mtune=cortex-a8
337     add_flag_common --extra-cflags=-mfpu=neon
338     # NOTE: softfp/hardfp selected at gyp time.
339     add_flag_common --extra-cflags=-mfloat-abi=hard
340   elif [ "$TARGET_ARCH" = "mipsel" ]; then
341     add_flag_common --enable-cross-compile
342     add_flag_common --cross-prefix=mips-linux-gnu-
343     add_flag_common --target-os=linux
344     add_flag_common --arch=mips
345     add_flag_common --extra-cflags=-mips32
346     add_flag_common --extra-cflags=-EL
347     add_flag_common --extra-ldflags=-mips32
348     add_flag_common --extra-ldflags=-EL
349     add_flag_common --disable-mipsfpu
350     add_flag_common --disable-mipsdspr1
351     add_flag_common --disable-mipsdspr2
352   else
353     echo "Error: Unknown TARGET_ARCH=$TARGET_ARCH for TARGET_OS=$TARGET_OS!"
354     exit 1
355   fi
356 fi
357
358 # Should be run on Windows.
359 if [ "$TARGET_OS" = "win" ]; then
360   if [ "$HOST_OS" = "win" ]; then
361     add_flag_common --toolchain=msvc
362     add_flag_common --enable-yasm
363     add_flag_common --extra-cflags=-I$FFMPEG_PATH/chromium/include/win
364   else
365     echo "Script should be run on Windows host. If this is not possible try a "
366     echo "merge of config files with new linux ia32 config.h by hand."
367     exit 1
368   fi
369 elif [ "$TARGET_OS" = "win-vs2013" ]; then
370   if [ "$HOST_OS" = "win" ]; then
371     add_flag_common --toolchain=msvc2013
372     add_flag_common --enable-yasm
373     add_flag_common --extra-cflags=-I$FFMPEG_PATH/chromium/include/win
374   else
375     echo "Script should be run on Windows host. If this is not possible try a "
376     echo "merge of config files with new linux ia32 config.h by hand."
377     exit 1
378   fi
379 else
380   add_flag_common --enable-pic
381 fi
382
383 # Should be run on Mac.
384 if [ "$TARGET_OS" = "mac" ]; then
385   if [ "$HOST_OS" = "mac" ]; then
386     add_flag_common --enable-yasm
387     add_flag_common --cc=clang
388     add_flag_common --cxx=clang++
389     add_flag_common --cpu=pentium-m
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."