/rules/build-prog.mk

https://github.com/pepeiborra/ghc · Makefile · 193 lines · 121 code · 33 blank · 39 comment · 1 complexity · e7a867d9027b5c1e1d143a9aa593c085 MD5 · raw file

  1. # -----------------------------------------------------------------------------
  2. #
  3. # (c) 2009 The University of Glasgow
  4. #
  5. # This file is part of the GHC build system.
  6. #
  7. # To understand how the build system works and how to modify it, see
  8. # http://hackage.haskell.org/trac/ghc/wiki/Building/Architecture
  9. # http://hackage.haskell.org/trac/ghc/wiki/Building/Modifying
  10. #
  11. # -----------------------------------------------------------------------------
  12. # Build a program. Invoke like this:
  13. #
  14. # utils/genapply_MODULES = Main
  15. # utils/genapply_HC_OPTS = -package Cabal
  16. # utils/genapply_dist_PROG = genapply
  17. #
  18. # $(eval $(call build-prog,utils/genapply,dist-install,1))
  19. define build-prog
  20. $(call trace, build-prog($1,$2,$3))
  21. $(call profStart, build-prog($1,$2,$3))
  22. # $1 = dir
  23. # $2 = distdir
  24. # $3 = GHC stage to use (0 == bootstrapping compiler)
  25. ifneq "$$(CLEANING)" "YES"
  26. ifeq "$$($1_$2_PROG)" ""
  27. $$(error $1_$2_PROG is not set)
  28. endif
  29. endif
  30. ifeq "$$(findstring $3,0 1 2)" ""
  31. $$(error $1/$2: stage argument to build-prog should be 0, 1, or 2)
  32. endif
  33. $(call clean-target,$1,$2,$1/$2)
  34. ifneq "$$($1_$2_NOT_NEEDED)" "YES"
  35. $$(eval $$(call build-prog-helper,$1,$2,$3))
  36. endif
  37. $(call profEnd, build-prog($1,$2,$3))
  38. endef
  39. define build-prog-helper
  40. # $1 = dir
  41. # $2 = distdir
  42. # $3 = GHC stage to use (0 == bootstrapping compiler)
  43. ifeq "$$($1_USES_CABAL)" "YES"
  44. $1_$2_USES_CABAL = YES
  45. endif
  46. $(call package-config,$1,$2,$3)
  47. $1_$2_depfile_base = $1/$2/build/.depend
  48. ifeq "$$($1_$2_INSTALL_INPLACE)" "NO"
  49. ifeq "$(findstring clean,$(MAKECMDGOALS))" ""
  50. $1_$2_INPLACE = $$(error $1_$2 should not be installed inplace, but INPLACE var evaluated)
  51. else
  52. $1_$2_INPLACE =
  53. endif
  54. else
  55. # Where do we install the inplace version?
  56. ifeq "$$($1_$2_SHELL_WRAPPER) $$(Windows)" "YES NO"
  57. $1_$2_INPLACE = $$(INPLACE_LIB)/$$($1_$2_PROG)
  58. else
  59. ifeq "$$($1_$2_TOPDIR)" "YES"
  60. $1_$2_INPLACE = $$(INPLACE_TOPDIR)/$$($1_$2_PROG)
  61. else
  62. $1_$2_INPLACE = $$(INPLACE_BIN)/$$($1_$2_PROG)
  63. endif
  64. endif
  65. endif
  66. ifeq "$$($1_$2_USES_CABAL)" "YES"
  67. $(call build-package-data,$1,$2,$3)
  68. ifneq "$$(NO_INCLUDE_PKGDATA)" "YES"
  69. ifeq "$3" "0"
  70. include $1/$2/package-data.mk
  71. else ifeq "$(phase)" "final"
  72. include $1/$2/package-data.mk
  73. endif
  74. endif
  75. endif
  76. $(call all-target,$1,all_$1_$2)
  77. $(call all-target,$1_$2,$1/$2/build/tmp/$$($1_$2_PROG))
  78. # INPLACE_BIN might be empty if we're distcleaning
  79. ifeq "$(findstring clean,$(MAKECMDGOALS))" ""
  80. ifneq "$$($1_$2_INSTALL_INPLACE)" "NO"
  81. $$($1_$2_INPLACE) : $1/$2/build/tmp/$$($1_$2_PROG) | $$$$(dir $$$$@)/.
  82. "$$(CP)" -p $$< $$@
  83. touch $$@
  84. endif
  85. endif
  86. $(call shell-wrapper,$1,$2)
  87. $1_$2_WAYS = v
  88. $(call hs-sources,$1,$2)
  89. $(call c-sources,$1,$2)
  90. # --- IMPLICIT RULES
  91. # Just the 'v' way for programs
  92. $(call distdir-way-opts,$1,$2,v,$3)
  93. ifeq "$3" "0"
  94. # For stage 0, we use GHC to compile C sources so that we don't have to
  95. # worry about where the RTS header files are
  96. $(call c-suffix-rules,$1,$2,v,YES)
  97. else
  98. $(call c-suffix-rules,$1,$2,v,NO)
  99. endif
  100. $(call hs-suffix-rules,$1,$2,v)
  101. $$(foreach dir,$$($1_$2_HS_SRC_DIRS),\
  102. $$(eval $$(call hs-suffix-rules-srcdir,$1,$2,v,$$(dir))))
  103. $(call c-objs,$1,$2,v)
  104. $(call hs-objs,$1,$2,v)
  105. $1_$2_LINK_WITH_GCC = NO
  106. ifeq "$$(BootingFromHc)" "YES"
  107. $1_$2_LINK_WITH_GCC = YES
  108. endif
  109. ifeq "$$($1_$2_v_HS_OBJS)" ""
  110. # We don't want to link the GHC RTS into C-only programs. There's no
  111. # point, and it confuses the test that all GHC-compiled programs
  112. # were compiled with the right GHC.
  113. $1_$2_GHC_LD_OPTS = -no-auto-link-packages -no-hs-main
  114. endif
  115. ifneq "$$(BINDIST)" "YES"
  116. # The quadrupled $'s here are because the _v_LIB variables aren't
  117. # necessarily set when this part of the makefile is read
  118. $1/$2/build/tmp/$$($1_$2_PROG) : \
  119. $$(foreach dep,$$($1_$2_DEP_NAMES),\
  120. $$(if $$(filter ghc,$$(dep)),\
  121. $(if $(filter 0,$3),$$(compiler_stage1_v_LIB),\
  122. $(if $(filter 1,$3),$$(compiler_stage2_v_LIB),\
  123. $(if $(filter 2,$3),$$(compiler_stage2_v_LIB),\
  124. $$(error Bad build stage)))),\
  125. $$$$(libraries/$$(dep)_dist-$(if $(filter 0,$3),boot,install)_v_LIB)))
  126. ifeq "$$($1_$2_LINK_WITH_GCC)" "NO"
  127. $1/$2/build/tmp/$$($1_$2_PROG) : $$($1_$2_v_HS_OBJS) $$($1_$2_v_C_OBJS) $$($1_$2_v_S_OBJS) $$($1_$2_OTHER_OBJS) | $$$$(dir $$$$@)/.
  128. "$$($1_$2_HC)" -o $$@ $$($1_$2_v_ALL_HC_OPTS) $$(LD_OPTS) $$($1_$2_GHC_LD_OPTS) $$($1_$2_v_HS_OBJS) $$($1_$2_v_C_OBJS) $$($1_$2_v_S_OBJS) $$($1_$2_OTHER_OBJS) $$(addprefix -l,$$($1_$2_EXTRA_LIBRARIES))
  129. else
  130. $1/$2/build/tmp/$$($1_$2_PROG) : $$($1_$2_v_HS_OBJS) $$($1_$2_v_C_OBJS) $$($1_$2_v_S_OBJS) $$($1_$2_OTHER_OBJS) | $$$$(dir $$$$@)/.
  131. "$$($1_$2_CC)" -o $$@ $$($1_$2_v_ALL_CC_OPTS) $$(LD_OPTS) $$($1_$2_v_HS_OBJS) $$($1_$2_v_C_OBJS) $$($1_$2_v_S_OBJS) $$($1_$2_OTHER_OBJS) $$($1_$2_v_EXTRA_CC_OPTS) $$(addprefix -l,$$($1_$2_EXTRA_LIBRARIES))
  132. endif
  133. # Note [lib-depends] if this program is built with stage1 or greater, we
  134. # need to depend on the libraries too. NB. since $(ALL_STAGE1_LIBS) and
  135. # $(ALL_RTS_LIBS) are not defined until after libraries/*/ghc.mk have
  136. # been included, this introduces an ordering dependency.
  137. ifneq "$$(CLEANING)" "YES"
  138. ifneq "$3" "0"
  139. ifneq "$$($1_$2_HS_SRCS)" ""
  140. ifeq "$$(strip $$(ALL_STAGE1_LIBS))" ""
  141. $$(error ordering failure in $1 ($2): ALL_STAGE1_LIBS is empty)
  142. endif
  143. endif
  144. $1/$2/build/tmp/$$($1_$2_PROG) : $$(ALL_STAGE1_LIBS) $$(ALL_RTS_LIBS) $$(OTHER_LIBS)
  145. endif
  146. endif
  147. endif
  148. ifneq "$$($1_$2_INSTALL_INPLACE)" "NO"
  149. $(call all-target,$1_$2,$$($1_$2_INPLACE))
  150. endif
  151. $(call clean-target,$1,$2_inplace,$$($1_$2_INPLACE))
  152. ifeq "$$($1_$2_INSTALL)" "YES"
  153. ifeq "$$($1_$2_TOPDIR)" "YES"
  154. INSTALL_TOPDIRS += $1/$2/build/tmp/$$($1_$2_PROG)
  155. else
  156. INSTALL_BINS += $1/$2/build/tmp/$$($1_$2_PROG)
  157. endif
  158. endif
  159. $(call dependencies,$1,$2,$3)
  160. endef