|
@@ -40,8 +40,6 @@ GO_BIN = $(HOST_DIR)/bin/go
|
|
|
|
|
|
define inner-golang-package
|
|
|
|
|
|
-$(2)_WORKSPACE ?= _gopath
|
|
|
-
|
|
|
$(2)_BUILD_OPTS += \
|
|
|
-ldflags "$$($(2)_LDFLAGS)" \
|
|
|
-tags "$$($(2)_TAGS)" \
|
|
@@ -63,25 +61,25 @@ endif
|
|
|
|
|
|
$(2)_INSTALL_BINS ?= $(1)
|
|
|
|
|
|
-# Source files in Go should be extracted in a precise folder in the hierarchy
|
|
|
-# of GOPATH. It usually resolves around domain/vendor/software. By default, we
|
|
|
-# derive domain/vendor/software from the upstream URL of the project, but we
|
|
|
-# allow $(2)_SRC_SUBDIR to be overridden if needed.
|
|
|
+# Source files in Go usually use an import path resolved around
|
|
|
+# domain/vendor/software. We infer domain/vendor/software from the upstream URL
|
|
|
+# of the project.
|
|
|
$(2)_SRC_DOMAIN = $$(call domain,$$($(2)_SITE))
|
|
|
$(2)_SRC_VENDOR = $$(word 1,$$(subst /, ,$$(call notdomain,$$($(2)_SITE))))
|
|
|
$(2)_SRC_SOFTWARE = $$(word 2,$$(subst /, ,$$(call notdomain,$$($(2)_SITE))))
|
|
|
|
|
|
-$(2)_SRC_SUBDIR ?= $$($(2)_SRC_DOMAIN)/$$($(2)_SRC_VENDOR)/$$($(2)_SRC_SOFTWARE)
|
|
|
-$(2)_SRC_PATH = $$(@D)/$$($(2)_WORKSPACE)/src/$$($(2)_SRC_SUBDIR)
|
|
|
+# $(2)_GOMOD is the root Go module path for the project, inferred if not set.
|
|
|
+# If the go.mod file does not exist, one is written with this root path.
|
|
|
+$(2)_GOMOD ?= $$($(2)_SRC_DOMAIN)/$$($(2)_SRC_VENDOR)/$$($(2)_SRC_SOFTWARE)
|
|
|
|
|
|
-# Configure step. Only define it if not already defined by the package .mk
|
|
|
-# file.
|
|
|
-ifndef $(2)_CONFIGURE_CMDS
|
|
|
-define $(2)_CONFIGURE_CMDS
|
|
|
- mkdir -p $$(dir $$($(2)_SRC_PATH))
|
|
|
- ln -sf $$(@D) $$($(2)_SRC_PATH)
|
|
|
+# Generate a go.mod file if it doesn't exist. Note: Go is configured
|
|
|
+# to use the "vendor" dir and not make network calls.
|
|
|
+define $(2)_GEN_GOMOD
|
|
|
+ if [ ! -f $$(@D)/go.mod ]; then \
|
|
|
+ printf "module $$($(2)_GOMOD)\n" > $$(@D)/go.mod; \
|
|
|
+ fi
|
|
|
endef
|
|
|
-endif
|
|
|
+$(2)_POST_PATCH_HOOKS += $(2)_GEN_GOMOD
|
|
|
|
|
|
# Build step. Only define it if not already defined by the package .mk
|
|
|
# file.
|
|
@@ -95,26 +93,24 @@ endif
|
|
|
# Build package for target
|
|
|
define $(2)_BUILD_CMDS
|
|
|
$$(foreach d,$$($(2)_BUILD_TARGETS),\
|
|
|
- cd $$($(2)_SRC_PATH); \
|
|
|
+ cd $$(@D); \
|
|
|
$$(HOST_GO_TARGET_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)
|
|
|
+ $$($(2)_GOMOD)/$$(d)
|
|
|
)
|
|
|
endef
|
|
|
else
|
|
|
# Build package for host
|
|
|
define $(2)_BUILD_CMDS
|
|
|
$$(foreach d,$$($(2)_BUILD_TARGETS),\
|
|
|
- cd $$($(2)_SRC_PATH); \
|
|
|
+ cd $$(@D); \
|
|
|
$$(HOST_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)
|
|
|
+ $$($(2)_GOMOD)/$$(d)
|
|
|
)
|
|
|
endef
|
|
|
endif
|