
# set to anything but "no" to enable
# WITH_PGF=no
WITH_PGF=yes

ifneq ($(WITH_PGF),no)
all: pdfconcat ppmtops pgf2pnm
else
all: pdfconcat ppmtops
endif

pdfconcat:
	$(CC) $(CFLAGS) -O3 -s -DNDEBUG=1 -DNO_CONFIG=1 -ansi -pedantic -Wunused -Wall -W -Wnested-externs -Winline -Wpointer-arith -Wbad-function-cast -Wcast-qual -Wmissing-prototypes -Wmissing-declarations pdfconcat.c -o pdfconcat

ppmtops:
	$(CC) $(CFLAGS) ppmtops.c -o ppmtops

ifneq ($(WITH_PGF),no)
pgf2pnm: main.cpp pnm.cpp
	@if [ -x /usr/include/libpgf ] ; then \
	$(CXX) $(CXXFLAGS) -fpermissive -c main.cpp -o main.o -I/usr/include/libpgf ; \
	$(CXX) $(CXXFLAGS) -fpermissive -c pnm.cpp -o pnm.o -I/usr/include/libpgf ; \
	$(CXX) $(CXXFLAGS) -fpermissive -o pgf2pnm main.o pnm.o $(LDFLAGS) -lpgf ; \
	else \
	echo "libpgf not installed !!" ; \
	fi
endif

install-common:
	@if [ -x pdfconcat ] ; then \
	mkdir -p "$(DESTDIR)"/usr/bin ; \
	install -c pdfconcat $(DESTDIR)/usr/bin ; \
	echo "install -c pdfconcat $(DESTDIR)/usr/bin" ; \
	mkdir -p "$(DESTDIR)"/usr/share/man/man1 ; \
	install -c -m 644 pdfconcat.1 "$(DESTDIR)"/usr/share/man/man1 ; \
	echo "install -c pdfconcat.1 "$(DESTDIR)"/usr/share/man/man1" ; fi
	@if [ -x ppmtops ] ; then \
	mkdir -p "$(DESTDIR)"/usr/bin ; \
	install -c ppmtops "$(DESTDIR)"/usr/bin ; \
	echo "install -c ppmtops "$(DESTDIR)"/usr/bin" ; fi

install-pgf:
	@if [ -x pgf2pnm ] ; then \
	mkdir -p "$(DESTDIR)"/usr/bin ; \
	install -c pgf2pnm "$(DESTDIR)"/usr/bin ; \
	echo "install -c pgf2pnm "$(DESTDIR)"/usr/bin" ; fi

ifneq ($(WITH_PGF),no)
install: install-common install-pgf
else
install: install-common
endif

clean:
	rm -f core *~ *.o pdfconcat ppmtops pgf2pnm

cleandir: clean

distclean: clean
