[Nut-upsdev] Re: adding libusb CFLAGS to generic-hid.c rule

Peter Selinger selinger at mathstat.dal.ca
Tue Nov 8 05:56:36 UTC 2005


Hi Charles,

I think this was a typo anyway; it should have always been <usb.h>,
right? We don't supply usb.h in the build directories.

Note that currently, almost all of the newhidups source files include
usb.h indirectly via newhidups.h -> libusb.h -> libhid.h -> usb.h.
This is a bit unhappy, considering that most of the source files have
no real need for usb.h at all.

I noticed that libusb.h does not contain any #defines or data type
declarations, so there is no reason for another header file to include
libusb.h. I will therefore change newhidups.h to include libhid.h
instead of libusb.h. This simplifies the chain of #includes a bit.

Unfortunately, many source files need the data types defined in
libhid.h. On the other hand, libhid.h needs usb.h for its function
prototypes (but not for the data type definitions). Thus, if the data
types of libhid.h were defined in a separate header file than the
function prototypes, there would be no need for the entire world to
include usb.h. Unfortunately, cleaning up the code in this way is not
currently a priority, since probably libhid.h will be rewritten
anyway.

All the sources that include libusb.h or libhid.h should have a
dependency on $(LIBUSB_CFLAGS). This is not just generic-hid.o (as in
your patch), but actually all the *-hid.o files, and more. 

Also, the $(LIBUSB_CFLAGS) is unnecessary during linking, so I have
removed it from those Makefile lines that are linking commands.

I am enclosing a patch for how I think it should be done. Let me know
if any of this breaks on OS X or does not suit you. 

Charles Lepple wrote:
> 
> Peter,
> 
> attached is a proposed patch to fix compilation of generic-hid.c when
> libusb's usb.h is not in /usr/include (but the -I flag is provided by
> "libusb-config --cflags"). It fixes the build under OS X, where Fink
> installs libusb with --prefix=3D/sw.
> 
> I changed "usb.h" to <usb.h> so that 'make depend' wouldn't generate a
> dependency on 'usb.h' with no path (which breaks the build later,
> since make is looking for usb.h in the build directory).
> 
> Any thoughts before I commit it? I don't want to stomp on any other
> pending changes you might have in that area.
-------------- next part --------------
Index: drivers/Makefile.drvbuild
===================================================================
RCS file: /cvsroot/nut/nut/drivers/Makefile.drvbuild,v
retrieving revision 1.1.1.1.8.1.2.12
diff -u -r1.1.1.1.8.1.2.12 Makefile.drvbuild
--- drivers/Makefile.drvbuild	7 Nov 2005 22:14:20 -0000	1.1.1.1.8.1.2.12
+++ drivers/Makefile.drvbuild	8 Nov 2005 05:52:46 -0000
@@ -79,7 +79,7 @@
   ../include/version.h ../include/upsconf.h dstate.h \
   ../include/parseconf.h ../include/upshandler.h ../include/extstate.h \
   serial.h al175.h
-apc-hid.o: apc-hid.c newhidups.h ../include/config.h libusb.h libhid.h \
+apc-hid.o: apc-hid.c newhidups.h ../include/config.h libhid.h \
   ../include/timehead.h hidtypes.h apc-hid.h ../include/extstate.h \
   dstate.h ../include/attribute.h ../include/parseconf.h \
   ../include/upshandler.h ../include/common.h ../include/attribute.h \
@@ -112,12 +112,12 @@
   ../include/version.h ../include/upsconf.h dstate.h \
   ../include/parseconf.h ../include/upshandler.h ../include/extstate.h \
   serial.h belkin.h ../include/timehead.h
-belkin-hid.o: belkin-hid.c newhidups.h ../include/config.h libusb.h \
-  libhid.h ../include/timehead.h hidtypes.h belkin-hid.h \
-  ../include/extstate.h dstate.h ../include/attribute.h \
-  ../include/parseconf.h ../include/upshandler.h ../include/common.h \
-  ../include/attribute.h ../include/config.h ../include/proto.h \
-  ../include/attribute.h ../include/version.h
+belkin-hid.o: belkin-hid.c newhidups.h ../include/config.h libhid.h \
+  ../include/timehead.h hidtypes.h belkin-hid.h ../include/extstate.h \
+  dstate.h ../include/attribute.h ../include/parseconf.h \
+  ../include/upshandler.h ../include/common.h ../include/attribute.h \
+  ../include/config.h ../include/proto.h ../include/attribute.h \
+  ../include/version.h
 belkinunv.o: belkinunv.c main.h ../include/common.h \
   ../include/attribute.h ../include/config.h ../include/proto.h \
   ../include/attribute.h ../include/version.h ../include/upsconf.h \
@@ -192,12 +192,12 @@
   ../include/attribute.h ../include/version.h ../include/upsconf.h \
   dstate.h ../include/parseconf.h ../include/upshandler.h \
   ../include/extstate.h serial.h gamatronic.h
