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.
7 # Builds Chromium, Google Chrome and *OS FFmpeg binaries.
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.
13 # For MIPS it assumes that cross-toolchain bin directory is in $PATH.
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
18 if [ "$3" = "" ]; then
20 echo " $0 [TARGET_OS] [TARGET_ARCH] [path/to/ffmpeg] [config-only]"
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]"
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)."
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"
37 echo "Specifying 'config-only' will skip the build step. Useful when a"
38 echo "given platform is not necessary for generate_gyp.py."
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"
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/"
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"
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"
73 # If configure & make works but this script doesn't, make sure to grep for
75 LIBAVCODEC_VERSION_MAJOR=55
76 LIBAVFORMAT_VERSION_MAJOR=55
77 LIBAVUTIL_VERSION_MAJOR=52
83 JOBS=$(grep processor /proc/cpuinfo | wc -l)
88 JOBS=$(grep processor /proc/cpuinfo | wc -l)
93 JOBS=$(grep processor /proc/cpuinfo | wc -l)
98 JOBS=$(sysctl -n hw.ncpu)
103 JOBS=$(sysctl -n hw.ncpu)
108 JOBS=$NUMBER_OF_PROCESSORS
111 echo "Unrecognized HOST_OS: $(uname)"
112 echo "Patches welcome!"
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"
124 echo "LD = $(ld --version | head -n1)"
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"
134 if (yasm --version | head -1 | grep -q "^yasm 0\."); then
135 echo "Must have yasm 1.0 or higher installed"
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"; }
146 # Appends configure flags.
153 # Flags that are used in all of Chrome/Chromium + OS.
154 function add_flag_common {
155 FLAGS_COMMON="$FLAGS_COMMON $*"
157 # Flags that are used in Chromium and ChromiumOS.
158 function add_flag_chromium {
159 FLAGS_CHROMIUM="$FLAGS_CHROMIUM $*"
161 # Flags that are used in Chrome and ChromeOS.
162 function add_flag_chrome {
163 FLAGS_CHROME="$FLAGS_CHROME $*"
165 # Flags that are used only in ChromiumOS (but not Chromium).
166 function add_flag_chromiumos {
167 FLAGS_CHROMIUMOS="$FLAGS_CHROMIUMOS $*"
169 # Flags that are used only in ChromeOS (but not Chrome).
170 function add_flag_chromeos {
171 FLAGS_CHROMEOS="$FLAGS_CHROMEOS $*"
174 # Builds using $1 as the output directory and all following arguments as
175 # configure script arguments.
178 CONFIG_DIR="build.$TARGET_ARCH.$TARGET_OS/$CONFIG"
181 # Create our working directory.
182 echo "Creating build directory..."
188 # Configure and check for exit status.
189 echo "Configuring $CONFIG..."
190 CMD="$FFMPEG_PATH/configure $*"
194 if [ ! -f config.h ]; then
195 echo "Configure failed!"
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
209 if [[ "$HOST_OS" = "$TARGET_OS" && "$CONFIG_ONLY" = "" ]]; then
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"
215 echo "Building $lib for $CONFIG..."
216 echo "make -j$JOBS $lib"
225 elif [ ! "$CONFIG_ONLY" = "" ]; then
226 echo "Skipping build step as requested."
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"
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
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
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
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\""
273 add_flag_common --optflags=-O2
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
284 if [[ "$TARGET_OS" = "linux" || "$TARGET_OS" = "linux-noasm" ]]; then
285 if [ "$TARGET_ARCH" = "x64" ]; then
286 # Nothing to add for now.
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
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
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
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
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
356 echo "Error: Unknown TARGET_ARCH=$TARGET_ARCH for TARGET_OS=$TARGET_OS!"
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
366 echo "Error: Unknown TARGET_ARCH=$TARGET_ARCH for TARGET_OS=$TARGET_OS!"
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
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."
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
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."
393 add_flag_common --enable-pic
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
411 echo "Error: Unknown TARGET_ARCH=$TARGET_ARCH for TARGET_OS=$TARGET_OS!"
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."
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
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
431 # ChromiumOS specific configuration.
432 # Warning: do *NOT* add avi, aac, h264, mp3, mp4, amr*
434 add_flag_chromiumos --enable-demuxer=flac
435 add_flag_chromiumos --enable-decoder=flac
436 add_flag_chromiumos --enable-parser=flac
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
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
457 echo "Chromium configure/build:"
458 build Chromium $FLAGS_COMMON $FLAGS_CHROMIUM
459 echo "Chrome configure/build:"
460 build Chrome $FLAGS_COMMON $FLAGS_CHROME
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
469 echo "Done. If desired you may copy config.h/config.asm into the" \
470 "source/config tree using copy_config.sh."