diff mbox series

[1/2] package/pkg-golang: allow packages to provide extldflags

Message ID 876f3a7bb6a2375193fc8f06ab856d2449f83727.1699547993.git.yann.morin@orange.com
State New
Headers show
Series [1/2] package/pkg-golang: allow packages to provide extldflags | expand

Commit Message

Yann E. MORIN Nov. 9, 2023, 4:39 p.m. UTC
From: "Yann E. MORIN" <yann.morin@orange.com>

For some packages, it may be necessary to pass extra extldflags. For
example, some packages will need to be able to specify what ld to use,
and so will need to pass -fuse-ld={bfd,gold} as extldflags.

Introduce FOO_EXTLDFLAGS, that packages can set to pass such flags.

Signed-off-by: Yann E. MORIN <yann.morin@orange.com>
Tested-by: Nathaniel Roach <nroach44@nroach44.id.au>
---
 docs/manual/adding-packages-golang.adoc | 6 ++++--
 package/pkg-golang.mk                   | 6 +++++-
 2 files changed, 9 insertions(+), 3 deletions(-)

Comments

Fiona Klute Feb. 4, 2025, 2:33 p.m. UTC | #1
Am 09.11.23 um 17:39 schrieb yann.morin@orange.com:
> From: "Yann E. MORIN" <yann.morin@orange.com>
>
> For some packages, it may be necessary to pass extra extldflags. For
> example, some packages will need to be able to specify what ld to use,
> and so will need to pass -fuse-ld={bfd,gold} as extldflags.
>
> Introduce FOO_EXTLDFLAGS, that packages can set to pass such flags.
>
> Signed-off-by: Yann E. MORIN <yann.morin@orange.com>
> Tested-by: Nathaniel Roach <nroach44@nroach44.id.au>

Tested-by: Fiona Klute (WIWA) <fiona.klute@gmx.de>

Thanks,
Fiona

> ---
>   docs/manual/adding-packages-golang.adoc | 6 ++++--
>   package/pkg-golang.mk                   | 6 +++++-
>   2 files changed, 9 insertions(+), 3 deletions(-)
>
> diff --git a/docs/manual/adding-packages-golang.adoc b/docs/manual/adding-packages-golang.adoc
> index c952cde577..c238050096 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 8e27602d41..206688fa7b 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),\


--
Dipl.-Ing. Fiona Klute
Mollwitzer Str. 2
44141 Dortmund
Germany

USt.-ID/VAT number: DE363488944
diff mbox series

Patch

diff --git a/docs/manual/adding-packages-golang.adoc b/docs/manual/adding-packages-golang.adoc
index c952cde577..c238050096 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 8e27602d41..206688fa7b 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),\