From a38bfce5994115a80ca9c48650b8e5aefc3b26bb Mon Sep 17 00:00:00 2001
From: Iustin Pop <iustin@google.com>
Date: Tue, 22 Mar 2011 10:47:59 +0100
Subject: [PATCH] Enable htools apidoc generation and unify dir names

Previously, Python api doc was under doc/api (which didn't match with
the target rule, apidoc). After this patch, we have the following:

- make py-apidoc generates Python api doc under doc/py-apidoc
- make hs-apidoc generates Haskell api doc under doc/hs-apidoc
- make apidoc does both (if hs-apidoc enabled at configure time)

Signed-off-by: Iustin Pop <iustin@google.com>
Reviewed-by: Michael Hanselmann <hansmi@google.com>
---
 .gitignore  |  3 ++-
 Makefile.am | 39 ++++++++++++++++++++++++++++++++++++---
 2 files changed, 38 insertions(+), 4 deletions(-)

diff --git a/.gitignore b/.gitignore
index ce682e0dc..bd2c8f67c 100644
--- a/.gitignore
+++ b/.gitignore
@@ -51,7 +51,8 @@
 /devel/upload
 
 # doc
-/doc/api
+/doc/py-apidoc/
+/doc/hs-apidoc/
 /doc/build
 /doc/py-coverage/
 /doc/hs-coverage/
diff --git a/Makefile.am b/Makefile.am
index 17a52c151..d913a1603 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -74,7 +74,8 @@ DIRS = \
 
 BUILDTIME_DIR_AUTOCREATE = \
 	scripts \
-	doc/api \
+	doc/py-apidoc \
+	$(HS_APIDOC) $(HS_APIDOC)/Ganeti $(HS_APIDOC)/Ganeti/HTools \
 	doc/py-coverage \
 	doc/hs-coverage \
 	.hpc
@@ -290,6 +291,8 @@ HFLAGS = -O -Wall -fwarn-monomorphism-restriction -fwarn-tabs -ihtools
 HEXTRA =
 # exclude options for coverage reports
 HPCEXCL = --exclude Main --exclude Ganeti.HTools.QC
+# directory for apidoc
+HS_APIDOC = doc/hs-apidoc
 
 HSRCS = \
 	htools/Ganeti/HTools/CLI.hs \
@@ -999,10 +1002,40 @@ install-exec-local:
 	@mkdir_p@ $* && touch $@
 
 .PHONY: apidoc
-apidoc: epydoc.conf $(RUN_IN_TEMPDIR) $(BUILT_SOURCES)
+if WANT_HTOOLSAPIDOC
+apidoc: py-apidoc hs-apidoc
+else
+apidoc: py-apidoc
+endif
+
+.PHONY: py-apidoc
+py-apidoc: epydoc.conf $(RUN_IN_TEMPDIR) $(BUILT_SOURCES)
 	$(RUN_IN_TEMPDIR) epydoc -v \
 		--conf $(CURDIR)/epydoc.conf \
-		--output $(CURDIR)/doc/api
+		--output $(CURDIR)/doc/py-apidoc
+
+.PHONY: hs-apidoc
+hs-apidoc: $(HSRCS2)
+	@test -n "$(HSCOLOUR)" || \
+	    { echo 'HsColour' not found during configure; exit 1; }
+	@test -n "$(HADDOCK)" || \
+	    { echo 'haddock' not found during configure; exit 1; }
+	rm -rf $(HS_APIDOC)/*
+	@mkdir_p@ $(HS_APIDOC)/Ganeti/HTools
+	$(HSCOLOUR) -print-css > $(HS_APIDOC)/Ganeti/hscolour.css
+	ln -s ../hscolour.css $(HS_APIDOC)/Ganeti/HTools/hscolour.css
+	set -e ; \
+	cd htools; \
+	RELSRCS="$(HSRCS:htools/%=%)"; \
+	for file in $$RELSRCS; do \
+		hfile=`echo $$file|sed 's/\\.hs$$//'`.html; \
+		$(HSCOLOUR) -css -anchor $$file > ../$(HS_APIDOC)/$$hfile ; \
+	done ; \
+	$(HADDOCK) --odir ../$(HS_APIDOC) --html --ignore-all-exports -w \
+		-t ganeti-htools -p haddock-prologue \
+		--source-module="%{MODULE/.//}.html" \
+		--source-entity="%{MODULE/.//}.html#%{NAME}" \
+		$(filter-out Ganeti/HTools/ExtLoader.hs,$(HSRCS:htools/%=%))
 
 .PHONY: TAGS
 TAGS: $(BUILT_SOURCES)
-- 
GitLab