# Copyright (C) 2015 Dmitry Skiba
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

{
  'includes': [
    # build_props are generated by gyp_generate
    '../out/build_props.gypi',
  ],

  'variables': {
    # scripts
    'format': 'python utils/format.py',
    'len': 'python -c "import sys; print (len(sys.argv) - 1)"',
    'dependency': '<(format) "{0}.gyp:{0}"',
    'relpath': 'python utils/relpath.py',
    'gyp_relpath': '<(relpath) <(root_path)/gyp',

    # paths
    'platform_root': '<!(<(gyp_relpath) <(platform_root))',
    'intermediate_headers_root': '<(headers_root)', # TODO: get rid of
    'intermediate_build_root': '<(build_root)', # TODO: get rid of

    # misc
    'force_action_input': '<(build_root)/force_action/cookie',
  },

  'make_global_settings': [
    [ 'CC', '<(CC)' ],
    [ 'CXX', '<(CXX)' ],
    [ 'LD', '<(LD)' ],
  ],

  'target_defaults': {

    'default_configuration': 'Debug',
    'configurations': {
      'Debug': {
      },
      'Release': {
        'defines': [
          'NDEBUG',
        ],
      },
    },

    'defines': [
      'HAVE_ANDROID_OS', # Use (undefined) HAVE_LINUX_ANDROID_OS for Linux-specific stuff
      'HAVE_POSIX_FILEMAP',
      'HAVE_PTHREADS',
      'HAVE_STRLCPY',
      '_FILE_OFFSET_BITS=64',
      'ANDROID_SMP=0',
      "OS_PATH_SEPARATOR='/'",
      'OS_SHARED_LIB_FORMAT_STR="lib%s.dylib"',
      'ANDROID_STATICALLY_LINKED',
      'HAVE_SYS_UIO_H',
    ],

    'xcode_settings': {
      'SDKROOT': '<(BUILD_SDK)',
      'ARCHS': [ '<(BUILD_ARCH)' ],
      'VALID_ARCHS': [ '<(BUILD_ARCH)' ],
      'ONLY_ACTIVE_ARCH': 'YES',
      'CLANG_CXX_LANGUAGE_STANDARD': 'c++11',
      'CLANG_CXX_LIBRARY': 'libc++',
      'GCC_C_LANGUAGE_STANDARD': 'c99',
      'GCC_OPTIMIZATION_LEVEL': '0', # TODO
      'OTHER_CFLAGS': [ '-fvisibility-inlines-hidden' ]
    },

    'dependencies+': [
      '<!(<(dependency) linuxemu)',
      '<!(<(dependency) bionicemu)',
    ],

    'target_conditions': [
      [ '_type == "shared_library" or _type == "executable"', {
        'xcode_settings': {
          'OTHER_LDFLAGS': [
            '-Wl,-no_pie', # to get mmap(address) working
            '-Wl,-pagezero_size,0x1000', # min mmap() address
          ],
        },
        'conditions': [
          [ 'GENERATOR == "xcode"', {
            'xcode_settings': {
              'CONFIGURATION_BUILD_DIR': '<(bin_root)',
            },
          }, {
            'product_dir': '<(bin_root)',
          }],
        ],
      }],
      [ '_type == "static_library"', {
        'conditions': [
          [ 'GENERATOR == "xcode"', {
            'xcode_settings': {
              'CONFIGURATION_BUILD_DIR': '<(lib_root)'
            },
          }, {
            'product_dir': '<(lib_root)',
          }],
        ],
      }],
      [ '_type == "shared_library"', {
        'xcode_settings': {
          'LD_DYLIB_INSTALL_NAME': '@executable_path/$(EXECUTABLE_PATH)',
        },
      }],
    ],
  },
}
