1 CABAL := $(shell find . -maxdepth 1 -name '*.cabal' -print -quit)
 
   6         stack $(STACK_FLAGS) build $(STACK_BUILD_FLAGS)
 
  10         ! grep -q '^Test-Suite\>' $(CABAL) || \
 
  11         { stack $(STACK_FLAGS) test $(STACK_TEST_FLAGS); }
 
  14         stack $(STACK_FLAGS) clean $(STACK_CLEAN_FLAGS)
 
  16         stack $(STACK_FLAGS) clean --full $(STACK_CLEAN_FLAGS)
 
  18 %/fast: override STACK_BUILD_FLAGS+=--fast
 
  19 %/fast: override STACK_HADDOCK_FLAGS+=--fast
 
  20 %/fast: override STACK_TEST_FLAGS+=--fast
 
  24 %/debug: override STACK_BUILD_FLAGS+=--flag $(CABAL:.cabal=):debug
 
  25 %/debug: override STACK_TEST_FLAGS+=--flag $(CABAL:.cabal=):debug
 
  30         stack $(STACK_FLAGS) haddock $(STACK_HADDOCK_FLAGS)
 
  32         markdown $*.md >$*.html
 
  34         sensible-browser $*.html
 
  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
 
  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
 
  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
 
  55         stack $(STACK_FLAGS) sdist $(STACK_SDIST_FLAGS)
 
  57         LANG=C stack $(STACK_FLAGS) upload $(STACK_UPLOAD_FLAGS) .
 
  63         sensible-browser stats/index.html
 
  68 GHC_PROF_CATEGORIES:=hc hm hd hy hr hb
 
  70 GHC_PROF_PS_WIDTH:=11in
 
  72 GHC_PROF_CC_LENGTH:=50
 
  73 STACK_ROOT:=$(shell stack path --local-install-root)
 
  77 TCT_PRINT_PROF=$(STACK_ROOT)/bin/tct-print
 
  79 commit:=$(shell if which git >/dev/null; then git describe --long --always; else echo COMMIT; fi)
 
  81 rmw=$(call if_arg,rm,$(wildcard $1))
 
  82 rmdirw=$(call if_arg,rmdir -p --ignore-fail-on-non-empty,$(wildcard $1))
 
  84 .PHONY: $(TCT_PRINT_PROF)
 
  86         stack $(STACK_FLAGS) build --profile --flag tct:prof $(STACK_BUILD_FLAGS)
 
  89 prof: $(addprefix prof/,$(TCT_COMMANDS))
 
  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)/$$*)
 
 101 prof/$(command)/$(commit):
 
 106 define prof/command/hC
 
 107 .PHONY: prof/$(command)
 
 108 prof/$(command):       prof/$(command)/$(hC)
 
 109 prof/$(command)/clean: prof/$(command)/$(hC)/clean
 
 111 prof/$(command)/$(hC): $(patsubst test/%,prof/%/$(hC),$(tests))
 
 112 .PRECIOUS: $(patsubst test/$(command)/%, \
 
 113                       prof/$(command)/$(commit)/%.$(hC).hp, \
 
 115 .PRECIOUS: $(patsubst test/$(command)/%, \
 
 116                       prof/$(command)/$(commit)/%.$(hC).ps, \
 
 118 prof/$(command)/$(hC)/clean:
 
 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 )
 
 126 prof/$(command)/%: prof/$(command)/%/$(hC) \
 
 127                    prof/$(command)/$(commit)/%.$(hC).hs
 
 128 prof/$(command)/%/$(hC): prof/$(command)/$(commit)/%.$(hC).ps
 
 131 prof/$(command)/$(commit)/%.$(hC).prof \
 
 132 prof/$(command)/$(commit)/%.$(hC).hp \
 
 133 prof/$(command)/%.$(command): \
 
 137  | prof/$(command)/$(commit)
 
 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 \
 
 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
 
 152 prof/$(command)/%/$(hC)/clean:
 
 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 )
 
 162 $(foreach command,$(TCT_COMMANDS), \
 
 163  $(eval $(call prof/command)) \
 
 164  $(foreach hC,$(GHC_PROF_CATEGORIES), \
 
 165   $(eval $(call prof/command/hC)) ))
 
 167 %.hC.hp: $(foreach hC,$(GHC_PROF_CATEGORIES),%.$(hC).hp)
 
 169 %.hC.ps: $(foreach hC,$(GHC_PROF_CATEGORIES),%.$(hC).ps)
 
 172         (cd $(@D) && hp2ps -b -c -e$(GHC_PROF_PS_WIDTH) -g $(notdir $*.hp))