mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: ejo@pengutronix.de, rhi@pengutronix.de, uol@pengutronix.de,
	renaud.barbier@abaco.com, Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH 3/4] scripts: unify libusb.h inclusion
Date: Tue, 14 Sep 2021 15:20:15 +0200	[thread overview]
Message-ID: <20210914132016.22572-3-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20210914132016.22572-1-a.fatoum@pengutronix.de>

We have three host tools using libusb:
imx-usb-loader omap3-usb-loader and omap4_usbboot

All three link against it using `pkg-config --libs libusb-1.0`. All
three also do `pkg-config --cflags libusb-1.0`, but omap3-usb-loader
doesn't actually use it and assumes that <libusb-1.0/libusb.h> will resolve
to something that's correct.

I've also run into downstream patches around broken toolchains that
change <libusb.h> to <libusb-1.0/libusb.h>, so the header is found.

Fix the first issue and workaround the broken toolchains by using GCC 5.0+
__has_include to fallback to <libusb-1.0/libusb.h> if it doesn't exist
or if GCC is older than 5.0.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 scripts/imx/imx-usb-loader.c |  2 +-
 scripts/libusb.h             | 17 +++++++++++++++++
 scripts/omap3-usb-loader.c   |  2 +-
 scripts/omap4_usbboot.c      |  2 +-
 4 files changed, 20 insertions(+), 3 deletions(-)
 create mode 100644 scripts/libusb.h

diff --git a/scripts/imx/imx-usb-loader.c b/scripts/imx/imx-usb-loader.c
index cff77f27f264..78af2b61bb06 100644
--- a/scripts/imx/imx-usb-loader.c
+++ b/scripts/imx/imx-usb-loader.c
@@ -29,12 +29,12 @@
 #include <errno.h>
 #include <string.h>
 #include <stdlib.h>
-#include <libusb.h>
 #include <getopt.h>
 #include <arpa/inet.h>
 #include <linux/kernel.h>
 
 #include "../compiler.h"
+#include "../libusb.h"
 #include "imx.h"
 
 #define get_min(a, b) (((a) < (b)) ? (a) : (b))
diff --git a/scripts/libusb.h b/scripts/libusb.h
new file mode 100644
index 000000000000..892d5422c451
--- /dev/null
+++ b/scripts/libusb.h
@@ -0,0 +1,17 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef SCRIPTS_LIBUSB_H_
+#define SCRIPTS_LIBUSB_H_
+
+#ifdef __has_include
+/* not using && to keep compatibility with older compilers */
+#if __has_include("<libusb.h>")
+#include <libusb.h>
+#define HAS_LIBUSB_H
+#endif
+#endif
+
+#ifndef HAS_LIBUSB_H
+#include <libusb-1.0/libusb.h>
+#endif
+
+#endif
diff --git a/scripts/omap3-usb-loader.c b/scripts/omap3-usb-loader.c
index 599a93856ac3..edc46938d9ba 100644
--- a/scripts/omap3-usb-loader.c
+++ b/scripts/omap3-usb-loader.c
@@ -28,7 +28,7 @@
 #include <errno.h>
 #include <libgen.h>		/* for basename */
 
-#include <libusb-1.0/libusb.h>		/* the main event */
+#include "libusb.h"
 
 /* Device specific defines (OMAP)
  * Primary source: http://www.ti.com/lit/pdf/sprugn4
diff --git a/scripts/omap4_usbboot.c b/scripts/omap4_usbboot.c
index 342efd0c9a40..71e4f0acd1fd 100644
--- a/scripts/omap4_usbboot.c
+++ b/scripts/omap4_usbboot.c
@@ -10,7 +10,7 @@
 #include <fcntl.h>
 #include <string.h>
 #include <sys/mman.h>
-#include <libusb.h>
+#include "libusb.h"
 #include <pthread.h>
 #include <termios.h>
 
-- 
2.30.2


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


  parent reply	other threads:[~2021-09-14 13:22 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-14 13:20 [PATCH 1/4] common: remove !SANDBOX dependency for target tools Ahmad Fatoum
2021-09-14 13:20 ` [PATCH 2/4] common: add new menu " Ahmad Fatoum
2021-09-14 16:00   ` Roland Hieber
2021-09-14 13:20 ` Ahmad Fatoum [this message]
2021-09-14 19:22   ` [PATCH 3/4] scripts: unify libusb.h inclusion Trent Piepho
2021-09-15  8:55     ` Ahmad Fatoum
2021-09-14 13:20 ` [PATCH 4/4] scripts: allow building USB loader tools for target as well Ahmad Fatoum
2021-09-14 19:11   ` Trent Piepho
2021-09-15  8:50     ` Ahmad Fatoum
2021-09-15  9:38       ` Trent Piepho
2021-09-15 10:23         ` Ahmad Fatoum
2021-09-15  8:44   ` Enrico Jörns

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210914132016.22572-3-a.fatoum@pengutronix.de \
    --to=a.fatoum@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    --cc=ejo@pengutronix.de \
    --cc=renaud.barbier@abaco.com \
    --cc=rhi@pengutronix.de \
    --cc=uol@pengutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox