]> gitweb @ CieloNegro.org - cabal-shared-makefile.git/blobdiff - cabal-package.mk
New configuration variable: USE_CABAL_COMMAND
[cabal-shared-makefile.git] / cabal-package.mk
index cc534f4648d16242d8d4f33147d30acee9b61f7d..65404dc96eb9d0fc6a689a1bb08db8edbf60a9df 100644 (file)
@@ -2,23 +2,51 @@
 #
 # Variables:
 #
+#   USE_CABAL_COMMAND :: whether to use the cabal(1) command instead
+#   of ./Setup
+#     default: "YES" if it's in the PATH, "NO" otherwise.
+#
 #   CONFIGURE_ARGS :: arguments to be passed to ./Setup configure
 #     default: --disable-optimization
 #
 #   RUN_COMMAND :: command to be run for "make run"
 #
 
-GHC      ?= ghc
-FIND     ?= find
-RM_RF    ?= rm -rf
-SUDO     ?= sudo
 AUTOCONF ?= autoconf
+CABAL    ?= cabal
+DARCS    ?= darcs
+DITZ     ?= ditz
+FIND     ?= find
+GREP     ?= grep
+GHC      ?= ghc
+GIT      ?= git
 HLINT    ?= hlint
 HPC      ?= hpc
-DITZ     ?= ditz
+RM_RF    ?= rm -rf
+RSYNC    ?= rsync
+SUDO     ?= sudo
+
+ifndef USE_CABAL_COMMAND
+ifeq ($(shell which $(CABAL) >/dev/null 2>&1; echo $$?),0)
+USE_CABAL_COMMAND := YES
+else
+USE_CABAL_COMMAND := NO
+endif
+endif
+
+ifeq ($(strip $(USE_CABAL_COMMAND)),YES)
+SETUP_CMD := $(shell which $(CABAL))
+else
+SETUP_CMD := ./Setup
+endif
 
 CONFIGURE_ARGS ?= --disable-optimization
-HLINT_OPTS     ?= --cross --report=dist/report.html
+HADDOCK_OPTS   ?= --hyperlink-source
+HLINT_OPTS     ?= \
+       --hint=Default --hint=Dollar --hint=Generalise \
+       --cross \
+       --ignore="Parse error" \
+       --report=dist/report.html
 
 SETUP_FILE := $(wildcard Setup.*hs)
 CABAL_FILE := $(wildcard *.cabal)
@@ -43,7 +71,7 @@ BUILDINFO_FILE    := $(BUILDINFO_IN_FILE:.in=)
 all: build
 
 build: setup-config build-hook
-       ./Setup build
+       $(SETUP_CMD) build
        $(RM_RF) *.tix
 
 build-hook:
@@ -62,18 +90,22 @@ setup-config: dist/setup-config setup-config-hook $(BUILDINFO_FILE)
 
 setup-config-hook:
 
-dist/setup-config: $(CABAL_FILE) Setup $(AUTOCONF_FILE)
-       ./Setup configure $(CONFIGURE_ARGS)
+dist/setup-config: $(CABAL_FILE) $(SETUP_CMD) $(AUTOCONF_FILE)
+       $(SETUP_CMD) configure $(CONFIGURE_ARGS)
 
 $(AUTOCONF_FILE): $(AUTOCONF_AC_FILE)
        $(AUTOCONF)
 
 $(BUILDINFO_FILE): $(BUILDINFO_IN_FILE) configure
-       ./Setup configure $(CONFIGURE_ARGS)
+       $(SETUP_CMD) configure $(CONFIGURE_ARGS)
 
 Setup: $(SETUP_FILE)
        $(GHC) --make Setup
 
+reconfigure:
+       rm -f dist/setup-config
+       $(MAKE) setup-config
+
 clean: clean-hook
        $(RM_RF) dist Setup *.o *.hi .setup-config *.buildinfo *.tix .hpc
        $(FIND) . -name '*~' -exec rm -f {} \;
@@ -81,32 +113,30 @@ clean: clean-hook
 clean-hook:
 
 doc: setup-config
-       ./Setup haddock
+       $(SETUP_CMD) haddock $(HADDOCK_OPTS)
 
 install: build
