Skip to contentSkip to conversation

package/directfb,sdl: fix static link

PATCH New Yann E. MORIN 2 participants 4 messages Feb 23, 2017

lore
Share & tools
lore
#0 lore raw

cover package/directfb,sdl: fix static link

Hello All!

This series fix (works around) static linking to SDL+DirectFB, by hacking the corresponding .pc files:

- include -lstdc++ to DirectFB's Libs.Private
- include 'directfb' to SDL's Requires

Regards,
Yann E. MORIN.

The following changes since commit c8b2bd81a1a5401c10287f2d5c6c8b4a14994764

trousers: update ARC comment (2017-02-23 22:08:39 +0100)

are available in the git repository at:

git://git.buildroot.org/~ymorin/git/buildroot.git

for you to fetch changes up to 3817238a2bff47662b0f46d309fd2d12b31da877

package/sdl: fix .pc file (2017-02-23 22:21:16 +0100)

----------------------------------------------------------------
Yann E. MORIN (2):
package/directfb: hack .pc file for static link package/sdl: fix .pc file

 package/directfb/directfb.mk | 6 ++++++
 package/sdl/sdl.mk           | 5 +++++
 2 files changed, 11 insertions(+)
Signature · 6 lines
.-----------------.--------------------.------------------.--------------------.
|  Yann E. MORIN  | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: |
| +33 662 376 056 | Software  Designer | \ / CAMPAIGN     |  ___               |
| +33 223 225 172 `------------.-------:  X  AGAINST      |  \e/  There is no  |
| http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL    |   v   conspiracy.  |
'------------------------------^-------^------------------^--------------------'
#1 lore raw

PATCH 1/2 package/directfb: hack .pc file for static link

DirectFB is written in C++, but can be linked to by a C library or program.

When doing shared link, this is fine because the linker gets help from the DT_NEEDED flags and nows what libraries to pull in during the link.

However, during a static link, the linker does not get such help. So pkg-config was invented to compensate for that deficiency, whereby a library would define its dependencies in a .pc file.

Alas, the .pc file for DirectFB does not define that it requires libstdc++, for the good reason that there is provision in pkg-config to properly cover this case. See this thread:

    https://lists.freedesktop.org/archives/pkg-config/2016-August/001053.html

So, we hack our way around this issue by appending -lstdc++ to the Libs.Private field in directfb.pc. This is but a hack; as per the thread above, this is perfectly acceptable given the conditions...

Step 1 at fixing:

    http://autobuild.buildroot.org/results/3d3/3d3036d40ddad71d872d910aae7a24975706d2e9/
    http://autobuild.buildroot.org/results/d1c/d1c35a6003396942b584f2f2a5e8bf4ac2fbe370/
    http://autobuild.buildroot.org/results/d45/d4504871bd47930e8363032d380cdfcc5bb8aee7/
    [...]
Cc Thomas Petazzoni <[email protected]>
---
 package/directfb/directfb.mk | 6 ++++++
 1 file changed, 6 insertions(+)
package/directfb/directfb.mk +6 -0
index 595d590..47cbf4e 100644
@@ -166,6 +166,12 @@ HOST_DIRECTFB_BUILD_CMDS = \
 HOST_DIRECTFB_INSTALL_CMDS = \
 	$(INSTALL) -m 0755 $(@D)/tools/directfb-csource $(HOST_DIR)/usr/bin
 
+define DIRECTFB_FIX_PC
+	$(SED) 's/^\(Libs.private:.*\)$$/\1 -lstdc++/' \
+		$(STAGING_DIR)/usr/lib/pkgconfig/direct.pc
+endef
+DIRECTFB_POST_INSTALL_STAGING_HOOKS += DIRECTFB_FIX_PC
+
 $(eval $(autotools-package))
 $(eval $(host-autotools-package))
 
Signature · 1 line
2.7.4
#2 lore raw

PATCH 2/2 package/sdl: fix .pc file

In reply to Yann E. MORIN

When DirectFB is enabled, SDL is linked with it, and states so by adding the necessary libs to its Libs.Private section in sdl.pc. In doing so this way, SDL misses a critical library from DirectFB: those in
DirectFB'sown Libs.Private field, which recently got expanded with
-lstdc++

And indeed, the correct way to depend on anothe library that provides a .pc file is to list it in the Requires field.

Add a post-staging install hook that does so.

We leave the Libs.Private field untouched, beause filtering out the libs from DirectFB is not trivial. It also does not impact the build: the libs would be listed twice, which although incorrect in theory, is not a problem in practice.

Step 2 at fixing:

    http://autobuild.buildroot.org/results/3d3/3d3036d40ddad71d872d910aae7a24975706d2e9/
    http://autobuild.buildroot.org/results/d1c/d1c35a6003396942b584f2f2a5e8bf4ac2fbe370/
    http://autobuild.buildroot.org/results/d45/d4504871bd47930e8363032d380cdfcc5bb8aee7/
    [...]
Cc Thomas Petazzoni <[email protected]>
---
 package/sdl/sdl.mk | 5 +++++
 1 file changed, 5 insertions(+)
package/sdl/sdl.mk +5 -0
index 38b4b97..9d8aa5d 100644
@@ -33,6 +33,11 @@ ifeq ($(BR2_PACKAGE_SDL_DIRECTFB),y)
 SDL_DEPENDENCIES += directfb
 SDL_CONF_OPTS += --enable-video-directfb=yes
 SDL_CONF_ENV = ac_cv_path_DIRECTFBCONFIG=$(STAGING_DIR)/usr/bin/directfb-config
+define SDL_FIX_PC
+	$(SED) 's/^\(Requires:.*\)$$/\1 directfb/' \
+		$(STAGING_DIR)/usr/lib/pkgconfig/sdl.pc
+endef
+SDL_POST_INSTALL_STAGING_HOOKS += SDL_FIX_PC
 else
 SDL_CONF_OPTS += --enable-video-directfb=no
 endif
Signature · 1 line
2.7.4
#3 lore raw

cover package/directfb,sdl: fix static link

In reply to Yann E. MORIN

Hello,

Quoted 3 lines · Yann E. MORIN

Yann E. MORIN (2):
package/directfb: hack .pc file for static link package/sdl: fix .pc file

Thanks for working on this. However, can we instead patch the directfb and sdl build system?

For example, the SDL build system should not add -ldirect to Libs: if DirectFB was detected with pkg-config, it should add it to the
Requires: line.

For DirectFB, I think libstdc++ could be unconditionally added to directfb.pc.in.

*But*: let's take a step back. Do we really care about using DirectFB in static-only scenarios ? If only DirectFB and SDL were active upstream projects, there would be some incentive to fix this problem properly. But really, there is no such incentive. So what about making DirectFB depend on !BR2_STATIC_LIBS instead, and be done with it ?

Nowhere in Buildroot we "select BR2_PACKAGE_DIRECTFB", which means it's really a simple change to do, as we don't need to propagate this dependency to any reverse dependency.

Best regards,

Thomas

Signature · 3 lines
Thomas Petazzoni, CTO, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com