-generic-hid.o: generic-hid.c newhidups.h ../include/config.h libusb.h \
-  libhid.h ../include/timehead.h hidtypes.h generic-hid.h \
-  ../include/extstate.h dstate.h ../include/attribute.h \
-  ../include/parseconf.h ../include/upshandler.h ../include/common.h \
-  ../include/attribute.h ../include/config.h ../include/proto.h \
-  ../include/attribute.h ../include/version.h main.h ../include/upsconf.h
+generic-hid.o: generic-hid.c newhidups.h ../include/config.h libhid.h \
+  ../include/timehead.h hidtypes.h generic-hid.h ../include/extstate.h \
+  dstate.h ../include/attribute.h ../include/parseconf.h \
+  ../include/upshandler.h ../include/common.h ../include/attribute.h \
+  ../include/config.h ../include/proto.h ../include/attribute.h \
+  ../include/version.h main.h ../include/upsconf.h
 genericups.o: genericups.c main.h ../include/common.h \
   ../include/attribute.h ../include/config.h ../include/proto.h \
   ../include/attribute.h ../include/version.h ../include/upsconf.h \
@@ -250,7 +250,7 @@
   ../include/version.h ../include/upsconf.h dstate.h \
   ../include/parseconf.h ../include/upshandler.h ../include/extstate.h \
   serial.h metasys.h
-mge-hid.o: mge-hid.c newhidups.h ../include/config.h libusb.h libhid.h \
+mge-hid.o: mge-hid.c newhidups.h ../include/config.h libhid.h \
   ../include/timehead.h hidtypes.h mge-hid.h ../include/extstate.h \
   dstate.h ../include/attribute.h ../include/parseconf.h \
   ../include/upshandler.h ../include/common.h ../include/attribute.h \
@@ -277,7 +277,7 @@
   ../include/attribute.h ../include/version.h ../include/upsconf.h \
   dstate.h ../include/parseconf.h ../include/upshandler.h \
   ../include/extstate.h libhid.h ../include/timehead.h hidtypes.h \
-  newhidups.h libusb.h generic-hid.h mge-hid.h apc-hid.h belkin-hid.h
+  libusb.h newhidups.h generic-hid.h mge-hid.h apc-hid.h belkin-hid.h
 nitram.o: nitram.c main.h ../include/common.h ../include/attribute.h \
   ../include/config.h ../include/proto.h ../include/attribute.h \
   ../include/version.h ../include/upsconf.h dstate.h \
@@ -330,12 +330,12 @@
   ../include/attribute.h ../include/version.h ../include/upsconf.h \
   dstate.h ../include/parseconf.h ../include/upshandler.h \
   ../include/extstate.h serial.h tripplite.h
-tripplite-hid.o: tripplite-hid.c newhidups.h ../include/config.h libusb.h \
-  libhid.h ../include/timehead.h hidtypes.h tripplite-hid.h \
-  ../include/extstate.h dstate.h ../include/attribute.h \
-  ../include/parseconf.h ../include/upshandler.h ../include/common.h \
-  ../include/attribute.h ../include/config.h ../include/proto.h \
-  ../include/attribute.h ../include/version.h
+tripplite-hid.o: tripplite-hid.c newhidups.h ../include/config.h libhid.h \
+  ../include/timehead.h hidtypes.h tripplite-hid.h ../include/extstate.h \
+  dstate.h ../include/attribute.h ../include/parseconf.h \
+  ../include/upshandler.h ../include/common.h ../include/attribute.h \
+  ../include/config.h ../include/proto.h ../include/attribute.h \
+  ../include/version.h
 tripplitesu.o: tripplitesu.c main.h ../include/common.h \
   ../include/attribute.h ../include/config.h ../include/proto.h \
   ../include/attribute.h ../include/version.h ../include/upsconf.h \
Index: drivers/Makefile.in
===================================================================
RCS file: /cvsroot/nut/nut/drivers/Makefile.in,v
retrieving revision 1.1.1.1.8.1.2.17
diff -u -r1.1.1.1.8.1.2.17 Makefile.in
--- drivers/Makefile.in	7 Nov 2005 22:14:20 -0000	1.1.1.1.8.1.2.17
+++ drivers/Makefile.in	8 Nov 2005 05:52:46 -0000
@@ -96,20 +96,16 @@
 		$(STRLCPY) libhid.o libusb.o hidparser.o \
 		generic-hid.o mge-hid.o apc-hid.o belkin-hid.o \
 		tripplite-hid.o
-	$(CC) $(CFLAGS) $(LIBUSB_CFLAGS) -o $@ $@.o main.o dstate.o \
+	$(CC) $(CFLAGS) -o $@ $@.o main.o dstate.o \
 		../common/state.o ../common/upsconf.o ../common/parseconf.o \
 		$(LIBOBJ) $(LIBUSB_LIBS) $(LDFLAGS) libhid.o libusb.o hidparser.o \
 		generic-hid.o mge-hid.o apc-hid.o belkin-hid.o \
                 tripplite-hid.o
 
