.. in Haskell code.

This patch should be removed starting from 2.14, as there cabal
provides proper macros for all packages.

The macro in this patch is intentionally kept compatible with the cabal
macros.

Signed-off-by: Petr Pudlak <[email protected]>
---
 Makefile.am        | 26 +++++++++++++++++++-------
 src/Ganeti/Lens.hs | 10 +++++++++-
 2 files changed, 28 insertions(+), 8 deletions(-)

diff --git a/Makefile.am b/Makefile.am
index 8033db1..c881e83 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -272,6 +272,7 @@ CLEANFILES = \
        $(addsuffix /*.o,$(HS_DIRS)) \
        $(addsuffix /*.$(HTEST_SUFFIX)_hi,$(HS_DIRS)) \
        $(addsuffix /*.$(HTEST_SUFFIX)_o,$(HS_DIRS)) \
+       hs-lens-version \
        Makefile.ghc \
        Makefile.ghc.bak \
        $(PYTHON_BOOTSTRAP) \
@@ -738,6 +739,11 @@ if HTEST
 HFLAGS += -DTEST
 endif
 
+# lens version; this should be removed in 2.14 in favor of cabal-generated
+# versions for all packages
+# see target hs-lens-version
+HFLAGS += $(shell cat hs-lens-version)
+
 HTEST_FLAGS = $(HFLAGS) -fhpc -itest/hs \
        -osuf .$(HTEST_SUFFIX)_o \
        -hisuf .$(HTEST_SUFFIX)_hi
@@ -1171,11 +1177,17 @@ install-exec-hook:
 
 HS_SRCS = $(HS_LIBTESTBUILT_SRCS)
 
+hs-lens-version:
+       ghc-pkg list --simple-output lens \
+       | sed -r -e 's/^lens-([0-9]+)\.([0-9]+)\.([0-9]+)(\.([0-9]+))?/\
+         -DLENS_MAJOR=\1 -DLENS_MINOR=\2 -DLENS_REV=\3/' \
+       > $@
+
 HS_MAKEFILE_GHC_SRCS = $(HS_SRC_PROGS:%=%.hs)
 if WANT_HSTESTS
 HS_MAKEFILE_GHC_SRCS += $(HS_TEST_PROGS:%=%.hs)
 endif
-Makefile.ghc: $(HS_MAKEFILE_GHC_SRCS) Makefile \
+Makefile.ghc: $(HS_MAKEFILE_GHC_SRCS) Makefile hs-lens-version \
               | $(built_base_sources) $(HS_BUILT_SRCS)
        $(GHC) -M -dep-makefile $@ -dep-suffix $(HPROF_SUFFIX) \
                -dep-suffix $(HTEST_SUFFIX) $(HFLAGS) -itest/hs \
@@ -1194,7 +1206,7 @@ Makefile.ghc: $(HS_MAKEFILE_GHC_SRCS) Makefile \
 
 @include_makefile_ghc@
 
-%.o:
+%.o: hs-lens-version
        @echo '[GHC]: $@ <- $^'
        @$(GHC) -c $(HFLAGS) \
                $(HS_PARALLEL3) $(HS_REGEX_PCRE) $(HEXTRA_COMBINED) 
$(@:%.o=%.hs)
@@ -1203,7 +1215,7 @@ Makefile.ghc: $(HS_MAKEFILE_GHC_SRCS) Makefile \
 # and then once with profiling. See
 # 
http://www.haskell.org/ghc/docs/7.0.4/html/users_guide/template-haskell.html#id636646
 if HPROFILE
-%.$(HPROF_SUFFIX)_o: %.o
+%.$(HPROF_SUFFIX)_o: %.o hs-lens-version
        @echo '[GHC|prof]: $@ <- $^'
        @$(GHC) -c $(HFLAGS) \
          $(HPROFFLAGS) \
@@ -1211,7 +1223,7 @@ if HPROFILE
                $(@:%.$(HPROF_SUFFIX)_o=%.hs)
 endif
 
-%.$(HTEST_SUFFIX)_o:
+%.$(HTEST_SUFFIX)_o: hs-lens-version
        @echo '[GHC|test]: $@ <- $^'
        @$(GHC) -c $(HTEST_FLAGS) \
                $(HS_PARALLEL3) $(HS_REGEX_PCRE) $(HEXTRA_COMBINED) 
$(@:%.$(HTEST_SUFFIX)_o=%.hs)
@@ -1223,7 +1235,7 @@ endif
 if HPROFILE
 $(HS_SRC_PROGS): %: %.$(HPROF_SUFFIX)_o | stamp-directories
 else
-$(HS_SRC_PROGS): %: %.o | stamp-directories
+$(HS_SRC_PROGS): %: %.o hs-lens-version | stamp-directories
 endif
        @echo '[GHC-link]: $@'
        $(GHC) $(HFLAGS) \
@@ -1232,7 +1244,7 @@ endif
        @rm -f $(notdir $@).tix
        @touch "$@"
 
-$(HS_TEST_PROGS): %: %.$(HTEST_SUFFIX)_o \
+$(HS_TEST_PROGS): %: %.$(HTEST_SUFFIX)_o hs-lens-version \
                           | stamp-directories $(built_python_sources)
        @if [ "$(HS_NODEV)" ]; then \
          echo "Error: cannot run unittests without the development" \
@@ -2623,7 +2635,7 @@ $(APIDOC_HS_DIR)/index.html: $(HS_LIBTESTBUILT_SRCS) 
Makefile
          $(HS_LIBTESTBUILT_SRCS)
 
 .PHONY: TAGS
-TAGS: $(GENERATED_FILES)
+TAGS: $(GENERATED_FILES) hs-lens-version
        rm -f TAGS
        $(GHC) -e ":etags TAGS_hs" -v0 \
          $(filter-out -O -Werror,$(HFLAGS)) \
diff --git a/src/Ganeti/Lens.hs b/src/Ganeti/Lens.hs
index b3bd69f..9443309 100644
--- a/src/Ganeti/Lens.hs
+++ b/src/Ganeti/Lens.hs
@@ -1,4 +1,4 @@
-{-# LANGUAGE RankNTypes #-}
+{-# LANGUAGE RankNTypes, CPP #-}
 
 {-| Provides all lens-related functions.
 
@@ -44,6 +44,14 @@ module Ganeti.Lens
   , atSet
   ) where
 
+
+-- The following macro is just a temporary solution for 2.12 and 2.13.
+-- Since 2.14 cabal creates proper macros for all dependencies.
+#define MIN_VERSION_lens(maj,min,rev) \
+  (((maj)<LENS_MAJOR)|| \
+   (((maj)==LENS_MAJOR)&&((min)<=LENS_MINOR))|| \
+   (((maj)==LENS_MAJOR)&&((min)==LENS_MINOR)&&((rev)<=LENS_REV)))
+
 import Control.Applicative ((<$>), WrappedMonad(..))
 import Control.Lens
 import Control.Monad
-- 
2.2.0.rc0.207.ga3a616c

Reply via email to