[v3] libusb: add an option to compile examples

Message ID 20180611134750.27627-1-gael.portay@savoirfairelinux.com
State Accepted
Headers show
Series
  • [v3] libusb: add an option to compile examples
Related show

Commit Message

Gaël PORTAY June 11, 2018, 1:47 p.m.
Signed-off-by: Gaël PORTAY <gael.portay@savoirfairelinux.com>
---
Changes since v1:
 - remove presence check.

Changes since v2:
 - fix typo in list of examples

 package/libusb/Config.in |  7 +++++++
 package/libusb/libusb.mk | 10 ++++++++++
 2 files changed, 17 insertions(+)

Comments

Thomas Petazzoni June 17, 2018, 1:13 p.m. | #1
Hello,

On Mon, 11 Jun 2018 09:47:50 -0400, Gaël PORTAY wrote:

> +ifeq ($(BR2_PACKAGE_LIBUSB_EXAMPLES),y)
> +LIBUSB_CONF_OPTS += --enable-examples-build
> +define LIBUSB_INSTALL_TARGET_EXAMPLES
> +	for example in listdevs xusb fxload hotplugtest testlibusb dpfp dpfp_threaded sam3u_benchmark ; do \

As I said in a review of an earlier version, you should use a make loop
instead of a shell loop. One benefit of make loops is that they bail
out if one iteration of the loop fails. A shell loop doesn't, and
continues with the next iterations.

> +		cp -dpfr $(@D)/examples/$${example} $(TARGET_DIR)/usr/bin; \

This should have use $(INSTALL) -D -m 0755 and a full destination path.

I've fixed both issues and applied.

Thanks!

Thomas
Gaël PORTAY June 17, 2018, 9:14 p.m. | #2
Thomas,

On Sun, Jun 17, 2018 at 03:13:45PM +0200, Thomas Petazzoni wrote:
> Hello,
> 
> On Mon, 11 Jun 2018 09:47:50 -0400, Gaël PORTAY wrote:
> 
> > +ifeq ($(BR2_PACKAGE_LIBUSB_EXAMPLES),y)
> > +LIBUSB_CONF_OPTS += --enable-examples-build
> > +define LIBUSB_INSTALL_TARGET_EXAMPLES
> > +	for example in listdevs xusb fxload hotplugtest testlibusb dpfp dpfp_threaded sam3u_benchmark ; do \
> 
> As I said in a review of an earlier version, you should use a make loop
> instead of a shell loop. One benefit of make loops is that they bail
> out if one iteration of the loop fails. A shell loop doesn't, and
> continues with the next iterations.
>

Sorry to have missed your review.

Hum... the shell's for loop exits in error too when an iteration fails;
which causes make failure for TARGET_INSTALL (unless set +e is
specified)... or maybe I missed something :/

Whatever, I really do prefer your solution.

> > +		cp -dpfr $(@D)/examples/$${example} $(TARGET_DIR)/usr/bin; \
> 
> This should have use $(INSTALL) -D -m 0755 and a full destination path.
> 
> I've fixed both issues and applied.
> 

I pretty sure I picked up this part of code from another package in
buildroot. I can apply the same changes to keep package consistent.

> Thanks!
> 
> Thomas
> -- 
> Thomas Petazzoni, CTO, Bootlin (formerly Free Electrons)
> Embedded Linux and Kernel engineering
> https://bootlin.com
> _______________________________________________
> buildroot mailing list
> buildroot@busybox.net
> http://lists.busybox.net/mailman/listinfo/buildroot
Thomas Petazzoni June 17, 2018, 9:30 p.m. | #3
Hello,

On Sun, 17 Jun 2018 17:14:01 -0400, Gaël PORTAY wrote:

> > As I said in a review of an earlier version, you should use a make loop
> > instead of a shell loop. One benefit of make loops is that they bail
> > out if one iteration of the loop fails. A shell loop doesn't, and
> > continues with the next iterations.
> >  
> 
> Sorry to have missed your review.
> 
> Hum... the shell's for loop exits in error too when an iteration fails;
> which causes make failure for TARGET_INSTALL (unless set +e is
> specified)... or maybe I missed something :/

I don't think shell snippets executed by make are executed with set -e.

> > > +		cp -dpfr $(@D)/examples/$${example} $(TARGET_DIR)/usr/bin; \  
> > 
> > This should have use $(INSTALL) -D -m 0755 and a full destination path.
> > 
> > I've fixed both issues and applied.
> >   
> 
> I pretty sure I picked up this part of code from another package in
> buildroot. I can apply the same changes to keep package consistent.

We do use "cp -dpfr" to copy entire directories. But for individual
files, we prefer $(INSTALL).

Best regards,

Thomas

Patch

diff --git a/package/libusb/Config.in b/package/libusb/Config.in
index 5238588aa8..d31a717fdf 100644
--- a/package/libusb/Config.in
+++ b/package/libusb/Config.in
@@ -6,5 +6,12 @@  config BR2_PACKAGE_LIBUSB
 
 	  http://libusb.info/
 
+if BR2_PACKAGE_LIBUSB
+
+config BR2_PACKAGE_LIBUSB_EXAMPLES
+	bool "build libusb examples"
+
+endif
+
 comment "libusb needs a toolchain w/ threads"
 	depends on !BR2_TOOLCHAIN_HAS_THREADS
diff --git a/package/libusb/libusb.mk b/package/libusb/libusb.mk
index aee3622f8d..32f15c9612 100644
--- a/package/libusb/libusb.mk
+++ b/package/libusb/libusb.mk
@@ -25,5 +25,15 @@  else
 LIBUSB_CONF_OPTS += --disable-udev
 endif
 
+ifeq ($(BR2_PACKAGE_LIBUSB_EXAMPLES),y)
+LIBUSB_CONF_OPTS += --enable-examples-build
+define LIBUSB_INSTALL_TARGET_EXAMPLES
+	for example in listdevs xusb fxload hotplugtest testlibusb dpfp dpfp_threaded sam3u_benchmark ; do \
+		cp -dpfr $(@D)/examples/$${example} $(TARGET_DIR)/usr/bin; \
+	done
+endef
+LIBUSB_POST_INSTALL_TARGET_HOOKS += LIBUSB_INSTALL_TARGET_EXAMPLES
+endif
+
 $(eval $(autotools-package))
 $(eval $(host-autotools-package))