# vim: set sts=2 ts=8 sw=2 tw=99 et ft=python: 
import os

# Here only one sdk should be available to generate only one executable in the end,
# as multi-sdk loading isn't supported out of the box by metamod, and would require specifying the full path in the vdf
# which in the end would ruin the multi-platform (unix, win etc) loading by metamod as it won't be able to append platform specific extension
# so just fall back to the single binary.
# Multi-sdk solutions should be manually loaded with a custom plugin loader (examples being sourcemod, stripper:source)
for sdk_name in MMSPlugin.sdks:
  for cxx in MMSPlugin.all_targets:
    sdk = MMSPlugin.sdks[sdk_name]

    if not cxx.target.arch in sdk.platformSpec[cxx.target.platform]:
      continue

    binary = MMSPlugin.HL2Library(builder, cxx, MMSPlugin.plugin_name, sdk)

    if binary.compiler.family == 'gcc' or binary.compiler.family == 'clang':
      binary.compiler.cxxflags += ['-Wno-register']
      binary.compiler.cxxflags += ['--std=c++17']

    binary.sources += [
      'Skin.cpp',
      'utils/module.cpp',
      'utils/memaddr.cpp',
      os.path.join('sdk', 'schemasystem.cpp')
    ]

    if sdk_name in ['dota', 'cs2']:
      binary.sources += [
      os.path.join(sdk.path, 'tier1', 'convar.cpp'),
      os.path.join(sdk.path, 'tier1', 'generichash.cpp'),
      os.path.join(sdk.path, 'entity2', 'entitysystem.cpp'),
      os.path.join(sdk.path, 'public', 'tier0', 'memoverride.cpp')
    ]

    if cxx.target.arch == 'x86':
      binary.sources += ['sourcehook/sourcehook_hookmangen.cpp']
    nodes = builder.Add(binary)
    MMSPlugin.binaries += [nodes]
    
  break