-       $(SUDO) ./Setup install
+       $(SUDO) $(SETUP_CMD) install
 
 sdist: setup-config
-       ./Setup sdist
+       $(SETUP_CMD) sdist
 
 test: build
        $(RM_RF) dist/test
-       ./Setup test
+       $(SETUP_CMD) test
        if ls *.tix >/dev/null 2>&1; then \
                $(HPC) sum --output="merged.tix" --union --exclude=Main *.tix; \
                $(HPC) markup --destdir="dist/hpc" --fun-entry-count "merged.tix"; \
        fi
 
-ditz:
-       $(DITZ) html dist/ditz
-
-ChangeLog:
-       rm -f $@
-       $(DITZ) releases | awk '{print $$1}' | sort --reverse | while read i; do \
-               $(DITZ) changelog $$i >> $@; \
-       done
-       head $@
-
+# -- Find FIXME Tags ----------------------------------------------------------
+ifeq ($(shell ls -d .git 2>/dev/null),.git)
+fixme:
+       @$(FIND) . \
+               -depth 1 -not -name '*.mk' \
+               -exec $(GIT) grep -E 'FIXME|THINKME|TODO' {} + \
+               || echo 'No FIXME, THINKME, nor TODO found.'
+else
 fixme:
        @$(FIND) . \
                \( -name 'dist' -or -name '.git' -or -name '_darcs' \) -prune \
@@ -114,33 +144,55 @@ fixme:
                \( -name '*.c'   -or -name '*.h'   -or \
                   -name '*.hs'  -or -name '*.lhs' -or \
                   -name '*.hsc' -or -name '*.cabal' \) \
-               -exec egrep 'FIXME|THINKME|TODO' {} \+ \
-               || echo 'No FIXME or THINKME found.'
+               -exec $(GREP) -n -E 'FIXME|THINKME|TODO' {} + \
+               || echo 'No FIXME, THINKME, nor TODO found.'
+endif
 
+# -- HLint --------------------------------------------------------------------
+HLINT_TARGETS ?= $$(find -E . -type d -name dist -prune -o -regex '.*\.(hsc?|lhs)' -print)
 lint:
-       $(HLINT) . $(HLINT_OPTS)
+       $(HLINT) $(HLINT_TARGETS) $(HLINT_OPTS)
 
+# -- Ditz the Distributed Issue Tracker ---------------------------------------
+ifeq (,$(wildcard .ditz-config))
+ditz:
+else
+ditz:
+       $(DITZ) html dist/ditz
+
+ChangeLog:
+       rm -f $@
+       $(DITZ) releases | awk '{print $$1}' | sort --reverse | while read i; do \
+               $(DITZ) changelog $$i >> $@; \
+       done
+       head $@
+endif
+
+# -- Pushing to remote hosts --------------------------------------------------
 push: push-repo push-ditz push-doc
 
 push-repo:
        if [ -d "_darcs" ]; then \
-               darcs push; \
+               $(DARCS) push; \
        elif [ -d ".git" ]; then \
-               git push --all && git push --tags; \
+               $(GIT) push --all && git push --tags; \
        fi
 
 push-ditz: ditz
-       rsync -av --delete \
-               dist/ditz/ \
-               www@nem.cielonegro.org:static.cielonegro.org/htdocs/ditz/$(PKG_NAME)
+       if [ -d "dist/ditz" ]; then \
+               $(RSYNC) -av --delete \
+                       dist/ditz/ \
+                       www@nem.cielonegro.org:static.cielonegro.org/htdocs/ditz/$(PKG_NAME); \
+       fi
 
 push-doc: doc
        if [ -d "dist/doc" ]; then \
-               rsync -av --delete \
+               $(RSYNC) -av --delete \
                        dist/doc/html/$(PKG_NAME)/ \
                        www@nem.cielonegro.org:static.cielonegro.org/htdocs/doc/$(PKG_NAME); \
        fi
 
+# -- Phony Targets ------------------------------------------------------------
 .PHONY: build build-hook setup-config setup-config-hook run clean clean-hook \
                install doc sdist test lint push push-repo push-ditz push-doc \
                ChangeLog