Thread (12 messages) 12 messages, 4 authors, 2021-09-15

Re: [PATCH 4/4] scripts: allow building USB loader tools for target as well

From: Ahmad Fatoum <a.fatoum@pengutronix.de>
Date: 2021-09-15 08:52:19

Hello Trent,

On 14.09.21 21:11, Trent Piepho wrote:
On Tue, Sep 14, 2021 at 6:21 AM Ahmad Fatoum [off-list ref] wrote:
quoted
We currently build the USB loader tools only for the host (build) system,
but it can be useful to cross compile them as well for the target.

We already have some target tools, but support for those is easier,
because they don't link against libraries. We use pkg-config to get
cc and ld flags, but we always assume that pkg-config is for the host
system and there is no well-defined way to request pkg-config for the
target system.

Support this by introducing a new CROSS_PKG_CONFIG. This will be
consulted only for target tools and default to
$(CROSS_COMPILE)pkgconfig.

Users can override it as necessary, for example, with Yocto, pkg-config
will be for the cross environment, so target tools can now be built
with:
I just added support to Buildroot for building imx-usb-loader from
Barebox, since it's nicer than the standalone version of the program.

Since pkgconfig was only used for host tools, I didn't need to make
both host and target pkgconfig work.  But of course that will no
longer be true after this patch.
It still wouldn't break your workflow, imx-usb-loader wasn't built
for target so far.
There is a problem with only supplying CROSS_PKG_CONFIG.  To get both
host and target pkgconfig to work, I also need to supply the env
variables used by pkgconfig, PKG_CONFIG_SYSROOT and PKG_CONFIG_LIBDIR.
You can set these on the environment before starting barebox build.
If you have a $(CROSS_COMPILE)pkg-config that doesn't need any further
configuration, you can use that.
The former makes the paths returned by pkgconfig correct and the
latter controls which set, target or host, of .pc files will be used.

Maybe something like this in the Makefile:

CROSS_PKG_CONFIG ?= $(CROSS_COMPILE)pkg-config
CROSS_PKG_CONFIG_SYSROOT ?= $(PKG_CONFIG_SYSROOT)
CROSS_PKG_CONFIG_LIBDIR ?= $(PKG_CONFIG_LIBDIR)
CROSS_PKG_CONFIG_ENV := \
       PKG_CONFIG_LIBDIR=$(CROSS_PKG_CONFIG_LIBDIR) \
       PKG_CONFIG_SYSROOT=$(CROSS_PKG_CONFIG_SYSROOT)

HOST_LIBUSB_CFLAGS := $(shell $(PKG_CONFIG) --cflags)
CROSS_LIBUSB_CFLAGS := $(shell $(CROSS_PKG_CONFIG_ENV)
$(CROSS_PKG_CONFIG) --cflags)

Then use those everywhere someone wants the libusb cflags.  Repeat for LDFLAGS.
I am not really sold on this. Linux doesn't mess with PKG_CONFIG_ variables
either. For perf the assume $(CROSS_COMPILE)pkg-config to be available.
I think it's a suitbale default for us too. The lines above can go into
a shell script wrapper.
You'll get fewer repeated invocations of pkg-config this way too.
Ye, I thought about that as well, but we do it like this for the host tools,
so I left it for now. It's not much overhead and it makes it a bit easier
to follow what is used.

Cheers,
Ahmad
 


-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help