-newhidups.o:
-	$(CC) $(CFLAGS) $(LIBUSB_CFLAGS) -c newhidups.c
-
-libhid.o:
-	$(CC) $(CFLAGS) $(LIBUSB_CFLAGS) -o libhid.o -c libhid.c
-
-libusb.o:
-	$(CC) $(CFLAGS) $(LIBUSB_CFLAGS) -o libusb.o -c libusb.c
+# all the stuff that needs to include $(LIBUSB_CFLAGS):
+newhidups.o libhid.o libusb.o apc-hid.o belkin-hid.o generic-hid.o \
+kebo-hid.o mge-hid.o tripplite-hid.o tripplite_usb.o bcmxcp_usb.o nut_usb.o:
+	$(CC) $(CFLAGS) $(LIBUSB_CFLAGS) -c $<
 
 # ==========================================================================
 # Special case: tripplite_usb driver - development version (early beta)
@@ -117,29 +113,20 @@
 tripplite_usb: tripplite_usb.o main.o dstate.o ../common/state.o \
 		../common/upsconf.o ../common/parseconf.o $(LIBDEP) \
 		$(STRLCPY) libhid.o libusb.o hidparser.o
-	$(CC) $(CFLAGS) $(LIBUSB_CFLAGS) -o $@ $@.o main.o dstate.o \
+	$(CC) $(CFLAGS) -o $@ $@.o main.o dstate.o \
 		../common/state.o ../common/upsconf.o ../common/parseconf.o \
 		$(LIBOBJ) $(LIBUSB_LIBS) $(LDFLAGS) -lm libhid.o libusb.o hidparser.o
 
-tripplite_usb.o: tripplite_usb.c newhidups.h libhid.h
-	$(CC) $(CFLAGS) $(LIBUSB_CFLAGS) -c tripplite_usb.c
-
 # ==========================================================================
 # Special case: bcmxcp_usb.c driver - development version (early beta)
 
 bcmxcp_usb: bcmxcp.o bcmxcp_usb.o nut_usb.o main.o dstate.o ../common/state.o \
 		../common/upsconf.o ../common/parseconf.o $(LIBDEP) $(STRLCPY)
-	$(CC) $(CFLAGS) $(LIBUSB_CFLAGS) -o $@ bcmxcp.o bcmxcp_usb.o nut_usb.o \
+	$(CC) $(CFLAGS) -o $@ bcmxcp.o bcmxcp_usb.o nut_usb.o \
 		main.o dstate.o ../common/state.o ../common/upsconf.o \
 		../common/parseconf.o \
 		$(LIBOBJ) $(LIBUSB_LIBS) $(LDFLAGS)
 
-bcmxcp_usb.o:
-	$(CC) $(CFLAGS) $(LIBUSB_CFLAGS) -c bcmxcp_usb.c
-
-nut_usb.o:
-	$(CC) $(CFLAGS) $(LIBUSB_CFLAGS) -o nut_usb.o -c nut_usb.c
-
 
 # ==========================================================================
 # Special case: mge-shut driver - development version (early beta)
Index: drivers/libhid.h
===================================================================
RCS file: /cvsroot/nut/nut/drivers/libhid.h,v
retrieving revision 1.1.1.1.8.1.2.7
diff -u -r1.1.1.1.8.1.2.7 libhid.h
--- drivers/libhid.h	24 Sep 2005 04:37:25 -0000	1.1.1.1.8.1.2.7
+++ drivers/libhid.h	8 Nov 2005 05:52:46 -0000
@@ -30,9 +30,9 @@
 
 #include <sys/types.h>
 #include <regex.h>
+#include <usb.h>
 #include "timehead.h"
 #include "hidtypes.h"
-#include "usb.h"
 
 /* use explicit booleans */
 #ifndef FALSE
Index: drivers/newhidups.c
===================================================================
RCS file: /cvsroot/nut/nut/drivers/newhidups.c,v
retrieving revision 1.1.1.1.8.6.2.21
diff -u -r1.1.1.1.8.6.2.21 newhidups.c
--- drivers/newhidups.c	7 Nov 2005 22:14:20 -0000	1.1.1.1.8.6.2.21
+++ drivers/newhidups.c	8 Nov 2005 05:52:47 -0000
@@ -23,6 +23,7 @@
 
 #include "main.h"
 #include "libhid.h"
+#include "libusb.h"
 #include "newhidups.h"
 
 /* include all known subdrivers */
Index: drivers/newhidups.h
===================================================================
RCS file: /cvsroot/nut/nut/drivers/newhidups.h,v
retrieving revision 1.1.1.1.8.3.2.15
diff -u -r1.1.1.1.8.3.2.15 newhidups.h
--- drivers/newhidups.h	7 Nov 2005 22:14:20 -0000	1.1.1.1.8.3.2.15
+++ drivers/newhidups.h	8 Nov 2005 05:52:47 -0000
@@ -29,7 +29,7 @@
 #include <string.h>
 #include <unistd.h>
 #include "config.h"
-#include "libusb.h"
+#include "libhid.h"
 
 #define DRIVER_VERSION		"0.28"
 


More information about the Nut-upsdev mailing list