import libs = libvulkan-headers%lib{vulkan-headers}

exe{asm_offset}: {h c}{**} $libs

# Must match the loader. WSI platforms follow the headers on the compiler
# search path.
#
have_xcb_xcb_h = [bool] ($c.find_system_header("xcb/xcb.h") != [null])
have_x11_xlib_h = [bool] ($c.find_system_header("X11/Xlib.h") != [null])
have_x11_extensions_xrandr_h = [bool] \
  ($c.find_system_header("X11/extensions/Xrandr.h") != [null])
have_wayland_client_h = [bool] \
  ($c.find_system_header("wayland-client.h") != [null])

# Build options (layout-affecting defines must match the loader library).
#
c.poptions =+ "-I$src_base" "-I$src_base/generated"
c.poptions += -DVK_ENABLE_BETA_EXTENSIONS

if ($c.target.class == 'windows')
{
  c.poptions += -DWIN32_LEAN_AND_MEAN -DVK_USE_PLATFORM_WIN32_KHR
}
else
{
  c.poptions += -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64

  c.poptions += -DFALLBACK_CONFIG_DIRS=\"/etc/xdg\" \
                -DFALLBACK_DATA_DIRS=\"/usr/local/share:/usr/share\" \
                -DSYSCONFDIR=\"/etc\"

  if ($c.target.class == 'linux' || $c.target.class == 'bsd')
    c.poptions += -DLOADER_ENABLE_LINUX_SORT \
                  -DHAVE_SECURE_GETENV

  if $have_xcb_xcb_h
    c.poptions += -DVK_USE_PLATFORM_XCB_KHR

  if $have_x11_xlib_h
    c.poptions += -DVK_USE_PLATFORM_XLIB_KHR

  if $have_x11_extensions_xrandr_h
    c.poptions += -DVK_USE_PLATFORM_XLIB_XRANDR_EXT

  if $have_wayland_client_h
    c.poptions += -DVK_USE_PLATFORM_WAYLAND_KHR

  if ($c.target.class == 'bsd')
    c.poptions += -D__BSD_VISIBLE=1

  if ($c.target.class == 'macos')
  {
    c.poptions += -DVK_USE_PLATFORM_METAL_EXT \
                  -DVK_USE_PLATFORM_MACOS_MVK
  }
}

# Private headers are not installed.
#
h{*}: install = false
