local m = {}

local rootdir = path.join(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(rootdir, "freetype/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(rootdir, "freetype/src/autofit/autofit.c"),
		path.join(rootdir, "freetype/src/base/ftbase.c"),
		path.join(rootdir, "freetype/src/base/ftbbox.c"),
		path.join(rootdir, "freetype/src/base/ftbdf.c"),
		path.join(rootdir, "freetype/src/base/ftbitmap.c"),
		path.join(rootdir, "freetype/src/base/ftcid.c"),
		path.join(rootdir, "freetype/src/base/ftfstype.c"),
		path.join(rootdir, "freetype/src/base/ftgasp.c"),
		path.join(rootdir, "freetype/src/base/ftglyph.c"),
		path.join(rootdir, "freetype/src/base/ftgxval.c"),
		path.join(rootdir, "freetype/src/base/ftinit.c"),
		path.join(rootdir, "freetype/src/base/ftmm.c"),
		path.join(rootdir, "freetype/src/base/ftotval.c"),
		path.join(rootdir, "freetype/src/base/ftpatent.c"),
		path.join(rootdir, "freetype/src/base/ftpfr.c"),
		path.join(rootdir, "freetype/src/base/ftstroke.c"),
		path.join(rootdir, "freetype/src/base/ftsynth.c"),
		path.join(rootdir, "freetype/src/base/fttype1.c"),
		path.join(rootdir, "freetype/src/base/ftwinfnt.c"),
		path.join(rootdir, "freetype/src/bdf/bdf.c"),
		path.join(rootdir, "freetype/src/bzip2/ftbzip2.c"),
		path.join(rootdir, "freetype/src/cache/ftcache.c"),
		path.join(rootdir, "freetype/src/cff/cff.c"),
		path.join(rootdir, "freetype/src/cid/type1cid.c"),
		path.join(rootdir, "freetype/src/gzip/ftgzip.c"),
		path.join(rootdir, "freetype/src/lzw/ftlzw.c"),
		path.join(rootdir, "freetype/src/pcf/pcf.c"),
		path.join(rootdir, "freetype/src/pfr/pfr.c"),
		path.join(rootdir, "freetype/src/psaux/psaux.c"),
		path.join(rootdir, "freetype/src/pshinter/pshinter.c"),
		path.join(rootdir, "freetype/src/psnames/psnames.c"),
		path.join(rootdir, "freetype/src/raster/raster.c"),
		path.join(rootdir, "freetype/src/sdf/sdf.c"),
		path.join(rootdir, "freetype/src/sfnt/sfnt.c"),
		path.join(rootdir, "freetype/src/smooth/smooth.c"),
		path.join(rootdir, "freetype/src/svg/svg.c"),
		path.join(rootdir, "freetype/src/truetype/truetype.c"),
		path.join(rootdir, "freetype/src/type1/type1.c"),
		path.join(rootdir, "freetype/src/type42/type42.c"),
		path.join(rootdir, "freetype/src/winfonts/winfnt.c"),
		path.join(rootdir, "freetype/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(rootdir, "freetype/builds/windows/ftsystem.c"),
		path.join(rootdir, "freetype/builds/windows/ftdebug.c"),
	}

	removefiles
	{
		path.join(rootdir, "freetype/src/base/ftdebug.c"),
	}

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

	filter "configurations:Debug"
		optimize"Speed"

	filter""
end

function m.link()
	includedirs{path.join(rootdir, "freetype/include")}
	links {"freetype"}
end

return m