]> Git — Sourcephile - comptalang.git/blob - GNUmakefile
Polissage : GNUmakefile : hlint : affiche l’emplacement du rapport.
[comptalang.git] / GNUmakefile
1 all: install
2 .PHONY: .
3 .SECONDARY:
4 .SUFFIXES:
5 MAKEFLAGS += -r
6 .SHELLFLAGS += -e
7
8 #
9 ## environment
10 ###
11 CABAL_SANDBOX:=.cabal-sandbox
12 GHC_PKG:=ghc-pkg
13 GHC_PROF_CATEGORIES:=hc hm hd hy hr hb
14 GHC_PROF_CPUS:=
15 GHC_PROF_PS_WIDTH:=11in
16 GHC_PROF_RATE:=0.1
17 GHC_PROF_CC_LENGTH:=50
18 HCOMPTA_CLI_PROF:=$(CABAL_SANDBOX)/bin/hcompta-cli-prof
19 HCOMPTA_COMMANDS:=balance gl journal
20 HCOMPTA_INTERFACES:=lib cli web
21 commit:=$(shell if which git >/dev/null; then git describe --long; else echo COMMIT; fi)
22
23 #
24 ## helpers
25 ###
26 if_arg=$(if $2,$1 $2)
27 rmw=$(call if_arg,rm,$(wildcard $1))
28 rmdirw=$(call if_arg,rmdir -p --ignore-fail-on-non-empty,$(wildcard $1))
29
30 #
31 ## install
32 ###
33 install: cabal/install $(HCOMPTA_INTERFACES:=/install)
34 cabal/install:
35 cabal $(CABAL_FLAGS) update $(CABAL_UPDATE_FLAGS)
36 cabal $(CABAL_FLAGS) install -v $(CABAL_INSTALL_FLAGS) cabal
37 .PHONY: $(HCOMPTA_INTERFACES)
38 lib lib/install: cli/unregister web/unregister cli/unregister/sandbox web/unregister/sandbox
39 cabal $(CABAL_FLAGS) install -v $(CABAL_INSTALL_FLAGS) ./lib
40 cli cli/install:
41 cabal $(CABAL_FLAGS) install -v $(CABAL_INSTALL_FLAGS) ./cli
42 web web/install:
43 cabal $(CABAL_FLAGS) install -v $(CABAL_INSTALL_FLAGS) alex happy
44 cabal $(CABAL_FLAGS) install -v $(CABAL_INSTALL_FLAGS) ./web
45
46 %/recomp: CABAL_INSTALL_FLAGS+=--ghc-options -fforce-recomp
47 %/recomp: %
48
49
50 #
51 ## clean
52 ###
53 clean: lib/clean $(HCOMPTA_INTERFACES:=/clean)
54 lib/clean:
55 (cd lib && cabal clean)
56 cli/clean:
57 (cd cli && cabal clean)
58 web/clean:
59 (cd web && cabal clean)
60
61 #
62 ## test
63 ###
64 test: $(HCOMPTA_INTERFACES:=/test)
65 lib/test:
66 (cd lib && cabal $(CABAL_FLAGS) test --show-details=always $(CABAL_TEST_FLAGS))
67 cli/test:
68 (cd cli && cabal $(CABAL_FLAGS) test --show-details=always $(CABAL_TEST_FLAGS))
69 web/test:
70 (cd web && cabal $(CABAL_FLAGS) test --show-details=always $(CABAL_TEST_FLAGS))
71 %/install/test: CABAL_INSTALL_FLAGS+=--enable-tests
72 %/install/test: %/install
73
74
75 #
76 ## doc
77 ###
78 .PHONY: doc
79 doc: doc/xhtml $(HCOMPTA_INTERFACES:=/doc)
80 %/prof: CABAL_INSTALL_FLAGS+=-fprof --enable-library-profiling --enable-executable-profiling
81 %/prof: $(CABAL_SANDBOX) %
82
83
84 lib/doc:
85 (cd lib && cabal $(CABAL_FLAGS) haddock --hyperlink-source $(CABAL_HADDOCK_FLAGS))
86 cli/doc:
87 (cd cli && cabal $(CABAL_FLAGS) haddock --hyperlink-source $(CABAL_HADDOCK_FLAGS))
88 web/doc:
89 (cd web && cabal $(CABAL_FLAGS) haddock --hyperlink-source $(CABAL_HADDOCK_FLAGS))
90 doc/%: .
91 $(MAKE) -C doc $*
92
93 #
94 ## dev
95 ###
96 %/dev: CABAL_INSTALL_FLAGS+=-fdev
97 %/dev: %
98
99
100 #
101 ## dump
102 ###
103 %/dump: CABAL_INSTALL_FLAGS+=-fdump
104 %/dump: %
105
106
107 #
108 ## hlint
109 ###
110 hlint: $(HCOMPTA_INTERFACES:=/hlint.html)
111 %/hlint: %/hlint.html
112
113 %/hlint.html: .
114 if hlint \
115 -i 'Redundant $$' \
116 -i 'Redundant bracket' \
117 -i 'Redundant do' \
118 -i 'Redundant lambda' \
119 -i "Use camelCase" \
120 -i 'Use if' \
121 -i 'Use String' \
122 -i 'Use string literal' \
123 --quiet --report="$@" \
124 "$*"/Hcompta; \
125 then rm -f "$@"; \
126 else echo; echo "BROWSE REPORT AT: file://$(abspath $@)"; fi
127
128 #
129 ## prof
130 ###
131 .PHONY: prof
132 prof: $(addprefix prof/,$(HCOMPTA_COMMANDS))
133
134 prof/commit/$(commit):
135 mkdir -p "$@"
136
137 lib/install/prof: CABAL_INSTALL_FLAGS+=-fprof --enable-library-profiling
138 lib/install/prof: cli/unregister/sandbox lib/install | $(CABAL_SANDBOX)
139
140
141 cli/install/prof: CABAL_INSTALL_FLAGS+=-fprof --enable-library-profiling --enable-executable-profiling
142 cli/install/prof: cli/install | $(CABAL_SANDBOX)
143 mv \
144 $(CABAL_SANDBOX)/bin/hcompta-cli \
145 $(CABAL_SANDBOX)/bin/hcompta-cli-prof
146
147 define prof/command
148
149 prof/clean: prof/$(command)/clean
150
151 prof/%.ledger/$(command)/clean: \
152 $(foreach hC,$(GHC_PROF_CATEGORIES), \
153 prof/%.ledger/$(command)/$(hC)/clean \
154 )
155 $$(call rmw, \
156 prof/$$*.ledger.$(command) \
157 )
158
159 endef
160
161 define prof/command/hC
162
163 prof/$(command): prof/$(command)/$(hC)
164 prof/$(command)/clean: prof/$(command)/$(hC)/clean
165 prof/%.ledger/$(command): prof/%.ledger.$(command)/$(hC)
166 prof/%.ledger/$(command)/$(hC): prof/commit/$$(commit)/%.ledger.$(command).$(hC).ps
167
168
169 prof/%.ledger.$(command): \
170 prof/commit/$$(commit)/%.ledger.$(command).$(hC).hs
171
172 prof/commit/$$(commit)/%.ledger.$(command).$(hC).hp \
173 prof/%.ledger.$(command): \
174 $$(HCOMPTA_CLI_PROF) \
175 prof/%.ledger \
176 | prof/commit/$$(commit)
177 GHCRTS=' \
178 -$(hC)$$(GHC_PROF_$(hC)) \
179 -i$$(GHC_PROF_RATE) \
180 -L$$(GHC_PROF_CC_LENGTH) \
181 -N$$(GHC_PROF_CPUS) \
182 -tprof/commit/$(commit)/$$*.ledger.$(command).$(hC).stats \
183 -p \
184 $$(GHCRTS)' \
185 $$(HCOMPTA_CLI_PROF) $$(HCOMPTA_FLAGS) \
186 $(command) $$(HCOMPTA_COMMAND_FLAGS) $$(filter %.ledger,$$^) \
187 >prof/$$*.ledger.$(command)
188 mv $(notdir $(HCOMPTA_CLI_PROF)).hp prof/commit/$(commit)/$$*.ledger.$(command).$(hC).hp
189 mv $(notdir $(HCOMPTA_CLI_PROF)).prof prof/commit/$(commit)/$$*.ledger.$(command).$(hC).prof
190
191 prof/$(command)/$(hC): \
192 $(addsuffix /$(command)/$(hC),$(wildcard prof/*.ledger))
193 prof/$(command)/$(hC)/clean:
194 $$(call rmw, \
195 prof/commit/$$(commit)/*.ledger.$(command).$(hC).aux \
196 prof/commit/$$(commit)/*.ledger.$(command).$(hC).hp \
197 prof/commit/$$(commit)/*.ledger.$(command).$(hC).prof \
198 prof/commit/$$(commit)/*.ledger.$(command).$(hC).ps \
199 prof/commit/$$(commit)/*.ledger.$(command).$(hC).stats \
200 )
201 prof/%.ledger/$(command)/$(hC)/clean:
202 $$(call rmw, \
203 prof/commit/$$(commit)/$$*.ledger.$(command).$(hC).aux \
204 prof/commit/$$(commit)/$$*.ledger.$(command).$(hC).hp \
205 prof/commit/$$(commit)/$$*.ledger.$(command).$(hC).prof \
206 prof/commit/$$(commit)/$$*.ledger.$(command).$(hC).ps \
207 prof/commit/$$(commit)/$$*.ledger.$(command).$(hC).stats \
208 )
209
210 endef
211
212 prof/%.ledger/clean: \
213 $(foreach command,$(HCOMPTA_COMMANDS), \
214 prof/%.ledger/$(command)/clean )
215
216
217 $(foreach command,$(HCOMPTA_COMMANDS), \
218 $(eval $(call prof/command)) \
219 $(foreach hC,$(GHC_PROF_CATEGORIES), \
220 $(eval $(call prof/command/hC)) ))
221
222 %.hC.hp: $(foreach hC,$(GHC_PROF_CATEGORIES),%.$(hC).hp)
223
224 %.hC.ps: $(foreach hC,$(GHC_PROF_CATEGORIES),%.$(hC).ps)
225
226 %.ps: %.hp
227 (cd $(@D) && hp2ps -b -c -e$(GHC_PROF_PS_WIDTH) -g $(notdir $*.hp))
228
229 #
230 ## not-threaded
231 ###
232 %/not-threaded: CABAL_INSTALL_FLAGS+=-f-threaded
233 %/not-threaded: %
234
235
236 #
237 ## ghc-pkg
238 ###
239 unregister: $(HCOMPTA_INTERFACES:=/unregister)
240
241 %/unregister: .
242 if $(GHC_PKG) list hcompta-$* | grep -q '^ * hcompta-$*-' ; \
243 then $(GHC_PKG) unregister hcompta-$* ; \
244 fi
245
246 %/unregister/sandbox: GHC_PKG:=cabal sandbox hc-pkg
247 %/unregister/sandbox: .
248 if $(GHC_PKG) list hcompta-$* | grep -q '^ * hcompta-$*-' ; \
249 then $(GHC_PKG) unregister hcompta-$* ; \
250 fi
251
252 #
253 ## sandbox
254 ###
255 $(CABAL_SANDBOX):
256 cabal $(CABAL_FLAGS) sandbox --sandbox="$@" $(CABAL_SANDBOX_FLAGS) init
257
258 %/sandbox: GHC_PKG:=cabal sandbox hc-pkg
259 %/sandbox: %
260
261
262 #
263 ## stats
264 ###
265 .PHONY: stats
266 stats:
267 gitstats . $@