#!/usr/bin/make
# doxygen makefile for libfactory++

default: all

# find_bin: helper function to find $(1) in PATH
find_bin = $(firstword $(wildcard $(addsuffix /$(1),$(subst :, ,$(PATH)))))

PERL_BIN = $(call find_bin,perl)
ifeq (,$(PERL_BIN))
    $(error Error: perl not found in PATH: $(PATH))
endif

DOXYGEN_BIN = $(call find_bin,doxygen)
ifeq (,$(DOXYGEN_BIN))
    $(error Error: doxygen not found in PATH: $(PATH))
endif

INCLUDES = $(wildcard ../include/*.hpp)
# ^^^^ ACHTUNG! Cannot use dir name ../include for INCLUDES because
# that dir has a symlink to itself and doxygen croaks on the endless
# recursion.

PACKAGE_VERSION = $(shell grep PACKAGE_VERSION ../Makefile | cut -d' ' -f3)

DOXY_IN = doxygen.rc.at
DOXYFILE = doxygen.rc

$(DOXY_IN): Makefile

$(DOXYFILE): $(DOXY_IN) Makefile
	sed -e 's,@DOXYGEN_INPUT@,index.txt $(INCLUDES),;' \
		-e 's,@PACKAGE_VERSION@,$(PACKAGE_VERSION),;' \
		-e 's,@PERL@,$(PERL_BIN),;' \
	< $< > $@

html: $(DOXYFILE)
	$(DOXYGEN_BIN) $(DOXYFILE)

doxygen: html

clean:
	-rm -fr $(DOXYFILE) *~ html latex def

all: doxygen
