Index: MSPDebugStack_OS_Package/DLL430_v3/src/TI/DLL430/EnergyTrace_TSPA/EnergyTraceProcessorId7.h
===================================================================
--- MSPDebugStack_OS_Package.orig/DLL430_v3/src/TI/DLL430/EnergyTrace_TSPA/EnergyTraceProcessorId7.h	2015-07-01 12:14:54.527495418 -0400
+++ MSPDebugStack_OS_Package/DLL430_v3/src/TI/DLL430/EnergyTrace_TSPA/EnergyTraceProcessorId7.h	2015-07-01 12:17:32.955712718 -0400
@@ -55,7 +55,7 @@
 
 #include "EnergyTraceProcessor.h"
 #include <DoubleBuffer.h>
-
+#include <cstdio>
 
 //#define ETLOG
 
Index: MSPDebugStack_OS_Package/Makefile
===================================================================
--- MSPDebugStack_OS_Package.orig/Makefile	2015-07-01 12:14:56.455498068 -0400
+++ MSPDebugStack_OS_Package/Makefile	2015-07-01 12:17:27.555705326 -0400
@@ -15,10 +15,16 @@
 MAKE_PCH += -x c++-header
 USE_PCH += -include $(PCH_HEADER)
 
+OS := $(shell uname -s)
+use_system_hidapi := $(shell pkg-config --modversion hidapi-libusb >/dev/null 2>/dev/null && echo 'yes' || echo 'no')
+
 export BOOST_DIR
 export BIT32
 export STATIC
 export DEBUG
+export OS
+export MAKE
+export use_system_hidapi
 
 INCLUDES := \
 	-I./DLL430_v3/src/TI/DLL430 \
@@ -98,6 +104,13 @@
 
 BSLLIB := $(LIBTHIRD)/libbsl430.a
 
+ifeq ($(use_system_hidapi),yes)
+	INCLUDES += $(shell pkg-config --cflags hidapi-libusb)
+	LIBS += $(shell pkg-config --libs hidapi-libusb)
+	HIDAPI := -lhidapi-libusb
+else
+	HIDAPI := ThirdParty/lib/hid-libusb.o
+endif
 
 SRC := \
         ./DLL430_v3/src/TI/DLL430/EEM/CycleCounter.cpp \
@@ -124,7 +137,7 @@
 OBJS := $(patsubst %.cpp, %.o, $(SRC))
 
 all: $(BSLLIB) $(OBJS)
-	$(CXX) $(CXXFLAGS) -shared $(OUTNAME)$(OUTPUT) -o $(OUTPUT) $(OBJS) $(HIDOBJ) $(LIBDIRS) $(BSTATIC) $(STATIC_LIBS) $(BDYNAMIC) $(LIBS)
+	$(CXX) $(CXXFLAGS) -shared $(OUTNAME)$(OUTPUT) -o $(OUTPUT) $(OBJS) $(HIDAPI) $(LIBDIRS) $(BSTATIC) $(STATIC_LIBS) $(BDYNAMIC) $(LIBS)
 
 $(PCH_COMPILED): $(PCH_HEADER)
 	$(CXX) $(MAKE_PCH) -o $@ $< $(CXXFLAGS) $(INCLUDES) $(DEFINES)
@@ -133,6 +146,9 @@
 	$(CXX) -c -o $@ $< $(USE_PCH) $(CXXFLAGS) $(INCLUDES) $(DEFINES)
 
 $(BSLLIB):
+ifneq ($(HIDAPI),-lhidapi-libusb)
+	$(MAKE) -C ThirdParty
+endif
 	$(MAKE) -C ./ThirdParty/BSL430_DLL
 
 install:
Index: MSPDebugStack_OS_Package/ThirdParty/BSL430_DLL/Makefile
===================================================================
--- MSPDebugStack_OS_Package.orig/ThirdParty/BSL430_DLL/Makefile	2015-07-01 12:14:56.451498064 -0400
+++ MSPDebugStack_OS_Package/ThirdParty/BSL430_DLL/Makefile	2015-07-01 12:17:27.555705326 -0400
@@ -32,7 +32,8 @@
 
 OBJS := $(patsubst %.cpp, %.o, $(SRC))
 
-OUTPUT := ../lib64/libbsl430.a
+OUTPUT_DIR := ../lib64
+OUTPUT := $(OUTPUT_DIR)/libbsl430.a
 
 PLATFORM := $(shell uname -s)
 ifeq ($(PLATFORM),Linux)
@@ -43,6 +44,10 @@
 	OUTPUT := ../lib/libbsl430.a
 	endif
 
+	ifeq ($(use_system_hidapi),yes)
+		INCLUDES += $(shell pkg-config --cflags hidapi-libusb)
+	endif
+
 	ifdef BOOST_DIR
 	INCLUDES += -I$(BOOST_DIR)
 	endif
@@ -55,7 +60,8 @@
 endif
 
 all: $(OBJS)
-	ar -cq $(OUTPUT) $(OBJS)
+	mkdir -p $(OUTPUT_DIR)
+	ar rcs $(OUTPUT) $(OBJS)
 
 $(PCH_COMPILED): $(PCH_HEADER)
 	$(CXX) $(MAKE_PCH) -c -o $@ $< $(CXXFLAGS) $(INCLUDES) $(DEFINES)
Index: MSPDebugStack_OS_Package/ThirdParty/Makefile
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ MSPDebugStack_OS_Package/ThirdParty/Makefile	2015-07-01 12:17:32.955712718 -0400
@@ -0,0 +1,5 @@
+
+all:
+	$(SHELL) install_thirdparty.sh
+
+.PHONY: all
Index: MSPDebugStack_OS_Package/ThirdParty/install_thirdparty.sh
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ MSPDebugStack_OS_Package/ThirdParty/install_thirdparty.sh	2015-07-01 12:17:32.955712718 -0400
@@ -0,0 +1,51 @@
+#!/bin/sh
+
+cd "$( dirname "${0}" )"
+
+rm -f lib/hid-libusb.o include/hidapi.h
+rm -rf hidapi
+
+git clone https://github.com/signal11/hidapi.git
+cd hidapi
+
+if [ "$( uname -s )" = "FreeBSD" ]
+then
+	# Use libusb_handle_events() instead of libusb_handle_events_completed()
+	# in libusb/hid.c
+	patch -b '' -p1 <<EOF
+diff --git a/libusb/hid.c b/libusb/hid.c
+index 6c1d247..2b4e192 100644
+--- a/libusb/hid.c
++++ b/libusb/hid.c
+@@ -757,7 +757,11 @@ static void *read_thread(void *param)
+ 	libusb_cancel_transfer(dev->transfer);
+ 
+ 	while (!dev->cancelled)
++#if defined(__FreeBSD__)
++		libusb_handle_events(usb_context);
++#else
+ 		libusb_handle_events_completed(usb_context, &dev->cancelled);
++#endif
+ 
+ 	/* Now that the read thread is stopping, Wake any threads which are
+ 	   waiting on data (in hid_read_timeout()). Do this under a mutex to
+EOF
+fi
+
+./bootstrap
+./configure
+${MAKE:-make}
+
+if [ ! -f hidapi/hidapi.h -o ! -f libusb/.libs/hid.o ]
+then
+	echo "hidapi: Build failed"
+	exit 1
+fi
+
+mkdir -p ../include ../lib
+cp hidapi/hidapi.h ../include/hidapi.h && \
+cp libusb/.libs/hid.o ../lib/hid-libusb.o && \
+cd .. && \
+rm -rf hidapi
+echo "hidapi: Build ok (ignore any errors above)"
+:
