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 " win [ia32|x64]"
24 echo " win-vs2013 [ia32|x64]"
25 echo " mac [ia32|x64]"
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)."
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"
36 echo "Specifying 'config-only' will skip the build step. Useful when a"
37 echo "given platform is not necessary for generate_gyp.py."
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"
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/"
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"
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"
71 # If configure & make works but this script doesn't, make sure to grep for
73 LIBAVCODEC_VERSION_MAJOR=55
74 LIBAVFORMAT_VERSION_MAJOR=55
75 LIBAVUTIL_VERSION_MAJOR=52
81 JOBS=$(grep processor /proc/cpuinfo | wc -l)
86 JOBS=$(grep processor /proc/cpuinfo | wc -l)
91 JOBS=$(grep processor /proc/cpuinfo | wc -l)
96 JOBS=$(sysctl -n hw.ncpu)
101 JOBS=$(sysctl -n hw.ncpu)
106 JOBS=$NUMBER_OF_PROCESSORS
109 echo "Unrecognized HOST_OS: $(uname)"
110 echo "Patches welcome!"
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"
122 echo "LD = $(ld --version | head -n1)"
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"
132 if (yasm --version | head -1 | grep -q "^yasm 0\."); then
133 echo "Must have yasm 1.0 or higher installed"
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"; }
144 # Appends configure flags.
151 # Flags that are used in all of Chrome/Chromium + OS.
152 function add_flag_common {
153 FLAGS_COMMON="$FLAGS_COMMON $*"
155 # Flags that are used in Chromium and ChromiumOS.
156 function add_flag_chromium {
157 FLAGS_CHROMIUM="$FLAGS_CHROMIUM $*"
159 # Flags that are used in Chrome and ChromeOS.
160 function add_flag_chrome {
161 FLAGS_CHROME="$FLAGS_CHROME $*"
163 # Flags that are used only in ChromiumOS (but not Chromium).
164 function add_flag_chromiumos {
165 FLAGS_CHROMIUMOS="$FLAGS_CHROMIUMOS $*"
167 # Flags that are used only in ChromeOS (but not Chrome).
168 function add_flag_chromeos {
169 FLAGS_CHROMEOS="$FLAGS_CHROMEOS $*"
172 # Builds using $1 as the output directory and all following arguments as
173 # configure script arguments.
176 CONFIG_DIR="build.$TARGET_ARCH.$TARGET_OS/$CONFIG"
179 # Create our working directory.
180 echo "Creating build directory..."
186 # Configure and check for exit status.
187 echo "Configuring $CONFIG..."
188 CMD="$FFMPEG_PATH/configure $*"
192 if [ ! -f config.h ]; then
193 echo "Configure failed!"
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
207 if [[ "$HOST_OS" = "$TARGET_OS" && "$CONFIG_ONLY" = "" ]]; then
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"
213 echo "Building $lib for $CONFIG..."
214 echo "make -j$JOBS $lib"
223 elif [ ! "$CONFIG_ONLY" = "" ]; then
224 echo "Skipping build step as requested."
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"
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
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
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
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\""
271 add_flag_common --optflags=-O2
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
282 if [ "$TARGET_OS" = "linux" ]; then
283 if [ "$TARGET_ARCH" = "x64" ]; then
284 # Nothing to add for now.
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
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
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
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
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
354 echo "Error: Unknown TARGET_ARCH=$TARGET_ARCH for TARGET_OS=$TARGET_OS!"
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
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."
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
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."
381 add_flag_common --enable-pic
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
399 echo "Error: Unknown TARGET_ARCH=$TARGET_ARCH for TARGET_OS=$TARGET_OS!"
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."
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
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
419 # ChromiumOS specific configuration.
420 # Warning: do *NOT* add avi, aac, h264, mp3, mp4, amr*
422 add_flag_chromiumos --enable-demuxer=flac
423 add_flag_chromiumos --enable-decoder=flac
424 add_flag_chromiumos --enable-parser=flac
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
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
445 echo "Chromium configure/build:"
446 build Chromium $FLAGS_COMMON $FLAGS_CHROMIUM
447 echo "Chrome configure/build:"
448 build Chrome $FLAGS_COMMON $FLAGS_CHROME
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
457 echo "Done. If desired you may copy config.h/config.asm into the" \
458 "source/config tree using copy_config.sh."