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