summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVadim Mikhailov <vadim.mikhailov@gmail.com>2017-04-04 17:36:50 -0700
committerVadim Mikhailov <mvp@users.noreply.github.com>2017-04-06 11:43:02 -0700
commit40d446b3943d2b4dcee9b51a9007d54045e6efb8 (patch)
tree6167df9b805ae661799497e34009e6317694552a
parent37057c241e3282fca8e6a3ba9fe6c43e91e06fc7 (diff)
Add support for FreeBSD and MacPorts on Mac
-rw-r--r--Makefile20
-rw-r--r--README.md9
-rw-r--r--uhubctl.c4
3 files changed, 25 insertions, 8 deletions
diff --git a/Makefile b/Makefile
index 936ed35..311d62c 100644
--- a/Makefile
+++ b/Makefile
@@ -13,17 +13,29 @@ RM := rm -rf
CC ?= gcc
CFLAGS ?= -g -O0
-
-CFLAGS += -Wall -Wextra
+CFLAGS += -Wall -Wextra
ifeq ($(UNAME_S),Linux)
- LDFLAGS += -Wl,-z,relro
+ LDFLAGS += -Wl,-z,relro -lusb-1.0
+endif
+
+ifeq ($(UNAME_S),Darwin)
+ifneq ($(wildcard /opt/local/include),)
+ # MacPorts
+ CFLAGS += -I/opt/local/include
+ LDFLAGS += -L/opt/local/lib
+endif
+ LDFLAGS += -lusb-1.0
+endif
+
+ifeq ($(UNAME_S),FreeBSD)
+ LDFLAGS += -lusb
endif
PROGRAM = uhubctl
$(PROGRAM): $(PROGRAM).c
- $(CC) $(CFLAGS) $@.c -o $@ -lusb-1.0 $(LDFLAGS)
+ $(CC) $(CFLAGS) $@.c -o $@ $(LDFLAGS)
install:
$(INSTALL_DIR) $(DESTDIR)$(sbindir)
diff --git a/README.md b/README.md
index a4bd7ba..c7b82e8 100644
--- a/README.md
+++ b/README.md
@@ -49,15 +49,16 @@ Compiling
=========
This utility was tested to compile and work on Linux
-(Ubuntu, Redhat/Fedora/CentOS) and on Mac OS X.
+(Ubuntu, Redhat/Fedora/CentOS), FreeBSD and Mac OS X.
It should be possible to compile it for Windows as well -
please report if you succeed in doing that.
First, you need to install library libusb-1.0 (version 1.0.12 or later):
-* Ubuntu: sudo apt-get install libusb-1.0-0-dev
-* Redhat: sudo yum install libusb1-devel
-* MacOSX: brew install libusb
+* Ubuntu: `sudo apt-get install libusb-1.0-0-dev`
+* Redhat: `sudo yum install libusb1-devel`
+* MacOSX: `brew install libusb`, or `sudo port install libusb-devel`
+* FreeBSD: libusb is included by default
* Windows: TBD?
To compile, simply run `make` - this will generate `uhubctl` binary.
diff --git a/uhubctl.c b/uhubctl.c
index 249f2e2..45c5943 100644
--- a/uhubctl.c
+++ b/uhubctl.c
@@ -19,7 +19,11 @@
#include <ctype.h>
#include <unistd.h>
+#ifdef __FreeBSD__
+#include <libusb.h>
+#else
#include <libusb-1.0/libusb.h>
+#endif
/* Max number of hub ports supported.
* This is somewhat artifically limited by "-p" option parser.