local m = {}

local scriptdir = path.getabsolute(path.getdirectory(_SCRIPT))

function m.generateproject(liboutdir, intdir)
	project"freetype"
	kind"staticLib"
	language"C" -- c++ will mangle names and sfml wont build
	targetdir (liboutdir)
	objdir(intdir)
	warnings"Off"

	includedirs {path.join(scriptdir, "include")}

	defines
	{
		"FT2_BUILD_LIBRARY",
		"NDEBUG", -- have freetype always be in release mode
		"FT_DEBUG_LEVEL_ERROR=0", -- fix linking errors <undefined reference...>
		"FT_DEBUG_LEVEL_TRACE=0" -- fix linking errors <undefined reference...>
	}

	files
	{
		path.join(scriptdir, "src/autofit/autofit.c"),
		path.join(scriptdir, "src/base/ftbase.c"),
		path.join(scriptdir, "src/base/ftbbox.c"),
		path.join(scriptdir, "src/base/ftbdf.c"),
		path.join(scriptdir, "src/base/ftbitmap.c"),
		path.join(scriptdir, "src/base/ftcid.c"),
		path.join(scriptdir, "src/base/ftfstype.c"),
		path.join(scriptdir, "src/base/ftgasp.c"),
		path.join(scriptdir, "src/base/ftglyph.c"),
		path.join(scriptdir, "src/base/ftgxval.c"),
		path.join(scriptdir, "src/base/ftinit.c"),
		path.join(scriptdir, "src/base/ftmm.c"),
		path.join(scriptdir, "src/base/ftotval.c"),
		path.join(scriptdir, "src/base/ftpatent.c"),
		path.join(scriptdir, "src/base/ftpfr.c"),
		path.join(scriptdir, "src/base/ftstroke.c"),
		path.join(scriptdir, "src/base/ftsynth.c"),
		path.join(scriptdir, "src/base/fttype1.c"),
		path.join(scriptdir, "src/base/ftwinfnt.c"),
		path.join(scriptdir, "src/bdf/bdf.c"),
		path.join(scriptdir, "src/bzip2/ftbzip2.c"),
		path.join(scriptdir, "src/cache/ftcache.c"),
		path.join(scriptdir, "src/cff/cff.c"),
		path.join(scriptdir, "src/cid/type1cid.c"),
		path.join(scriptdir, "src/gzip/ftgzip.c"),
		path.join(scriptdir, "src/lzw/ftlzw.c"),
		path.join(scriptdir, "src/pcf/pcf.c"),
		path.join(scriptdir, "src/pfr/pfr.c"),
		path.join(scriptdir, "src/psaux/psaux.c"),
		path.join(scriptdir, "src/pshinter/pshinter.c"),
		path.join(scriptdir, "src/psnames/psnames.c"),
		path.join(scriptdir, "src/raster/raster.c"),
		path.join(scriptdir, "src/sdf/sdf.c"),
		path.join(scriptdir, "src/sfnt/sfnt.c"),
		path.join(scriptdir, "src/smooth/smooth.c"),
		path.join(scriptdir, "src/svg/svg.c"),
		path.join(scriptdir, "src/truetype/truetype.c"),
		path.join(scriptdir, "src/type1/type1.c"),
		path.join(scriptdir, "src/type42/type42.c"),
		path.join(scriptdir, "src/winfonts/winfnt.c"),
		path.join(scriptdir, "src/base/ftdebug.c"), --fix linking errors related to FT_THROW, et)c
	}

	filter "system:linux"
	defines
	{
		"HAVE_FCNTL_H",--fix error in ftsystem.c <implicit declaration of function ‘open’>
		"HAVE_UNISTD_H" --fix error in ftsystem.c <implicit declaration of function ‘read’>
	}

	filter"system:windows"
	files
	{
		path.join(scriptdir, "builds/windows/ftsystem.c"),
		path.join(scriptdir, "builds/windows/ftdebug.c"),
	}

	filter"system:linux"
	files{path.join(scriptdir, "builds/unix/ftsystem.c")}

	filter "configurations:Debug"
		optimize"Speed"

	filter""
end

function m.link()
	externalincludedirs{path.join(scriptdir, "include")}
	links {"freetype"}
end

return m