On Wed, Feb 11, 2015 at 05:24:19PM +0100, Klaus Aehlig wrote:
On Wed, Feb 11, 2015 at 04:33:39PM +0100, 'Petr Pudlak' via ganeti-devel wrote:
.. 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) \

Normally we also .gitignore automatically generated files.

@@ -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

This is bad Makefile style: you add the explicit dependency here (because
you have to) but you hide the actual usage in a unrelated variable; this
is hard for maintainance having to guess that hs-lens-version is used in
HFLAGS. Can we just make the use explicit and drop adding the call to HFLAGS?

        @echo '[GHC]: $@ <- $^'
        @$(GHC) -c $(HFLAGS) \
                $(HS_PARALLEL3) $(HS_REGEX_PCRE) $(HEXTRA_COMBINED) 
$(@:%.o=%.hs)

Thanks,
Klaus

--
Klaus Aehlig
Google Germany GmbH, Dienerstr. 12, 80331 Muenchen
Registergericht und -nummer: Hamburg, HRB 86891
Sitz der Gesellschaft: Hamburg
Geschaeftsfuehrer: Graham Law, Christine Elizabeth Flores

ACK. Since the interdiff would be probably more messy than the original patch, I'm resending the whole patch below:


diff --git a/.gitignore b/.gitignore
index 5e7756a..0b65795 100644
--- a/.gitignore
+++ b/.gitignore
@@ -23,6 +23,7 @@
 # /
 /.hsenv
 /Makefile
+/hs-lens-version
 /Makefile.ghc
 /Makefile.ghc.bak
 /Makefile.in
diff --git a/Makefile.am b/Makefile.am
index 8033db1..5980819 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) \
@@ -1171,14 +1172,21 @@ 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 \
+         $(shell cat hs-lens-version) \
                $(HS_PARALLEL3) $(HS_REGEX_PCRE) $(HEXTRA_COMBINED) 
$(HS_MAKEFILE_GHC_SRCS)
 # Since ghc -M does not generate dependency line for object files, dependencies
 # from a target executable seed object (e.g. src/hluxid.o) to objects which
@@ -1194,26 +1202,29 @@ Makefile.ghc: $(HS_MAKEFILE_GHC_SRCS) Makefile \
@include_makefile_ghc@ -%.o:
+%.o: hs-lens-version
        @echo '[GHC]: $@ <- $^'
        @$(GHC) -c $(HFLAGS) \
+         $(shell cat hs-lens-version) \
                $(HS_PARALLEL3) $(HS_REGEX_PCRE) $(HEXTRA_COMBINED) 
$(@:%.o=%.hs)
# For TH+profiling we need to compile twice: Once without profiling,
 # 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) \
+         $(shell cat hs-lens-version) \
          $(HPROFFLAGS) \
                $(HS_PARALLEL3) $(HS_REGEX_PCRE) $(HEXTRA_COMBINED) \
                $(@:%.$(HPROF_SUFFIX)_o=%.hs)
 endif
-%.$(HTEST_SUFFIX)_o:
+%.$(HTEST_SUFFIX)_o: hs-lens-version
        @echo '[GHC|test]: $@ <- $^'
        @$(GHC) -c $(HTEST_FLAGS) \
+         $(shell cat hs-lens-version) \
                $(HS_PARALLEL3) $(HS_REGEX_PCRE) $(HEXTRA_COMBINED) 
$(@:%.$(HTEST_SUFFIX)_o=%.hs)
%.hi: %.o ;
@@ -1223,16 +1234,17 @@ 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) \
+         $(shell cat hs-lens-version) \
                $(HPROFFLAGS) \
                $(HS_PARALLEL3) $(HS_REGEX_PCRE) $(HEXTRA_COMBINED) --make 
$(@:%=%.hs)
        @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" \
@@ -1241,6 +1253,7 @@ $(HS_TEST_PROGS): %: %.$(HTEST_SUFFIX)_o \
        fi
        @echo '[GHC-link|test]: $@'
        $(GHC) $(HTEST_FLAGS) \
+         $(shell cat hs-lens-version) \
                $(HS_PARALLEL3) $(HS_REGEX_PCRE) $(HEXTRA_COMBINED) --make 
$(@:%=%.hs)
        @rm -f $(notdir $@).tix
        @touch "$@"
@@ -2623,10 +2636,11 @@ $(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)) \
+         $(shell cat hs-lens-version) \
                -osuf tags.o \
                -hisuf tags.hi \
     -lcurl \
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

Reply via email to