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
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 lib/install cli/install web/install
35 cabal update $(CABAL_FLAGS) $(CABAL_UPDATE_FLAGS)
36 cabal install -v $(CABAL_FLAGS) $(CABAL_INSTALL_FLAGS) cabal
39 cabal install -v --force-reinstalls $(CABAL_FLAGS) $(CABAL_INSTALL_FLAGS) ./lib
41 cabal install -v --force-reinstalls $(CABAL_FLAGS) $(CABAL_INSTALL_FLAGS) ./cli
43 cabal install -v $(CABAL_FLAGS) $(CABAL_INSTALL_FLAGS) alex happy
44 cabal install -v --force-reinstalls $(CABAL_FLAGS) $(CABAL_INSTALL_FLAGS) ./web
49 clean: lib/clean cli/clean web/clean doc/clean
51 (cd lib && cabal clean)
53 (cd cli && cabal clean)
55 (cd web && cabal clean)
60 test: lib/test cli/test web/test
62 (cd lib && cabal test --show-details=always $(CABAL_FLAGS) $(CABAL_TEST_FLAGS))
64 (cd cli && cabal test --show-details=always $(CABAL_FLAGS) $(CABAL_TEST_FLAGS))
66 (cd web && cabal test --show-details=always $(CABAL_FLAGS) $(CABAL_TEST_FLAGS))
67 %/install/test: CABAL_INSTALL_FLAGS+=--enable-tests
68 %/install/test: %/install
75 doc: doc/xhtml lib/doc cli/doc web/doc
76 %/prof: CABAL_INSTALL_FLAGS+=-fprof --ghc-options -fforce-recomp --enable-library-profiling --enable-executable-profiling
77 %/prof: $(CABAL_SANDBOX) %
81 (cd lib && cabal haddock --hyperlink-source $(CABAL_FLAGS) $(CABAL_HADDOCK_FLAGS))
83 (cd cli && cabal haddock --hyperlink-source $(CABAL_FLAGS) $(CABAL_HADDOCK_FLAGS))
85 (cd web && cabal haddock --hyperlink-source $(CABAL_FLAGS) $(CABAL_HADDOCK_FLAGS))
92 %/dev: CABAL_INSTALL_FLAGS+=-fdev
100 prof: $(foreach command,$(HCOMPTA_COMMANDS),prof/$(command))
102 prof/commit/$(commit):
105 lib/install/prof: CABAL_INSTALL_FLAGS+=-fprof --ghc-options -fforce-recomp --enable-library-profiling
106 lib/install/prof: cli/unregister/sandbox lib/install | $(CABAL_SANDBOX)
109 cli/install/prof: CABAL_INSTALL_FLAGS+=-fprof --ghc-options -fforce-recomp --enable-library-profiling --enable-executable-profiling
110 cli/install/prof: cli/install | $(CABAL_SANDBOX)
112 $(CABAL_SANDBOX)/bin/hcompta-cli \
113 $(CABAL_SANDBOX)/bin/hcompta-cli-prof
117 prof/clean: prof/$(command)/clean
119 prof/%.ledger/$(command)/clean: \
120 $(foreach hC,$(GHC_PROF_CATEGORIES), \
121 prof/%.ledger/$(command)/$(hC)/clean \
124 prof/$$*.ledger.$(command) \
129 define prof/command/hC
131 prof/$(command): prof/$(command)/$(hC)
132 prof/$(command)/clean: prof/$(command)/$(hC)/clean
133 prof/%.ledger/$(command): prof/%.ledger.$(command)/$(hC)
134 prof/%.ledger/$(command)/$(hC): prof/commit/$$(commit)/%.ledger.$(command).$(hC).ps
137 prof/%.ledger.$(command): \
138 prof/commit/$$(commit)/%.ledger.$(command).$(hC).hs
140 prof/commit/$$(commit)/%.ledger.$(command).$(hC).hp \
141 prof/%.ledger.$(command): \
142 $$(HCOMPTA_CLI_PROF) \
144 | prof/commit/$$(commit)
146 -$(hC)$$(GHC_PROF_$(hC)) \
147 -i$$(GHC_PROF_RATE) \
148 -L$$(GHC_PROF_CC_LENGTH) \
149 -N$$(GHC_PROF_CPUS) \
150 -tprof/commit/$(commit)/$$*.ledger.$(command).$(hC).stats \
153 $$(HCOMPTA_CLI_PROF) $$(HCOMPTA_FLAGS) \
154 $(command) $$(HCOMPTA_COMMAND_FLAGS) $$(filter %.ledger,$$^) \
155 >prof/$$*.ledger.$(command)
156 mv hcompta-cli-prof.hp prof/commit/$(commit)/$$*.ledger.$(command).$(hC).hp
157 mv hcompta-cli-prof.prof prof/commit/$(commit)/$$*.ledger.$(command).$(hC).prof
159 prof/$(command)/$(hC): \
160 $(addsuffix /$(command)/$(hC),$(wildcard prof/*.ledger))
161 prof/$(command)/$(hC)/clean:
163 prof/commit/$$(commit)/*.ledger.$(command).$(hC).aux \
164 prof/commit/$$(commit)/*.ledger.$(command).$(hC).hp \
165 prof/commit/$$(commit)/*.ledger.$(command).$(hC).prof \
166 prof/commit/$$(commit)/*.ledger.$(command).$(hC).ps \
167 prof/commit/$$(commit)/*.ledger.$(command).$(hC).stats \
169 prof/%.ledger/$(command)/$(hC)/clean:
171 prof/commit/$$(commit)/$$*.ledger.$(command).$(hC).aux \
172 prof/commit/$$(commit)/$$*.ledger.$(command).$(hC).hp \
173 prof/commit/$$(commit)/$$*.ledger.$(command).$(hC).prof \
174 prof/commit/$$(commit)/$$*.ledger.$(command).$(hC).ps \
175 prof/commit/$$(commit)/$$*.ledger.$(command).$(hC).stats \
180 prof/%.ledger/clean: \
181 $(foreach command,$(HCOMPTA_COMMANDS), \
182 prof/%.ledger/$(command)/clean \
186 $(foreach command,$(HCOMPTA_COMMANDS), \
187 $(eval $(call prof/command)) \
188 $(foreach hC,$(GHC_PROF_CATEGORIES), \
189 $(eval $(call prof/command/hC)) ))
191 %.hC.hp: $(foreach hC,$(GHC_PROF_CATEGORIES),%.$(hC).hp)
193 %.hC.ps: $(foreach hC,$(GHC_PROF_CATEGORIES),%.$(hC).ps)
196 (cd $(@D) && hp2ps -b -c -e$(GHC_PROF_PS_WIDTH) -g $(notdir $*.hp))
198 #prof/%.ledger/clean:
200 # $(foreach command,$(HCOMPTA_COMMANDS), \
201 # prof/$*.ledger.$(command) \
202 # $(foreach hC,$(GHC_PROF_CATEGORIES),\
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 \
209 # $(call rmdirw,prof/commit/$(commit))
214 %/not-threaded: CABAL_INSTALL_FLAGS+=-f-threaded
222 cabal sandbox --sandbox="$@" init $(CABAL_FLAGS) $(CABAL_SANDBOX_FLAGS)
224 %/sandbox: GHC_PKG:=cabal sandbox hc-pkg
232 unregister: $(addsuffix /unregister,web cli lib)
235 if $(GHC_PKG) list hcompta-$* | grep -q '^ * hcompta-$*-' ; \
236 then $(GHC_PKG) unregister hcompta-$* ; \