# Copyright 2016 Google Inc.
#
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

declare_args() {
}

import("../third_party.gni")

third_party("libsdl") {
  public_include_dirs = [ "../externals/sdl/include" ]

  include_dirs = [ "." ]
  sources = [
    "../externals/sdl/src/SDL.c",
    "../externals/sdl/src/SDL_assert.c",
    "../externals/sdl/src/SDL_error.c",
    "../externals/sdl/src/SDL_hints.c",
    "../externals/sdl/src/SDL_log.c",
    "../externals/sdl/src/atomic/SDL_atomic.c",
    "../externals/sdl/src/atomic/SDL_spinlock.c",
    "../externals/sdl/src/audio/SDL_audio.c",
    "../externals/sdl/src/audio/SDL_audiocvt.c",
    "../externals/sdl/src/audio/SDL_audiodev.c",
    "../externals/sdl/src/audio/SDL_audiotypecvt.c",
    "../externals/sdl/src/audio/SDL_mixer.c",
    "../externals/sdl/src/audio/SDL_wave.c",
    "../externals/sdl/src/cpuinfo/SDL_cpuinfo.c",
    "../externals/sdl/src/dynapi/SDL_dynapi.c",
    "../externals/sdl/src/events/SDL_clipboardevents.c",
    "../externals/sdl/src/events/SDL_dropevents.c",
    "../externals/sdl/src/events/SDL_events.c",
    "../externals/sdl/src/events/SDL_gesture.c",
    "../externals/sdl/src/events/SDL_keyboard.c",
    "../externals/sdl/src/events/SDL_mouse.c",
    "../externals/sdl/src/events/SDL_quit.c",
    "../externals/sdl/src/events/SDL_touch.c",
    "../externals/sdl/src/events/SDL_windowevents.c",
    "../externals/sdl/src/file/SDL_rwops.c",
    "../externals/sdl/src/haptic/SDL_haptic.c",
    "../externals/sdl/src/haptic/dummy/SDL_syshaptic.c",
    "../externals/sdl/src/joystick/SDL_gamecontroller.c",
    "../externals/sdl/src/joystick/SDL_joystick.c",
    "../externals/sdl/src/joystick/dummy/SDL_sysjoystick.c",
    "../externals/sdl/src/power/SDL_power.c",
    "../externals/sdl/src/render/SDL_render.c",
    "../externals/sdl/src/render/SDL_yuv_sw.c",
    "../externals/sdl/src/render/software/SDL_blendfillrect.c",
    "../externals/sdl/src/render/software/SDL_blendline.c",
    "../externals/sdl/src/render/software/SDL_blendpoint.c",
    "../externals/sdl/src/render/software/SDL_drawline.c",
    "../externals/sdl/src/render/software/SDL_drawpoint.c",
    "../externals/sdl/src/render/software/SDL_render_sw.c",
    "../externals/sdl/src/render/software/SDL_rotate.c",
    "../externals/sdl/src/stdlib/SDL_getenv.c",
    "../externals/sdl/src/stdlib/SDL_iconv.c",
    "../externals/sdl/src/stdlib/SDL_malloc.c",
    "../externals/sdl/src/stdlib/SDL_qsort.c",
    "../externals/sdl/src/stdlib/SDL_stdlib.c",
    "../externals/sdl/src/stdlib/SDL_string.c",
    "../externals/sdl/src/thread/SDL_thread.c",
    "../externals/sdl/src/timer/SDL_timer.c",
    "../externals/sdl/src/video/SDL_RLEaccel.c",
    "../externals/sdl/src/video/SDL_blit.c",
    "../externals/sdl/src/video/SDL_blit_0.c",
    "../externals/sdl/src/video/SDL_blit_1.c",
    "../externals/sdl/src/video/SDL_blit_A.c",
    "../externals/sdl/src/video/SDL_blit_N.c",
    "../externals/sdl/src/video/SDL_blit_auto.c",
    "../externals/sdl/src/video/SDL_blit_copy.c",
    "../externals/sdl/src/video/SDL_blit_slow.c",
    "../externals/sdl/src/video/SDL_bmp.c",
    "../externals/sdl/src/video/SDL_clipboard.c",
    "../externals/sdl/src/video/SDL_egl.c",
    "../externals/sdl/src/video/SDL_fillrect.c",
    "../externals/sdl/src/video/SDL_pixels.c",
    "../externals/sdl/src/video/SDL_rect.c",
    "../externals/sdl/src/video/SDL_shape.c",
    "../externals/sdl/src/video/SDL_stretch.c",
    "../externals/sdl/src/video/SDL_surface.c",
    "../externals/sdl/src/video/SDL_video.c",
  ]
  defines = [
    "HAVE_ACOS",
    "HAVE_ASIN",
    "HAVE_ATAN",
    "HAVE_ATAN2",
    "HAVE_CEIL",
    "HAVE_COPYSIGN",
    "HAVE_COS",
    "HAVE_COSF",
    "HAVE_FABS",
    "HAVE_FLOOR",
    "HAVE_LOG",
    "HAVE_POW",
    "HAVE_SCALBN",
    "HAVE_SIN",
    "HAVE_SINF",
    "HAVE_SQRT",
    "HAVE_SQRTF",
    "HAVE_TAN",
    "HAVE_TANF",
    "SDL_HAPTIC_DISABLED=1",
    "SDL_JOYSTICK_DISABLED=1",
    "USING_PREMAKE_CONFIG_H",
  ]
  libs = []

  if (!is_win) {
    defines += [
      "SDL_LOADSO_DLOPEN=1",
      "SDL_THREAD_PTHREAD=1",
      "SDL_THREAD_PTHREAD_RECURSIVE_MUTEX=1",
      "SDL_TIMER_UNIX=1",
      "SDL_VIDEO_OPENGL=1",
      "SDL_VIDEO_RENDER_OGL=1",
    ]
    sources += [
      "../externals/sdl/src/loadso/dlopen/SDL_sysloadso.c",
      "../externals/sdl/src/render/opengl/SDL_render_gl.c",
      "../externals/sdl/src/render/opengl/SDL_shaders_gl.c",
      "../externals/sdl/src/thread/pthread/SDL_syscond.c",
      "../externals/sdl/src/thread/pthread/SDL_sysmutex.c",
      "../externals/sdl/src/thread/pthread/SDL_syssem.c",
      "../externals/sdl/src/thread/pthread/SDL_systhread.c",
      "../externals/sdl/src/thread/pthread/SDL_systls.c",
      "../externals/sdl/src/timer/unix/SDL_systimer.c",
    ]
  }

  if (is_mac) {
    sources += [
      "../externals/sdl/src/file/cocoa/SDL_rwopsbundlesupport.m",
      "../externals/sdl/src/filesystem/cocoa/SDL_sysfilesystem.m",
      "../externals/sdl/src/video/cocoa/SDL_cocoaclipboard.m",
      "../externals/sdl/src/video/cocoa/SDL_cocoaevents.m",
      "../externals/sdl/src/video/cocoa/SDL_cocoakeyboard.m",
      "../externals/sdl/src/video/cocoa/SDL_cocoamessagebox.m",
      "../externals/sdl/src/video/cocoa/SDL_cocoamodes.m",
      "../externals/sdl/src/video/cocoa/SDL_cocoamouse.m",
      "../externals/sdl/src/video/cocoa/SDL_cocoamousetap.m",
      "../externals/sdl/src/video/cocoa/SDL_cocoaopengl.m",
      "../externals/sdl/src/video/cocoa/SDL_cocoashape.m",
      "../externals/sdl/src/video/cocoa/SDL_cocoavideo.m",
      "../externals/sdl/src/video/cocoa/SDL_cocoawindow.m",
    ]
    defines += [
      "SDL_FILESYSTEM_COCOA=1",
      "SDL_VIDEO_DRIVER_COCOA=1",
      "SDL_VIDEO_OPENGL_CGL=1",
    ]
    libs += [
      "Carbon.framework",
      "IOKit.framework",
    ]
  }
}