11 CABAL_SANDBOX:=.cabal-sandbox
13 GHC_PROF_CATEGORIES:=hc hm hd hy hr hb
15 GHC_PROF_PS_WIDTH:=11in
17 GHC_PROF_CC_LENGTH:=50
18 HCOMPTA_CLI_PROF:=$(CABAL_SANDBOX)/bin/hcompta-prof
19 HCOMPTA_COMMANDS:=balance gl journal
20 HCOMPTA_PACKAGES:=lib jcc ledger cli web
21 HCOMPTA_IN_FORMATS:=jcc ledger
22 commit:=$(shell if which git >/dev/null; then git describe --long; else echo COMMIT; fi)
28 rmw=$(call if_arg,rm,$(wildcard $1))
29 rmdirw=$(call if_arg,rmdir -p --ignore-fail-on-non-empty,$(wildcard $1))
34 install: cabal/install $(HCOMPTA_PACKAGES:=/install)
36 cabal $(CABAL_FLAGS) update $(CABAL_UPDATE_FLAGS)
37 cabal $(CABAL_FLAGS) install -v $(CABAL_INSTALL_FLAGS) cabal
38 .PHONY: $(HCOMPTA_PACKAGES)
44 cli/unregister/sandbox \
45 web/unregister/sandbox \
46 ledger/unregister/sandbox \
47 jcc/unregister/sandbox
48 cabal $(CABAL_FLAGS) install -v $(CABAL_INSTALL_FLAGS) ./lib
52 cli/unregister/sandbox \
53 web/unregister/sandbox
54 cabal $(CABAL_FLAGS) install -v $(CABAL_INSTALL_FLAGS) ./jcc
55 ledger ledger/install: \
58 cli/unregister/sandbox \
59 web/unregister/sandbox
60 cabal $(CABAL_FLAGS) install -v $(CABAL_INSTALL_FLAGS) ./ledger
62 cabal $(CABAL_FLAGS) install -v $(CABAL_INSTALL_FLAGS) ./cli
64 cabal $(CABAL_FLAGS) install -v $(CABAL_INSTALL_FLAGS) alex happy
65 cabal $(CABAL_FLAGS) install -v $(CABAL_INSTALL_FLAGS) ./web
67 %/recomp: CABAL_INSTALL_FLAGS+=--ghc-options -fforce-recomp
74 clean: lib/clean $(HCOMPTA_PACKAGES:=/clean)
76 (cd lib && cabal clean)
78 (cd jcc && cabal clean)
80 (cd ledger && cabal clean)
82 (cd cli && cabal clean)
84 (cd web && cabal clean)
89 test: $(HCOMPTA_PACKAGES:=/test)
91 (cd lib && cabal $(CABAL_FLAGS) test --show-details=always $(CABAL_TEST_FLAGS))
93 (cd jcc && cabal $(CABAL_FLAGS) test --show-details=always $(CABAL_TEST_FLAGS))
95 (cd ledger && cabal $(CABAL_FLAGS) test --show-details=always $(CABAL_TEST_FLAGS))
97 (cd cli && cabal $(CABAL_FLAGS) test --show-details=always $(CABAL_TEST_FLAGS))
99 (cd web && cabal $(CABAL_FLAGS) test --show-details=always $(CABAL_TEST_FLAGS))
100 %/install/test: CABAL_INSTALL_FLAGS+=--enable-tests
101 %/install/test: %/install
108 doc: doc/xhtml $(HCOMPTA_PACKAGES:=/doc)
112 cabal $(CABAL_FLAGS) configure $(CABAL_CONFIGURE_FLAGS) && \
113 cabal $(CABAL_FLAGS) haddock --hyperlink-source $(CABAL_HADDOCK_FLAGS))
116 cabal $(CABAL_FLAGS) configure $(CABAL_CONFIGURE_FLAGS) && \
117 cabal $(CABAL_FLAGS) haddock --hyperlink-source $(CABAL_HADDOCK_FLAGS))
120 cabal $(CABAL_FLAGS) configure $(CABAL_CONFIGURE_FLAGS) && \
121 cabal $(CABAL_FLAGS) haddock --hyperlink-source $(CABAL_HADDOCK_FLAGS))
124 cabal $(CABAL_FLAGS) configure $(CABAL_CONFIGURE_FLAGS) && \
125 cabal $(CABAL_FLAGS) haddock --hyperlink-source $(CABAL_HADDOCK_FLAGS))
128 cabal $(CABAL_FLAGS) configure $(CABAL_CONFIGURE_FLAGS) && \
129 cabal $(CABAL_FLAGS) haddock --hyperlink-source $(CABAL_HADDOCK_FLAGS))
136 %/dev: CABAL_INSTALL_FLAGS+=-fdev
143 %/dump: CABAL_INSTALL_FLAGS+=-fdump
150 hlint: $(HCOMPTA_PACKAGES:=/hlint.html)
151 %/hlint: %/hlint.html
156 -i 'Redundant bracket' \
158 -i 'Redundant lambda' \
162 -i 'Use string literal' \
163 --quiet --report="$@" \
166 else echo; echo "BROWSE REPORT AT: file://$(abspath $@)"; fi
172 prof: $(addprefix prof/,$(HCOMPTA_COMMANDS))
174 prof/commit/$(commit):
177 lib/install/prof: CABAL_INSTALL_FLAGS+=-fprof --enable-library-profiling
178 lib/install/prof: cli/unregister/sandbox lib/install | $(CABAL_SANDBOX)
181 jcc/install/prof: CABAL_INSTALL_FLAGS+=-fprof --enable-library-profiling
182 jcc/install/prof: cli/unregister/sandbox web/unregister/sandbox jcc/install | $(CABAL_SANDBOX)
185 ledger/install/prof: CABAL_INSTALL_FLAGS+=-fprof --enable-library-profiling
186 ledger/install/prof: cli/unregister/sandbox web/unregister/sandbox ledger/install | $(CABAL_SANDBOX)
189 cli/install/prof: CABAL_INSTALL_FLAGS+=-fprof --enable-library-profiling --enable-executable-profiling
190 cli/install/prof: cli/install | $(CABAL_SANDBOX)
192 $(CABAL_SANDBOX)/bin/hcompta \
196 prof/clean: prof/$(command)/clean
201 prof/%.$(in)/clean: \
202 $(foreach command,$(HCOMPTA_COMMANDS), \
203 $(foreach journal,$(HCOMPTA_IN_FORMATS), \
204 prof/%.$(in)/$(command)/clean ))
209 define prof/command/in
211 prof/%.$(in)/$(command)/clean: \
212 $(foreach hC,$(GHC_PROF_CATEGORIES), \
213 prof/%.$(in)/$(command)/$(hC)/clean \
216 prof/$$*.$(in).$(command) \
221 define prof/command/hC
222 prof/$(command): prof/$(command)/$(hC)
223 prof/$(command)/clean: prof/$(command)/$(hC)/clean
224 prof/$(command)/$(hC): \
225 $(addsuffix /$(command)/$(hC),$(wildcard prof/*.$(in)))
226 prof/$(command)/$(hC)/clean:
228 prof/commit/$$(commit)/*.$(in).$(command).$(hC).aux \
229 prof/commit/$$(commit)/*.$(in).$(command).$(hC).hp \
230 prof/commit/$$(commit)/*.$(in).$(command).$(hC).prof \
231 prof/commit/$$(commit)/*.$(in).$(command).$(hC).ps \
232 prof/commit/$$(commit)/*.$(in).$(command).$(hC).stats \
237 define prof/command/in/hC
238 prof/%.$(in)/$(command): prof/%.$(in).$(command)/$(hC)
239 prof/%.$(in)/$(command)/$(hC): prof/commit/$$(commit)/%.$(in).$(command).$(hC).ps
242 prof/%.$(in).$(command): \
243 prof/commit/$$(commit)/%.$(in).$(command).$(hC).hs
245 prof/commit/$$(commit)/%.$(in).$(command).$(hC).hp \
246 prof/%.$(in).$(command): \
247 $$(HCOMPTA_CLI_PROF) \
249 | prof/commit/$$(commit)
251 -$(hC)$$(GHC_PROF_$(hC)) \
252 -i$$(GHC_PROF_RATE) \
253 -L$$(GHC_PROF_CC_LENGTH) \
254 -N$$(GHC_PROF_CPUS) \
255 -tprof/commit/$(commit)/$$*.$(in).$(command).$(hC).stats \
258 $$(HCOMPTA_CLI_PROF) $$(HCOMPTA_FLAGS) \
259 $(command) $$(HCOMPTA_COMMAND_FLAGS) $$(filter %.$(in),$$^) \
260 >prof/$$*.$(in).$(command)
261 mv $(notdir $(HCOMPTA_CLI_PROF)).hp prof/commit/$(commit)/$$*.$(in).$(command).$(hC).hp
262 mv $(notdir $(HCOMPTA_CLI_PROF)).prof prof/commit/$(commit)/$$*.$(in).$(command).$(hC).prof
264 prof/%.$(in)/$(command)/$(hC)/clean:
266 prof/commit/$$(commit)/$$*.$(in).$(command).$(hC).aux \
267 prof/commit/$$(commit)/$$*.$(in).$(command).$(hC).hp \
268 prof/commit/$$(commit)/$$*.$(in).$(command).$(hC).prof \
269 prof/commit/$$(commit)/$$*.$(in).$(command).$(hC).ps \
270 prof/commit/$$(commit)/$$*.$(in).$(command).$(hC).stats \
275 $(foreach in,$(HCOMPTA_IN_FORMATS), \
276 $(eval $(call prof/in)) )
277 $(foreach command,$(HCOMPTA_COMMANDS), \
278 $(eval $(call prof/command)) \
279 $(foreach hC,$(GHC_PROF_CATEGORIES), \
280 $(eval $(call prof/command/hC)) ) \
281 $(foreach in,$(HCOMPTA_IN_FORMATS), \
282 $(eval $(call prof/command/in)) \
283 $(foreach hC,$(GHC_PROF_CATEGORIES), \
284 $(eval $(call prof/command/in/hC)) )))
286 %.hC.hp: $(foreach hC,$(GHC_PROF_CATEGORIES),%.$(hC).hp)
288 %.hC.ps: $(foreach hC,$(GHC_PROF_CATEGORIES),%.$(hC).ps)
291 (cd $(@D) && hp2ps -b -c -e$(GHC_PROF_PS_WIDTH) -g $(notdir $*.hp))
296 %/not-threaded: CABAL_INSTALL_FLAGS+=-f-threaded
303 unregister: $(HCOMPTA_PACKAGES:=/unregister)
306 if $(GHC_PKG) list hcompta-$* | grep -q '^ * hcompta-$*-' ; \
307 then $(GHC_PKG) unregister hcompta-$* ; \
310 %/unregister/sandbox: GHC_PKG:=cabal sandbox hc-pkg
311 %/unregister/sandbox: .
312 if $(GHC_PKG) list hcompta-$* | grep -q '^ * hcompta-$*-' ; \
313 then $(GHC_PKG) unregister hcompta-$* ; \
320 cabal $(CABAL_FLAGS) sandbox --sandbox="$@" $(CABAL_SANDBOX_FLAGS) init
322 %/sandbox: GHC_PKG:=cabal sandbox hc-pkg