From 99d8d45b744c98f08e12296667efebef52bfc8b6 Mon Sep 17 00:00:00 2001
From: fiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b>
Date: Sun, 25 Nov 2007 01:51:36 +0000
Subject: [PATCH] + Makefile now checks GHC version.  If GHC is 6.6,
 pandoc.cabal.ghc66   is copied to pandoc.cabal, and the old pandoc.cabal is
 copied to   pandoc.cabal.orig.  Otherwise, pandoc.cabal is copied to
 pandoc.cabal.orig   but otherwise unmodified.  This way, the Makefile will
 work properly   with either GHC 6.6 or 6.8. + The changes in debian/rules
 from r1066 have been reverted, since they   are no longer needed.  Also,
 debian/rules has been converted to UTF-8. + INSTALL instructions have been
 updated accordingly.

git-svn-id: https://pandoc.googlecode.com/svn/trunk@1095 788f1e2b-df1e-0410-8736-df70ead52e1b
---
 INSTALL      | 12 ++++++------
 Makefile     | 13 +++++++++++--
 debian/rules | 19 +++----------------
 3 files changed, 20 insertions(+), 24 deletions(-)

diff --git a/INSTALL b/INSTALL
index 41e3059ac..5334bac85 100644
--- a/INSTALL
+++ b/INSTALL
@@ -38,12 +38,6 @@ Installing Pandoc
 -----------------
 
 1.  Change to the directory containing the Pandoc distribution.
-    If you are using a version of Cabal < 1.2 (which you probably
-    are unless you've upgraded to GHC 6.8), do the following before
-    proceeding:
-
-        cp pandoc.cabal pandoc.cabal.orig
-        cp pandoc.cabal.ghc66 pandoc.cabal
 
 2.  Compile:
 
@@ -167,6 +161,12 @@ tarball, unpack, and type:
 This will install the pandoc executable and the Haskell libraries,
 but not the shell scripts, man pages, or other documentation.
 
+Note:  If you are using GHC 6.6.*, you will need to start by
+replacing `pandoc.cabal` with a version suitable for GHC 6.6:
+
+    cp pandoc.cabal pandoc.cabal.orig
+    cp pandoc.cabal.ghc66 pandoc.cabal 
+
 Installing pandoc using MacPorts
 ================================
 
diff --git a/Makefile b/Makefile
index dd3a47339..eb132eade 100644
--- a/Makefile
+++ b/Makefile
@@ -68,6 +68,7 @@ INSTALL_DATA    := $(INSTALL) -m 644
 STRIP           := strip
 GHC             ?= ghc
 GHC_PKG         ?= ghc-pkg
+GHC_VERSION     := $(shell $(GHC) --version | sed -e 's/[^0-9]*//')
 
 #-------------------------------------------------------------------------------
 # Recipes
@@ -116,12 +117,20 @@ cleanup_files+=$(WRAPPERS)
 $(WRAPPERS): %: $(SRCDIR)/wrappers/%.in $(SRCDIR)/wrappers/*.sh
 	@$(generate-shell-script)
 
+CABAL_BACKUP=$(CABAL).orig
+cleanup_files+=$(CABAL_BACKUP)
+$(CABAL_BACKUP):
+	cp $(CABAL) $(CABAL_BACKUP) ; \
+	if echo $(GHC_VERSION) | grep -q '^6.6'; then \
+		cp $(CABAL).ghc66 $(CABAL); \
+	fi
+
 .PHONY: configure
 cleanup_files+=Setup.hi Setup.o $(BUILDCMD) $(BUILDVARS)
 configure: $(BUILDCONF) templates
-$(BUILDCONF): $(CABAL)
+$(BUILDCONF): $(CABAL) $(CABAL_BACKUP) 
 	$(GHC) -package Cabal Setup.hs -o $(BUILDCMD)
-	$(BUILDCMD) configure --prefix=$(PREFIX)
+	$(BUILDCMD) configure --prefix=$(PREFIX) --with-compiler=$(GHC) --with-hc-pkg=$(GHC_PKG)
 	# Make configuration time settings persistent (definitely a hack).
 	@echo "PREFIX?=$(PREFIX)" >$(BUILDVARS)
 	@echo "DESTDIR?=$(DESTDIR)" >>$(BUILDVARS)
diff --git a/debian/rules b/debian/rules
index 13705683e..8e3dc240f 100755
--- a/debian/rules
+++ b/debian/rules
@@ -1,7 +1,7 @@
 #!/usr/bin/make -f
 #
 # debian/rules for pandoc.
-# Copyright � 2006  Recai Okta� <roktasATdebian.org>
+# Copyright © 2006  Recai Oktaş <roktasATdebian.org>
 #
 # This file is based on John Goerzen's Cabal Debian template.
 # See http://www.n-heptane.com/nhlab/repos/cabalDebianTemplate/
@@ -33,21 +33,8 @@ endif
 # Export all variables which will be used in various stages of build process.
 export PREFIX DESTDIR DATADIR DOCDIR HCFLAGS
 
-# Special code dealing with ghc 6.6 -> 6.8 transition.
-.PHONY: cabalbackup cabalrestore
-cabalbackup: $(THIS).cabal.ghccurrent
-$(THIS).cabal.ghccurrent:
-	if [ -f $(THIS).cabal.ghc66 ]; then                \
-		mv $(THIS).cabal $(THIS).cabal.ghccurrent; \
-		cp $(THIS).cabal.ghc66 $(THIS).cabal;      \
-	fi
-cabalrestore:
-	if [ -f $(THIS).cabal.ghc66 ] && [ -f $(THIS).cabal.ghccurrent ]; then \
-		mv $(THIS).cabal.ghccurrent $(THIS).cabal;                     \
-	fi
-
 configure: configure-stamp
-configure-stamp: cabalbackup
+configure-stamp:
 	dh_testdir
 	$(MAKE) configure
 
@@ -133,5 +120,5 @@ binary-arch: build install
 	dh_md5sums -a
 	dh_builddeb -a
 
-binary: binary-indep binary-arch cabalrestore
+binary: binary-indep binary-arch
 .PHONY: build clean binary-indep binary-arch binary install build-indep install-indep