]> gitweb @ CieloNegro.org - cabal-shared-makefile.git/blob - cabal-package.mk
831b0b20a9fb8ed03c0cb9ed6f9d5d8021de17dc
[cabal-shared-makefile.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 HADDOCK_OPTS   ?= --hyperlink-source
22 HLINT_OPTS     ?= \
23         --hint=Default --hint=Dollar --hint=Generalise \
24         --cross \
25         --ignore="Parse error" \
26         --report=dist/report.html
27
28 SETUP_FILE := $(wildcard Setup.*hs)
29 CABAL_FILE := $(wildcard *.cabal)
30 PKG_NAME   := $(CABAL_FILE:.cabal=)
31
32 ifeq ($(shell ls configure.ac 2>/dev/null),configure.ac)
33   AUTOCONF_AC_FILE := configure.ac
34   AUTOCONF_FILE    := configure
35 else
36   ifeq ($(shell ls configure.in 2>/dev/null),configure.in)
37     AUTOCONF_AC_FILE := configure.in
38     AUTOCONF_FILE    := configure
39   else
40     AUTOCONF_AC_FILE :=
41     AUTOCONF_FILE    :=
42   endif
43 endif
44
45 BUILDINFO_IN_FILE := $(wildcard *.buildinfo.in)
46 BUILDINFO_FILE    := $(BUILDINFO_IN_FILE:.in=)
47
48 all: build
49
50 build: setup-config build-hook
51         ./Setup build
52         $(RM_RF) *.tix
53
54 build-hook:
55
56 ifeq ($(RUN_COMMAND),)
57 run:
58         @echo "cabal-package.mk: No command to run."
59         @echo "cabal-package.mk: If you want to run something, define RUN_COMMAND variable."
60 else
61 run: build
62         @echo ".:.:. Let's go .:.:."
63         $(RUN_COMMAND)
64 endif
65
66 setup-config: dist/setup-config setup-config-hook $(BUILDINFO_FILE)
67
68 setup-config-hook:
69
70 dist/setup-config: $(CABAL_FILE) Setup $(AUTOCONF_FILE)
71         ./Setup configure $(CONFIGURE_ARGS)
72
73 $(AUTOCONF_FILE): $(AUTOCONF_AC_FILE)
74         $(AUTOCONF)
75
76 $(BUILDINFO_FILE): $(BUILDINFO_IN_FILE) configure
77         ./Setup configure $(CONFIGURE_ARGS)
78
79 Setup: $(SETUP_FILE)
80         $(GHC) --make Setup
81
82 reconfigure:
83         rm -f dist/setup-config
84         $(MAKE) setup-config
85
86 clean: clean-hook
87         $(RM_RF) dist Setup *.o *.hi .setup-config *.buildinfo *.tix .hpc
88         $(FIND) . -name '*~' -exec rm -f {} \;
89
90 clean-hook:
91
92 doc: setup-config
93         ./Setup haddock $(HADDOCK_OPTS)
94
95 install: build
96         $(SUDO) ./Setup install
97
98 sdist: setup-config
99         ./Setup sdist
100
101 test: build
102         $(RM_RF) dist/test
103         ./Setup test
104         if ls *.tix >/dev/null 2>&1; then \
105                 $(HPC) sum --output="merged.tix" --union --exclude=Main *.tix; \
106                 $(HPC) markup --destdir="dist/hpc" --fun-entry-count "merged.tix"; \
107         fi
108
109 # -- Find FIXME Tags ----------------------------------------------------------
110 fixme:
111         @$(FIND) . \
112                 \( -name 'dist' -or -name '.git' -or -name '_darcs' \) -prune \
113                 -or \
114                 \( -name '*.c'   -or -name '*.h'   -or \
115                    -name '*.hs'  -or -name '*.lhs' -or \
116                    -name '*.hsc' -or -name '*.cabal' \) \
117                 -exec egrep 'FIXME|THINKME|TODO' {} \+ \
118                 || echo 'No FIXME, THINKME, nor TODO found.'
119
120 # -- HLint --------------------------------------------------------------------
121 HLINT_TARGETS ?= $$(find -E . -type d -name dist -prune -o -regex '.*\.(hsc?|lhs)' -print)
122 lint:
123         $(HLINT) $(HLINT_TARGETS) $(HLINT_OPTS)
124
125 # -- Ditz the Distributed Issue Tracker ---------------------------------------
126 ifeq (,$(wildcard .ditz-config))
127 ditz:
128 else
129 ditz:
130         $(DITZ) html dist/ditz
131
132 ChangeLog:
133         rm -f $@
134         $(DITZ) releases | awk '{print $$1}' | sort --reverse | while read i; do \
135                 $(DITZ) changelog $$i >> $@; \
136         done
137         head $@
138 endif
139
140 # -- Pushing to remote hosts --------------------------------------------------
141 push: push-repo push-ditz push-doc
142
143 push-repo:
144         if [ -d "_darcs" ]; then \
145                 darcs push; \
146         elif [ -d ".git" ]; then \
147                 git push --all && git push --tags; \
148         fi
149
150 push-ditz: ditz
151         if [ -d "dist/ditz" ]; then \
152                 rsync -av --delete \
153                         dist/ditz/ \
154                         www@nem.cielonegro.org:static.cielonegro.org/htdocs/ditz/$(PKG_NAME); \
155         fi
156
157 push-doc: doc
158         if [ -d "dist/doc" ]; then \
159                 rsync -av --delete \
160                         dist/doc/html/$(PKG_NAME)/ \
161                         www@nem.cielonegro.org:static.cielonegro.org/htdocs/doc/$(PKG_NAME); \
162         fi
163
164 # -- Phony Targets ------------------------------------------------------------
165 .PHONY: build build-hook setup-config setup-config-hook run clean clean-hook \
166                 install doc sdist test lint push push-repo push-ditz push-doc \
167                 ChangeLog