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