diff --git a/docs/manual/adding-packages-golang.adoc b/docs/manual/adding-packages-golang.adoc index 6de0916a83..21b6a122a9 100644 --- a/docs/manual/adding-packages-golang.adoc +++ b/docs/manual/adding-packages-golang.adoc @@ -94,20 +94,20 @@ therefore only use a few of them, or none. defaults to +.+. We then have two cases: ** +FOO_BUILD_TARGETS+ is +.+. In this case, we assume only one binary - will be produced, and that by default we name it after the package - name. If that is not appropriate, the name of the produced binary - can be overridden using +FOO_BIN_NAME+. + will be built and installed, and by default we name it after the + package name; if that is not appropriate, the name of the binary can + be overridden using +FOO_BIN_NAME+. -** +FOO_BUILD_TARGETS+ is not +.+. In this case, we iterate over the - values to build each target, and for each produced a binary that is - the non-directory component of the target. For example if - +FOO_BUILD_TARGETS = cmd/docker cmd/dockerd+ the binaries produced - are +docker+ and +dockerd+. - -* +FOO_INSTALL_BINS+ can be used to pass the list of binaries that - should be installed in +/usr/bin+ on the target. If - +FOO_INSTALL_BINS+ is not specified, it defaults to the lower-case - name of package. +** +FOO_BUILD_TARGETS+ is not +.+. In this case, it is interpreted as a + space-separated list, and we iterate over the targets to build and + install a binary named after the non-directory component of the + target. For example if +FOO_BUILD_TARGETS = cmd/docker cmd/dockerd+, + the binaries built and installed are +docker+ and +dockerd+. If + +FOO_BUILD_TARGETS+ contains only one target, then it is possible to + override the built and installed binary by setting +FOO_BIN_NAME+, + as above; if +FOO_BUILD_TARGETS+ contains two or more targets, then + it is not possible to override the names of the installed binaries + (use a post-install hook for that). With the Go infrastructure, all the steps required to build and install the packages are already defined, and they generally work well diff --git a/package/pkg-golang.mk b/package/pkg-golang.mk index a4e8bd30cc..ff8d28aa7e 100644 --- a/package/pkg-golang.mk +++ b/package/pkg-golang.mk @@ -61,9 +61,16 @@ $(2)_BUILD_TARGETS ?= . # after each build target building them (below in _BUILD_CMDS). ifeq ($$($(2)_BUILD_TARGETS),.) $(2)_BIN_NAME ?= $$($(2)_RAWNAME) +$(2)_INSTALL_BINS ?= $$($(2)_BIN_NAME) +else ifeq ($$(words $$($(2)_BUILD_TARGETS)),1) +$(2)_BIN_NAME ?= $$(notdir $$($(2)_BUILD_TARGETS)) +$(2)_INSTALL_BINS ?= $$($(2)_BIN_NAME) +else +ifneq ($$($(2)_BIN_NAME),) +$$(error $(1) sets $(2)_BIN_NAME while there are multiple targets in $(2)_BUILD_TARGETS) +endif +$(2)_INSTALL_BINS ?= $$(notdir $$($(2)_BUILD_TARGETS)) endif - -$(2)_INSTALL_BINS ?= $$($(2)_RAWNAME) # Source files in Go usually use an import path resolved around # domain/vendor/software. We infer domain/vendor/software from the upstream URL