CC=gcc
CXX=g++
DEBUGFLAGS =  -g -O2
CFLAGS = $(DEBUGFLAGS) $(XCFLAGS) -I/usr/include/freetype2 -I/usr/include/harfbuzz  -DWEBASSEMBLY_BUILD -DWEBASSEMBLY_BUILD_LOCAL
CPPFLGAGS = -fno-rtti -fno-exceptions
LDFLAGS =  $(DEBUGFLAGS) $(XLDFLAGS) 
CXX_LINK = $(CXX) -o $@ $(LDFLAGS)

texsources = tex/xetex0.c tex/xetexini.c tex/xetex-pool.c  \
md5.c xmemory.c texfile.c kpseemu.c texmfmp.c main.c \
bibtex.c xetexdir/XeTeX_ext.c xetexdir/XeTeX_pic.c xetexdir/trans.c \
xetexdir/image/bmpimage.c xetexdir/image/jpegimage.c \
xetexdir/image/pngimage.c xetexdir/image/numbers.c xetexdir/image/mfileio.c

xetexsources = xetexdir/XeTeXOTMath.cpp \
xetexdir/XeTeXLayoutInterface.cpp \
xetexdir/XeTeXFontMgr.cpp xetexdir/XeTeXFontInst.cpp \
xetexdir/XeTeXFontMgr_FC.cpp xetexdir/hz.cpp \
xetexdir/pdfimage.cpp

teckitsources = teckit/teckit-Engine.cpp 

texobjects = $(texsources:.c=.o)

xetexobjects = $(xetexsources:.cpp=.o)

teckitobjects = $(teckitsources:.cpp=.o)

swiftlatex: $(texobjects) $(xetexobjects) $(teckitobjects)
	$(CXX_LINK) $(texobjects) $(xetexobjects) $(teckitobjects) xpdf/xpdf.a -lharfbuzz -lfreetype -lz -lgraphite2 -licuuc -lpng -lcurl

$(texobjects): %.o: %.c
	$(CC) -c $(CFLAGS) -I. -I tex/ $< -o $@

$(xetexobjects): %.o: %.cpp
	$(CXX) -c $(CFLAGS) $(CPPFLGAGS)  -I. -I tex/ -I xetexdir/ -I xpdf/ -I xpdf/goo/ -I xpdf/xpdf/ $< -o $@

$(teckitobjects): %.o: %.cpp
	$(CXX) -c $(CFLAGS) $(CPPFLGAGS) -I. -I teckit/ $< -o $@

clean:
	rm -f *.o tex/*.o xetexdir/*.o xetexdir/image/*.o teckit/*.o swiftlatex

