#!/usr/bin/make -f

LIBS=-lXm -lX11 -lXt $(shell pkg-config --libs poppler)
INCLUDES=$(strip $(shell pkg-config --cflags poppler))
CPPFLAGS+=$(INCLUDES) $(INCLUDES)/goo $(INCLUDES)/splash -Wno-write-strings -DHAVE_DIRENT_H

override_dh_clean:
	dh_clean
	rm -rf build

override_dh_auto_configure:

prepare::
	mkdir -p build
	cp goo/parseargs.* xpdf/CoreOutputDev.* xpdf/GlobalParams.* build
	cp xpdf/PDFCore.* xpdf/XPDFApp.* xpdf/XPDFCore.* xpdf/XPDFTree.* build
	cp xpdf/XPDFTreeP.h xpdf/XPDFViewer.* xpdf/xpdf.cc build
	
	# perform extensive goo rename (as required by poppler)
	sed -i s/GString/GooString/g build/*
	sed -i s/GMutex/GooMutex/g build/*
	sed -i s/GHash/GooHash/g build/*
	sed -i s/GList/GooList/g build/*
	sed -i s/\<aconf\.h\>/\<poppler-config\.h\>/g build/*
	cp xpdf/config.h xpdf/about-text.h xpdf/*.xbm xpdf/xpdfIcon.xpm build

override_dh_auto_build: prepare build/CoreOutputDev.o build/GlobalParams.o build/PDFCore.o build/XPDFApp.o build/XPDFCore.o build/XPDFTree.o build/XPDFViewer.o build/parseargs.o build/xpdf.o
	$(CXX) $(LDFLAGS) -o build/xpdf build/*.o $(LIBS)

%:
	dh ${@}
