1 CABAL := $(shell find . -name '*.cabal' -print -quit)
 
   2 HS := $(shell find . -name '*.hs')
 
   7         stack $(STACK_FLAGS) build $(STACK_BUILD_FLAGS)
 
  11         ! grep -q '^Test-Suite\>' $(CABAL) || \
 
  12         { stack $(STACK_FLAGS) test $(STACK_TEST_FLAGS); }
 
  15         stack $(STACK_FLAGS) clean $(STACK_CLEAN_FLAGS)
 
  17         stack $(STACK_FLAGS) clean --full $(STACK_CLEAN_FLAGS)
 
  19 %/fast: override STACK_BUILD_FLAGS+=--fast
 
  20 %/fast: override STACK_HADDOCK_FLAGS+=--fast
 
  21 %/fast: override STACK_TEST_FLAGS+=--fast
 
  26         stack $(STACK_FLAGS) haddock $(STACK_HADDOCK_FLAGS)
 
  28         markdown $*.md >$*.html
 
  30         sensible-browser $*.html
 
  33         sed -i -e '/^-- BEGIN: generated hints/,/^-- END: Generated by hlint/d' HLint.hs
 
  34         echo '-- BEGIN: generated hints' >> HLint.hs
 
  35         hlint --find . | grep '^'infix | sort -u >> HLint.hs
 
  36         echo '-- END: generated hints' >> HLint.hs
 
  39         if hlint --quiet --report=hlint.html -XNoCPP \
 
  40          $(shell cabal-cargs --format=ghc --only=default_extensions --sourcefile=$(CABAL)) $(HLINT_FLAGS) .; \
 
  41         then rm -f hlint.html; \
 
  42         else sensible-browser hlint.html & fi
 
  45         name=$$(sed -ne 's/^name: *\(.*\)/\1/p' "$(CABAL)"); \
 
  46         version=$$(sed -ne 's/^version: *\(.*\)/\1/p' "$(CABAL)"); \
 
  47         git tag --merged | grep -Fqx "$$name-$$version" || \
 
  48         git tag -f -s -m "$$name v$$version" $$name-$$version
 
  51         stack $(STACK_FLAGS) sdist $(STACK_SDIST_FLAGS)
 
  53         LANG=C stack $(STACK_FLAGS) upload $(STACK_UPLOAD_FLAGS) .
 
  59         sensible-browser stats/index.html
 
  64 GHC_PROF_CATEGORIES:=hc hm hd hy hr hb
 
  66 GHC_PROF_PS_WIDTH:=11in
 
  68 GHC_PROF_CC_LENGTH:=50
 
  69 STACK_ROOT:=$(shell stack path --local-install-root)
 
  73 TCT_PRINT_PROF=$(STACK_ROOT)/bin/tct-print
 
  75 commit:=$(shell if which git >/dev/null; then git describe --long --always; else echo COMMIT; fi)
 
  77 rmw=$(call if_arg,rm,$(wildcard $1))
 
  78 rmdirw=$(call if_arg,rmdir -p --ignore-fail-on-non-empty,$(wildcard $1))
 
  80 .PHONY: $(TCT_PRINT_PROF)
 
  82         stack $(STACK_FLAGS) build --profile --flag tct:prof $(STACK_BUILD_FLAGS)
 
  85 prof: $(addprefix prof/,$(TCT_COMMANDS))
 
  88 tests:=$(wildcard test/$(command)/*.tct)
 
  89 prof/clean: prof/$(command)/clean
 
  90 prof/$(command)/clean:
 
  91         $$(call rmw,   prof/$(command)/$(commit)/*.out)
 
  92         $$(call rmdirw,prof/$(command)/$(commit))
 
  93 prof/$(command)/%/clean: \
 
  94  $(foreach hC,$(GHC_PROF_CATEGORIES),prof/$(command)/%/$(hC)/clean)
 
  95         $$(call rmw,prof/$(command)/$$*)
 
  97 prof/$(command)/$(commit):
 
 102 define prof/command/hC
 
 103 .PHONY: prof/$(command)
 
 104 prof/$(command):       prof/$(command)/$(hC)
 
 105 prof/$(command)/clean: prof/$(command)/$(hC)/clean
 
 107 prof/$(command)/$(hC): $(patsubst test/%,prof/%/$(hC),$(tests))
 
 108 .PRECIOUS: $(patsubst test/$(command)/%, \
 
 109                       prof/$(command)/$(commit)/%.$(hC).hp, \
 
 111 .PRECIOUS: $(patsubst test/$(command)/%, \
 
 112                       prof/$(command)/$(commit)/%.$(hC).ps, \
 
 114 prof/$(command)/$(hC)/clean:
 
 116          prof/$(command)/$(commit)/*.$(hC).aux \
 
 117          prof/$(command)/$(commit)/*.$(hC).hp \
 
 118          prof/$(command)/$(commit)/*.$(hC).prof \
 
 119          prof/$(command)/$(commit)/*.$(hC).ps \
 
 120          prof/$(command)/$(commit)/*.$(hC).stats )
 
 122 prof/$(command)/%: prof/$(command)/%/$(hC) \
 
 123                    prof/$(command)/$(commit)/%.$(hC).hs
 
 124 prof/$(command)/%/$(hC): prof/$(command)/$(commit)/%.$(hC).ps
 
 127 prof/$(command)/$(commit)/%.$(hC).prof \
 
 128 prof/$(command)/$(commit)/%.$(hC).hp \
 
 129 prof/$(command)/%.$(command): \
 
 133  | prof/$(command)/$(commit)
 
 135          -$(hC)$$(GHC_PROF_$(hC)) \
 
 136          -i$$(GHC_PROF_RATE) \
 
 137          -L$$(GHC_PROF_CC_LENGTH) \
 
 138          $$(if $$(GHC_PROF_CPUS),-N$$(GHC_PROF_CPUS)) \
 
 139          -tprof/$(command)/$(commit)/$$*.$(hC).stats \
 
 142         $$(TCT_PRINT_PROF) $$(TCT_FLAGS) \
 
 143          $(command) $$(TCT_COMMAND_FLAGS) test/$(command)/$$* \
 
 144          >prof/$(command)/$(commit)/$$*.out
 
 145         mv $(notdir $(TCT_PRINT_PROF)).hp   prof/$(command)/$(commit)/$$*.$(hC).hp
 
 146         mv $(notdir $(TCT_PRINT_PROF)).prof prof/$(command)/$(commit)/$$*.$(hC).prof
 
 148 prof/$(command)/%/$(hC)/clean:
 
 150          prof/$(command)/$(commit)/$$*.$(hC).aux \
 
 151          prof/$(command)/$(commit)/$$*.$(hC).hp \
 
 152          prof/$(command)/$(commit)/$$*.$(hC).prof \
 
 153          prof/$(command)/$(commit)/$$*.$(hC).ps \
 
 154          prof/$(command)/$(commit)/$$*.$(hC).stats )
 
 158 $(foreach command,$(TCT_COMMANDS), \
 
 159  $(eval $(call prof/command)) \
 
 160  $(foreach hC,$(GHC_PROF_CATEGORIES), \
 
 161   $(eval $(call prof/command/hC)) ))
 
 163 %.hC.hp: $(foreach hC,$(GHC_PROF_CATEGORIES),%.$(hC).hp)
 
 165 %.hC.ps: $(foreach hC,$(GHC_PROF_CATEGORIES),%.$(hC).ps)
 
 168         (cd $(@D) && hp2ps -b -c -e$(GHC_PROF_PS_WIDTH) -g $(notdir $*.hp))