local m = {}

local rootdir = path.join(path.getabsolute(path.getdirectory(_SCRIPT)), "../")

local ogg = require("build-ogg")
local flac = require("build-flac")
local vorbis = require("build-vorbis")
local freetype = require("build-freetype")

function m.generateproject(liboutdir, intdir)
	project"sfml"
	cppdialect"c++17"
	kind "staticLib"
	targetdir (liboutdir)
	objdir(intdir)
	warnings"Off"

	defines
	{
		"SFML_STATIC",
		"MA_NO_MP3",
		"MA_NO_FLAC",
		"MA_NO_ENCODING",
		"MA_NO_RESOURCE_MANAGER",
		"MA_NO_GENERATION",
		"MA_USE_STDINT",
		"STBI_FAILURE_USERMSG",
		"SFML_IS_BIG_ENDIAN=0",
		"FT2_BUILD_LIBRARY",
		"FLAC__NO_DLL",
		"OV_EXCLUDE_STATIC_CALLBACKS",
	}

	includedirs
	{
		path.join(rootdir, "SFML/include"),
		path.join(rootdir, "SFML/src"),
		path.join(rootdir, "SFML/extlibs/headers/glad/include"),
		path.join(rootdir, "SFML/extlibs/headers/mingw"),
		path.join(rootdir, "SFML/extlibs/headers/miniaudio"),
		path.join(rootdir, "SFML/extlibs/headers/minimp3"),
		path.join(rootdir, "SFML/extlibs/headers/stb_image"),
		path.join(rootdir, "SFML/extlibs/headers/vulkan"),

	}
	files
	{
		path.join(rootdir, "SFML/include/SFML/**.hpp"),
		path.join(rootdir, "SFML/include/SFML/**.inl"),
		path.join(rootdir, "SFML/src/SFML/**.hpp"),
		path.join(rootdir, "SFML/src/SFML/**.cpp"),
	}

	freetype.link()
	ogg.link()
	flac.link()
	vorbis.link()

	filter"system:windows"
	removefiles
	{
		path.join(rootdir, "SFML/src/SFML/System/Unix/**"),
		path.join(rootdir, "SFML/src/SFML/System/Android/**"),
		path.join(rootdir, "SFML/src/SFML/Window/Unix/**"),
		path.join(rootdir, "SFML/src/SFML/Network/Unix/**"),
		path.join(rootdir, "SFML/src/SFML/Window/OpenBSD/**"),
		path.join(rootdir, "SFML/src/SFML/Window/NetBSD/**"),
		path.join(rootdir, "SFML/src/SFML/Window/macOS/**"),
		path.join(rootdir, "SFML/src/SFML/Window/iOS/**"),
		path.join(rootdir, "SFML/src/SFML/Window/FreeBSD/**"),
		path.join(rootdir, "SFML/src/SFML/Window/DRM/**"),
		path.join(rootdir, "SFML/src/SFML/Window/Android/**"),
		path.join(rootdir, "SFML/src/SFML/System/Android/**"),
		path.join(rootdir, "SFML/src/SFML/Main/MainAndroid.cpp"),
		path.join(rootdir, "SFML/src/SFML/Main/MainiOS.cpp"),
	}

	filter"system:linux"
	removefiles
	{
		path.join(rootdir, "SFML/src/SFML/System/Android/**"),
		path.join(rootdir, "SFML/src/SFML/System/Win32/**"),
		path.join(rootdir, "SFML/src/SFML/Network/Win32/**"),
		path.join(rootdir, "SFML/src/SFML/Window/Win32/**"),
		path.join(rootdir, "SFML/src/SFML/Window/OpenBSD/**"),
		path.join(rootdir, "SFML/src/SFML/Window/NetBSD/**"),
		path.join(rootdir, "SFML/src/SFML/Window/macOS/**"),
		path.join(rootdir, "SFML/src/SFML/Window/iOS/**"),
		path.join(rootdir, "SFML/src/SFML/Window/FreeBSD/**"),
		path.join(rootdir, "SFML/src/SFML/Window/DRM/**"),
		path.join(rootdir, "SFML/src/SFML/Window/Android/**"),
		path.join(rootdir, "SFML/src/SFML/Main/**"),
	}
	filter""

end

function m.link()
	defines{"SFML_STATIC"}
	includedirs
	{
		path.join(rootdir, "SFML/include"),
	}

	links{"sfml"}
	freetype.link()
	flac.link()
	vorbis.link()
	ogg.link()

	filter"system:windows"
	links{"legacy_stdio_definitions", "opengl32", "gdi32", "winmm", "ws2_32"}

	filter"system:linux"
	links{"Xi", "Xrandr", "Xcursor", "X11", "udev", "pthread", "OpenGL"}

end

return m
