]> Git — Sourcephile - comptalang.git/blob - GNUmakefile
Polissage : CLI.Command.* : --help.
[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 $(CABAL_FLAGS) update $(CABAL_UPDATE_FLAGS)
36 cabal $(CABAL_FLAGS) install -v $(CABAL_INSTALL_FLAGS) cabal
37 .PHONY: lib cli web
38 lib lib/install: cli/unregister web/unregister cli/unregister/sandbox web/unregister/sandbox
39 cabal $(CABAL_FLAGS) install -v $(CABAL_INSTALL_FLAGS) ./lib
40 cli cli/install:
41 cabal $(CABAL_FLAGS) install -v $(CABAL_INSTALL_FLAGS) ./cli
42 web web/install:
43 cabal $(CABAL_FLAGS) install -v $(CABAL_INSTALL_FLAGS) alex happy
44 cabal $(CABAL_FLAGS) install -v $(CABAL_INSTALL_FLAGS) ./web
45
46 %/recomp: CABAL_INSTALL_FLAGS+=--ghc-options -fforce-recomp
47 %/recomp: %
48
49
50 #
51 ## clean
52 ###
53 clean: lib/clean cli/clean web/clean doc/clean
54 lib/clean:
55 (cd lib && cabal clean)
56 cli/clean:
57 (cd cli && cabal clean)
58 web/clean:
59 (cd web && cabal clean)
60
61 #
62 ## test
63 ###
64 test: lib/test cli/test web/test
65 lib/test:
66 (cd lib && cabal $(CABAL_FLAGS) test --show-details=always $(CABAL_TEST_FLAGS))
67 cli/test:
68 (cd cli && cabal $(CABAL_FLAGS) test --show-details=always $(CABAL_TEST_FLAGS))
69 web/test:
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
73
74
75 #
76 ## doc
77 ###
78 .PHONY: doc
79 doc: doc/xhtml lib/doc cli/doc web/doc
80 %/prof: CABAL_INSTALL_FLAGS+=-fprof --enable-library-profiling --enable-executable-profiling
81 %/prof: $(CABAL_SANDBOX) %
82
83
84 lib/doc:
85 (cd lib && cabal $(CABAL_FLAGS) haddock --hyperlink-source $(CABAL_HADDOCK_FLAGS))
86 cli/doc:
87 (cd cli && cabal $(CABAL_FLAGS) haddock --hyperlink-source $(CABAL_HADDOCK_FLAGS))
88 web/doc:
89 (cd web && cabal $(CABAL_FLAGS) haddock --hyperlink-source $(CABAL_HADDOCK_FLAGS))
90 doc/%: .
91 $(MAKE) -C doc $*
92
93 #
94 ## dev
95 ###
96 %/dev: CABAL_INSTALL_FLAGS+=-fdev
97 %/dev: %
98
99
100 #
101 ## dump
102 ###
103 %/dump: CABAL_INSTALL_FLAGS+=-fdump
104 %/dump: %
105
106
107 #
108 ## prof
109 ###
110 .PHONY: prof
111 prof: $(foreach command,$(HCOMPTA_COMMANDS),prof/$(command))
112
113 prof/commit/$(commit):
114 mkdir -p "$@"
115
116 lib/install/prof: CABAL_INSTALL_FLAGS+=-fprof --enable-library-profiling
117 lib/install/prof: cli/unregister/sandbox lib/install | $(CABAL_SANDBOX)
118
119
120 cli/install/prof: CABAL_INSTALL_FLAGS+=-fprof --enable-library-profiling --enable-executable-profiling
121 cli/install/prof: cli/install | $(CABAL_SANDBOX)
122 mv \
123 $(CABAL_SANDBOX)/bin/hcompta-cli \
124 $(CABAL_SANDBOX)/bin/hcompta-cli-prof
125
126 define prof/command
127
128 prof/clean: prof/$(command)/clean
129
130 prof/%.ledger/$(command)/clean: \
131 $(foreach hC,$(GHC_PROF_CATEGORIES), \
132 prof/%.ledger/$(command)/$(hC)/clean \
133 )
134 $$(call rmw, \
135 prof/$$*.ledger.$(command) \
136 )
137
138 endef
139
140 define prof/command/hC
141
142 prof/$(command): prof/$(command)/$(hC)
143 prof/$(command)/clean: prof/$(command)/$(hC)/clean
144 prof/%.ledger/$(command): prof/%.ledger.$(command)/$(hC)
145 prof/%.ledger/$(command)/$(hC): prof/commit/$$(commit)/%.ledger.$(command).$(hC).ps
146
147
148 prof/%.ledger.$(command): \
149 prof/commit/$$(commit)/%.ledger.$(command).$(hC).hs
150
151 prof/commit/$$(commit)/%.ledger.$(command).$(hC).hp \
152 prof/%.ledger.$(command): \
153 $$(HCOMPTA_CLI_PROF) \
154 prof/%.ledger \
155 | prof/commit/$$(commit)
156 GHCRTS=' \
157 -$(hC)$$(GHC_PROF_$(hC)) \
158 -i$$(GHC_PROF_RATE) \
159 -L$$(GHC_PROF_CC_LENGTH) \
160 -N$$(GHC_PROF_CPUS) \
161 -tprof/commit/$(commit)/$$*.ledger.$(command).$(hC).stats \
162 -p \
163 $$(GHCRTS)' \
164 $$(HCOMPTA_CLI_PROF) $$(HCOMPTA_FLAGS) \
165 $(command) $$(HCOMPTA_COMMAND_FLAGS) $$(filter %.ledger,$$^) \
166 >prof/$$*.ledger.$(command)
167 mv $(notdir $(HCOMPTA_CLI_PROF)).hp prof/commit/$(commit)/$$*.ledger.$(command).$(hC).hp
168 mv $(notdir $(HCOMPTA_CLI_PROF)).prof prof/commit/$(commit)/$$*.ledger.$(command).$(hC).prof
169
170 prof/$(command)/$(hC): \
171 $(addsuffix /$(command)/$(hC),$(wildcard prof/*.ledger))
172 prof/$(command)/$(hC)/clean:
173 $$(call rmw, \
174 prof/commit/$$(commit)/*.ledger.$(command).$(hC).aux \
175 prof/commit/$$(commit)/*.ledger.$(command).$(hC).hp \
176 prof/commit/$$(commit)/*.ledger.$(command).$(hC).prof \
177 prof/commit/$$(commit)/*.ledger.$(command).$(hC).ps \
178 prof/commit/$$(commit)/*.ledger.$(command).$(hC).stats \
179 )
180 prof/%.ledger/$(command)/$(hC)/clean:
181 $$(call rmw, \
182 prof/commit/$$(commit)/$$*.ledger.$(command).$(hC).aux \
183 prof/commit/$$(commit)/$$*.ledger.$(command).$(hC).hp \
184 prof/commit/$$(commit)/$$*.ledger.$(command).$(hC).prof \
185 prof/commit/$$(commit)/$$*.ledger.$(command).$(hC).ps \
186 prof/commit/$$(commit)/$$*.ledger.$(command).$(hC).stats \
187 )
188
189 endef
190
191 prof/%.ledger/clean: \
192 $(foreach command,$(HCOMPTA_COMMANDS), \
193 prof/%.ledger/$(command)/clean )
194
195
196 $(foreach command,$(HCOMPTA_COMMANDS), \
197 $(eval $(call prof/command)) \
198 $(foreach hC,$(GHC_PROF_CATEGORIES), \
199 $(eval $(call prof/command/hC)) ))
200
201 %.hC.hp: $(foreach hC,$(GHC_PROF_CATEGORIES),%.$(hC).hp)
202
203 %.hC.ps: $(foreach hC,$(GHC_PROF_CATEGORIES),%.$(hC).ps)
204
205 %.ps: %.hp
206 (cd $(@D) && hp2ps -b -c -e$(GHC_PROF_PS_WIDTH) -g $(notdir $*.hp))
207
208 #
209 ## not-threaded
210 ###
211 %/not-threaded: CABAL_INSTALL_FLAGS+=-f-threaded
212 %/not-threaded: %
213
214
215 #
216 ## ghc-pkg
217 ###
218 unregister: $(addsuffix /unregister,web cli lib)
219
220 %/unregister: .
221 if $(GHC_PKG) list hcompta-$* | grep -q '^ * hcompta-$*-' ; \
222 then $(GHC_PKG) unregister hcompta-$* ; \
223 fi
224
225 %/unregister/sandbox: GHC_PKG:=cabal sandbox hc-pkg
226 %/unregister/sandbox: .
227 if $(GHC_PKG) list hcompta-$* | grep -q '^ * hcompta-$*-' ; \
228 then $(GHC_PKG) unregister hcompta-$* ; \
229 fi
230
231 #
232 ## sandbox
233 ###
234 $(CABAL_SANDBOX):
235 cabal $(CABAL_FLAGS) sandbox --sandbox="$@" $(CABAL_SANDBOX_FLAGS) init
236
237 %/sandbox: GHC_PKG:=cabal sandbox hc-pkg
238 %/sandbox: %
239
240
241 #
242 ## stats
243 ###
244 .PHONY: stats
245 stats:
246 gitstats . $@