diff --git a/Makefile b/Makefile index ab251f4..0f59bbd 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,9 +79,9 @@ 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) diff --git a/README.md b/README.md index 14e013a..abdf898 100644 --- a/README.md +++ b/README.md @@ -90,3 +90,14 @@ 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 pkg-config +$ make +``` + diff --git a/compat/clock_gettime/clock_gettime.h b/compat/clock_gettime/clock_gettime.h index 83fdac7..3c4c29b 100644 --- a/compat/clock_gettime/clock_gettime.h +++ b/compat/clock_gettime/clock_gettime.h @@ -3,9 +3,17 @@ #include // Apple-only, but this isn't inclued on other BSDs +#ifdef __OpenBSD__ #ifdef _CLOCKID_T_DEFINED_ #define CLOCKID_T #endif +#endif + +#ifdef __APPLE__ +#ifdef CLOCK_MONOTONIC +#define CLOCKID_T +#endif +#endif #ifndef CLOCKID_T #define CLOCKID_T diff --git a/compat/clock_nanosleep/clock_nanosleep.h b/compat/clock_nanosleep/clock_nanosleep.h index 9a8da5d..34eb801 100644 --- a/compat/clock_nanosleep/clock_nanosleep.h +++ b/compat/clock_nanosleep/clock_nanosleep.h @@ -1,9 +1,17 @@ #ifndef CLOCK_NANOSLEEP_H #define CLOCK_NANOSLEEP_H +#ifdef __OpenBSD__ #ifdef _CLOCKID_T_DEFINED_ #define CLOCKID_T #endif +#endif + +#ifdef __APPLE__ +#ifdef CLOCK_MONOTONIC +#define CLOCKID_T +#endif +#endif #ifndef CLOCKID_T #define CLOCKID_T diff --git a/compat/compat.h b/compat/compat.h index 5905e10..f0525bb 100644 --- a/compat/compat.h +++ b/compat/compat.h @@ -18,6 +18,9 @@ # define le16toh(x) OSSwapLittleToHostInt16(x) # define le32toh(x) OSSwapLittleToHostInt32(x) +#elif defined(__FreeBSD__) +#include + #else // other platforms # include