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=$(sysctl -n hw.ncpu)
96 JOBS=$(sysctl -n hw.ncpu)
101 JOBS=$NUMBER_OF_PROCESSORS
104 echo "Unrecognized HOST_OS: $(uname)"
105 echo "Patches welcome!"
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"
117 echo "LD = $(ld --version | head -n1)"
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"
124 echo "Switch /usr/bin/ld to the regular binutils ld and try again"
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"
135 if (yasm --version | head -1 | grep -q "^yasm 0\."); then
136 echo "Must have yasm 1.0 or higher installed"
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"; }
147 # Appends configure flags.
154 # Flags that are used in all of Chrome/Chromium + OS.
155 function add_flag_common {
156 FLAGS_COMMON="$FLAGS_COMMON $*"
158 # Flags that are used in Chromium and ChromiumOS.
159 function add_flag_chromium {
160 FLAGS_CHROMIUM="$FLAGS_CHROMIUM $*"
162 # Flags that are used in Chrome and ChromeOS.
163 function add_flag_chrome {
164 FLAGS_CHROME="$FLAGS_CHROME $*"
166 # Flags that are used only in ChromiumOS (but not Chromium).
167 function add_flag_chromiumos {
168 FLAGS_CHROMIUMOS="$FLAGS_CHROMIUMOS $*"
170 # Flags that are used only in ChromeOS (but not Chrome).
171 function add_flag_chromeos {
172 FLAGS_CHROMEOS="$FLAGS_CHROMEOS $*"
175 # Builds using $1 as the output directory and all following arguments as
176 # configure script arguments.
179 CONFIG_DIR="build.$TARGET_ARCH.$TARGET_OS/$CONFIG"
182 # Create our working directory.
183 echo "Creating build directory..."
189 # Configure and check for exit status.
190 echo "Configuring $CONFIG..."
191 CMD="$FFMPEG_PATH/configure $*"
195 if [ ! -f config.h ]; then
196 echo "Configure failed!"
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
210 if [[ "$HOST_OS" = "$TARGET_OS" && "$CONFIG_ONLY" = "" ]]; then
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"
216 echo "Building $lib for $CONFIG..."
217 echo "make -j$JOBS $lib"
226 elif [ ! "$CONFIG_ONLY" = "" ]; then
227 echo "Skipping build step as requested."
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"
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
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
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
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\""
274 add_flag_common --optflags=-O2
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
285 if [ "$TARGET_OS" = "linux" ]; then
286 if [ "$TARGET_ARCH" = "x64" ]; then
287 # Nothing to add for now.
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
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
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
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
353 echo "Error: Unknown TARGET_ARCH=$TARGET_ARCH for TARGET_OS=$TARGET_OS!"
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
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."
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
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."
380 add_flag_common --enable-pic
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
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."