rules/haddock: Set __HADDOCK_VERSION__
authorBen Gamari <bgamari.foss@gmail.com>
Thu, 12 Nov 2015 10:15:34 +0000 (11:15 +0100)
committerBen Gamari <ben@smart-cactus.org>
Thu, 12 Nov 2015 10:15:35 +0000 (11:15 +0100)
Test Plan: Validate

Reviewers: austin, thomie

Reviewed By: thomie

Subscribers: kgardas, thomie

Differential Revision: https://phabricator.haskell.org/D1467

rules/haddock.mk

index 988e254..499adad 100644 (file)
 #
 # -----------------------------------------------------------------------------
 
+HADDOCK_VER := $(shell grep "^version:" utils/haddock/haddock.cabal | sed "s/^version: \+//")
+HADDOCK_MAJOR_VER := $(shell echo $(HADDOCK_VER) | sed 's/\([0-9]\+\).\([0-9]\+\).\([0-9]\+\)/\1/')
+HADDOCK_MINOR_VER := $(shell echo $(HADDOCK_VER) | sed 's/\([0-9]\+\).\([0-9]\+\).\([0-9]\+\)/\2/')
+HADDOCK_PATCH_VER := $(shell echo $(HADDOCK_VER) | sed 's/\([0-9]\+\).\([0-9]\+\).\([0-9]\+\)/\3/')
+HADDOCK_VERSION_STRING := $(shell echo $$(($(HADDOCK_MAJOR_VER) * 1000 + $(HADDOCK_MINOR_VER) * 10 + $(HADDOCK_PATCH_VER))))
 
 define haddock  # args: $1 = dir,  $2 = distdir
 $(call trace, haddock($1,$2))
@@ -40,6 +45,7 @@ $1_$2_HADDOCK_FLAGS += --source-module=src/%{MODULE/./-}.html --source-entity=sr
 endif
 
 ifneq "$$(BINDIST)" "YES"
+
 # We need the quadruple dollars for the dependencies, as it isn't
 # guaranteed that we are processing the packages in dependency order,
 # so we don't want to expand it yet.
@@ -56,6 +62,7 @@ endif
          --hoogle \
          --title="$$($1_PACKAGE)-$$($1_$2_VERSION)$$(if $$(strip $$($1_$2_SYNOPSIS)),: $$(strip $$($1_$2_SYNOPSIS)),)" \
          --prologue="$1/$2/haddock-prologue.txt" \
+    --optghc="-D__HADDOCK_VERSION__=$$(HADDOCK_VERSION_STRING)" \
          $$(foreach mod,$$($1_$2_HIDDEN_MODULES),--hide=$$(mod)) \
          $$(foreach pkg,$$($1_$2_DEPS),$$(if $$($$(pkg)_HADDOCK_FILE),--read-interface=../$$(pkg)$$(comma)../$$(pkg)/src/%{MODULE/./-}.html\#%{NAME}$$(comma)$$($$(pkg)_HADDOCK_FILE))) \
          $$(foreach opt,$$($1_$2_$$(HADDOCK_WAY)_ALL_HC_OPTS),--optghc=$$(opt)) \