diff --git a/Makefile b/Makefile index ab251f4..6c99b3f 100644 --- a/Makefile +++ b/Makefile @@ -1,36 +1,77 @@ PROGNAME=dump1090 -# Try to autodetect available libraries if no explicit setting was used - -ifndef RTLSDR - ifdef RTLSDR_PREFIX - RTLSDR := yes - else - RTLSDR := $(shell pkg-config --exists librtlsdr && echo "yes" || echo "no") - endif -endif - -ifndef BLADERF - BLADERF := $(shell pkg-config --exists libbladeRF && echo "yes" || echo "no") -endif - -ifndef HACKRF - HACKRF := $(shell pkg-config --exists libhackrf && echo "yes" || echo "no") -endif - -ifndef LIMESDR - LIMESDR := $(shell pkg-config --exists LimeSuite && echo "yes" || echo "no") -endif - DUMP1090_VERSION ?= unknown CPPFLAGS += -DMODES_DUMP1090_VERSION=\"$(DUMP1090_VERSION)\" -DMODES_DUMP1090_VARIANT=\"dump1090-fa\" DIALECT = -std=c11 CFLAGS += $(DIALECT) -O3 -g -Wall -Wmissing-declarations -Werror -W -D_DEFAULT_SOURCE -fno-common -LIBS = -lpthread -lm -lrt +LIBS = -lpthread -lm SDR_OBJ = sdr.o fifo.o sdr_ifile.o +# Try to autodetect available libraries via pkg-config if no explicit setting was used +PKGCONFIG=$(shell pkg-config --version >/dev/null 2>&1 && echo "yes" || echo "no") +ifeq ($(PKGCONFIG), yes) + ifndef RTLSDR + ifdef RTLSDR_PREFIX + RTLSDR := yes + else + RTLSDR := $(shell pkg-config --exists librtlsdr && echo "yes" || echo "no") + endif + endif + + ifndef BLADERF + BLADERF := $(shell pkg-config --exists libbladeRF && echo "yes" || echo "no") + endif + + ifndef HACKRF + HACKRF := $(shell pkg-config --exists libhackrf && echo "yes" || echo "no") + endif + + ifndef LIMESDR + LIMESDR := $(shell pkg-config --exists LimeSuite && echo "yes" || echo "no") + endif +else + # pkg-config not available. Only use explicitly enabled libraries. + RTLSDR ?= no + BLADERF ?= no + HACKRF ?= no + LIMESDR ?= no +endif + +UNAME := $(shell uname) + +ifeq ($(UNAME), Linux) + CFLAGS += -D_DEFAULT_SOURCE + LIBS += -lrt + LIBS_USB += -lusb-1.0 +endif + +ifeq ($(UNAME), Darwin) + ifneq ($(shell sw_vers -productVersion | egrep '^10\.([0-9]|1[01])\.'),) # Mac OS X ver <= 10.11 + CFLAGS += -DMISSING_GETTIME + COMPAT += compat/clock_gettime/clock_gettime.o + endif + CFLAGS += -DMISSING_NANOSLEEP + COMPAT += compat/clock_nanosleep/clock_nanosleep.o + LIBS_USB += -lusb-1.0 +endif + +ifeq ($(UNAME), OpenBSD) + CFLAGS += -DMISSING_NANOSLEEP + COMPAT += compat/clock_nanosleep/clock_nanosleep.o + LIBS_USB += -lusb-1.0 +endif + +ifeq ($(UNAME), FreeBSD) + CFLAGS += -D_DEFAULT_SOURCE + LIBS += -lrt + LIBS_USB += -lusb +endif + +RTLSDR ?= yes +BLADERF ?= yes + ifeq ($(RTLSDR), yes) SDR_OBJ += sdr_rtlsdr.o CPPFLAGS += -DENABLE_RTLSDR @@ -38,13 +79,19 @@ ifeq ($(RTLSDR), yes) ifdef RTLSDR_PREFIX CPPFLAGS += -I$(RTLSDR_PREFIX)/include ifeq ($(STATIC), yes) - LIBS_SDR += -L$(RTLSDR_PREFIX)/lib -Wl,-Bstatic -lrtlsdr -Wl,-Bdynamic -lusb-1.0 + LIBS_SDR += -L$(RTLSDR_PREFIX)/lib -Wl,-Bstatic -lrtlsdr -Wl,-Bdynamic $(LIBS_USB) else - LIBS_SDR += -L$(RTLSDR_PREFIX)/lib -lrtlsdr -lusb-1.0 + LIBS_SDR += -L$(RTLSDR_PREFIX)/lib -lrtlsdr $(LIBS_USB) endif else - CFLAGS += $(shell pkg-config --cflags librtlsdr) # some packaged .pc files are massively broken, try to handle it + + # FreeBSD's librtlsdr.pc includes -std=gnu89 in cflags + RTLSDR_CFLAGS := $(shell pkg-config --cflags librtlsdr) + CFLAGS += $(filter-out -std=%,$(RTLSDR_CFLAGS)) + + # some linux librtlsdr packages return a bare -L with no path in --libs + # which horribly confuses things because it eats the next option on the command line RTLSDR_LFLAGS := $(shell pkg-config --libs-only-L librtlsdr) ifeq ($(RTLSDR_LFLAGS),-L) LIBS_SDR += $(shell pkg-config --libs-only-l --libs-only-other librtlsdr) diff --git a/README.md b/README.md index 14e013a..2d6cdb2 100644 --- a/README.md +++ b/README.md @@ -90,3 +90,15 @@ libhackrf. ``make LIMESDR=no`` will disable LimeSDR support and remove the dependency on libLimeSuite. + +## Building on OSX + +Minimal testing, YMMV. + +``` +$ brew install librtlsdr +$ brew install libbladerf +$ brew install pkg-config +$ make +``` + diff --git a/compat/clock_gettime/clock_gettime.c b/compat/clock_gettime/clock_gettime.c index 372ff2e..cd2f824 100644 --- a/compat/clock_gettime/clock_gettime.c +++ b/compat/clock_gettime/clock_gettime.c @@ -58,8 +58,8 @@ * */ - -#include "clock_gettime.h" +#include "../compat.h" +#include #include // for clock_get_time #include // for mach_timespec_t, CALENDAR_CLOCK, etc #include // for KERN_SUCCESS, kern_return_t @@ -70,6 +70,8 @@ #include // for EINVAL, errno #include // for getpid +static mach_timebase_info_data_t __clock_gettime_inf; + int clock_gettime(clockid_t clk_id, struct timespec *tp) { kern_return_t ret; diff --git a/compat/clock_gettime/clock_gettime.h b/compat/clock_gettime/clock_gettime.h index 83fdac7..a7dc7ae 100644 --- a/compat/clock_gettime/clock_gettime.h +++ b/compat/clock_gettime/clock_gettime.h @@ -1,27 +1,6 @@ #ifndef CLOCK_GETTIME_H #define CLOCK_GETTIME_H -#include // Apple-only, but this isn't inclued on other BSDs - -#ifdef _CLOCKID_T_DEFINED_ -#define CLOCKID_T -#endif - -#ifndef CLOCKID_T -#define CLOCKID_T -typedef enum -{ - CLOCK_REALTIME, - CLOCK_MONOTONIC, - CLOCK_PROCESS_CPUTIME_ID, - CLOCK_THREAD_CPUTIME_ID -} clockid_t; -#endif // ifndef CLOCKID_T - -struct timespec; - -static mach_timebase_info_data_t __clock_gettime_inf; - int clock_gettime(clockid_t clk_id, struct timespec *tp); #endif // CLOCK_GETTIME_H diff --git a/compat/clock_nanosleep/clock_nanosleep.c b/compat/clock_nanosleep/clock_nanosleep.c index f6e3d84..0eeb359 100644 --- a/compat/clock_nanosleep/clock_nanosleep.c +++ b/compat/clock_nanosleep/clock_nanosleep.c @@ -22,10 +22,7 @@ #include // for errno, EINVAL #include // for nanosleep, NULL -#include "clock_nanosleep.h" -#ifdef MISSING_GETTIME -#include "../clock_gettime/clock_gettime.h" // for clock_gettime -#endif +#include "../compat.h" int clock_nanosleep(clockid_t id, int flags, const struct timespec *ts, struct timespec *ots) { diff --git a/compat/clock_nanosleep/clock_nanosleep.h b/compat/clock_nanosleep/clock_nanosleep.h index 9a8da5d..5e1f0c3 100644 --- a/compat/clock_nanosleep/clock_nanosleep.h +++ b/compat/clock_nanosleep/clock_nanosleep.h @@ -1,28 +1,6 @@ #ifndef CLOCK_NANOSLEEP_H #define CLOCK_NANOSLEEP_H -#ifdef _CLOCKID_T_DEFINED_ -#define CLOCKID_T -#endif - -#ifndef CLOCKID_T -#define CLOCKID_T -typedef enum -{ - CLOCK_REALTIME, - CLOCK_MONOTONIC, - CLOCK_PROCESS_CPUTIME_ID, - CLOCK_THREAD_CPUTIME_ID -} clockid_t; -#endif // ifndef CLOCKID_T - - -#ifndef TIMER_ABSTIME -#define TIMER_ABSTIME 1 -#endif // TIMER_ABSTIME - -struct timespec; - int clock_nanosleep (clockid_t id, int flags, const struct timespec *ts, struct timespec *ots); diff --git a/compat/compat.h b/compat/compat.h index 5905e10..f94015f 100644 --- a/compat/compat.h +++ b/compat/compat.h @@ -17,6 +17,10 @@ # include # define le16toh(x) OSSwapLittleToHostInt16(x) # define le32toh(x) OSSwapLittleToHostInt32(x) +# define le64toh(x) OSSwapLittleToHostInt64(x) + +#elif defined(__FreeBSD__) +#include #else // other platforms @@ -24,6 +28,30 @@ #endif +/* clock_* and time-related types */ + +#include + +#if defined(CLOCK_REALTIME) +# define HAVE_CLOCKID_T +#endif + +#ifndef HAVE_CLOCKID_T +typedef enum +{ + CLOCK_REALTIME, + CLOCK_MONOTONIC, + CLOCK_PROCESS_CPUTIME_ID, + CLOCK_THREAD_CPUTIME_ID +} clockid_t; +#endif // !HAVE_CLOCKID_T + +#ifndef TIMER_ABSTIME +#define TIMER_ABSTIME 1 +#endif // !TIMER_ABSTIME + +struct timespec; + #ifdef MISSING_NANOSLEEP #include "clock_nanosleep/clock_nanosleep.h" #endif