-----------------------------------------------------------
--                                                       --
--   FreeType2 build config                              --
--                                                       --
--      Output variables:                                --
--        libfreetype = path to .lib file                --
-----------------------------------------------------------

-- Modules
--------------------------------
local ft_modules = {
	"base",
	"autofit",
	"cff",
	"psaux",
	"pshinter",
	"psnames",
	"raster",
	"sfnt",
	"smooth",
	"truetype",
}

-- Settings
--------------------------------
local settings = TableDeepCopy(global_settings)
SetSettingsPrefix(settings, "FT2")

-- Compile flags
settings.cc.includes:Add(RelPath("include"))
settings.cc.flags:Add("-DFT2_BUILD_LIBRARY")

-- Build target
--------------------------------

local obj = {}

-- Compile each module to object files.
for k,name in pairs(ft_modules) do
	local mod_base = RelPath("src/" .. name)
	local module_file = PathJoin(mod_base, "module.lua")

	-- Check if we have a module.lua file
	-- that defines the modules sources
	local f = io.open(module_file)
	if f then
		Import(module_file)
	else
		-- Otherwise, We assume there is a <name>.c
		src = PathJoin(mod_base, string.format("%s.c", name))
	end

	obj[name] = Compile(settings, src)
	PseudoTarget("ft2_" .. name, obj[name])
end

libfreetype = StaticLibrary(settings, "freetype", obj)
PseudoTarget("ft2", libfreetype)
