#!/usr/bin/make -f

libraries=-lXm $(shell pkg-config --libs poppler --libs xt --libs x11)
includes=$(strip $(shell pkg-config --cflags poppler))
CPPFLAGS=$(includes) $(includes)/goo $(includes)/splash -Wno-write-strings -DHAVE_DIRENT_H

files=goo/parseargs xpdf/CoreOutputDev xpdf/GlobalParams xpdf/PDFCore
files+=xpdf/XPDFApp xpdf/XPDFCore xpdf/XPDFTree xpdf/XPDFViewer xpdf/xpdf
headers=xpdf/config.h xpdf/XPDFTreeP.h xpdf/about-text.h xpdf/*.xbm xpdf/xpdfIcon.xpm

sources=$(shell for file in $(files); do echo $$file.*; done)
objects=$(shell for file in $(files); do echo build/$$(basename $$file).o; done)

override_dh_clean:
	dh_clean
	rm -rf build

override_dh_auto_configure:

prepare::
	mkdir -p build
	cp $(sources) build
	sed -e s/GString/GooString/g -e s/GMutex/GooMutex/g -e s/GHash/GooHash/g \
	    -e s/GList/GooList/g -e s/\<aconf\.h\>/\<poppler-config\.h\>/g -i build/*
	cp $(headers) build
	mv build/parseargs.c build/parseargs.cc

override_dh_auto_build: prepare $(objects)
	$(CXX) $(LDFLAGS) -o build/xpdf.real build/*.o $(libraries)

%:
	dh ${@}
