# file: src/docs/Makefile
#
#  2001 OpenCA Group

TOP	= ..
include $(TOP)/Makefile.global-vars

P2M_FLAGS	= --center="OpenCA Documentation" --release="OpenCA $(VERSION)"

DEST_DOCDIR	= ${DEST_DATADIR}/openca

# shared is a misnomer, since man pages are of shared nature, too, they go into e.g. /usr/share/man:
DOCDIR		= shared

DOCS	= \
	$(DOCDIR)/openca-structure.txt	\
	$(DOCDIR)/cgi-public.txt

DEST_DOCS	= $(DOCS:$(DOCDIR)/%=$(DEST_DOCDIR)/%)

MANDIRS	= \
	man3

PODS	= \
	man3/base.3.pod

POD_MANS	= $(PODS:%.pod=%)
MANS		= $(POD_MANS)

DEST_MANDIRS	= $(MANDIRS:%=$(DEST_MANDIR)/%)
DEST_MANS	= $(MANS:%=$(DEST_MANDIR)/%)

#---- variable settings above, rules below ----

.PHONY:	default test install install-ca install-ldap install-node install-ra install-pub clean distclean

default::	man

test::

install::	install-man install-doc

man::		$(MANS)

.SUFFIXES:	.pod

.pod:
		section=`echo $< | sed -n -e 's/man\(.\).*/\1/p'`; \
		$(POD2MAN) $(P2M_FLAGS) --section=$$section $< > $@

$(DEST_MANDIR) $(DEST_MANDIRS) $(DEST_DOCDIR):
		$(INSTALL) -d -o ${openca_user} -g ${openca_group} -m 755 $@

install-man::	$(DEST_MANS)

$(DEST_MANS)::	$(DEST_MANDIR) $(DEST_MANDIRS)
$(DEST_MANS)::
		$(INSTALL) -o ${openca_user} -g ${openca_group} -m 644 $(@:$(DEST_MANDIR)/%=%) $@

install-doc::	$(DEST_DOCS)

$(DEST_DOCS)::	$(DEST_DOCDIR)
$(DEST_DOCS)::
		$(INSTALL) -o ${openca_user} -g ${openca_group} -m 644 $(@:$(DEST_DOCDIR)/%=$(DOCDIR)/%) $@

# software is decoupled from the documentation, so do nothing here:
install-ca install-common install-ldap install-node install-ra install-pub install-scep:

clean::
		$(RM) $(POD_MANS)

distclean::	clean
distclean::
		#$(RM)
