%YAML 1.2
--- |
  # GRPC GYP build file

  # This file has been automatically generated from a template file.
  # Please look at the templates directory instead.
  # This file can be regenerated from the template by running
  # tools/buildgen/generate_projects.sh

  # Copyright 2015 gRPC authors.
  #
  # 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.
  <%
  def is_absl_lib(target_name):
      return target_name.startswith("absl/");
  %>
  {
    'variables': {
     # The openssl and zlib dependencies must be passed in as variables
     # defined in an included gypi file, usually common.gypi.
     'openssl_gyp_target%': 'Please Define openssl_gyp_target variable',
     'zlib_gyp_target%': 'Please Define zlib_gyp_target variable',

     'grpc_gcov%': 'false',
     'grpc_alpine%': 'false',
    },
    'target_defaults': {
      'configurations': {
        % for name, args in configs.iteritems():
        %  if name in ['dbg', 'opt']:
        '${{'dbg':'Debug', 'opt': 'Release'}[name]}': {
          % for arg, prop in [('CPPFLAGS', 'cflags'), ('DEFINES', 'defines')]:
          %  if args.get(arg, None) is not None:
          '${prop}': [
            % for item in args.get(arg).split():
            '${item}',
            % endfor
          ],
          %  endif
          % endfor
        },
        %  endif
        % endfor
      },
      % for arg, prop in [('CPPFLAGS', 'cflags'), ('LDFLAGS', 'ldflags')]:
      %  if defaults['global'].get(arg, None) is not None:
      '${prop}': [
        % for item in defaults['global'].get(arg).split():
        '${item}',
        % endfor
      ],
      %  endif
      % endfor
      'cflags_c': [
        '-Werror',
        '-std=c99',
      ],
      'cflags_cc': [
        '-Werror',
        '-std=c++11',
      ],
      'include_dirs': [
        '.',
        '../..',
        'include',
      ],
      'defines': [
        'GRPC_ARES=0',
      ],
      'dependencies': [
        '<(openssl_gyp_target)',
        '<(zlib_gyp_target)',
      ],
      'conditions': [
        ['grpc_gcov=="true"', {
          % for arg, prop in [('CPPFLAGS', 'cflags'), ('DEFINES', 'defines'), ('LDFLAGS', 'ldflags')]:
          %  if configs['gcov'].get(arg, None) is not None:
          '${prop}': [
            % for item in configs['gcov'].get(arg).split():
            '${item}',
            % endfor
          ],
          %  endif
          % endfor
        }],
        ['grpc_alpine=="true"', {
          'defines': [
            'GPR_MUSL_LIBC_COMPAT'
          ]
        }],
        ['OS == "win"', {
          'defines': [
            '_WIN32_WINNT=0x0600',
            'WIN32_LEAN_AND_MEAN',
            '_HAS_EXCEPTIONS=0',
            'UNICODE',
            '_UNICODE',
            'NOMINMAX',
          ],
          'msvs_settings': {
            'VCCLCompilerTool': {
              'RuntimeLibrary': 1, # static debug
            }
          },
          "libraries": [
            "ws2_32"
          ]
        }],
        ['OS == "mac"', {
          'xcode_settings': {
            % if defaults['global'].get('CPPFLAGS', None) is not None:
            'OTHER_CFLAGS': [
              % for item in defaults['global'].get('CPPFLAGS').split():
              '${item}',
              % endfor
            ],
            'OTHER_CPLUSPLUSFLAGS': [
              % for item in defaults['global'].get('CPPFLAGS').split():
              '${item}',
              % endfor
              '-stdlib=libc++',
              '-std=c++11',
              '-Wno-error=deprecated-declarations',
            ],
            % endif
          },
        }]
      ]
    },
    'targets': [
      % for lib in libs:
      %  if getattr(lib, 'platforms', None) is None and lib.name != 'ares' and not is_absl_lib(lib.name):
      {
        'target_name': '${lib.name}',
        'type': 'static_library',
        'dependencies': [
          % for dep in getattr(lib, 'deps', []):
          '${dep}',
          % endfor
        ],
        'sources': [
          % for source in lib.src:
          '${source}',
          % endfor
        ],
      },
      %  endif
      % endfor
    ]
  }
