Patchwork pkgconfig: add -native script that uses the native sysroot instead of target

login
register
mail settings
Submitter Ross Burton
Date Jan. 8, 2013, 3:23 p.m.
Message ID <1357658627-31689-1-git-send-email-ross.burton@intel.com>
Download mbox | patch
Permalink /patch/42329/
State Accepted
Commit 4bb69608bb81c44853729d7bb8fc9ddf75bf32c4
Headers show

Comments

Ross Burton - Jan. 8, 2013, 3:23 p.m.
pkg-config-native is useful when building a package for the target that needs to
compile a build-time tool, to avoid having to hard-code many paths.

Signed-off-by: Ross Burton <ross.burton@intel.com>
---
 meta/recipes-devtools/pkgconfig/pkgconfig.inc                |   10 ++++++++++
 .../pkgconfig/pkgconfig/pkg-config-native.in                 |    7 +++++++
 2 files changed, 17 insertions(+)
 create mode 100644 meta/recipes-devtools/pkgconfig/pkgconfig/pkg-config-native.in
Enrico Scholz - Jan. 8, 2013, 4:06 p.m.
Ross Burton <ross.burton-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
writes:

> pkg-config-native is useful when building a package for the target that needs to
> compile a build-time tool, to avoid having to hard-code many paths.

how will you call this wrapper when e.g. makefile contains:

| foo_CFLAGS = $(shell pkg-config --cflags foo)

? 

A more powerful approach might be to install it as 'pkg-config' under
${STAGING_BINDIR_NATIVE}/pkg-config-native/ and prepend this dir to
$PATH when executing the makefile above.


> --- /dev/null
> +++ b/meta/recipes-devtools/pkgconfig/pkgconfig/pkg-config-native.in
> @@ -0,0 +1,7 @@
> +#! /bin/sh
> +
> +PKG_CONFIG_PATH="@PATH_NATIVE@"
> +PKG_CONFIG_LIBDIR="@LIBDIR_NATIVE@"
> +unset PKG_CONFIG_SYSROOT_DIR
> +
> +pkg-config "$@"

1. last 'pkg-config' should be called with 'exec'

2. it depends on too much assumptions (e.g. that PKG_CONFIG_PATH and
   _LIBDIR are already exported.

I would write it:

| #! /bin/sh
| exec env -u PKG_CONFIG_SYSROOT_DIR \
|    PKG_CONFIG_PATH="@PATH_NATIVE@" \
|    PKG_CONFIG_LIBDIR="@LIBDIR_NATIVE@" \
|    pkg-config "$@"


Enrico
Ross Burton - Jan. 8, 2013, 4:15 p.m.
On 8 January 2013 16:06, Enrico Scholz <enrico.scholz@sigma-chemnitz.de> wrote:
> how will you call this wrapper when e.g. makefile contains:
>
> | foo_CFLAGS = $(shell pkg-config --cflags foo)

You use PKG_CONFIG_FOR_BUILD, along with CC_FOR_BUILD etc.

> A more powerful approach might be to install it as 'pkg-config' under
> ${STAGING_BINDIR_NATIVE}/pkg-config-native/ and prepend this dir to
> $PATH when executing the makefile above.

This is for when cross-compiling a package that needs a native tool,
and building that tool is easiest with pkg-config.  The pkg-config
binaries *need* to have different names.

Concrete example: I've a patch to GTK+3 which uses
PKG_CONFIG_FOR_BUILD to find a host gdk-pixbuf so it can build a
native gtk-update-icon-cache instead of depending on gtk+3-native.
This pkg-config needs a different name as otherwise it would be used
instead of the cross-pkg-config.

Ross

Patch

diff --git a/meta/recipes-devtools/pkgconfig/pkgconfig.inc b/meta/recipes-devtools/pkgconfig/pkgconfig.inc
index c54e325..c4fa456 100644
--- a/meta/recipes-devtools/pkgconfig/pkgconfig.inc
+++ b/meta/recipes-devtools/pkgconfig/pkgconfig.inc
@@ -15,6 +15,7 @@  DEPENDS_class-nativesdk = ""
 SRC_URI = "http://pkgconfig.freedesktop.org/releases/pkg-config-${PV}.tar.gz \
            file://autofoo.patch \
            file://glibconfig-sysdefs.h \
+           file://pkg-config-native.in \
            file://disable-legacy.patch"
 
 S = "${WORKDIR}/pkg-config-${PV}/"
@@ -43,3 +44,12 @@  FILES_${PN} += "${datadir}/aclocal/pkg.m4"
 # will end up requiring 'pkgconfig(pkg-config)'.  Allow this behavior by
 # specifying an appropriate provide.
 RPROVIDES_${PN} += "pkgconfig(pkg-config) (= ${PV})"
+
+# Install a pkg-config-native wrapper that will use the native sysroot instead
+# of the MACHINE sysroot, for using pkg-config when building native tools.
+do_install_append_class-native () {
+    sed -e "s|@PATH_NATIVE@|${PKG_CONFIG_PATH}|" \
+        -e "s|@LIBDIR_NATIVE@|${PKG_CONFIG_LIBDIR}|" \
+        < ${WORKDIR}/pkg-config-native.in > ${B}/pkg-config-native
+    install -m755 ${B}/pkg-config-native ${D}${bindir}/pkg-config-native
+}
diff --git a/meta/recipes-devtools/pkgconfig/pkgconfig/pkg-config-native.in b/meta/recipes-devtools/pkgconfig/pkgconfig/pkg-config-native.in
new file mode 100644
index 0000000..5e44bb4
--- /dev/null
+++ b/meta/recipes-devtools/pkgconfig/pkgconfig/pkg-config-native.in
@@ -0,0 +1,7 @@ 
+#! /bin/sh
+
+PKG_CONFIG_PATH="@PATH_NATIVE@"
+PKG_CONFIG_LIBDIR="@LIBDIR_NATIVE@"
+unset PKG_CONFIG_SYSROOT_DIR
+
+pkg-config "$@"