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_INTERFACES:=lib ledger cli web
21 commit:=$(shell if which git >/dev/null; then git describe --long; else echo COMMIT; fi)
27 rmw=$(call if_arg,rm,$(wildcard $1))
28 rmdirw=$(call if_arg,rmdir -p --ignore-fail-on-non-empty,$(wildcard $1))
33 install: cabal/install $(HCOMPTA_INTERFACES:=/install)
35 cabal $(CABAL_FLAGS) update $(CABAL_UPDATE_FLAGS)
36 cabal $(CABAL_FLAGS) install -v $(CABAL_INSTALL_FLAGS) cabal
37 .PHONY: $(HCOMPTA_INTERFACES)
42 cli/unregister/sandbox \
43 web/unregister/sandbox \
44 ledger/unregister/sandbox
45 cabal $(CABAL_FLAGS) install -v $(CABAL_INSTALL_FLAGS) ./lib
46 ledger ledger/install: \
49 cli/unregister/sandbox \
50 web/unregister/sandbox
51 cabal $(CABAL_FLAGS) install -v $(CABAL_INSTALL_FLAGS) ./ledger
53 cabal $(CABAL_FLAGS) install -v $(CABAL_INSTALL_FLAGS) ./cli
55 cabal $(CABAL_FLAGS) install -v $(CABAL_INSTALL_FLAGS) alex happy
56 cabal $(CABAL_FLAGS) install -v $(CABAL_INSTALL_FLAGS) ./web
58 %/recomp: CABAL_INSTALL_FLAGS+=--ghc-options -fforce-recomp
65 clean: lib/clean $(HCOMPTA_INTERFACES:=/clean)
67 (cd lib && cabal clean)
69 (cd ledger && cabal clean)
71 (cd cli && cabal clean)
73 (cd web && cabal clean)
78 test: $(HCOMPTA_INTERFACES:=/test)
80 (cd lib && cabal $(CABAL_FLAGS) test --show-details=always $(CABAL_TEST_FLAGS))
82 (cd ledger && cabal $(CABAL_FLAGS) test --show-details=always $(CABAL_TEST_FLAGS))
84 (cd cli && cabal $(CABAL_FLAGS) test --show-details=always $(CABAL_TEST_FLAGS))
86 (cd web && cabal $(CABAL_FLAGS) test --show-details=always $(CABAL_TEST_FLAGS))
87 %/install/test: CABAL_INSTALL_FLAGS+=--enable-tests
88 %/install/test: %/install
95 doc: doc/xhtml $(HCOMPTA_INTERFACES:=/doc)
98 (cd lib && cabal $(CABAL_FLAGS) haddock --hyperlink-source $(CABAL_HADDOCK_FLAGS))
100 (cd ledger && cabal $(CABAL_FLAGS) haddock --hyperlink-source $(CABAL_HADDOCK_FLAGS))
102 (cd cli && cabal $(CABAL_FLAGS) haddock --hyperlink-source $(CABAL_HADDOCK_FLAGS))
104 (cd web && cabal $(CABAL_FLAGS) haddock --hyperlink-source $(CABAL_HADDOCK_FLAGS))
111 %/dev: CABAL_INSTALL_FLAGS+=-fdev
118 %/dump: CABAL_INSTALL_FLAGS+=-fdump
125 hlint: $(HCOMPTA_INTERFACES:=/hlint.html)
126 %/hlint: %/hlint.html
131 -i 'Redundant bracket' \
133 -i 'Redundant lambda' \
137 -i 'Use string literal' \
138 --quiet --report="$@" \
141 else echo; echo "BROWSE REPORT AT: file://$(abspath $@)"; fi
147 prof: $(addprefix prof/,$(HCOMPTA_COMMANDS))
149 prof/commit/$(commit):
152 lib/install/prof: CABAL_INSTALL_FLAGS+=-fprof --enable-library-profiling
153 lib/install/prof: cli/unregister/sandbox lib/install | $(CABAL_SANDBOX)
156 ledger/install/prof: CABAL_INSTALL_FLAGS+=-fprof --enable-library-profiling
157 ledger/install/prof: cli/unregister/sandbox web/unregister/sandbox ledger/install | $(CABAL_SANDBOX)
160 cli/install/prof: CABAL_INSTALL_FLAGS+=-fprof --enable-library-profiling --enable-executable-profiling
161 cli/install/prof: cli/install | $(CABAL_SANDBOX)
163 $(CABAL_SANDBOX)/bin/hcompta \
168 prof/clean: prof/$(command)/clean
170 prof/%.ledger/$(command)/clean: \
171 $(foreach hC,$(GHC_PROF_CATEGORIES), \
172 prof/%.ledger/$(command)/$(hC)/clean \
175 prof/$$*.ledger.$(command) \
180 define prof/command/hC
182 prof/$(command): prof/$(command)/$(hC)
183 prof/$(command)/clean: prof/$(command)/$(hC)/clean
184 prof/%.ledger/$(command): prof/%.ledger.$(command)/$(hC)
185 prof/%.ledger/$(command)/$(hC): prof/commit/$$(commit)/%.ledger.$(command).$(hC).ps
188 prof/%.ledger.$(command): \
189 prof/commit/$$(commit)/%.ledger.$(command).$(hC).hs
191 prof/commit/$$(commit)/%.ledger.$(command).$(hC).hp \
192 prof/%.ledger.$(command): \
193 $$(HCOMPTA_CLI_PROF) \
195 | prof/commit/$$(commit)
197 -$(hC)$$(GHC_PROF_$(hC)) \
198 -i$$(GHC_PROF_RATE) \
199 -L$$(GHC_PROF_CC_LENGTH) \
200 -N$$(GHC_PROF_CPUS) \
201 -tprof/commit/$(commit)/$$*.ledger.$(command).$(hC).stats \
204 $$(HCOMPTA_CLI_PROF) $$(HCOMPTA_FLAGS) \
205 $(command) $$(HCOMPTA_COMMAND_FLAGS) $$(filter %.ledger,$$^) \
206 >prof/$$*.ledger.$(command)
207 mv $(notdir $(HCOMPTA_CLI_PROF)).hp prof/commit/$(commit)/$$*.ledger.$(command).$(hC).hp
208 mv $(notdir $(HCOMPTA_CLI_PROF)).prof prof/commit/$(commit)/$$*.ledger.$(command).$(hC).prof
210 prof/$(command)/$(hC): \
211 $(addsuffix /$(command)/$(hC),$(wildcard prof/*.ledger))
212 prof/$(command)/$(hC)/clean:
214 prof/commit/$$(commit)/*.ledger.$(command).$(hC).aux \
215 prof/commit/$$(commit)/*.ledger.$(command).$(hC).hp \
216 prof/commit/$$(commit)/*.ledger.$(command).$(hC).prof \
217 prof/commit/$$(commit)/*.ledger.$(command).$(hC).ps \
218 prof/commit/$$(commit)/*.ledger.$(command).$(hC).stats \
220 prof/%.ledger/$(command)/$(hC)/clean:
222 prof/commit/$$(commit)/$$*.ledger.$(command).$(hC).aux \
223 prof/commit/$$(commit)/$$*.ledger.$(command).$(hC).hp \
224 prof/commit/$$(commit)/$$*.ledger.$(command).$(hC).prof \
225 prof/commit/$$(commit)/$$*.ledger.$(command).$(hC).ps \
226 prof/commit/$$(commit)/$$*.ledger.$(command).$(hC).stats \
231 prof/%.ledger/clean: \
232 $(foreach command,$(HCOMPTA_COMMANDS), \
233 prof/%.ledger/$(command)/clean )
236 $(foreach command,$(HCOMPTA_COMMANDS), \
237 $(eval $(call prof/command)) \
238 $(foreach hC,$(GHC_PROF_CATEGORIES), \
239 $(eval $(call prof/command/hC)) ))
241 %.hC.hp: $(foreach hC,$(GHC_PROF_CATEGORIES),%.$(hC).hp)
243 %.hC.ps: $(foreach hC,$(GHC_PROF_CATEGORIES),%.$(hC).ps)
246 (cd $(@D) && hp2ps -b -c -e$(GHC_PROF_PS_WIDTH) -g $(notdir $*.hp))
251 %/not-threaded: CABAL_INSTALL_FLAGS+=-f-threaded
258 unregister: $(HCOMPTA_INTERFACES:=/unregister)
261 if $(GHC_PKG) list hcompta-$* | grep -q '^ * hcompta-$*-' ; \
262 then $(GHC_PKG) unregister hcompta-$* ; \
265 %/unregister/sandbox: GHC_PKG:=cabal sandbox hc-pkg
266 %/unregister/sandbox: .
267 if $(GHC_PKG) list hcompta-$* | grep -q '^ * hcompta-$*-' ; \
268 then $(GHC_PKG) unregister hcompta-$* ; \
275 cabal $(CABAL_FLAGS) sandbox --sandbox="$@" $(CABAL_SANDBOX_FLAGS) init
277 %/sandbox: GHC_PKG:=cabal sandbox hc-pkg