1# -*- Python -*-
2#
3#
4# All the helper functions are defined in:
5#  - site_scons/talk.py
6# Use 'import talk' in any .scons file to get access to it.
7# Add any new helper functions to it; unittest are available
8# in talk_unittest.py.
9#
10# Each 'component' that is built is defined in a .scons file.
11# See talk.Components(...) for further info on file naming convention.
12#
13# To add a new platform clone and modify the root_env object. Remember to add
14# the new environment object to the envs list otherwise it will not be included
15# in the build.
16#
17#
18#
19
20import talk
21import os
22import platform
23
24#-------------------------------------------------------------------------------
25# The build files/directories to 'build'.
26# If the name is the name of a directory then that directory shall contain a
27# .scons file with the same name as the directory itself:
28#  Ex: The directory session/phone contains a file called phone.scons
29# This list must be in order of library dependencies. e.g., if
30# session/phone/phone.scons defines a target that links to a library target
31# defined in sound/sound.scons, then 'sound' must come first.
32# When no particular order is imposed by library dependencies, try to keep in
33# mostly alphabetical order.
34#
35components = talk.Components("libjingle.scons")
36
37#-------------------------------------------------------------------------------
38# Build environments
39#
40
41# The list of build environments.
42envs = []
43
44# The root of all builds.
45root_env = Environment(
46  tools = [
47    'component_bits',
48    'component_setup',
49    'replace_strings',
50    'talk_noops',
51    #'talk_utils',
52  ],
53  BUILD_SCONSCRIPTS = components,
54  DESTINATION_ROOT = '$MAIN_DIR/build',
55  CPPPATH = [
56    '$OBJ_ROOT',     # generated headers are relative to here
57    '$MAIN_DIR/..',  # TODO(dape): how can we use GOOGLECLIENT instead?
58  ],
59  CPPDEFINES = [
60    'LOGGING=1',
61
62    # Feature selection
63    'FEATURE_ENABLE_SSL',
64    'FEATURE_ENABLE_VOICEMAIL',
65    'FEATURE_ENABLE_PSTN',
66    'HAVE_SRTP',
67  ],
68  # Ensure the os environment is captured for any scripts we call out to
69  ENV = os.environ,
70)
71
72# This is where we set common environments
73#
74# Detect if building on 64-bit or 32-bit platform.
75DeclareBit('build_platform_64bit', 'Platform of the build machine is 64-bit')
76if platform.architecture()[0] == "64bit":
77  root_env.SetBits('build_platform_64bit')
78
79# This bit denotes that an env is for 64-bit builds. When set, all build
80# artifacts will be 64-bit. When unset, all build artifacts will be 32-bit.
81DeclareBit('host_platform_64bit',
82           'Platform of the host machine (where artifacts will execute) is '
83               '64-bit')
84
85# This bit denotes that we are cross-compiling using a sysroot.
86DeclareBit('cross_compile',
87           'Cross compiling using the SYSROOT environment variable')
88
89def CrossArch(env):
90  """Return whether or not the host platform architecture differs from the build
91     environment architecture."""
92  if env.Bit('cross_compile'):
93    # The architecture of the Python process may not match the architecture of
94    # the sysroot, so we just assume it's not a cross-arch build or that it
95    # doesn't matter. Currently it only matters if you try to build a cross-arch
96    # Debian package, so just don't do that.
97    return False
98  else:
99    return env.Bit('host_platform_64bit') != env.Bit('build_platform_64bit')
100root_env.AddMethod(CrossArch)
101
102DeclareBit('use_static_openssl', 'Build OpenSSL as a static library')
103
104DeclareBit('have_dbus_glib',
105           'Whether the build system has the dbus-glib-1 package')
106DeclareBit('have_libpulse',
107           'Whether the build system has the libpulse package')
108
109
110# List all the locales we localize to.
111root_env.AppendUnique(locales = [
112    'af', 'am', 'ar', 'bg', 'bn', 'ca', 'cs', 'da', 'de', 'el', 'en', 'en-GB',
113    'es', 'es-419', 'et', 'eu', 'fa', 'fi', 'fil', 'fr', 'fr-CA', 'gl', 'gu',
114    'hi', 'hr', 'hu', 'id', 'is', 'it', 'iw', 'ja', 'kn', 'ko', 'lt', 'lv',
115    'ml', 'mr', 'ms', 'nl', 'no', 'or', 'pl', 'pt-BR', 'pt-PT', 'ro', 'ru',
116    'sk', 'sl', 'sr', 'sv', 'sw', 'ta', 'te', 'th', 'tl', 'tr', 'uk', 'ur',
117    'vi', 'zh-CN', 'zh-HK', 'zh-TW', 'zu'])
118
119AddTargetGroup('all_breakpads', 'breakpad files can be built')
120
121AddTargetGroup('all_dsym', 'dsym debug packages can be built')
122
123#-------------------------------------------------------------------------------
124# W I N D O W S
125#
126win_env = root_env.Clone(
127  tools = [
128    'atlmfc_vc80',
129    #'code_signing',
130    'component_targets_msvs',
131    'directx_9_0_c',
132    #'grid_builder',
133    'midl',
134    'target_platform_windows'
135  ],
136  # Don't use default vc80 midl.exe.  It doesn't understand vista_sdk idl files.
137  MIDL = '$PLATFORM_SDK_VISTA_6_0_DIR/Bin/midl.exe ',
138  WIX_DIR = '$GOOGLECLIENT/third_party/wix/v3_0_2925/files',
139  # Flags for debug and optimization are added to CCFLAGS instead
140  CCPDBFLAGS = '',
141  CCFLAGS_DEBUG = '',
142  CCFLAGS_OPTIMIZED = '',
143  # We force a x86 target even when building on x64 Windows platforms.
144  TARGET_ARCH = 'x86',
145)
146
147
148win_env.Decider('MD5-timestamp')
149win_env.Append(
150  COMPONENT_LIBRARY_PUBLISH = True,  # Put dlls in output dir too
151  CCFLAGS = [
152    '/Fd${TARGET}.pdb', # pdb per object allows --jobs=
153    '/WX',          # warnings are errors
154    '/Zc:forScope', # handle 'for (int i = 0 ...)' right
155    '/EHs-c-',      # disable C++ EH
156    '/GR-',         # disable RTTI
157    '/Gy',          # enable function level linking
158    '/wd4996',      # ignore POSIX deprecated warnings
159
160    # promote certain level 4 warnings
161    '/w14701',     # potentially uninitialized var
162    '/w14702',     # unreachable code
163    '/w14706',     # assignment within a conditional
164    '/w14709',     # comma operator within array index
165    '/w14063',     # case 'identifier' is not a valid value for switch of enum
166    '/w14064',     # switch of incomplete enum 'enumeration'
167    '/w14057',     # 'identifier1' indirection to slightly different base
168                   #   types from 'identifier2'
169    '/w14263',     # member function does not override any base class virtual
170                   #   member function
171    '/w14266',     # no override available for virtual memberfunction from base
172                   #  'type'; function is hidden
173    '/w14296',     # expression is always false
174    '/w14355',     # 'this' : used in base member initializer list
175  ],
176  CPPDEFINES = [
177    '_ATL_CSTRING_EXPLICIT_CONSTRUCTORS',
178    # TODO(dape): encapsulate all string operations that are not based
179    # on std::string/std::wstring and make sure we use the safest versions
180    # available on all platforms.
181    '_CRT_SECURE_NO_WARNINGS',
182    '_USE_32BIT_TIME_T',
183    '_UNICODE',
184    'UNICODE',
185    '_HAS_EXCEPTIONS=0',
186    'WIN32',
187    # TODO(dape): remove this from logging.cc and enable here instead.
188    #'WIN32_LEAN_AND_MEAN',
189
190    'WINVER=0x0500',
191    '_WIN32_WINNT=0x0501',
192    '_WIN32_IE=0x0501',
193    # The Vista platform SDK 6.0 needs at least
194    # this NTDDI version or else the headers
195    # that LMI includes from it won't compile.
196    'NTDDI_VERSION=NTDDI_WINXP',
197
198    # npapi.h requires the following:
199    '_WINDOWS',
200  ],
201  CPPPATH = [
202    '$THIRD_PARTY/wtl_71/include',
203    '$PLATFORM_SDK_VISTA_6_0_DIR/Include',
204  ],
205  LIBPATH = [
206    '$PLATFORM_SDK_VISTA_6_0_DIR/Lib'
207  ],
208  LINKFLAGS = [
209    '-manifest', # TODO(thaloun): Why do we need this?
210    # Some of the third-party libraries we link in don't have public symbols, so
211    # ignore that linker warning.
212    '/ignore:4221',
213    '/nxcompat',    # Binary was tested to be be compatible with Windows DEP.
214    '/dynamicbase', # Use ASLR to dynamically rebase at load-time.
215    '/fixed:no',    # Binary can be loaded at any base-address.
216  ],
217  MIDLFLAGS = [
218    '/win32',
219    '/I$PLATFORM_SDK_VISTA_6_0_DIR/include'
220  ]
221)
222
223# TODO(dape): Figure out what this does; found it in
224# omaha/main.scons. This fixes the problem with redefinition
225# of OS_WINDOWS symbol.
226win_env.FilterOut(CPPDEFINES = ['OS_WINDOWS=OS_WINDOWS'])
227
228# Set up digital signing
229DeclareBit('test_signing', 'Sign binaries with the test certificate')
230win_env.SetBitFromOption('test_signing', False)
231if win_env.Bit('test_signing'):
232   win_env.Replace(
233     CERTIFICATE_PATH = win_env.File(
234         '$GOOGLECLIENT/tools/test_key/testkey.pfx').abspath,
235     CERTIFICATE_PASSWORD = 'test',
236   )
237AddTargetGroup('signed_binaries', 'digitally signed binaries can be built')
238
239win_dbg_env = win_env.Clone(
240  BUILD_TYPE = 'dbg',
241  BUILD_TYPE_DESCRIPTION = 'Windows debug build',
242  BUILD_GROUPS = ['default', 'all'],
243  tools = ['target_debug'],
244)
245
246win_dbg_env.Prepend(
247  CCFLAGS = [
248    '/ZI',     # enable debugging
249    '/Od',     # disable optimizations
250    '/MTd',    # link with LIBCMTD.LIB debug lib
251    '/RTC1',   # enable runtime checks
252  ],
253)
254
255envs.append(win_dbg_env)
256
257win_dbg64_env = win_dbg_env.Clone(
258  BUILD_TYPE = 'dbg64',
259  BUILD_TYPE_DESCRIPTION = 'Windows debug 64bit build',
260  BUILD_GROUPS = ['all'],
261)
262
263win_dbg64_env.FilterOut(CCFLAGS = ['/ZI'])
264
265win_dbg64_env.Append(
266  CCFLAGS = [
267    '/Zi',     # enable debugging that is 64 bit compatible.
268    # TODO(fbarchard): fix warnings and remove these disables.
269    '/wd4244', # disable cast warning
270    '/wd4267', # disable cast warning
271  ],
272  ARFLAGS = [
273    '/MACHINE:x64',
274  ],
275  CPPDEFINES = [
276    'WIN64',
277    'ARCH_CPU_64_BITS',
278  ],
279  LIBFLAGS = [
280    '/MACHINE:x64',
281  ],
282  LINKFLAGS = [
283    '/MACHINE:x64',
284  ],
285)
286
287win_dbg64_env.FilterOut(CPPDEFINES = ['_USE_32BIT_TIME_T'])
288
289win_dbg64_env.Prepend(
290  LIBPATH = [
291      '$VC80_DIR/vc/lib/amd64',
292      '$ATLMFC_VC80_DIR/lib/amd64',
293      '$PLATFORM_SDK_VISTA_6_0_DIR/Lib/x64',
294  ],
295)
296win_dbg64_env.PrependENVPath(
297  'PATH',
298  win_dbg64_env.Dir('$VC80_DIR/vc/bin/x86_amd64'))
299
300win_dbg64_env.SetBits('host_platform_64bit')
301
302envs.append(win_dbg64_env)
303
304win_coverage_env = win_dbg_env.Clone(
305  tools = ['code_coverage'],
306  BUILD_TYPE = 'coverage',
307  BUILD_TYPE_DESCRIPTION = 'Windows code coverage build',
308  BUILD_GROUPS = ['all'],
309)
310
311win_coverage_env.Append(
312  CPPDEFINES = [
313    'COVERAGE_ENABLED',
314  ],
315)
316
317envs.append(win_coverage_env)
318
319win_opt_env = win_env.Clone(
320  BUILD_TYPE = 'opt',
321  BUILD_TYPE_DESCRIPTION = 'Windows opt build',
322  BUILD_GROUPS = ['all'],
323  tools = ['target_optimized'],
324)
325
326win_opt_env.Prepend(
327  CCFLAGS=[
328      '/Zi',       # enable debugging
329      '/O1',       # optimize for size
330      '/fp:fast',  # float faster but less precise
331      '/MT',       # link with LIBCMT.LIB (multi-threaded, static linked crt)
332      '/GS',       # enable security checks
333  ],
334  LINKFLAGS = [
335    '/safeseh',     # protect against attacks against exception handlers
336    '/opt:ref',     # Remove unused references (functions/data).
337  ],
338)
339
340envs.append(win_opt_env)
341
342#-------------------------------------------------------------------------------
343# P O S I X
344#
345posix_env = root_env.Clone()
346posix_env.Append(
347  CPPDEFINES = [
348    'HASHNAMESPACE=__gnu_cxx',
349    'HASH_NAMESPACE=__gnu_cxx',
350    'POSIX',
351    'DISABLE_DYNAMIC_CAST',
352    # The POSIX standard says we have to define this.
353    '_REENTRANT',
354  ],
355  CCFLAGS = [
356    '-Wall',
357    '-Werror',
358    '-Wno-switch',
359    '-fno-exceptions',
360    # Needed for a clean ABI and for link-time dead-code removal to work
361    # properly.
362    '-fvisibility=hidden',
363    # Generate debugging info in the DWARF2 format.
364    '-gdwarf-2',
365    # Generate maximal debugging information. (It is stripped from what we ship
366    # to users, so we want it for both dbg and opt.)
367    # Note that hammer automatically supplies "-g" for mac/linux dbg, so that
368    # flag must be filtered out of linux_dbg and mac_dbg envs below.
369    '-g3',
370  ],
371  CXXFLAGS = [
372    '-Wno-non-virtual-dtor',
373    '-Wno-ctor-dtor-privacy',
374    '-fno-rtti',
375  ],
376)
377
378# Switch-hit between NSS and OpenSSL
379if 'NSS_BUILD_PLATFORM' in root_env['ENV']:
380   posix_env.AppendUnique(CPPDEFINES=['HAVE_NSS_SSL_H=1',
381                                      'NSS_SSL_RELATIVE_PATH'])
382else:
383   posix_env.AppendUnique(CPPDEFINES=['HAVE_OPENSSL_SSL_H=1'])
384
385
386#-------------------------------------------------------------------------------
387# M A C OSX
388#
389mac_env = posix_env.Clone(
390  tools = [
391    'target_platform_mac',
392    #'talk_mac',
393    #'fill_plist',
394  ],
395)
396# Use static OpenSSL on mac so that we can use the latest APIs on all
397# supported mac platforms (10.5+).
398mac_env.SetBits('use_static_openssl')
399
400# For libjingle we don't specify a sysroot or minimum OS version.
401mac_osx_version_min_32 = ""
402mac_osx_version_min_64 = ""
403
404# Generic mac environment common to all targets
405mac_env.Append(
406  CPPDEFINES = [
407    'OSX',
408  ],
409  CCFLAGS = [
410    '-arch', 'i386',
411    '-fasm-blocks',
412  ],
413  LINKFLAGS = [
414    '-Wl,-search_paths_first',
415    # This flag makes all members of a static library be included in the
416    # final exe - that increases the size of the exe, but without it
417    # Obj-C categories aren't properly included in the exe.
418    # TODO(thaloun): consider only defining for libs that actually have objc.
419    '-ObjC',
420    '-arch', 'i386',
421    '-dead_strip',
422  ],
423  FRAMEWORKS = [
424    'CoreServices',
425    'Security',
426    'SystemConfiguration',
427    'OpenGL',
428    'CoreAudio',
429    'Quartz',
430    'Cocoa',
431    'QTKit',
432  ]
433)
434
435if 'NSS_BUILD_PLATFORM' in root_env['ENV']:
436  mac_env.AppendUnique(LINKFLAGS = ['-Lthird_party/mozilla/dist/' + root_env['ENV']['NSS_BUILD_PLATFORM'] + '/lib'])
437else:
438  mac_env.AppendUnique(LINKFLAGS = ['-Lthird_party/openssl'])
439
440
441# add debug flags to environment
442def mac_debug_include(env):
443  env.Append(
444    CCFLAGS = [
445      '-O0',
446    ],
447    CPPDEFINES = [
448      'DEBUG=1',
449    ],
450  )
451  # Remove -g set by hammer, which is not what we want (we have set -g3 above).
452  env.FilterOut(CCFLAGS = ['-g'])
453
454# add 32/64 bit specific options to specified environment
455def mac_common_include_x86_32(env):
456  env.Append(
457    CCFLAGS = [
458      '-m32',
459    ],
460    LINKFLAGS = [
461      '-m32',
462    ],
463    FRAMEWORKS = [
464      'Carbon',
465      'QuickTime',
466    ],
467  )
468  envs.append(env)
469
470def mac_common_include_x86_64(env):
471  env.Append(
472    CCFLAGS = [
473      '-m64',
474      '-fPIC',
475    ],
476    CPPDEFINES = [
477      'ARCH_CPU_64_BITS',
478      'CARBON_DEPRECATED',
479    ],
480    LINKFLAGS = [
481      '-m64',
482    ],
483    FRAMEWORKS = [
484      'AppKit',
485    ],
486  )
487  env.SetBits('host_platform_64bit')
488  envs.append(env)
489
490def mac_osx_version_min(env, ver):
491  if ver != "":
492    sdk_path = '/Developer/SDKs/MacOSX%s.sdk' % ver
493    env.Append(
494      CCFLAGS = [
495        '-mmacosx-version-min=' + ver,
496        '-isysroot', sdk_path,
497      ],
498      LINKFLAGS = [
499        '-mmacosx-version-min=' + ver,
500        '-isysroot', sdk_path,
501      ],
502      osx_sdk_path = sdk_path,
503      osx_version_min = ver,
504    )
505
506# Create all environments
507mac_dbg_env = mac_env.Clone(
508  BUILD_TYPE = 'dbg',
509  BUILD_TYPE_DESCRIPTION = 'Mac debug build',
510  BUILD_GROUPS = ['default', 'all'],
511  tools = ['target_debug'],
512)
513
514mac_opt_env = mac_env.Clone(
515  BUILD_TYPE = 'opt',
516  BUILD_TYPE_DESCRIPTION = 'Mac opt build',
517  BUILD_GROUPS = ['all'],
518  tools = ['target_optimized'],
519)
520
521mac_dbg64_env = mac_dbg_env.Clone(
522  BUILD_TYPE = 'dbg64',
523  BUILD_TYPE_DESCRIPTION = 'Mac debug 64bit build',
524  BUILD_GROUPS = ['all'],
525)
526
527mac_opt64_env = mac_opt_env.Clone(
528  BUILD_TYPE = 'opt64',
529  BUILD_TYPE_DESCRIPTION = 'Mac opt 64bit build',
530  BUILD_GROUPS = ['all'],
531)
532
533mac_debug_include(mac_dbg_env)
534mac_debug_include(mac_dbg64_env)
535mac_common_include_x86_32(mac_dbg_env)
536mac_common_include_x86_32(mac_opt_env)
537mac_common_include_x86_64(mac_dbg64_env)
538mac_common_include_x86_64(mac_opt64_env)
539mac_osx_version_min(mac_dbg_env, mac_osx_version_min_32)
540mac_osx_version_min(mac_opt_env, mac_osx_version_min_32)
541mac_osx_version_min(mac_dbg64_env, mac_osx_version_min_64)
542mac_osx_version_min(mac_opt64_env, mac_osx_version_min_64)
543
544
545#-------------------------------------------------------------------------------
546# L I N U X
547#
548linux_common_env = posix_env.Clone(
549  tools = [
550    'target_platform_linux',
551    'talk_linux',
552  ],
553)
554
555linux_common_env.Append(
556  CPPDEFINES = [
557    'LINUX',
558  ],
559  CCFLAGS = [
560    # Needed for link-time dead-code removal to work properly.
561    '-ffunction-sections',
562    '-fdata-sections',
563  ],
564  LINKFLAGS = [
565    # Enable dead-code removal.
566    '-Wl,--gc-sections',
567    # Elide dependencies on shared libraries that we're not actually using.
568    '-Wl,--as-needed',
569    '-Wl,--start-group',
570  ],
571  _LIBFLAGS = ['-Wl,--end-group'],
572)
573
574# Remove default rpath set by Hammer. Hammer sets it to LIB_DIR, which is wrong.
575# The rpath is the _run-time_ library search path for the resulting binary, i.e.
576# the one used by ld.so at load time. Setting it equal to the path to build
577# output on the build machine is nonsense.
578linux_common_env.Replace(
579  RPATH = [],
580)
581
582# Enable the optional DBus-GLib code if the build machine has the required
583# dependency.
584linux_common_env.EnableFeatureWherePackagePresent('have_dbus_glib',
585                                                  'HAVE_DBUS_GLIB',
586                                                  'dbus-glib-1')
587
588def linux_common_include_x86_32(env):
589  """Include x86-32 settings into an env based on linux_common."""
590  env.Append(
591    CCFLAGS = [
592      '-m32',
593    ],
594    LINKFLAGS = [
595      '-m32',
596    ],
597  )
598
599def linux_common_include_x86_64(env):
600  """Include x86-64 settings into an env based on linux_common."""
601  env.Append(
602    CCFLAGS = [
603      '-m64',
604      '-fPIC',
605    ],
606    LINKFLAGS = [
607      '-m64',
608    ],
609  )
610  env.SetBits('host_platform_64bit')
611
612#-------------------------------------------------------------------------------
613# L I N U X -- C R O S S -- B U I L D
614
615# Cross build requires the following tool names be provided by the environment:
616linux_cross_common_env = linux_common_env.Clone(
617  AR = os.environ.get("AR"),
618  AS = os.environ.get("AS"),
619  LD = os.environ.get("LD"),
620  NM = os.environ.get("NM"),
621  RANLIB = os.environ.get("RANLIB"),
622  CC = str(os.environ.get("CC")) +
623    ' --sysroot=' + str(os.environ.get("SYSROOT")),
624  CXX = str(os.environ.get("CXX")) +
625    ' --sysroot=' + str(os.environ.get("SYSROOT")),
626)
627linux_cross_common_env.SetBits('cross_compile')
628
629# The rest of these paths and flags are optional:
630if os.environ.get("CPPPATH"):
631  linux_cross_common_env.Append(
632    CPPPATH = os.environ.get("CPPPATH").split(':'),
633  )
634if os.environ.get("LIBPATH"):
635  linux_cross_common_env.Append(
636    LIBPATH = os.environ.get("LIBPATH").split(':'),
637  )
638if os.environ.get("CFLAGS"):
639  linux_cross_common_env.Append(
640    CFLAGS = os.environ.get("CFLAGS").split(' '),
641  )
642if os.environ.get("CCFLAGS"):
643  linux_cross_common_env.Append(
644    CCFLAGS = os.environ.get("CCFLAGS").split(' '),
645  )
646if os.environ.get("CXXFLAGS"):
647  linux_cross_common_env.Append(
648    CXXFLAGS = os.environ.get("CXXFLAGS").split(' '),
649  )
650if os.environ.get("LIBFLAGS"):
651  linux_cross_common_env.Append(
652    _LIBFLAGS = os.environ.get("LIBFLAGS").split(' '),
653  )
654if os.environ.get("LINKFLAGS"):
655  linux_cross_common_env.Prepend(
656    LINKFLAGS = os.environ.get("LINKFLAGS").split(' '),
657  )
658
659#-------------------------------------------------------------------------------
660# L I N U X -- T R A D I T I O N A L -- X 8 6
661#
662# Settings that are specific to our desktop Linux x86 targets.
663def linux_common_include_traditional(env):
664  """Include traditional Linux settings into an env based on linux_common."""
665  # OpenSSL has infamously poor ABI stability, so that building against one
666  # version and running against a different one often will not work. Since our
667  # non-ChromeOS Linux builds are used on many different distros and distro
668  # versions, this means we can't safely dynamically link to OpenSSL because the
669  # product would end up being broken on any computer with a different version
670  # installed. So instead we build it ourself and statically link to it.
671  env.SetBits('use_static_openssl')
672  # Enable the optional PulseAudio code if the build machine has the required
673  # dependency.
674  # TODO(?): This belongs in linux_common_env, but we can't safely move it there
675  # yet because pkg-config is not being used properly with ChromeOS builds (see
676  # TODO below).
677  env.EnableFeatureWherePackagePresent('have_libpulse',
678                                       'HAVE_LIBPULSE',
679                                       'libpulse')
680
681def linux_traditional_include_dbg(env):
682  """Include traditional Linux dbg settings into an env based on the above."""
683  # Remove -g set by hammer, which is not what we want (we have set -g3 above).
684  env.FilterOut(CCFLAGS = ['-g'])
685
686def linux_traditional_include_opt(env):
687  """Include traditional Linux opt settings into an env based on the above."""
688  # Remove -O2 set by hammer, which is not what we want.
689  env.FilterOut(CCFLAGS = ['-O2'])
690  env.Append(CCFLAGS = ['-Os'])
691
692def gen_linux_nonhermetic(linux_env, type_suffix, desc_suffix):
693  groups = ['nonhermetic']
694  if not linux_env.CrossArch():
695    groups = groups + ['nonhermetic-native']
696    # The non-hermetic, native-arch dbg build is the default.
697    dbg_groups = groups + ['default']
698    native_desc = ', native '
699    # No suffix for native modes.
700    type_suffix = ''
701  else:
702    groups = groups + ['nonhermetic-cross']
703    dbg_groups = groups
704    native_desc = ', cross-built for '
705
706  linux_dbg_env = linux_env.Clone(
707    BUILD_TYPE = 'dbg' + type_suffix,
708    BUILD_TYPE_DESCRIPTION = 'Linux debug build%s%s' % (native_desc,
709        desc_suffix),
710    BUILD_GROUPS = dbg_groups,
711    tools = ['target_debug'],
712  )
713  linux_traditional_include_dbg(linux_dbg_env)
714  envs.append(linux_dbg_env)
715
716  linux_opt_env = linux_env.Clone(
717    BUILD_TYPE = 'opt' + type_suffix,
718    BUILD_TYPE_DESCRIPTION = 'Linux optimized build%s%s' % (native_desc,
719        desc_suffix),
720    BUILD_GROUPS = groups,
721    tools = ['target_optimized'],
722  )
723  linux_traditional_include_opt(linux_opt_env)
724  envs.append(linux_opt_env)
725
726linux_nonhermetic_common_env = linux_common_env.Clone()
727linux_common_include_traditional(linux_nonhermetic_common_env)
728
729linux_nonhermetic_x86_32_env = linux_nonhermetic_common_env.Clone()
730linux_common_include_x86_32(linux_nonhermetic_x86_32_env)
731gen_linux_nonhermetic(linux_nonhermetic_x86_32_env, '32', '32-bit')
732
733linux_nonhermetic_x86_64_env = linux_nonhermetic_common_env.Clone()
734linux_common_include_x86_64(linux_nonhermetic_x86_64_env)
735gen_linux_nonhermetic(linux_nonhermetic_x86_64_env, '64', '64-bit')
736
737def gen_linux_hermetic(linux_env, type_suffix, desc):
738  groups = ['hermetic']
739
740  linux_dbg_env = linux_env.Clone(
741    BUILD_TYPE = 'hermetic-dbg' + type_suffix,
742    BUILD_TYPE_DESCRIPTION = 'Hermetic %s Linux debug build' % desc,
743    BUILD_GROUPS = groups,
744    tools = ['target_debug'],
745  )
746  linux_traditional_include_dbg(linux_dbg_env)
747  envs.append(linux_dbg_env)
748
749  linux_opt_env = linux_env.Clone(
750    BUILD_TYPE = 'hermetic-opt' + type_suffix,
751    BUILD_TYPE_DESCRIPTION = 'Hermetic %s Linux optimized build' % desc,
752    BUILD_GROUPS = groups,
753    tools = ['target_optimized'],
754  )
755  linux_traditional_include_opt(linux_opt_env)
756  envs.append(linux_opt_env)
757
758linux_hermetic_common_env = linux_cross_common_env.Clone()
759linux_common_include_traditional(linux_hermetic_common_env)
760
761linux_hermetic_x86_32_env = linux_hermetic_common_env.Clone()
762linux_common_include_x86_32(linux_hermetic_x86_32_env)
763gen_linux_hermetic(linux_hermetic_x86_32_env, '32', '32-bit')
764
765linux_hermetic_x86_64_env = linux_hermetic_common_env.Clone()
766linux_common_include_x86_64(linux_hermetic_x86_64_env)
767gen_linux_hermetic(linux_hermetic_x86_64_env, '64', '64-bit')
768
769#-------------------------------------------------------------------------------
770# L I N U X -- C R O S S -- B U I L D -- A R M
771
772# TODO(noahric): All the following Linux builds are running against a sysroot
773# but improperly using the host machine's pkg-config environment. The ChromeOS
774# ones should probably be using
775# https://cs.corp.google.com/#chrome/src/build/linux/pkg-config-wrapper.
776
777linux_cross_arm_env = linux_cross_common_env.Clone()
778linux_cross_arm_env.Append(
779  CPPDEFINES = [
780    'NACL_BUILD_ARCH=arm',
781    'DISABLE_EFFECTS=1',
782  ],
783  CCFLAGS = [
784    '-fPIC',
785  ],
786)
787DeclareBit('arm', 'ARM build')
788linux_cross_arm_env.SetBits('arm')
789
790# Detect NEON support from the -mfpu build flag.
791DeclareBit('arm_neon', 'ARM supporting neon')
792if '-mfpu=neon' in linux_cross_arm_env['CFLAGS'] or \
793   '-mfpu=neon' in linux_cross_arm_env['CCFLAGS'] or \
794   '-mfpu=neon' in linux_cross_arm_env['CXXFLAGS']:
795  print "Building with ARM NEON support."
796  linux_cross_arm_env.SetBits('arm_neon')
797
798# Detect hardfp from the -mfloat-abi build flag
799DeclareBit('arm_hardfp', 'ARM supporting hardfp')
800if '-mfloat-abi=hard' in linux_cross_arm_env['CFLAGS'] or \
801   '-mfloat-abi=hard' in linux_cross_arm_env['CCFLAGS'] or \
802   '-mfloat-abi=hard' in linux_cross_arm_env['CXXFLAGS']:
803  print "Building with hard floating point support."
804  linux_cross_arm_env.SetBits('arm_hardfp')
805
806linux_cross_arm_dbg_env = linux_cross_arm_env.Clone(
807  BUILD_TYPE = 'arm-dbg',
808  BUILD_TYPE_DESCRIPTION = 'Cross-compiled ARM debug build',
809  BUILD_GROUPS = ['arm'],
810  tools = ['target_debug'],
811)
812envs.append(linux_cross_arm_dbg_env)
813
814linux_cross_arm_opt_env = linux_cross_arm_env.Clone(
815  BUILD_TYPE = 'arm-opt',
816  BUILD_TYPE_DESCRIPTION = 'Cross-compiled ARM optimized build',
817  BUILD_GROUPS = ['arm'],
818  tools = ['target_optimized'],
819)
820envs.append(linux_cross_arm_opt_env)
821
822
823
824# Create a group for installers
825AddTargetGroup('all_installers', 'installers that can be built')
826
827# Parse child .scons files
828BuildEnvironments(envs)
829
830# Explicitly set which targets to build when not stated on commandline
831Default(None)
832# Build the following, which excludes unit test output (ie running them)
833# To run unittests, specify the test to run, or run_all_tests.  See -h option.
834Default(['all_libraries', 'all_programs', 'all_test_programs'])
835
836# .sln creation code lifted from googleclient/bar/main.scons.  Must be after
837# the call to BuildEnvironments for all_foo aliases to be defined.
838# Run 'hammer --mode=all --vsproj' to generate
839DeclareBit('vsproj', 'Generate Visual Studio projects and solution files.')
840win_env.SetBitFromOption('vsproj', False)
841
842if win_env.Bit('vsproj'):
843  vs_env = win_env.Clone()
844  vs_env.Append(
845    COMPONENT_VS_SOURCE_SUFFIXES = [
846      '.def',
847      '.grd',
848      '.html',
849      '.idl',
850      '.mk',
851      '.txt',
852      '.py',
853      '.scons',
854      '.wxs.template',
855    ]
856  )
857
858  # Source project
859  p = vs_env.ComponentVSDirProject(
860    'flute_source',
861    ['$MAIN_DIR',
862    ],
863    COMPONENT_VS_SOURCE_FOLDERS = [
864      # Files are assigned to first matching folder. Folder names of None
865      # are filters.
866      (None, '$DESTINATION_ROOT'),
867      ('flute', '$MAIN_DIR'),
868      ('google3', '$GOOGLE3'),
869      ('third_party', '$THIRD_PARTY'),
870    ],
871    # Force source project to main dir, so that Visual Studio can find the
872    # source files corresponding to build errors.
873    COMPONENT_VS_PROJECT_DIR = '$MAIN_DIR',
874  )
875  vs_env.AlwaysBuild(p)
876
877  # Solution and target projects
878  s = vs_env.ComponentVSSolution(
879    # 'libjingle',  # Please uncomment this line if you build VS proj files.
880    ['all_libraries', 'all_programs', 'all_test_programs'],
881    projects = [p],
882  )
883
884  print '***Unfortunately the vsproj creator isn\'t smart enough to '
885  print '***automatically get the correct output locations.  It is very easy'
886  print '***though to change it in the properties pane to the following'
887  print '***$(SolutionDir)/build/<foo>/staging/<bar>.exe'
888  Default(None)
889  Default([s])
890