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

if AMXX.mysql_path:
  binary = AMXX.MetaModule(builder, 'mysql')

  binary.compiler.cxxincludes += [
    os.path.join(AMXX.mysql_path, 'include'),
    os.path.join(builder.currentSourcePath, 'mysql'),
    os.path.join(builder.currentSourcePath, 'thread'),
  ]

  binary.compiler.defines += [
    'SM_DEFAULT_THREADER',
    'HAVE_STDINT_H',
  ]

  if builder.target_platform is 'linux' or builder.target_platform is 'mac':
    binary.compiler.defines += ['stricmp=strcasecmp']
    binary.compiler.linkflags += [
      os.path.join(AMXX.mysql_path, 'lib', 'libmysqlclient_r.a'),
      '-lpthread',
      '-lm'
    ]
  elif builder.target_platform is 'windows':
    binary.compiler.linkflags += [
      os.path.join(AMXX.mysql_path, 'lib', 'opt', 'mysqlclient.lib'),
      'ws2_32.lib'
    ]

  binary.compiler.linkflags += [AMXX.zlib.binary]
    
  binary.sources = [
    'basic_sql.cpp',
    'handles.cpp',
    'module.cpp',
    'threading.cpp',
    '../../public/sdk/amxxmodule.cpp',
    'oldcompat_sql.cpp',
    'thread/BaseWorker.cpp',
    'thread/ThreadWorker.cpp',
    'mysql/MysqlQuery.cpp',
    'mysql/MysqlResultSet.cpp',
    'mysql/MysqlDatabase.cpp',
    'mysql/MysqlDriver.cpp',
  ]

  if builder.target_platform == 'windows':
    binary.sources += ['version.rc']
    
  if builder.target_platform == 'windows':
    binary.sources += [
      'thread/WinThreads.cpp',
    ]
  else:
    binary.sources += [
      'thread/PosixThreads.cpp',
    ]

  AMXX.modules += [builder.Add(binary)]