diff mbox series

[meta-oe] unixodbc: fix odbc.pc file generation

Message ID 20240221064314.3635222-1-Qi.Chen@windriver.com
State Accepted
Headers show
Series [meta-oe] unixodbc: fix odbc.pc file generation | expand

Commit Message

ChenQi Feb. 21, 2024, 6:43 a.m. UTC
From: Chen Qi <Qi.Chen@windriver.com>

The build process currently succeeds but the odbc.pc file is not correctly
generated.

The error message is like below in log.do_compile and log.do_install:

  /bin/bash: line 1: ../exe/odbc_config: cannot execute binary file: Exec format error

I can see the message comes from the following line in exe/Makefile.am:

@sed "s![@]ODBC_ULEN[@]!`$(top_builddir)/exe/odbc_config$(EXEEXT) --ulen`!" \
          $(top_builddir)/DriverManager/odbc.pc > $(top_builddir)/exe/odbc.pc.tmp

It's running the exe/odbc_config program we built out. But the binary is for the target
platform and if we run it on the build host, we get that error message. The resulting ulen
and build_cflags in the final odbc.pc file are also empty.

Fix the issue by using qemu usermode to launch the target binary.

Signed-off-by: Chen Qi <Qi.Chen@windriver.com>
---
 ...add-CROSS_LAUNCHER-to-run-odbc_confi.patch | 54 +++++++++++++++++++
 .../unixodbc/unixodbc_2.3.11.bb               | 18 ++++++-
 2 files changed, 71 insertions(+), 1 deletion(-)
 create mode 100644 meta-oe/recipes-support/unixodbc/files/0001-exe-Makefile.am-add-CROSS_LAUNCHER-to-run-odbc_confi.patch
diff mbox series

Patch

