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.

186 lines
5.1 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. endef
  81. # $(1) source go root
  82. # $(2) destination prefix
  83. # $(3) go version id
  84. define GoCompiler/Default/Install/Src
  85. $(call GoCompiler/Default/Install/make-dirs,$(2),$(3))
  86. $(call GoCompiler/Default/Install/install-share-data,$(1),$(2),$(3),lib)
  87. $(call GoCompiler/Default/Install/install-share-data,$(1),$(2),$(3),misc)
  88. $(call GoCompiler/Default/Install/install-share-data,$(1),$(2),$(3),src)
  89. $(call GoCompiler/Default/Install/install-share-data,$(1),$(2),$(3),test)
  90. $(FIND) \
  91. "$(2)/share/go-$(3)/src/" \
  92. \! -type d -a \( -name "*.bat" -o -name "*.rc" \) \
  93. -delete
  94. if [ -d "$(1)/pkg/include" ]; then \
  95. $(INSTALL_DIR) "$(2)/lib/go-$(3)/pkg" ; \
  96. $(INSTALL_DIR) "$(2)/share/go-$(3)/pkg" ; \
  97. $(CP) "$(1)/pkg/include" "$(2)/share/go-$(3)/pkg/" ; \
  98. $(LN) "../../../share/go-$(3)/pkg/include" "$(2)/lib/go-$(3)/pkg/" ; \
  99. fi
  100. endef
  101. # $(1) destination prefix
  102. # $(2) go version id
  103. define GoCompiler/Default/Uninstall
  104. rm -rf "$(1)/lib/go-$(2)"
  105. rm -rf "$(1)/share/go-$(2)"
  106. endef
  107. # $(1) destination prefix
  108. define GoCompiler/Default/Uninstall/BinLinks
  109. rm -f "$(1)/bin/go"
  110. rm -f "$(1)/bin/gofmt"
  111. endef
  112. # $(1) profile name
  113. # $(2) source go root
  114. # $(3) destination prefix
  115. # $(4) go version id
  116. # $(5) GOOS_GOARCH
  117. # $(6) install suffix (optional)
  118. define GoCompiler/AddProfile
  119. # $$(1) valid GOOS_GOARCH combinations
  120. define GoCompiler/$(1)/CheckHost
  121. $$(call GoCompiler/Default/CheckHost,$$(1),$(4))
  122. endef
  123. # $$(1) additional environment variables (optional)
  124. define GoCompiler/$(1)/Make
  125. $$(call GoCompiler/Default/Make,$(2),$(3),$(4),$$(1))
  126. endef
  127. # $$(1) override install prefix (optional)
  128. define GoCompiler/$(1)/Install/Bin
  129. $$(call GoCompiler/Default/Install/Bin,$(2),$$(or $$(1),$(3)),$(4),$(5),$(6))
  130. endef
  131. # $$(1) override install prefix (optional)
  132. define GoCompiler/$(1)/Install/BinLinks
  133. $$(call GoCompiler/Default/Install/BinLinks,$$(or $$(1),$(3)),$(4))
  134. endef
  135. # $$(1) override install prefix (optional)
  136. define GoCompiler/$(1)/Install/Doc
  137. $$(call GoCompiler/Default/Install/Doc,$(2),$$(or $$(1),$(3)),$(4))
  138. endef
  139. # $$(1) override install prefix (optional)
  140. define GoCompiler/$(1)/Install/Src
  141. $$(call GoCompiler/Default/Install/Src,$(2),$$(or $$(1),$(3)),$(4))
  142. endef
  143. # $$(1) override install prefix (optional)
  144. define GoCompiler/$(1)/Uninstall
  145. $$(call GoCompiler/Default/Uninstall,$$(or $$(1),$(3)),$(4))
  146. endef
  147. # $$(1) override install prefix (optional)
  148. define GoCompiler/$(1)/Uninstall/BinLinks
  149. $$(call GoCompiler/Default/Uninstall/BinLinks,$$(or $$(1),$(3)))
  150. endef
  151. endef