#-------------------------------------------------------------------------------
# FreeType 2 specific rules and variables
#-------------------------------------------------------------------------------

FT2_INCLUDE = [ FDirName $(HAIKU_TOP) headers libs freetype2 ] ;
FT2_SRC     = [ FDirName $(HAIKU_TOP) src libs freetype2 ] ;

FT2_LIB     = freetype ;

FT2_COMPONENTS ?= gzip       # support for gzip-compressed files.
		  autofit
                  base       # base component (public APIs)
                  bdf        # BDF font driver
                  cache      # cache sub-system
                  cff        # CFF/CEF font driver
                  cid        # Postscript CID-keyed font driver
		lzw	   # LZW routines
                  pcf        # PCF font driver
                  pfr        # PFR/TrueDoc font driver
                  psaux      # Common Postscript routines module
                  pshinter   # Postscript hinter module
                  psnames    # Postscript names handling
                  raster     # Monochrome rasterizer
                  smooth     # Anti-aliased rasterizer
                  sfnt       # SFNT-based format support routines
                  truetype   # TrueType font driver
                  type1      # Postscript Type 1 font driver
                  type42     # Postscript Type 42 (embedded TrueType) driver
                  winfonts   # Windows FON/FNT font driver
                  ;

rule UseFreeTypeHeaders
{
	SubDirSysHdrs $(FT2_INCLUDE) ;
}

rule UseFreeTypeObjectHeaders
{
	# UseFreeTypeObjectHeaders <sources> [ : <objects> ] ;
	SourceSysHdrs $(1) : $(FT2_INCLUDE) : $(2) ;
}

rule FT2_SubDir
{
	# FT2_SubDir <dir>
	# <dir>: Components of a directory in the original hierarchy.
	local dir = $(1) ;
	local topDir ;
	switch $(dir[1])
	{
		case "include"	: topDir = $(FT2_INCLUDE) ;
		case src		: topDir = $(FT2_SRC) ;
		case *			: ECHO "Unknown FreeType2 directory: " $(dir) ;
	}
	return [ FDirName $(topDir) $(dir[2-]) ] ;
}

rule FT2_Library
{
	# FT2_Library <libname> : <sources>
	# Builds objects from sources and adds the objects to the list of objects
	# to be linked into the library.
	# <libname> The name of the library.
	# <sources> The sources.

	DEFINES += FT2_BUILD_LIBRARY ;

	local library = lib$(1).so ;
	local sources = $(2) ;
	
	Objects $(sources) ;
	LIBRARY_OBJECTS on $(library) += [ FGristFiles $(sources:S=$(SUFOBJ)) ] ;
}

rule FT2_LinkLibrary
{
	# FT2_LinkLibrary <libname>
	# Links the library from the objects build with FT2_LIBRARY before.

	local library = lib$(1).so ;
	local objects = [ on $(library) return $(LIBRARY_OBJECTS) ] ;
	ObjectReferences $(objects) ;
	objects = [ FGristFiles $(objects) ] ;
	SharedLibraryFromObjects $(library) : $(objects) ;
}