diff --git a/meta-oe/recipes-support/unixodbc/files/0001-exe-Makefile.am-add-CROSS_LAUNCHER-to-run-odbc_confi.patch b/meta-oe/recipes-support/unixodbc/files/0001-exe-Makefile.am-add-CROSS_LAUNCHER-to-run-odbc_confi.patch
new file mode 100644
index 000000000..c763a9feb
--- /dev/null
+++ b/meta-oe/recipes-support/unixodbc/files/0001-exe-Makefile.am-add-CROSS_LAUNCHER-to-run-odbc_confi.patch
@@ -0,0 +1,54 @@ 
+From e886222c70d4b251f0785f670477b7aee938e5af Mon Sep 17 00:00:00 2001
+From: Chen Qi <Qi.Chen@windriver.com>
+Date: Wed, 21 Feb 2024 13:55:41 +0800
+Subject: [PATCH] exe/Makefile.am: add CROSS_LAUNCHER to run odbc_config
+
+In case of cross compilation, the odbc_config cannot run, the error message
+would be like below:
+
+  /bin/bash: line 1: ../exe/odbc_config: cannot execute binary file: Exec format error
+
+Add CROSS_LAUNCHER to allow the possibility of running odbc_config correctly in
+case of cross compilation.
+
+For example, here's a possible value for it (Yocto project environment, aarch64 target).
+  export CROSS_LAUNCHER="PSEUDO_UNLOAD=1 qemu-aarch64 -r 5.15 \
+  -L /PATH/TO/unixodbc/2.3.11/recipe-sysroot \
+  -E LD_LIBRARY_PATH=/PATH/TO/unixodbc/2.3.11/recipe-sysroot//usr/lib:/PATH/TO/unixodbc/2.3.11/recipe-sysroot//usr/lib  "
+
+Other projects can use the launcher they like to allow correct generation of
+the odbc.pc file in cross compilation environment.
+
+Upstream-Status: Submitted [Personal Email, nick.gorham@easysoft.com]
+
+As said in the official website, https://www.unixodbc.org/, the way to report bug and send
+out patch is via personal email. So there's a public link above.
+
+Signed-off-by: Chen Qi <Qi.Chen@windriver.com>
+---
+ exe/Makefile.am | 6 ++++--
+ 1 file changed, 4 insertions(+), 2 deletions(-)
+
+diff --git a/exe/Makefile.am b/exe/Makefile.am
+index 03f3d5a..5f33cf2 100644
+--- a/exe/Makefile.am
++++ b/exe/Makefile.am
+@@ -59,11 +59,13 @@ slencheck_SOURCES = slencheck.c
+ dltest_DEPENDENCIES = $(LTDLDEPS)
+ dltest_LDADD = $(LIBLTDL)
+ 
++CROSS_LAUNCHER ?= ""
++
+ all-am:
+-	@sed "s![@]ODBC_ULEN[@]!`$(top_builddir)/exe/odbc_config$(EXEEXT) --ulen`!" \
++	@sed "s![@]ODBC_ULEN[@]!`$(CROSS_LAUNCHER)$(top_builddir)/exe/odbc_config$(EXEEXT) --ulen`!" \
+ 	  $(top_builddir)/DriverManager/odbc.pc > $(top_builddir)/exe/odbc.pc.tmp
+ 	@mv -f $(top_builddir)/exe/odbc.pc.tmp $(top_builddir)/DriverManager/odbc.pc
+-	@sed "s![@]ODBC_CFLAGS[@]!`$(top_builddir)/exe/odbc_config$(EXEEXT) --cflags | sed 's/ -I.*//'`!" \
++	@sed "s![@]ODBC_CFLAGS[@]!`$(CROSS_LAUNCHER)$(top_builddir)/exe/odbc_config$(EXEEXT) --cflags | sed 's/ -I.*//'`!" \
+ 	  $(top_builddir)/DriverManager/odbc.pc > $(top_builddir)/exe/odbc.pc.tmp
+ 	@mv -f $(top_builddir)/exe/odbc.pc.tmp $(top_builddir)/DriverManager/odbc.pc
+ 
+-- 
+2.34.1
+
diff --git a/meta-oe/recipes-support/unixodbc/unixodbc_2.3.11.bb b/meta-oe/recipes-support/unixodbc/unixodbc_2.3.11.bb
index 3a9e390a2..0ab4f8864 100644
--- a/meta-oe/recipes-support/unixodbc/unixodbc_2.3.11.bb
+++ b/meta-oe/recipes-support/unixodbc/unixodbc_2.3.11.bb
@@ -10,23 +10,39 @@  DEPENDS = "libtool readline"
 
 SRC_URI = "https://www.unixodbc.org/unixODBC-${PV}.tar.gz \
            file://do-not-use-libltdl-source-directory.patch \
+           file://0001-exe-Makefile.am-add-CROSS_LAUNCHER-to-run-odbc_confi.patch \
 "
 SRC_URI[sha256sum] = "d9e55c8e7118347e3c66c87338856dad1516b490fb7c756c1562a2c267c73b5c"
 
 UPSTREAM_CHECK_REGEX = "unixODBC-(?P<pver>\d+(\.\d+)+)\.tar"
 
-inherit autotools-brokensep multilib_header
+inherit autotools-brokensep multilib_header qemu
 
 S = "${WORKDIR}/unixODBC-${PV}"
 
 EXTRA_OEMAKE += "LIBS=-lltdl"
 
+DEPENDS:append:class-target = "${@' qemu-native' if bb.utils.contains('MACHINE_FEATURES', 'qemu-usermode', True, False, d) else ''}"
+QEMU_WRAPPER = "${@qemu_wrapper_cmdline(d, '${STAGING_DIR_HOST}', ['${STAGING_DIR_HOST}/${libdir}','${STAGING_DIR_HOST}/${base_libdir}'])}"
+
 do_configure:prepend() {
     # old m4 files will cause libtool version don't match
     rm -rf m4/*
     rm -fr libltdl
 }
 
+do_compile:prepend() {
+    if ${@bb.utils.contains('MACHINE_FEATURES', 'qemu-usermode', 'true', 'false', d)}; then
+	export CROSS_LAUNCHER="${QEMU_WRAPPER} "
+    fi
+}
+
+do_install:prepend() {
+    if ${@bb.utils.contains('MACHINE_FEATURES', 'qemu-usermode', 'true', 'false', d)}; then
+	export CROSS_LAUNCHER="${QEMU_WRAPPER} "
+    fi
+}
+
 do_install:append() {
     oe_multilib_header unixodbc.h unixODBC/config.h unixODBC/unixodbc_conf.h
 }