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