Tests for Data.Time.HTTP
[time-http.git] / cabal-package.mk
1 # -*- makefile-gmake -*-
2 #
3 # Variables:
4 #
5 #   CONFIGURE_ARGS :: arguments to be passed to ./Setup configure
6 #     default: --disable-optimization
7 #
8 #   RUN_COMMAND :: command to be run for "make run"
9 #
10
11 GHC      ?= ghc
12 FIND     ?= find
13 RM_RF    ?= rm -rf
14 SUDO     ?= sudo
15 AUTOCONF ?= autoconf
16 HLINT    ?= hlint
17 HPC      ?= hpc
18 DITZ     ?= ditz
19
20 CONFIGURE_ARGS ?= --disable-optimization
21
22 SETUP_FILE := $(wildcard Setup.*hs)
23 CABAL_FILE := $(wildcard *.cabal)
24 PKG_NAME   := $(CABAL_FILE:.cabal=)
25
26 ifeq ($(shell ls configure.ac 2>/dev/null),configure.ac)
27   AUTOCONF_AC_FILE := configure.ac
28   AUTOCONF_FILE    := configure
29 else
30   ifeq ($(shell ls configure.in 2>/dev/null),configure.in)
31     AUTOCONF_AC_FILE := configure.in
32     AUTOCONF_FILE    := configure
33   else
34     AUTOCONF_AC_FILE :=
35     AUTOCONF_FILE    :=
36   endif
37 endif
38
39 BUILDINFO_IN_FILE := $(wildcard *.buildinfo.in)
40 BUILDINFO_FILE    := $(BUILDINFO_IN_FILE:.in=)
41
42 all: build
43
44 build: setup-config build-hook
45         ./Setup build
46         $(RM_RF) *.tix
47
48 build-hook:
49
50 ifeq ($(RUN_COMMAND),)
51 run:
52         @echo "cabal-package.mk: No command to run."
53         @echo "cabal-package.mk: If you want to run something, define RUN_COMMAND variable."
54 else
55 run: build
56         @echo ".:.:. Let's go .:.:."
57         $(RUN_COMMAND)
58 endif
59
60 setup-config: dist/setup-config setup-config-hook $(BUILDINFO_FILE)
61
62 setup-config-hook:
63
64 dist/setup-config: $(CABAL_FILE) Setup $(AUTOCONF_FILE)
65         ./Setup configure $(CONFIGURE_ARGS)
66
67 $(AUTOCONF_FILE): $(AUTOCONF_AC_FILE)
68         $(AUTOCONF)
69
70 $(BUILDINFO_FILE): $(BUILDINFO_IN_FILE) configure
71         ./Setup configure $(CONFIGURE_ARGS)
72
73 Setup: $(SETUP_FILE)
74         $(GHC) --make Setup
75
76 clean: clean-hook
77         $(RM_RF) dist Setup *.o *.hi .setup-config *.buildinfo *.tix .hpc
78         $(FIND) . -name '*~' -exec rm -f {} \;
79
80 clean-hook:
81
82 doc: setup-config
83         ./Setup haddock
84
85 install: build
86         $(SUDO) ./Setup install
87
88 sdist: setup-config
89         ./Setup sdist
90
91 test: build
92         $(RM_RF) dist/test
93         ./Setup test
94         if ls *.tix >/dev/null 2>&1; then \
95                 $(HPC) sum --output="merged.tix" --union --exclude=Main *.tix; \
96                 $(HPC) markup --destdir="dist/hpc" --fun-entry-count "merged.tix"; \
97         fi
98
99 ditz:
100         $(DITZ) html dist/ditz
101
102 fixme:
103         @$(FIND) . \
104                 \( -name 'dist' -or -name '.git' -or -name '_darcs' \) -prune \
105                 -or \
106                 \( -name '*.c'   -or -name '*.h'   -or \
107                    -name '*.hs'  -or -name '*.lhs' -or \
108                    -name '*.hsc' -or -name '*.cabal' \) \
109                 -exec egrep -i '(fixme|thinkme)' {} \+ \
110                 || echo 'No FIXME or THINKME found.'
111
112 lint:
113         $(HLINT) . --report
114
115 push: push-repo push-ditz push-doc
116
117 push-repo:
118         if [ -d "_darcs" ]; then \
119                 darcs push; \
120         elif [ -d ".git" ]; then \
121                 git push --all && git push --tags; \
122         fi
123
124 push-ditz: ditz
125         rsync -av --delete \
126                 dist/ditz/ \
127                 www@nem.cielonegro.org:static.cielonegro.org/htdocs/ditz/$(PKG_NAME)
128
129 push-doc: doc
130         if [ -d "dist/doc" ]; then \
131                 rsync -av --delete \
132                         dist/doc/html/$(PKG_NAME)/ \
133                         www@nem.cielonegro.org:static.cielonegro.org/htdocs/doc/$(PKG_NAME); \
134         fi
135
136 .PHONY: build build-hook setup-config setup-config-hook run clean clean-hook \
137                 install doc sdist test lint push push-repo push-ditz push-doc