You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

188 lines
5.2 KiB

  1. #
  2. # Copyright (C) 2018, 2020 Jeffery To
  3. #
  4. # This is free software, licensed under the GNU General Public License v2.
  5. # See /LICENSE for more information.
  6. #
  7. ifeq ($(origin GO_INCLUDE_DIR),undefined)
  8. GO_INCLUDE_DIR:=$(dir $(lastword $(MAKEFILE_LIST)))
  9. endif
  10. include $(GO_INCLUDE_DIR)/golang-values.mk
  11. # $(1) valid GOOS_GOARCH combinations
  12. # $(2) go version id
  13. define GoCompiler/Default/CheckHost
  14. $(if $(filter $(GO_HOST_OS_ARCH),$(1)),,$(error go-$(2) cannot be installed on $(GO_HOST_OS)/$(GO_HOST_ARCH)))
  15. endef
  16. # $(1) source go root
  17. # $(2) destination prefix
  18. # $(3) go version id
  19. # $(4) additional environment variables (optional)
  20. define GoCompiler/Default/Make
  21. ( \
  22. cd $(1)/src ; \
  23. $(if $(2),GOROOT_FINAL=$(2)/lib/go-$(3)) \
  24. $(4) \
  25. $(BASH) make.bash --no-banner ; \
  26. )
  27. endef
  28. # $(1) destination prefix
  29. # $(2) go version id
  30. define GoCompiler/Default/Install/make-dirs
  31. $(INSTALL_DIR) $(1)/lib/go-$(2)
  32. $(INSTALL_DIR) $(1)/share/go-$(2)
  33. endef
  34. # $(1) source go root
  35. # $(2) destination prefix
  36. # $(3) go version id
  37. # $(4) file/directory name
  38. define GoCompiler/Default/Install/install-share-data
  39. $(CP) $(1)/$(4) $(2)/share/go-$(3)/
  40. $(LN) ../../share/go-$(3)/$(4) $(2)/lib/go-$(3)/
  41. endef
  42. # $(1) source go root
  43. # $(2) destination prefix
  44. # $(3) go version id
  45. # $(4) GOOS_GOARCH
  46. # $(5) install suffix (optional)
  47. define GoCompiler/Default/Install/Bin
  48. $(call GoCompiler/Default/Install/make-dirs,$(2),$(3))
  49. $(call GoCompiler/Default/Install/install-share-data,$(1),$(2),$(3),api)
  50. $(INSTALL_DATA) -p $(1)/VERSION $(2)/lib/go-$(3)/
  51. for file in AUTHORS CONTRIBUTING.md CONTRIBUTORS LICENSE PATENTS README.md SECURITY.md; do \
  52. if [ -f $(1)/$$$$file ]; then \
  53. $(INSTALL_DATA) -p $(1)/$$$$file $(2)/share/go-$(3)/ ; \
  54. fi ; \
  55. done
  56. $(INSTALL_DIR) $(2)/lib/go-$(3)/bin
  57. ifeq ($(4),$(GO_HOST_OS_ARCH))
  58. $(INSTALL_BIN) -p $(1)/bin/* $(2)/lib/go-$(3)/bin/
  59. else
  60. $(INSTALL_BIN) -p $(1)/bin/$(4)/* $(2)/lib/go-$(3)/bin/
  61. endif
  62. $(INSTALL_DIR) $(2)/lib/go-$(3)/pkg
  63. $(CP) $(1)/pkg/$(4)$(if $(5),_$(5)) $(2)/lib/go-$(3)/pkg/
  64. $(INSTALL_DIR) $(2)/lib/go-$(3)/pkg/tool/$(4)
  65. $(INSTALL_BIN) -p $(1)/pkg/tool/$(4)/* $(2)/lib/go-$(3)/pkg/tool/$(4)/
  66. endef
  67. # $(1) destination prefix
  68. # $(2) go version id
  69. define GoCompiler/Default/Install/BinLinks
  70. $(INSTALL_DIR) $(1)/bin
  71. $(LN) ../lib/go-$(2)/bin/go $(1)/bin/go
  72. $(LN) ../lib/go-$(2)/bin/gofmt $(1)/bin/gofmt
  73. endef
  74. # $(1) source go root
  75. # $(2) destination prefix
  76. # $(3) go version id
  77. define GoCompiler/Default/Install/Doc
  78. $(call GoCompiler/Default/Install/make-dirs,$(2),$(3))
  79. $(call GoCompiler/Default/Install/install-share-data,$(1),$(2),$(3),doc)
  80. $(call GoCompiler/Default/Install/install-share-data,$(1),$(2),$(3),favicon.ico)
  81. $(call GoCompiler/Default/Install/install-share-data,$(1),$(2),$(3),robots.txt)
  82. endef
  83. # $(1) source go root
  84. # $(2) destination prefix
  85. # $(3) go version id
  86. define GoCompiler/Default/Install/Src
  87. $(call GoCompiler/Default/Install/make-dirs,$(2),$(3))
  88. $(call GoCompiler/Default/Install/install-share-data,$(1),$(2),$(3),lib)
  89. $(call GoCompiler/Default/Install/install-share-data,$(1),$(2),$(3),misc)
  90. $(call GoCompiler/Default/Install/install-share-data,$(1),$(2),$(3),src)
  91. $(call GoCompiler/Default/Install/install-share-data,$(1),$(2),$(3),test)
  92. $(FIND) \
  93. $(2)/share/go-$(3)/src/ \
  94. \! -type d -a \( -name '*.bat' -o -name '*.rc' \) \
  95. -delete
  96. if [ -d $(1)/pkg/include ]; then \
  97. $(INSTALL_DIR) $(2)/lib/go-$(3)/pkg ; \
  98. $(INSTALL_DIR) $(2)/share/go-$(3)/pkg ; \
  99. $(CP) $(1)/pkg/include $(2)/share/go-$(3)/pkg/ ; \
  100. $(LN) ../../../share/go-$(3)/pkg/include $(2)/lib/go-$(3)/pkg/ ; \
  101. fi
  102. endef
  103. # $(1) destination prefix
  104. # $(2) go version id
  105. define GoCompiler/Default/Uninstall
  106. rm -rf $(1)/lib/go-$(2)
  107. rm -rf $(1)/share/go-$(2)
  108. endef
  109. # $(1) destination prefix
  110. define GoCompiler/Default/Uninstall/BinLinks
  111. rm -f $(1)/bin/go
  112. rm -f $(1)/bin/gofmt
  113. endef
  114. # $(1) profile name
  115. # $(2) source go root
  116. # $(3) destination prefix
  117. # $(4) go version id
  118. # $(5) GOOS_GOARCH
  119. # $(6) install suffix (optional)
  120. define GoCompiler/AddProfile
  121. # $$(1) valid GOOS_GOARCH combinations
  122. define GoCompiler/$(1)/CheckHost
  123. $$(call GoCompiler/Default/CheckHost,$$(1),$(4))
  124. endef
  125. # $$(1) additional environment variables (optional)
  126. define GoCompiler/$(1)/Make
  127. $$(call GoCompiler/Default/Make,$(2),$(3),$(4),$$(1))
  128. endef
  129. # $$(1) override install prefix (optional)
  130. define GoCompiler/$(1)/Install/Bin
  131. $$(call GoCompiler/Default/Install/Bin,$(2),$$(or $$(1),$(3)),$(4),$(5),$(6))
  132. endef
  133. # $$(1) override install prefix (optional)
  134. define GoCompiler/$(1)/Install/BinLinks
  135. $$(call GoCompiler/Default/Install/BinLinks,$$(or $$(1),$(3)),$(4))
  136. endef
  137. # $$(1) override install prefix (optional)
  138. define GoCompiler/$(1)/Install/Doc
  139. $$(call GoCompiler/Default/Install/Doc,$(2),$$(or $$(1),$(3)),$(4))
  140. endef
  141. # $$(1) override install prefix (optional)
  142. define GoCompiler/$(1)/Install/Src
  143. $$(call GoCompiler/Default/Install/Src,$(2),$$(or $$(1),$(3)),$(4))
  144. endef
  145. # $$(1) override install prefix (optional)
  146. define GoCompiler/$(1)/Uninstall
  147. $$(call GoCompiler/Default/Uninstall,$$(or $$(1),$(3)),$(4))
  148. endef
  149. # $$(1) override install prefix (optional)
  150. define GoCompiler/$(1)/Uninstall/BinLinks
  151. $$(call GoCompiler/Default/Uninstall/BinLinks,$$(or $$(1),$(3)))
  152. endef
  153. endef