diff --git a/host/CMakeLists.txt b/host/CMakeLists.txt index 28473300..ef285702 100644 --- a/host/CMakeLists.txt +++ b/host/CMakeLists.txt @@ -123,8 +123,7 @@ endif(MSVC) # System configuration ################################################################################ -# Linux (TODO determine if this will actually be sufficient for BSD) -if(${CMAKE_SYSTEM_NAME} MATCHES "Linux" OR ${CMAKE_SYSTEM_NAME} MATCHES "BSD" OR CYGWIN) +if(${CMAKE_SYSTEM_NAME} MATCHES "Linux" OR CYGWIN) set(BLADERF_OS_LINUX 1) if(NOT CMAKE_CROSSCOMPILING AND NOT CYGWIN) @@ -141,6 +140,9 @@ if(${CMAKE_SYSTEM_NAME} MATCHES "Linux" OR ${CMAKE_SYSTEM_NAME} MATCHES "BSD" OR endif() endif(NOT CMAKE_CROSSCOMPILING AND NOT CYGWIN) +elseif(${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD") + set(BLADERF_OS_FREEBSD 1) + elseif(${CMAKE_SYSTEM_NAME} MATCHES "Darwin") set(BLADERF_OS_OSX 1) diff --git a/host/cmake/modules/FindLibUSB.cmake b/host/cmake/modules/FindLibUSB.cmake index c890f23a..f1589393 100644 --- a/host/cmake/modules/FindLibUSB.cmake +++ b/host/cmake/modules/FindLibUSB.cmake @@ -47,12 +47,26 @@ if(WIN32) ) endif() +# FreeBSD has built-in libusb since 800069 +if(${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD") + exec_program(sysctl ARGS -n kern.osreldate OUTPUT_VARIABLE FREEBSD_VERSION) + set(MIN_FREEBSD_VERSION 800068) + if(FREEBSD_VERSION GREATER ${MIN_FREEBSD_VERSION}) + set(LIBUSB_FOUND TRUE) + set(LIBUSB_SKIP_VERSION_CHECK TRUE) + set(LIBUSB_INCLUDE_DIRS "/usr/include") + set(LIBUSB_HEADER_FILE "${LIBUSB_INCLUDE_DIRS}/libusb.h") + set(LIBUSB_LIBRARIES "usb") + set(LIBUSB_LIBRARY_DIRS "/usr/lib/") + endif(FREEBSD_VERSION GREATER ${MIN_FREEBSD_VERSION}) +endif(${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD") + find_package(PkgConfig) if(PKG_CONFIG_FOUND) pkg_check_modules(PKGCONFIG_LIBUSB libusb-1.0 QUIET) endif(PKG_CONFIG_FOUND) -if(PKGCONFIG_LIBUSB_FOUND) +if(PKGCONFIG_LIBUSB_FOUND AND NOT LIBUSB_FOUND) set(LIBUSB_INCLUDE_DIRS ${PKGCONFIG_LIBUSB_INCLUDE_DIRS}) foreach(i ${PKGCONFIG_LIBUSB_LIBRARIES}) string(REGEX MATCH "[^-]*" ibase "${i}") @@ -115,10 +129,10 @@ else(PKGCONFIG_LIBUSB_FOUND) set(LIBUSB_LIBRARIES ${usb_LIBRARY}) endif(usb_LIBRARY) -endif(PKGCONFIG_LIBUSB_FOUND) +endif(PKGCONFIG_LIBUSB_FOUND AND NOT LIBUSB_FOUND) if(LIBUSB_INCLUDE_DIRS AND LIBUSB_LIBRARIES) - set(LIBUSB_FOUND true) + set(LIBUSB_FOUND TRUE) endif(LIBUSB_INCLUDE_DIRS AND LIBUSB_LIBRARIES) if(LIBUSB_FOUND) diff --git a/host/common/include/host_config.h.in b/host/common/include/host_config.h.in index 7c6ca5dc..d6662ff0 100644 --- a/host/common/include/host_config.h.in +++ b/host/common/include/host_config.h.in @@ -28,15 +28,16 @@ #define HOST_CONFIG_H__ #cmakedefine01 BLADERF_OS_LINUX +#cmakedefine01 BLADERF_OS_FREEBSD #cmakedefine01 BLADERF_OS_OSX #cmakedefine01 BLADERF_OS_WINDOWS #cmakedefine01 BLADERF_BIG_ENDIAN -#if !(BLADERF_OS_LINUX || BLADERF_OS_OSX || BLADERF_OS_WINDOWS) +#if !(BLADERF_OS_LINUX || BLADERF_OS_OSX || BLADERF_OS_WINDOWS || BLADERF_OS_FREEBSD) # error "Build not configured for any supported operating systems" #endif -#if 1 < (BLADERF_OS_LINUX + BLADERF_OS_OSX + BLADERF_OS_WINDOWS) +#if 1 < (BLADERF_OS_LINUX + BLADERF_OS_OSX + BLADERF_OS_WINDOWS + BLADERF_OS_FREEBSD) #error "Build configured for multiple operating systems" #endif @@ -77,6 +78,27 @@ #define HOST_TO_BE64(val) be64toh(val) #define BE64_TO_HOST(val) be64toh(val) +/*----------------------- + * FREEBSD + *---------------------*/ +#elif BLADERF_OS_FREEBSD +#include + +#define HOST_TO_LE16(val) htole16(val) +#define LE16_TO_HOST(val) le16toh(val) +#define HOST_TO_BE16(val) htobe16(val) +#define BE16_TO_HOST(val) be16toh(val) + +#define HOST_TO_LE32(val) htole32(val) +#define LE32_TO_HOST(val) le32toh(val) +#define HOST_TO_BE32(val) htobe32(val) +#define BE32_TO_HOST(val) be32toh(val) + +#define HOST_TO_LE64(val) htole64(val) +#define LE64_TO_HOST(val) le64toh(val) +#define HOST_TO_BE64(val) be64toh(val) +#define BE64_TO_HOST(val) be64toh(val) + /*----------------------- * Apple OSX *---------------------*/ @@ -140,6 +162,15 @@ #include #include +/******************************************************************************* + * Miscellaneous FREEBSD fixups + ******************************************************************************/ +#elif BLADERF_OS_FREEBSD + +#include +#include +#include + /******************************************************************************* * Miscellaneous OSX fixups ******************************************************************************/ diff --git a/host/libraries/libbladeRF/CMakeLists.txt b/host/libraries/libbladeRF/CMakeLists.txt index 10a57727..f4e6fa62 100644 --- a/host/libraries/libbladeRF/CMakeLists.txt +++ b/host/libraries/libbladeRF/CMakeLists.txt @@ -413,10 +413,17 @@ configure_file( @ONLY ) +if(${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD") +install( + FILES ${CMAKE_CURRENT_BINARY_DIR}/libbladeRF.pc + DESTINATION ${CMAKE_INSTALL_PREFIX}/libdata/pkgconfig +) +else() install( FILES ${CMAKE_CURRENT_BINARY_DIR}/libbladeRF.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig/ ) +endif(${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD") ################################################################################ # Library installation information diff --git a/host/libraries/libbladeRF/src/file_ops.c b/host/libraries/libbladeRF/src/file_ops.c index 5c9aed2b..3530eca8 100644 --- a/host/libraries/libbladeRF/src/file_ops.c +++ b/host/libraries/libbladeRF/src/file_ops.c @@ -172,7 +172,7 @@ static size_t strip_last_path_entry(char *buf, char dir_delim) return len; } -#if BLADERF_OS_LINUX || BLADERF_OS_OSX +#if BLADERF_OS_LINUX || BLADERF_OS_OSX || BLADERF_OS_FREEBSD #define ACCESS_FILE_EXISTS F_OK #define DIR_DELIMETER '/' @@ -234,6 +234,22 @@ static inline size_t get_binary_dir(char *buf, size_t max_len) return 0; } } +#elif BLADERF_OS_FREEBSD +static inline size_t get_binary_dir(char *buf, size_t max_len) +{ + int mib[4]; + mib[0] = CTL_KERN; + mib[1] = KERN_PROC; + mib[2] = KERN_PROC_PATHNAME; + mib[3] = -1; + ssize_t result = sysctl(mib, 4, buf, &max_len, NULL, 0); + + if (result > 0) { + return strip_last_path_entry(buf, DIR_DELIMETER); + } else { + return 0; + } +} #elif BLADERF_OS_OSX #include static inline size_t get_binary_dir(char *buf, size_t max_len)