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-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)
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)
38 lib lib/install: cli/unregister web/unregister cli/unregister/sandbox web/unregister/sandbox
39 cabal $(CABAL_FLAGS) install -v $(CABAL_INSTALL_FLAGS) ./lib
41 cabal $(CABAL_FLAGS) install -v $(CABAL_INSTALL_FLAGS) ./cli
43 cabal $(CABAL_FLAGS) install -v $(CABAL_INSTALL_FLAGS) alex happy
44 cabal $(CABAL_FLAGS) install -v $(CABAL_INSTALL_FLAGS) ./web
46 %/recomp: CABAL_INSTALL_FLAGS+=--ghc-options -fforce-recomp
53 clean: lib/clean $(HCOMPTA_INTERFACES:=/clean)
55 (cd lib && cabal clean)
57 (cd cli && cabal clean)
59 (cd web && cabal clean)
64 test: $(HCOMPTA_INTERFACES:=/test)
66 (cd lib && cabal $(CABAL_FLAGS) test --show-details=always $(CABAL_TEST_FLAGS))
68 (cd cli && cabal $(CABAL_FLAGS) test --show-details=always $(CABAL_TEST_FLAGS))
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
79 doc: doc/xhtml $(HCOMPTA_INTERFACES:=/doc)
80 %/prof: CABAL_INSTALL_FLAGS+=-fprof --enable-library-profiling --enable-executable-profiling
81 %/prof: $(CABAL_SANDBOX) %
85 (cd lib && cabal $(CABAL_FLAGS) haddock --hyperlink-source $(CABAL_HADDOCK_FLAGS))
87 (cd cli && cabal $(CABAL_FLAGS) haddock --hyperlink-source $(CABAL_HADDOCK_FLAGS))
89 (cd web && cabal $(CABAL_FLAGS) haddock --hyperlink-source $(CABAL_HADDOCK_FLAGS))
96 %/dev: CABAL_INSTALL_FLAGS+=-fdev
103 %/dump: CABAL_INSTALL_FLAGS+=-fdump
110 hlint: $(HCOMPTA_INTERFACES:=/hlint.html)
114 -i 'Redundant bracket' \
116 -i 'Redundant lambda' \
120 -i 'Use string literal' \
121 --quiet --report="$@" \
122 "$*"/Hcompta && rm -f "$@"
128 prof: $(foreach command,$(HCOMPTA_COMMANDS),prof/$(command))
130 prof/commit/$(commit):
133 lib/install/prof: CABAL_INSTALL_FLAGS+=-fprof --enable-library-profiling
134 lib/install/prof: cli/unregister/sandbox lib/install | $(CABAL_SANDBOX)
137 cli/install/prof: CABAL_INSTALL_FLAGS+=-fprof --enable-library-profiling --enable-executable-profiling
138 cli/install/prof: cli/install | $(CABAL_SANDBOX)
140 $(CABAL_SANDBOX)/bin/hcompta-cli \
141 $(CABAL_SANDBOX)/bin/hcompta-cli-prof
145 prof/clean: prof/$(command)/clean
147 prof/%.ledger/$(command)/clean: \
148 $(foreach hC,$(GHC_PROF_CATEGORIES), \
149 prof/%.ledger/$(command)/$(hC)/clean \
152 prof/$$*.ledger.$(command) \
157 define prof/command/hC
159 prof/$(command): prof/$(command)/$(hC)
160 prof/$(command)/clean: prof/$(command)/$(hC)/clean
161 prof/%.ledger/$(command): prof/%.ledger.$(command)/$(hC)
162 prof/%.ledger/$(command)/$(hC): prof/commit/$$(commit)/%.ledger.$(command).$(hC).ps
165 prof/%.ledger.$(command): \
166 prof/commit/$$(commit)/%.ledger.$(command).$(hC).hs
168 prof/commit/$$(commit)/%.ledger.$(command).$(hC).hp \
169 prof/%.ledger.$(command): \
170 $$(HCOMPTA_CLI_PROF) \
172 | prof/commit/$$(commit)
174 -$(hC)$$(GHC_PROF_$(hC)) \
175 -i$$(GHC_PROF_RATE) \
176 -L$$(GHC_PROF_CC_LENGTH) \
177 -N$$(GHC_PROF_CPUS) \
178 -tprof/commit/$(commit)/$$*.ledger.$(command).$(hC).stats \
181 $$(HCOMPTA_CLI_PROF) $$(HCOMPTA_FLAGS) \
182 $(command) $$(HCOMPTA_COMMAND_FLAGS) $$(filter %.ledger,$$^) \
183 >prof/$$*.ledger.$(command)
184 mv $(notdir $(HCOMPTA_CLI_PROF)).hp prof/commit/$(commit)/$$*.ledger.$(command).$(hC).hp
185 mv $(notdir $(HCOMPTA_CLI_PROF)).prof prof/commit/$(commit)/$$*.ledger.$(command).$(hC).prof
187 prof/$(command)/$(hC): \
188 $(addsuffix /$(command)/$(hC),$(wildcard prof/*.ledger))
189 prof/$(command)/$(hC)/clean:
191 prof/commit/$$(commit)/*.ledger.$(command).$(hC).aux \
192 prof/commit/$$(commit)/*.ledger.$(command).$(hC).hp \
193 prof/commit/$$(commit)/*.ledger.$(command).$(hC).prof \
194 prof/commit/$$(commit)/*.ledger.$(command).$(hC).ps \
195 prof/commit/$$(commit)/*.ledger.$(command).$(hC).stats \
197 prof/%.ledger/$(command)/$(hC)/clean:
199 prof/commit/$$(commit)/$$*.ledger.$(command).$(hC).aux \
200 prof/commit/$$(commit)/$$*.ledger.$(command).$(hC).hp \
201 prof/commit/$$(commit)/$$*.ledger.$(command).$(hC).prof \
202 prof/commit/$$(commit)/$$*.ledger.$(command).$(hC).ps \
203 prof/commit/$$(commit)/$$*.ledger.$(command).$(hC).stats \
208 prof/%.ledger/clean: \
209 $(foreach command,$(HCOMPTA_COMMANDS), \
210 prof/%.ledger/$(command)/clean )
213 $(foreach command,$(HCOMPTA_COMMANDS), \
214 $(eval $(call prof/command)) \
215 $(foreach hC,$(GHC_PROF_CATEGORIES), \
216 $(eval $(call prof/command/hC)) ))
218 %.hC.hp: $(foreach hC,$(GHC_PROF_CATEGORIES),%.$(hC).hp)
220 %.hC.ps: $(foreach hC,$(GHC_PROF_CATEGORIES),%.$(hC).ps)
223 (cd $(@D) && hp2ps -b -c -e$(GHC_PROF_PS_WIDTH) -g $(notdir $*.hp))
228 %/not-threaded: CABAL_INSTALL_FLAGS+=-f-threaded
235 unregister: $(HCOMPTA_INTERFACES:=/unregister)
238 if $(GHC_PKG) list hcompta-$* | grep -q '^ * hcompta-$*-' ; \
239 then $(GHC_PKG) unregister hcompta-$* ; \
242 %/unregister/sandbox: GHC_PKG:=cabal sandbox hc-pkg
243 %/unregister/sandbox: .
244 if $(GHC_PKG) list hcompta-$* | grep -q '^ * hcompta-$*-' ; \
245 then $(GHC_PKG) unregister hcompta-$* ; \
252 cabal $(CABAL_FLAGS) sandbox --sandbox="$@" $(CABAL_SANDBOX_FLAGS) init
254 %/sandbox: GHC_PKG:=cabal sandbox hc-pkg