]> Git — Sourcephile - comptalang.git/blob - GNUmakefile
Ajout : profilage du code.
[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
20 # gl journal
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 lib/install cli/install web/install
34 cabal/install:
35 cabal update $(CABAL_FLAGS) $(CABAL_UPDATE_FLAGS)
36 cabal install -v $(CABAL_FLAGS) $(CABAL_INSTALL_FLAGS) cabal
37 .PHONY: lib cli web
38 lib lib/install:
39 cabal install -v --force-reinstalls $(CABAL_FLAGS) $(CABAL_INSTALL_FLAGS) ./lib
40 cli cli/install:
41 cabal install -v --force-reinstalls $(CABAL_FLAGS) $(CABAL_INSTALL_FLAGS) ./cli
42 web web/install:
43 cabal install -v $(CABAL_FLAGS) $(CABAL_INSTALL_FLAGS) alex happy
44 cabal install -v --force-reinstalls $(CABAL_FLAGS) $(CABAL_INSTALL_FLAGS) ./web
45
46 #
47 ## clean
48 ###
49 clean: lib/clean cli/clean web/clean doc/clean
50 lib/clean:
51 (cd lib && cabal clean)
52 cli/clean:
53 (cd cli && cabal clean)
54 web/clean:
55 (cd web && cabal clean)
56
57 #
58 ## test
59 ###
60 test: lib/test cli/test web/test
61 lib/test:
62 (cd lib && cabal test --show-details=always $(CABAL_FLAGS) $(CABAL_TEST_FLAGS))
63 cli/test:
64 (cd cli && cabal test --show-details=always $(CABAL_FLAGS) $(CABAL_TEST_FLAGS))
65 web/test:
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
69
70
71 #
72 ## doc
73 ###
74 .PHONY: doc
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) %
78
79
80 lib/doc:
81 (cd lib && cabal haddock --hyperlink-source $(CABAL_FLAGS) $(CABAL_HADDOCK_FLAGS))
82 cli/doc:
83 (cd cli && cabal haddock --hyperlink-source $(CABAL_FLAGS) $(CABAL_HADDOCK_FLAGS))
84 web/doc:
85 (cd web && cabal haddock --hyperlink-source $(CABAL_FLAGS) $(CABAL_HADDOCK_FLAGS))
86 doc/%: .
87 $(MAKE) -C doc $*
88
89 #
90 ## dev
91 ###
92 %/dev: CABAL_INSTALL_FLAGS+=-fdev
93 %/dev: %
94
95
96 #
97 ## prof
98 ###
99 .PHONY: prof
100 prof: $(foreach command,$(HCOMPTA_COMMANDS),prof/$(command))
101
102 prof/commit/$(commit):
103 mkdir -p "$@"
104
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)
107
108
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)
111 mv \
112 $(CABAL_SANDBOX)/bin/hcompta-cli \
113 $(CABAL_SANDBOX)/bin/hcompta-cli-prof
114
115 define prof/command
116
117 prof/clean: prof/$(command)/clean
118
119 prof/%.ledger/$(command)/clean: \
120 $(foreach hC,$(GHC_PROF_CATEGORIES), \
121 prof/%.ledger/$(command)/$(hC)/clean \
122 )
123 $$(call rmw, \
124 prof/$$*.ledger.$(command) \
125 )
126
127 endef
128
129 define prof/command/hC
130
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
135
136
137 prof/%.ledger.$(command): \
138 prof/commit/$$(commit)/%.ledger.$(command).$(hC).hs
139
140 prof/commit/$$(commit)/%.ledger.$(command).$(hC).hp \
141 prof/%.ledger.$(command): \
142 $$(HCOMPTA_CLI_PROF) \
143 prof/%.ledger \
144 | prof/commit/$$(commit)
145 GHCRTS=' \
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 \
151 -p \
152 $$(GHCRTS)' \
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
158
159 prof/$(command)/$(hC): \
160 $(addsuffix /$(command)/$(hC),$(wildcard prof/*.ledger))
161 prof/$(command)/$(hC)/clean:
162 $$(call rmw, \
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 \
168 )
169 prof/%.ledger/$(command)/$(hC)/clean:
170 $$(call rmw, \
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 \
176 )
177
178 endef
179
180 prof/%.ledger/clean: \
181 $(foreach command,$(HCOMPTA_COMMANDS), \
182 prof/%.ledger/$(command)/clean \
183 )
184
185
186 $(foreach command,$(HCOMPTA_COMMANDS), \
187 $(eval $(call prof/command)) \
188 $(foreach hC,$(GHC_PROF_CATEGORIES), \
189 $(eval $(call prof/command/hC)) ))
190
191 %.hC.hp: $(foreach hC,$(GHC_PROF_CATEGORIES),%.$(hC).hp)
192
193 %.hC.ps: $(foreach hC,$(GHC_PROF_CATEGORIES),%.$(hC).ps)
194
195 %.ps: %.hp
196 (cd $(@D) && hp2ps -b -c -e$(GHC_PROF_PS_WIDTH) -g $(notdir $*.hp))
197
198 #prof/%.ledger/clean:
199 # $(call rmw, \
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 \
208 # )))
209 # $(call rmdirw,prof/commit/$(commit))
210
211 #
212 ## not-threaded
213 ###
214 %/not-threaded: CABAL_INSTALL_FLAGS+=-f-threaded
215 %/not-threaded: %
216
217
218 #
219 ## sandbox
220 ###
221 $(CABAL_SANDBOX):
222 cabal sandbox --sandbox="$@" init $(CABAL_FLAGS) $(CABAL_SANDBOX_FLAGS)
223
224 %/sandbox: GHC_PKG:=cabal sandbox hc-pkg
225 %/sandbox: %
226
227
228 #
229 ## ghc-pkg
230 ###
231
232 unregister: $(addsuffix /unregister,web cli lib)
233
234 %/unregister:
235 if $(GHC_PKG) list hcompta-$* | grep -q '^ * hcompta-$*-' ; \
236 then $(GHC_PKG) unregister hcompta-$* ; \
237 fi