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

for cxx in builder.targets:
  binary = SM.ExtLibrary(builder, cxx, 'regex.ext')
  binary.compiler.cxxincludes += [
    os.path.join(SM.mms_root, 'core', 'sourcehook'),
  ]
  if binary.compiler.family == 'gcc' or binary.compiler.family == 'clang':
    binary.compiler.cxxflags += ['-fno-rtti']
  elif binary.compiler.family == 'msvc':
    binary.compiler.cxxflags += ['/GR-']

  arch = binary.compiler.target.arch
  if binary.compiler.target.platform == 'linux':
    if arch == 'x86':
      path = os.path.join(builder.sourcePath, 'extensions', 'regex', 'lib_linux', 'libpcre.a')
    elif arch == 'x86_64':
      path = os.path.join(builder.sourcePath, 'extensions', 'regex', 'lib_linux64', 'libpcre.a')
  elif binary.compiler.target.platform == 'windows':
    if arch == 'x86':
      path = os.path.join(builder.sourcePath, 'extensions', 'regex', 'lib_win', 'pcre.lib')
    elif arch == 'x86_64':
      path = os.path.join(builder.sourcePath, 'extensions', 'regex', 'lib_win64', 'pcre.lib')
  elif binary.compiler.target.platform == 'mac':
    if arch == 'x86':
      path = os.path.join(builder.sourcePath, 'extensions', 'regex', 'lib_darwin', 'libpcre.a')
    elif arch == 'x86_64':
      path = os.path.join(builder.sourcePath, 'extensions', 'regex', 'lib_darwin64', 'libpcre.a')
  binary.compiler.postlink += [path]

  binary.sources += [
    'extension.cpp',
    'CRegEx.cpp',
    '../../public/smsdk_ext.cpp'
  ]

  SM.extensions += [builder.Add(binary)]