#!/usr/bin/python

# This script is wrapper for NaCl that adds some support for how GYP
# is invoked by NaCl beyond what can be done it the gclient hooks.

import glob
import os
import shlex
import sys

print 'Updating projects from gyp files...'

try:
  import gyp
except ImportError, e:
  sys.path.append(os.path.join(os.path.dirname(sys.argv[0]),
                               '..', '..', 'tools', 'gyp', 'pylib'))
  import gyp

if __name__ == '__main__':
  args = sys.argv[1:]

  # If we didn't get a file, check an env var, and then fall back to
  # assuming 'src/build/all.gyp'
  if len(args) == 0:
    args += shlex.split(os.environ.get('NACL_GYP_FILE',
                                       'native_client/build/all.gyp'))

  # Add settings that are only included in the standalone NaCl Gyp
  # build and won't get included when NaCl is built as part of another
  # project, such as Chrome.  configs.gypi includes compiler
  # configuration that arguably should be built into Gyp; Chrome
  # provides its own conflicting version in its common.gypi.
  args += ['-I', 'native_client/build/configs.gypi']
  # Enable warnings that we don't necessarily want to enable for
  # Chrome source that is built as NaCl untrusted code.
  args += ['-I', 'native_client/build/standalone_flags.gypi']

  # Pick depth explicitly.
  args += ['--depth', '.']

  # Building NaCl as standalone (not as part of Chrome)
  args += ['-D', 'nacl_standalone=1']

  args += ['-D', 'sysroot=native_client/toolchain/linux_x86_linux_arm/arm_trusted']

  # Off we go...
  sys.exit(gyp.main(args))
