]> gitweb @ CieloNegro.org - cabal-shared-makefile.git/blob - cabal-package.mk
new variable: HLINT_OPTS
[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 HLINT_OPTS     ?= --cross --report=dist/report.html
22
23 SETUP_FILE := $(wildcard Setup.*hs)
24 CABAL_FILE := $(wildcard *.cabal)
25 PKG_NAME   := $(CABAL_FILE:.cabal=)
26
27 ifeq ($(shell ls configure.ac 2>/dev/null),configure.ac)
28   AUTOCONF_AC_FILE := configure.ac
29   AUTOCONF_FILE    := configure
30 else
31   ifeq ($(shell ls configure.in 2>/dev/null),configure.in)
32     AUTOCONF_AC_FILE := configure.in
33     AUTOCONF_FILE    := configure
34   else
35     AUTOCONF_AC_FILE :=
36     AUTOCONF_FILE    :=
37   endif
38 endif
39
40 BUILDINFO_IN_FILE := $(wildcard *.buildinfo.in)
41 BUILDINFO_FILE    := $(BUILDINFO_IN_FILE:.in=)
42
43 all: build
44
45 build: setup-config build-hook
46         ./Setup build
47         $(RM_RF) *.tix
48
49 build-hook:
50
51 ifeq ($(RUN_COMMAND),)
52 run:
53         @echo "cabal-package.mk: No command to run."
54         @echo "cabal-package.mk: If you want to run something, define RUN_COMMAND variable."
55 else
56 run: build
57         @echo ".:.:. Let's go .:.:."
58         $(RUN_COMMAND)
59 endif
60
61 setup-config: dist/setup-config setup-config-hook $(BUILDINFO_FILE)
62
63 setup-config-hook:
64
65 dist/setup-config: $(CABAL_FILE) Setup $(AUTOCONF_FILE)
66         ./Setup configure $(CONFIGURE_ARGS)
67
68 $(AUTOCONF_FILE): $(AUTOCONF_AC_FILE)
69         $(AUTOCONF)
70
71 $(BUILDINFO_FILE): $(BUILDINFO_IN_FILE) configure
72         ./Setup configure $(CONFIGURE_ARGS)
73
74 Setup: $(SETUP_FILE)
75         $(GHC) --make Setup
76
77 clean: clean-hook
78         $(RM_RF) dist Setup *.o *.hi .setup-config *.buildinfo *.tix .hpc
79         $(FIND) . -name '*~' -exec rm -f {} \;
80
81 clean-hook:
82
83 doc: setup-config
84         ./Setup haddock
85
86 install: build
87         $(SUDO) ./Setup install
88
89 sdist: setup-config
90         ./Setup sdist
91
92 test: build
93         $(RM_RF) dist/test
94         ./Setup test
95         if ls *.tix >/dev/null 2>&1; then \
96                 $(HPC) sum --output="merged.tix" --union --exclude=Main *.tix; \
97                 $(HPC) markup --destdir="dist/hpc" --fun-entry-count "merged.tix"; \
98         fi
99
100 ditz:
101         $(DITZ) html dist/ditz
102
103 ChangeLog:
104         rm -f $@
105         $(DITZ) releases | awk '{print $$1}' | sort --reverse | while read i; do \
106                 $(DITZ) changelog $$i >> $@; \
107         done
108         head $@
109
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 -i '(fixme|thinkme)' {} \+ \
118                 || echo 'No FIXME or THINKME found.'
119
120 lint:
121         $(HLINT) . $(HLINT_OPTS)
122
123 push: push-repo push-ditz push-doc
124
125 push-repo:
126         if [ -d "_darcs" ]; then \
127                 darcs push; \
128         elif [ -d ".git" ]; then \
129                 git push --all && git push --tags; \
130         fi
131
132 push-ditz: ditz
133         rsync -av --delete \
134                 dist/ditz/ \
135                 www@nem.cielonegro.org:static.cielonegro.org/htdocs/ditz/$(PKG_NAME)
136
137 push-doc: doc
138         if [ -d "dist/doc" ]; then \
139                 rsync -av --delete \
140                         dist/doc/html/$(PKG_NAME)/ \
141                         www@nem.cielonegro.org:static.cielonegro.org/htdocs/doc/$(PKG_NAME); \
142         fi
143
144 .PHONY: build build-hook setup-config setup-config-hook run clean clean-hook \
145                 install doc sdist test lint push push-repo push-ditz push-doc \
146                 ChangeLog