]> Git — Sourcephile - comptalang.git/blob - GNUmakefile
Modification : sépare hcompta-ledger de hcompta-lib.
[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-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)
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 $(HCOMPTA_INTERFACES:=/install)
34 cabal/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: \
39 cli/unregister \
40 web/unregister \
41 ledger/unregister \
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: \
47 cli/unregister \
48 web/unregister \
49 cli/unregister/sandbox \
50 web/unregister/sandbox
51 cabal $(CABAL_FLAGS) install -v $(CABAL_INSTALL_FLAGS) ./ledger
52 cli cli/install:
53 cabal $(CABAL_FLAGS) install -v $(CABAL_INSTALL_FLAGS) ./cli
54 web web/install:
55 cabal $(CABAL_FLAGS) install -v $(CABAL_INSTALL_FLAGS) alex happy
56 cabal $(CABAL_FLAGS) install -v $(CABAL_INSTALL_FLAGS) ./web
57
58 %/recomp: CABAL_INSTALL_FLAGS+=--ghc-options -fforce-recomp
59 %/recomp: %
60
61
62 #
63 ## clean
64 ###
65 clean: lib/clean $(HCOMPTA_INTERFACES:=/clean)
66 lib/clean:
67 (cd lib && cabal clean)
68 ledger/clean:
69 (cd ledger && cabal clean)
70 cli/clean:
71 (cd cli && cabal clean)
72 web/clean:
73 (cd web && cabal clean)
74
75 #
76 ## test
77 ###
78 test: $(HCOMPTA_INTERFACES:=/test)
79 lib/test:
80 (cd lib && cabal $(CABAL_FLAGS) test --show-details=always $(CABAL_TEST_FLAGS))
81 ledger/test:
82 (cd ledger && cabal $(CABAL_FLAGS) test --show-details=always $(CABAL_TEST_FLAGS))
83 cli/test:
84 (cd cli && cabal $(CABAL_FLAGS) test --show-details=always $(CABAL_TEST_FLAGS))
85 web/test:
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
89
90
91 #
92 ## doc
93 ###
94 .PHONY: doc
95 doc: doc/xhtml $(HCOMPTA_INTERFACES:=/doc)
96
97 lib/doc:
98 (cd lib && cabal $(CABAL_FLAGS) haddock --hyperlink-source $(CABAL_HADDOCK_FLAGS))
99 ledger/doc:
100 (cd ledger && cabal $(CABAL_FLAGS) haddock --hyperlink-source $(CABAL_HADDOCK_FLAGS))
101 cli/doc:
102 (cd cli && cabal $(CABAL_FLAGS) haddock --hyperlink-source $(CABAL_HADDOCK_FLAGS))
103 web/doc:
104 (cd web && cabal $(CABAL_FLAGS) haddock --hyperlink-source $(CABAL_HADDOCK_FLAGS))
105 doc/%: .
106 $(MAKE) -C doc $*
107
108 #
109 ## dev
110 ###
111 %/dev: CABAL_INSTALL_FLAGS+=-fdev
112 %/dev: %
113
114
115 #
116 ## dump
117 ###
118 %/dump: CABAL_INSTALL_FLAGS+=-fdump
119 %/dump: %
120
121
122 #
123 ## hlint
124 ###
125 hlint: $(HCOMPTA_INTERFACES:=/hlint.html)
126 %/hlint: %/hlint.html
127
128 %/hlint.html: .
129 if hlint \
130 -i 'Redundant $$' \
131 -i 'Redundant bracket' \
132 -i 'Redundant do' \
133 -i 'Redundant lambda' \
134 -i "Use camelCase" \
135 -i 'Use if' \
136 -i 'Use String' \
137 -i 'Use string literal' \
138 --quiet --report="$@" \
139 "$*"/Hcompta; \
140 then rm -f "$@"; \
141 else echo; echo "BROWSE REPORT AT: file://$(abspath $@)"; fi
142
143 #
144 ## prof
145 ###
146 .PHONY: prof
147 prof: $(addprefix prof/,$(HCOMPTA_COMMANDS))
148
149 prof/commit/$(commit):
150 mkdir -p "$@"
151
152 lib/install/prof: CABAL_INSTALL_FLAGS+=-fprof --enable-library-profiling
153 lib/install/prof: cli/unregister/sandbox lib/install | $(CABAL_SANDBOX)
154
155
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)
158
159
160 cli/install/prof: CABAL_INSTALL_FLAGS+=-fprof --enable-library-profiling --enable-executable-profiling
161 cli/install/prof: cli/install | $(CABAL_SANDBOX)
162 mv \
163 $(CABAL_SANDBOX)/bin/hcompta \
164 $(HCOMPTA_CLI_PROF)
165
166 define prof/command
167
168 prof/clean: prof/$(command)/clean
169
170 prof/%.ledger/$(command)/clean: \
171 $(foreach hC,$(GHC_PROF_CATEGORIES), \
172 prof/%.ledger/$(command)/$(hC)/clean \
173 )
174 $$(call rmw, \
175 prof/$$*.ledger.$(command) \
176 )
177
178 endef
179
180 define prof/command/hC
181
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
186
187
188 prof/%.ledger.$(command): \
189 prof/commit/$$(commit)/%.ledger.$(command).$(hC).hs
190
191 prof/commit/$$(commit)/%.ledger.$(command).$(hC).hp \
192 prof/%.ledger.$(command): \
193 $$(HCOMPTA_CLI_PROF) \
194 prof/%.ledger \
195 | prof/commit/$$(commit)
196 GHCRTS=' \
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 \
202 -p \
203 $$(GHCRTS)' \
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
209
210 prof/$(command)/$(hC): \
211 $(addsuffix /$(command)/$(hC),$(wildcard prof/*.ledger))
212 prof/$(command)/$(hC)/clean:
213 $$(call rmw, \
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 \
219 )
220 prof/%.ledger/$(command)/$(hC)/clean:
221 $$(call rmw, \
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 \
227 )
228
229 endef
230
231 prof/%.ledger/clean: \
232 $(foreach command,$(HCOMPTA_COMMANDS), \
233 prof/%.ledger/$(command)/clean )
234
235
236 $(foreach command,$(HCOMPTA_COMMANDS), \
237 $(eval $(call prof/command)) \
238 $(foreach hC,$(GHC_PROF_CATEGORIES), \
239 $(eval $(call prof/command/hC)) ))
240
241 %.hC.hp: $(foreach hC,$(GHC_PROF_CATEGORIES),%.$(hC).hp)
242
243 %.hC.ps: $(foreach hC,$(GHC_PROF_CATEGORIES),%.$(hC).ps)
244
245 %.ps: %.hp
246 (cd $(@D) && hp2ps -b -c -e$(GHC_PROF_PS_WIDTH) -g $(notdir $*.hp))
247
248 #
249 ## not-threaded
250 ###
251 %/not-threaded: CABAL_INSTALL_FLAGS+=-f-threaded
252 %/not-threaded: %
253
254
255 #
256 ## ghc-pkg
257 ###
258 unregister: $(HCOMPTA_INTERFACES:=/unregister)
259
260 %/unregister: .
261 if $(GHC_PKG) list hcompta-$* | grep -q '^ * hcompta-$*-' ; \
262 then $(GHC_PKG) unregister hcompta-$* ; \
263 fi
264
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-$* ; \
269 fi
270
271 #
272 ## sandbox
273 ###
274 $(CABAL_SANDBOX):
275 cabal $(CABAL_FLAGS) sandbox --sandbox="$@" $(CABAL_SANDBOX_FLAGS) init
276
277 %/sandbox: GHC_PKG:=cabal sandbox hc-pkg
278 %/sandbox: %
279
280
281 #
282 ## stats
283 ###
284 .PHONY: stats
285 stats:
286 gitstats . $@