diff mbox series

kbuild: respect pkg-config-provided lua -L flags

Message ID 20210419080100.490921-1-dominique.martinet@atmark-techno.com
State New
Headers show
Series kbuild: respect pkg-config-provided lua -L flags | expand

Commit Message

Dominique Martinet April 19, 2021, 8:01 a.m. UTC
- KBUILD_LIBS was set but unused
- (pkg-config)_LIBS was also unused, replace it to get only the -L flags
- remember the -L flags in EXTRA_LDFLAGS
- also pass EXTRA_LDFLAGS to tests so they can find the lib too

Signed-off-by: Dominique Martinet <dominique.martinet@atmark-techno.com>
---
I struggled a bit trying to build swupdate with a different version of
lua on alpine linux, because they keep the name lua.so while putting it
in a different directory:

/usr/lib/
├── lua5.3
│   ├── liblua-5.3.so.0 -> liblua-5.3.so.0.0.0
│   ├── liblua-5.3.so.0.0.0
│   ├── liblua.a
│   └── liblua.so -> liblua-5.3.so.0.0.0
├── pkgconfig
│   └── lua5.3.pc
│ ...
├── liblua-5.3.so.0 -> lua5.3/liblua-5.3.so.0
└── liblua-5.3.so.0.0.0 -> lua5.3/liblua-5.3.so.0.0.0

linking with -L/usr/lib/lua5.3 -llua, and having various step of
failures where the linker could not find liblua.so (building or tests)


I no longer require to build with a different lua so don't really care
about this patch, but since I struggled a bit figured it might be best
to send in case others need it.
It hopefully shouldn't do any harm anyway.. I think!


 Makefile       | 2 +-
 Makefile.flags | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)
diff mbox series

Patch

diff --git a/Makefile b/Makefile
index cc1545222582..9e9aa79cda96 100644
--- a/Makefile
+++ b/Makefile
@@ -488,7 +488,7 @@  acceptance-tests: swupdate ${tools-bins} FORCE
 
 PHONY += test
 test:
-	$(Q)$(MAKE) $(build)=test SWOBJS="$(swupdate-objs)" SWLIBS="$(swupdate-libs) ${swupdate-ipc-lib}" LDLIBS="$(LDLIBS)" tests
+	$(Q)$(MAKE) $(build)=test SWOBJS="$(swupdate-objs)" SWLIBS="$(swupdate-libs) ${swupdate-ipc-lib}" EXTRA_LDFLAGS="$(EXTRA_LDFLAGS)" LDLIBS="$(LDLIBS)" tests
 
 # The actual objects are generated when descending,
 # make sure no implicit rule kicks in
diff --git a/Makefile.flags b/Makefile.flags
index 7003af14d767..efe26c6ce35d 100644
--- a/Makefile.flags
+++ b/Makefile.flags
@@ -85,7 +85,7 @@  endif
 # Usage: $(eval $(call pkg_check_modules,VARIABLE-PREFIX,MODULES))
 define pkg_check_modules
 $(1)_CFLAGS := $(shell $(PKG_CONFIG) $(PKG_CONFIG_FLAGS) --cflags $(2))
-$(1)_LIBS := $(shell $(PKG_CONFIG) $(PKG_CONFIG_FLAGS) --libs $(2))
+$(1)_LDFLAGS := $(shell $(PKG_CONFIG) $(PKG_CONFIG_FLAGS) --libs-only-L $(2))
 $(1)_LDLIBS := $(patsubst -l%,%,$(shell $(PKG_CONFIG) $(PKG_CONFIG_FLAGS) --libs-only-l $(2)))
 endef
 
@@ -108,7 +108,7 @@  ifneq ($(CONFIG_LUA),)
 LDFLAGS_swupdate += -Wl,-E
 $(eval $(call pkg_check_modules, LUABUILD, ${CONFIG_LUAPKG}))
 KBUILD_CFLAGS += $(LUABUILD_CFLAGS)
-KBUILD_LIBS += $(LUABUILD_LIBS)
+EXTRA_LDFLAGS += $(LUABUILD_LDFLAGS)
 LDLIBS += $(LUABUILD_LDLIBS)
 LUAVER :=  $(shell $(PKG_CONFIG) $(PKG_CONFIG_FLAGS) --modversion ${CONFIG_LUAPKG} | cut -d'.' -f1,2)
 endif