+BR2_PACKAGE_HOST_GO_TARGET_CGO_LINKING_SUPPORTS+.
The main macro of the Go package infrastructure is
-+golang-package+. It is similar to the +generic-package+ macro. Only
-target packages are supported with +golang-package+.
++golang-package+. It is similar to the +generic-package+ macro. The
+ability to build host packages is also available, with the
++host-golang-package+ macro.
+Host packages built by +host-golang-package+ macro should depend on
+BR2_PACKAGE_HOST_GO_HOST_ARCH_SUPPORTS.
Just like the generic infrastructure, the Go infrastructure works
by defining a number of variables before calling the +golang-package+.
# We pass an empty GOBIN, otherwise "go install: cannot install
# cross-compiled binaries when GOBIN is set"
-GO_TARGET_ENV = \
- $(HOST_GO_TARGET_ENV) \
+GO_COMMON_ENV = \
PATH=$(BR_PATH) \
GOBIN= \
CGO_ENABLED=$(HOST_GO_CGO_ENABLED)
+GO_TARGET_ENV = \
+ $(HOST_GO_TARGET_ENV) \
+ $(GO_COMMON_ENV)
+
+GO_HOST_ENV = \
+ $(GO_COMMON_ENV)
+
################################################################################
# inner-golang-package -- defines how the configuration, compilation and
# installation of a Go package should be done, implements a few hooks to tune
# packages
# argument 4 is the type (target or host)
#
-# NOTE Only type target is supported at the moment
################################################################################
define inner-golang-package
# Build step. Only define it if not already defined by the package .mk
# file.
ifndef $(2)_BUILD_CMDS
+ifeq ($(4),target)
+# Build package for target
define $(2)_BUILD_CMDS
$$(foreach d,$$($(2)_BUILD_TARGETS),\
cd $$($(2)_SRC_PATH); \
./$$(d)
)
endef
+else
+# Build package for host
+define $(2)_BUILD_CMDS
+ $$(foreach d,$$($(2)_BUILD_TARGETS),\
+ cd $$($(2)_SRC_PATH); \
+ $$(GO_HOST_ENV) \
+ GOPATH="$$(@D)/$$($(2)_WORKSPACE)" \
+ $$($(2)_GO_ENV) \
+ $$(GO_BIN) build -v $$($(2)_BUILD_OPTS) \
+ -o $$(@D)/bin/$$(or $$($(2)_BIN_NAME),$$(notdir $$(d))) \
+ ./$$(d)
+ )
+endef
+endif
endif
# Target installation step. Only define it if not already defined by the
endef
endif
+# Host installation step
+ifndef $(2)_INSTALL_CMDS
+define $(2)_INSTALL_CMDS
+ $$(foreach d,$$($(2)_INSTALL_BINS),\
+ $(INSTALL) -D -m 0755 $$(@D)/bin/$$(d) $(HOST_DIR)/bin/$$(d)
+ )
+endef
+endif
+
# Call the generic package infrastructure to generate the necessary make
# targets
$(call inner-generic-package,$(1),$(2),$(3),$(4))
################################################################################
golang-package = $(call inner-golang-package,$(pkgname),$(call UPPERCASE,$(pkgname)),$(call UPPERCASE,$(pkgname)),target)
+host-golang-package = $(call inner-golang-package,host-$(pkgname),$(call UPPERCASE,host-$(pkgname)),$(call UPPERCASE,$(pkgname)),host)