diff --git a/docs/manual/adding-packages-golang.adoc b/docs/manual/adding-packages-golang.adoc index aa25426591..6de0916a83 100644 --- a/docs/manual/adding-packages-golang.adoc +++ b/docs/manual/adding-packages-golang.adoc @@ -84,8 +84,10 @@ therefore only use a few of them, or none. infrastructure will automatically generate a minimal +go.mod+ file in the package source tree if it doesn't exist. -* +FOO_LDFLAGS+ and +FOO_TAGS+ can be used to pass respectively the - +LDFLAGS+ or the +TAGS+ to the +go+ build command. +* +FOO_LDFLAGS+, +FOO_EXTLDFLAGS+, and +FOO_TAGS+ can be used to pass + respectively the go +LDFLAGS+ (via the `-ldflags` command line flag), + the external linker flags +EXTLDFLAGS+ (via the `-extldflags` + command line flag), or the +TAGS+ to the +go+ build command. * +FOO_BUILD_TARGETS+ can be used to pass the list of targets that should be built. If +FOO_BUILD_TARGETS+ is not specified, it diff --git a/package/pkg-golang.mk b/package/pkg-golang.mk index 33cf9bfb1a..a3421af288 100644 --- a/package/pkg-golang.mk +++ b/package/pkg-golang.mk @@ -114,10 +114,14 @@ ifndef $(2)_BUILD_CMDS ifeq ($(4),target) ifeq ($(BR2_STATIC_LIBS),y) -$(2)_LDFLAGS += -extldflags '-static' +$(2)_EXTLDFLAGS += -static $(2)_TAGS += osusergo netgo endif +ifneq ($$($(2)_EXTLDFLAGS),) +$(2)_LDFLAGS += -extldflags '$$($(2)_EXTLDFLAGS)' +endif + # Build package for target define $(2)_BUILD_CMDS $$(foreach d,$$($(2)_BUILD_TARGETS),\