GHC_PROF_PS_WIDTH:=11in
GHC_PROF_RATE:=0.1
GHC_PROF_CC_LENGTH:=50
-STACK_ROOT=$(shell stack path --local-install-root)
+STACK_ROOT:=$(shell stack path --local-install-root)
TCT_COMMANDS:=html5
TCT_INPUTS:=tct
TCT_PRINT_PROF=$(STACK_ROOT)/bin/tct-print
+
commit:=$(shell if which git >/dev/null; then git describe --long --always; else echo COMMIT; fi)
+if_arg=$(if $2,$1 $2)
+rmw=$(call if_arg,rm,$(wildcard $1))
+rmdirw=$(call if_arg,rmdir -p --ignore-fail-on-non-empty,$(wildcard $1))
.PHONY: $(TCT_PRINT_PROF)
$(TCT_PRINT_PROF):
prof: $(addprefix prof/,$(TCT_COMMANDS))
define prof/command
+tests:=$(wildcard test/$(command)/*.tct)
prof/clean: prof/$(command)/clean
-prof/$(command)/%/clean: $(foreach hC,$(GHC_PROF_CATEGORIES),prof/$(command)/%/$(hC)/clean)
+prof/$(command)/clean:
+ $$(call rmw, prof/$(command)/$(commit)/*.out)
+ $$(call rmdirw,prof/$(command)/$(commit))
+prof/$(command)/%/clean: \
+ $(foreach hC,$(GHC_PROF_CATEGORIES),prof/$(command)/%/$(hC)/clean)
$$(call rmw,prof/$(command)/$$*)
-prof/commit/$$(commit)/$$(command):
+prof/$(command)/$(commit):
mkdir -p "$$@"
endef
.PHONY: prof/$(command)
prof/$(command): prof/$(command)/$(hC)
prof/$(command)/clean: prof/$(command)/$(hC)/clean
-prof/$(command)/$(hC): $(addsuffix /$(hC),$(wildcard prof/$(command)/*))
+
+prof/$(command)/$(hC): $(patsubst test/%,prof/%/$(hC),$(tests))
+.PRECIOUS: $(patsubst test/$(command)/%, \
+ prof/$(command)/$(commit)/%.$(hC).hp, \
+ $(tests))
+.PRECIOUS: $(patsubst test/$(command)/%, \
+ prof/$(command)/$(commit)/%.$(hC).ps, \
+ $(tests))
prof/$(command)/$(hC)/clean:
$$(call rmw, \
- prof/commit/$$(commit)/$(command)/*.$(hC).aux \
- prof/commit/$$(commit)/$(command)/*.$(hC).hp \
- prof/commit/$$(commit)/$(command)/*.$(hC).prof \
- prof/commit/$$(commit)/$(command)/*.$(hC).ps \
- prof/commit/$$(commit)/$(command)/*.$(hC).stats )
-
-.PHONY: prof/$(command)/%
-prof/$(command)/%: prof/$(command)/%/$(hC)
-prof/$(command)/%: prof/commit/$$(commit)/$(command)/%.$(hC).hs
-prof/$(command)/%/$(hC): prof/commit/$$(commit)/$(command)/%.$(hC).ps
+ prof/$(command)/$(commit)/*.$(hC).aux \
+ prof/$(command)/$(commit)/*.$(hC).hp \
+ prof/$(command)/$(commit)/*.$(hC).prof \
+ prof/$(command)/$(commit)/*.$(hC).ps \
+ prof/$(command)/$(commit)/*.$(hC).stats )
+
+prof/$(command)/%: prof/$(command)/%/$(hC) \
+ prof/$(command)/$(commit)/%.$(hC).hs
+prof/$(command)/%/$(hC): prof/$(command)/$(commit)/%.$(hC).ps
-prof/commit/$$(commit)/$(command)/%.$(hC).hp \
+prof/$(command)/$(commit)/%.$(hC).prof \
+prof/$(command)/$(commit)/%.$(hC).hp \
prof/$(command)/%.$(command): \
$$(TCT_PRINT_PROF) \
- prof/$(command)/% \
+ test/$(command)/% \
$(TCT_PRINT_PROF) \
- | prof/commit/$$(commit)/$$(command)
+ | prof/$(command)/$(commit)
GHCRTS=' \
-$(hC)$$(GHC_PROF_$(hC)) \
-i$$(GHC_PROF_RATE) \
-L$$(GHC_PROF_CC_LENGTH) \
$$(if $$(GHC_PROF_CPUS),-N$$(GHC_PROF_CPUS)) \
- -tprof/commit/$(commit)/$(command)/$$*.$(hC).stats \
+ -tprof/$(command)/$(commit)/$$*.$(hC).stats \
-p \
$$(GHCRTS)' \
$$(TCT_PRINT_PROF) $$(TCT_FLAGS) \
- $(command) $$(TCT_COMMAND_FLAGS) prof/$(command)/$$* \
- >prof/$(command)/$$*.$(command)
- mv $(notdir $(TCT_PRINT_PROF)).hp prof/commit/$(commit)/$(command)/$$*.$(hC).hp
- mv $(notdir $(TCT_PRINT_PROF)).prof prof/commit/$(commit)/$(command)/$$*.$(hC).prof
+ $(command) $$(TCT_COMMAND_FLAGS) test/$(command)/$$* \
+ >prof/$(command)/$(commit)/$$*.out
+ mv $(notdir $(TCT_PRINT_PROF)).hp prof/$(command)/$(commit)/$$*.$(hC).hp
+ mv $(notdir $(TCT_PRINT_PROF)).prof prof/$(command)/$(commit)/$$*.$(hC).prof
prof/$(command)/%/$(hC)/clean:
$$(call rmw, \
- prof/commit/$$(commit)/$(command)/$$*.$(hC).aux \
- prof/commit/$$(commit)/$(command)/$$*.$(hC).hp \
- prof/commit/$$(commit)/$(command)/$$*.$(hC).prof \
- prof/commit/$$(commit)/$(command)/$$*.$(hC).ps \
- prof/commit/$$(commit)/$(command)/$$*.$(hC).stats )
+ prof/$(command)/$(commit)/$$*.$(hC).aux \
+ prof/$(command)/$(commit)/$$*.$(hC).hp \
+ prof/$(command)/$(commit)/$$*.$(hC).prof \
+ prof/$(command)/$(commit)/$$*.$(hC).ps \
+ prof/$(command)/$(commit)/$$*.$(hC).stats )
endef
%.hC.ps: $(foreach hC,$(GHC_PROF_CATEGORIES),%.$(hC).ps)
-%.ps: %.hp
+%.ps %.aux: %.hp
(cd $(@D) && hp2ps -b -c -e$(GHC_PROF_PS_WIDTH) -g $(notdir $*.hp))