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 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. define GoCompiler/Default/Install/Bin
  47. $(call GoCompiler/Default/Install/make-dirs,$(2),$(3))
  48. $(call GoCompiler/Default/Install/install-share-data,$(1),$(2),$(3),api)
  49. $(INSTALL_DATA) -p $(1)/VERSION $(2)/lib/go-$(3)/
  50. for file in AUTHORS CONTRIBUTING.md CONTRIBUTORS LICENSE PATENTS README README.md; do \
  51. if [ -f $(1)/$$$$file ]; then \
  52. $(INSTALL_DATA) -p $(1)/$$$$file $(2)/share/go-$(3)/ ; \
  53. fi ; \
  54. done
  55. $(INSTALL_DIR) $(2)/lib/go-$(3)/bin
  56. ifeq ($(4),$(GO_HOST_OS_ARCH))
  57. $(INSTALL_BIN) -p $(1)/bin/* $(2)/lib/go-$(3)/bin/
  58. else
  59. $(INSTALL_BIN) -p $(1)/bin/$(4)/* $(2)/lib/go-$(3)/bin/
  60. endif
  61. $(INSTALL_DIR) $(2)/lib/go-$(3)/pkg
  62. $(CP) $(1)/pkg/$(4) $(2)/lib/go-$(3)/pkg/
  63. $(INSTALL_DIR) $(2)/lib/go-$(3)/pkg/tool/$(4)
  64. $(INSTALL_BIN) -p $(1)/pkg/tool/$(4)/* $(2)/lib/go-$(3)/pkg/tool/$(4)/
  65. endef
  66. # $(1) destination prefix
  67. # $(2) go version id
  68. define GoCompiler/Default/Install/BinLinks
  69. $(INSTALL_DIR) $(1)/bin
  70. $(LN) ../lib/go-$(2)/bin/go $(1)/bin/go
  71. $(LN) ../lib/go-$(2)/bin/gofmt $(1)/bin/gofmt
  72. endef
  73. # $(1) source go root
  74. # $(2) destination prefix
  75. # $(3) go version id
  76. define GoCompiler/Default/Install/Doc
  77. $(call GoCompiler/Default/Install/make-dirs,$(2),$(3))
  78. $(call GoCompiler/Default/Install/install-share-data,$(1),$(2),$(3),doc)
  79. $(call GoCompiler/Default/Install/install-share-data,$(1),$(2),$(3),favicon.ico)
  80. $(call GoCompiler/Default/Install/install-share-data,$(1),$(2),$(3),robots.txt)
  81. endef
  82. # $(1) source go root
  83. # $(2) destination prefix
  84. # $(3) go version id
  85. define GoCompiler/Default/Install/Src
  86. $(call GoCompiler/Default/Install/make-dirs,$(2),$(3))
  87. $(call GoCompiler/Default/Install/install-share-data,$(1),$(2),$(3),lib)
  88. $(call GoCompiler/Default/Install/install-share-data,$(1),$(2),$(3),misc)
  89. $(call GoCompiler/Default/Install/install-share-data,$(1),$(2),$(3),src)
  90. $(call GoCompiler/Default/Install/install-share-data,$(1),$(2),$(3),test)
  91. $(FIND) \
  92. $(2)/share/go-$(3)/src/ \
  93. \! -type d -a \( -name '*.bat' -o -name '*.rc' \) \
  94. -delete
  95. if [ -d $(1)/pkg/include ]; then \
  96. $(INSTALL_DIR) $(2)/lib/go-$(3)/pkg ; \
  97. $(INSTALL_DIR) $(2)/share/go-$(3)/pkg ; \
  98. $(CP) $(1)/pkg/include $(2)/share/go-$(3)/pkg/ ; \
  99. $(LN) ../../../share/go-$(3)/pkg/include $(2)/lib/go-$(3)/pkg/ ; \
  100. fi
  101. endef
  102. # $(1) destination prefix
  103. # $(2) go version id
  104. define GoCompiler/Default/Uninstall
  105. rm -rf $(1)/lib/go-$(2)
  106. rm -rf $(1)/share/go-$(2)
  107. endef
  108. # $(1) destination prefix
  109. define GoCompiler/Default/Uninstall/BinLinks
  110. rm -f $(1)/bin/go
  111. rm -f $(1)/bin/gofmt
  112. endef
  113. # $(1) profile name
  114. # $(2) source go root
  115. # $(3) destination prefix
  116. # $(4) go version id
  117. # $(5) GOOS_GOARCH
  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))
  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