ghc.mk 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. include $(TOP)/mk/cabal.mk
  2. include $(TOP)/mk/stack.mk
  3. ifeq ($(GHC),)
  4. ifdef HAS_STACK
  5. GHC := stack ghc --
  6. else
  7. GHC := $(shell which ghc)
  8. endif
  9. endif
  10. ifeq ($(RUNGHC),)
  11. ifdef HAS_STACK
  12. RUNGHC := stack runghc --
  13. else
  14. RUNGHC := $(shell which runghc)
  15. endif
  16. endif
  17. # GHC version removing the patchlevel number (e.g. in GHC 7.10.3, the
  18. # patchlevel number is 3).
  19. # We ask if GHC is available for removing a warning on Travis when
  20. # testing the documentation.
  21. ifneq ($(GHC),)
  22. # major.minor.subminor, e.g. 8.10.2
  23. ifdef HAS_STACK
  24. GHC_VER := $(shell stack query | sed -n 's/.*actual: ghc-\([0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\).*/\1/p')
  25. # The following variant needs GNU awk (not POSIX compatible) [issue #5480]:
  26. # GHC_VER := $(shell stack query | awk 'match ($$0, /actual: ghc-([0-9]+\.[0-9]+\.[0-9]+)/, ver) { print (ver[1]); }')
  27. else
  28. GHC_VER := $(shell $(GHC) --numeric-version | cut -d. -f1-3)
  29. endif
  30. # major.minor, e.g. 8.10
  31. #GHC_VERSION := $(shell echo $(GHC_VER) | cut -d. -f1-2)
  32. # ALT: `cut` can be done within `make`:
  33. # substitute dot by space, select words 1-2, substitute space by dot
  34. # Howeve, for the last substitution step, we need a hack to define
  35. # $(space) as leading spaces are ignored in the first argument to subst.
  36. # See https://www.gnu.org/software/make/manual/make.html#Text-Functions
  37. empty :=
  38. space := $(empty) $(empty)
  39. GHC_VERSION := $(subst $(space),.,$(wordlist 1,2,$(subst .,$(space),$(GHC_VER))))
  40. endif