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