Fix writing TCT to XML.
[doclang.git] / GNUmakefile
index 9c9eada27d5f212ad9f8995eb18129c5d3231526..dabdab471232408d4be1a4714f8161afa8c8c76c 100644 (file)
@@ -1,5 +1,4 @@
-CABAL := $(shell find . -name '*.cabal' -print -quit)
-HS := $(shell find . -name '*.hs')
+CABAL := $(shell find . -maxdepth 1 -name '*.cabal' -printf %f -quit)
 
 all: build
 
@@ -22,6 +21,11 @@ cleaner:
 %/fast: %
        
 
+%/debug: override STACK_BUILD_FLAGS+=--flag $(CABAL:.cabal=):debug
+%/debug: override STACK_TEST_FLAGS+=--flag $(CABAL:.cabal=):debug
+%/debug: %
+       
+
 doc:
        stack $(STACK_FLAGS) haddock $(STACK_HADDOCK_FLAGS)
 %.html: %.md
@@ -29,13 +33,13 @@ doc:
 %.html/view: %.html
        sensible-browser $*.html
 
-HLint.hs: $(HS)
+HLint.hs: $(shell find . -name '*.hs')
        sed -i -e '/^-- BEGIN: generated hints/,/^-- END: Generated by hlint/d' HLint.hs
        echo '-- BEGIN: generated hints' >> HLint.hs
        hlint --find . | grep '^'infix | sort -u >> HLint.hs
        echo '-- END: generated hints' >> HLint.hs
 
-lint: HLint.hs $(HS)
+lint: HLint.hs
        if hlint --quiet --report=hlint.html -XNoCPP \
         $(shell cabal-cargs --format=ghc --only=default_extensions --sourcefile=$(CABAL)) $(HLINT_FLAGS) .; \
        then rm -f hlint.html; \
@@ -57,3 +61,113 @@ stats:
        gitstats . $@
 stats/view: stats
        sensible-browser stats/index.html
+
+#
+##  prof
+###
+GHC_PROF_CATEGORIES:=hc hm hd hy hr hb
+GHC_PROF_CPUS:=
+GHC_PROF_PS_WIDTH:=11in
+GHC_PROF_RATE:=0.1
+GHC_PROF_CC_LENGTH:=50
+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):
+       stack $(STACK_FLAGS) build --profile --flag tct:prof $(STACK_BUILD_FLAGS)
+
+.PHONY: prof
+prof: $(addprefix prof/,$(TCT_COMMANDS))
+
+define prof/command
+tests:=$(wildcard test/$(command)/*.tct)
+prof/clean: prof/$(command)/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/$(command)/$(commit):
+       mkdir -p "$$@"
+
+endef
+
+define prof/command/hC
+.PHONY: prof/$(command)
+prof/$(command):       prof/$(command)/$(hC)
+prof/$(command)/clean: prof/$(command)/$(hC)/clean
+
+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/$(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/$(command)/$(commit)/%.$(hC).prof \
+prof/$(command)/$(commit)/%.$(hC).hp \
+prof/$(command)/%.$(command): \
+ $$(TCT_PRINT_PROF) \
+ test/$(command)/% \
+ $(TCT_PRINT_PROF) \
+ | 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/$(command)/$(commit)/$$*.$(hC).stats \
+        -p \
+        $$(GHCRTS)' \
+       $$(TCT_PRINT_PROF) $$(TCT_FLAGS) \
+        $(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/$(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
+
+$(foreach command,$(TCT_COMMANDS), \
+ $(eval $(call prof/command)) \
+ $(foreach hC,$(GHC_PROF_CATEGORIES), \
+  $(eval $(call prof/command/hC)) ))
+
+%.hC.hp: $(foreach hC,$(GHC_PROF_CATEGORIES),%.$(hC).hp)
+       
+%.hC.ps: $(foreach hC,$(GHC_PROF_CATEGORIES),%.$(hC).ps)
+       
+%.ps %.aux: %.hp
+       (cd $(@D) && hp2ps -b -c -e$(GHC_PROF_PS_WIDTH) -g $(notdir $*.hp))
+