include ../Makefile.system
FLXMAKEFILECOMMON=skip
include ../Makefile.allegro
GKDIR=glyph-keeper-0.32

ifeq ($(FLXLABOS),linux)
	LIBNAME=libglyphkeeper.so
	LIBFLAGS += -shared -fPIC
	CFLAGS+=-fPIC
endif
ifeq ($(FLXLABOS),windows)
	LIBNAME=glyphkeeper.dll
	LIBFLAGS += -shared -Wl,--out-implib,lib/libglyphkeeper.a
	CFLAGS+=-DGLYPH_DLL
endif
ifeq ($(FLXLABOS),mac)
	LIBNAME=libglyphkeeper.dylib
	LIBFLAGS += -fPIC -dynamiclib
	CFLAGS += -fPIC -fno-common
endif

vpath %.c $(GKDIR)/src $(GKDIR)/freetype/src
vpath %.o object/

CFLAGS += -I$(GKDIR)/freetype/include
FTCFLAGS += $(CFLAGS) -DFT2_BUILD_LIBRARY 
GKCFLAGS += $(CFLAGS) -DGK_NO_LEGACY -DGLYPH_TARGET=GLYPH_TARGET_ALLEGRO -I../allegro/allegro/include

FTOBJECTS=autofit.o ftbase.o ftbbox.o ftbdf.o ftbitmap.o ftdebug.o ftglyph.o ftgxval.o ftinit.o ftmm.o ftotval.o ftpfr.o ftstroke.o ftsynth.o ftsystem.o fttype1.o ftwinfnt.o bdf.o ftcache.o cff.o type1cid.o ftgzip.o gxvalid.o ftlzw.o otvalid.o pcf.o pfr.o psaux.o pshinter.o psnames.o raster.o sfnt.o smooth.o truetype.o type1.o type42.o winfnt.o

GKOBJECTS=glyph.o

build: prebuild $(FTOBJECTS) $(GKOBJECTS) postbuild
	gcc -o lib/$(LIBNAME) $(addprefix object/,$(FTOBJECTS)) $(addprefix object/,$(GKOBJECTS)) $(LIBFLAGS)

# We have to use a modified version of glyph.h to prevent the text routines
# from drawing a filled rectangle behind the text. Normally we could do this
# by just having the compiler look in 'include' before 
# 'glyph-keeper-0.32/include'. However, the file 'glyph_internal.h' (and
# possibly others) directly reference the latter file, as in
# include "../include/glyph.h", which thwarts this approach. So, we have
# to actually copy over the original file. Consistent with the principle
# of never modifying the original distribution of helper libraries, we
# replace the original file when we're done.
prebuild:
	mv $(GKDIR)/include/glyph.h $(GKDIR)/include/glyph.h.bck; cp include/glyph.h $(GKDIR)/include	

postbuild:
	mv -f $(GKDIR)/include/glyph.h.bck $(GKDIR)/include/glyph.h

$(FTOBJECTS): %.o : %.c
	gcc -c $(FTCFLAGS) -o object/$@ $<

$(GKOBJECTS): %.o : %.c
	gcc -c $(GKCFLAGS) -o object/$@ $<

install:
	cp lib/$(LIBNAME) $(FLXLABVERSIONDIR)
	cp FREETYPE_LICENSE.* $(FLXLABLICENSEDIR)
	cp GLYPHKEEPER_LICENSE.* $(FLXLABLICENSEDIR)

uninstall:
	rm -f $(FLXLABLICENSEDIR)/FREETYPE_LICENSE.*
	rm -f $(FLXLABLICENSEDIR)/GLYPHKEEPER_LICENSE.*
	rm -f $(FLXLABVERSIONDIR)/$(LIBNAME)

clean:
	rm -f object/* lib/*

tilde_clean:
	rm -f *~



