]> Git — Sourcephile - doclang.git/blob - GNUmakefile
Add GNUmakefile profiling targets.
[doclang.git] / GNUmakefile
1 CABAL := $(shell find . -name '*.cabal' -print -quit)
2 HS := $(shell find . -name '*.hs')
3
4 all: build
5
6 build:
7 stack $(STACK_FLAGS) build $(STACK_BUILD_FLAGS)
8
9 .PHONY: test
10 test:
11 ! grep -q '^Test-Suite\>' $(CABAL) || \
12 { stack $(STACK_FLAGS) test $(STACK_TEST_FLAGS); }
13
14 clean:
15 stack $(STACK_FLAGS) clean $(STACK_CLEAN_FLAGS)
16 cleaner:
17 stack $(STACK_FLAGS) clean --full $(STACK_CLEAN_FLAGS)
18
19 %/fast: override STACK_BUILD_FLAGS+=--fast
20 %/fast: override STACK_HADDOCK_FLAGS+=--fast
21 %/fast: override STACK_TEST_FLAGS+=--fast
22 %/fast: %
23
24
25 doc:
26 stack $(STACK_FLAGS) haddock $(STACK_HADDOCK_FLAGS)
27 %.html: %.md
28 markdown $*.md >$*.html
29 %.html/view: %.html
30 sensible-browser $*.html
31
32 HLint.hs: $(HS)
33 sed -i -e '/^-- BEGIN: generated hints/,/^-- END: Generated by hlint/d' HLint.hs
34 echo '-- BEGIN: generated hints' >> HLint.hs
35 hlint --find . | grep '^'infix | sort -u >> HLint.hs
36 echo '-- END: generated hints' >> HLint.hs
37
38 lint: HLint.hs $(HS)
39 if hlint --quiet --report=hlint.html -XNoCPP \
40 $(shell cabal-cargs --format=ghc --only=default_extensions --sourcefile=$(CABAL)) $(HLINT_FLAGS) .; \
41 then rm -f hlint.html; \
42 else sensible-browser hlint.html & fi
43
44 tag:
45 name=$$(sed -ne 's/^name: *\(.*\)/\1/p' "$(CABAL)"); \
46 version=$$(sed -ne 's/^version: *\(.*\)/\1/p' "$(CABAL)"); \
47 git tag --merged | grep -Fqx "$$name-$$version" || \
48 git tag -f -s -m "$$name v$$version" $$name-$$version
49
50 tar:
51 stack $(STACK_FLAGS) sdist $(STACK_SDIST_FLAGS)
52 upload:
53 LANG=C stack $(STACK_FLAGS) upload $(STACK_UPLOAD_FLAGS) .
54
55 .PHONY: stats
56 stats:
57 gitstats . $@
58 stats/view: stats
59 sensible-browser stats/index.html
60
61 #
62 ## prof
63 ###
64 GHC_PROF_CATEGORIES:=hc hm hd hy hr hb
65 GHC_PROF_CPUS:=
66 GHC_PROF_PS_WIDTH:=11in
67 GHC_PROF_RATE:=0.1
68 GHC_PROF_CC_LENGTH:=50
69 STACK_ROOT:=$(shell stack path --local-install-root)
70
71 TCT_COMMANDS:=html5
72 TCT_INPUTS:=tct
73 TCT_PRINT_PROF=$(STACK_ROOT)/bin/tct-print
74
75 commit:=$(shell if which git >/dev/null; then git describe --long --always; else echo COMMIT; fi)
76 if_arg=$(if $2,$1 $2)
77 rmw=$(call if_arg,rm,$(wildcard $1))
78 rmdirw=$(call if_arg,rmdir -p --ignore-fail-on-non-empty,$(wildcard $1))
79
80 .PHONY: $(TCT_PRINT_PROF)
81 $(TCT_PRINT_PROF):
82 stack $(STACK_FLAGS) build --profile --flag tct:prof $(STACK_BUILD_FLAGS)
83
84 .PHONY: prof
85 prof: $(addprefix prof/,$(TCT_COMMANDS))
86
87 define prof/command
88 tests:=$(wildcard test/$(command)/*.tct)
89 prof/clean: prof/$(command)/clean
90 prof/$(command)/clean:
91 $$(call rmw, prof/$(command)/$(commit)/*.out)
92 $$(call rmdirw,prof/$(command)/$(commit))
93 prof/$(command)/%/clean: \
94 $(foreach hC,$(GHC_PROF_CATEGORIES),prof/$(command)/%/$(hC)/clean)
95 $$(call rmw,prof/$(command)/$$*)
96
97 prof/$(command)/$(commit):
98 mkdir -p "$$@"
99
100 endef
101
102 define prof/command/hC
103 .PHONY: prof/$(command)
104 prof/$(command): prof/$(command)/$(hC)
105 prof/$(command)/clean: prof/$(command)/$(hC)/clean
106
107 prof/$(command)/$(hC): $(patsubst test/%,prof/%/$(hC),$(tests))
108 .PRECIOUS: $(patsubst test/$(command)/%, \
109 prof/$(command)/$(commit)/%.$(hC).hp, \
110 $(tests))
111 .PRECIOUS: $(patsubst test/$(command)/%, \
112 prof/$(command)/$(commit)/%.$(hC).ps, \
113 $(tests))
114 prof/$(command)/$(hC)/clean:
115 $$(call rmw, \
116 prof/$(command)/$(commit)/*.$(hC).aux \
117 prof/$(command)/$(commit)/*.$(hC).hp \
118 prof/$(command)/$(commit)/*.$(hC).prof \
119 prof/$(command)/$(commit)/*.$(hC).ps \
120 prof/$(command)/$(commit)/*.$(hC).stats )
121
122 prof/$(command)/%: prof/$(command)/%/$(hC) \
123 prof/$(command)/$(commit)/%.$(hC).hs
124 prof/$(command)/%/$(hC): prof/$(command)/$(commit)/%.$(hC).ps
125
126
127 prof/$(command)/$(commit)/%.$(hC).prof \
128 prof/$(command)/$(commit)/%.$(hC).hp \
129 prof/$(command)/%.$(command): \
130 $$(TCT_PRINT_PROF) \
131 test/$(command)/% \
132 $(TCT_PRINT_PROF) \
133 | prof/$(command)/$(commit)
134 GHCRTS=' \
135 -$(hC)$$(GHC_PROF_$(hC)) \
136 -i$$(GHC_PROF_RATE) \
137 -L$$(GHC_PROF_CC_LENGTH) \
138 $$(if $$(GHC_PROF_CPUS),-N$$(GHC_PROF_CPUS)) \
139 -tprof/$(command)/$(commit)/$$*.$(hC).stats \
140 -p \
141 $$(GHCRTS)' \
142 $$(TCT_PRINT_PROF) $$(TCT_FLAGS) \
143 $(command) $$(TCT_COMMAND_FLAGS) test/$(command)/$$* \
144 >prof/$(command)/$(commit)/$$*.out
145 mv $(notdir $(TCT_PRINT_PROF)).hp prof/$(command)/$(commit)/$$*.$(hC).hp
146 mv $(notdir $(TCT_PRINT_PROF)).prof prof/$(command)/$(commit)/$$*.$(hC).prof
147
148 prof/$(command)/%/$(hC)/clean:
149 $$(call rmw, \
150 prof/$(command)/$(commit)/$$*.$(hC).aux \
151 prof/$(command)/$(commit)/$$*.$(hC).hp \
152 prof/$(command)/$(commit)/$$*.$(hC).prof \
153 prof/$(command)/$(commit)/$$*.$(hC).ps \
154 prof/$(command)/$(commit)/$$*.$(hC).stats )
155
156 endef
157
158 $(foreach command,$(TCT_COMMANDS), \
159 $(eval $(call prof/command)) \
160 $(foreach hC,$(GHC_PROF_CATEGORIES), \
161 $(eval $(call prof/command/hC)) ))
162
163 %.hC.hp: $(foreach hC,$(GHC_PROF_CATEGORIES),%.$(hC).hp)
164
165 %.hC.ps: $(foreach hC,$(GHC_PROF_CATEGORIES),%.$(hC).ps)
166
167 %.ps %.aux: %.hp
168 (cd $(@D) && hp2ps -b -c -e$(GHC_PROF_PS_WIDTH) -g $(notdir $*.hp))
169