From 1d59daa8398c1f77477f669d37a5b907287ccf7d Mon Sep 17 00:00:00 2001 From: Helge Titlestad Date: Mon, 21 Sep 2015 17:56:46 +0200 Subject: [PATCH 1/3] Make it possible to compile and link without librtlsdr for net-only operation --- Makefile | 15 +++++++++++++-- dump1090.c | 22 +++++++++++++++++++++- dump1090.h | 5 +++++ view1090.h | 3 +++ 4 files changed, 42 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 6bfe9ee14..95f256e30 100644 --- a/Makefile +++ b/Makefile @@ -10,8 +10,19 @@ SHAREDIR=$(PREFIX)/share/$(PROGNAME) EXTRACFLAGS=-DHTMLPATH=\"$(SHAREDIR)\" endif -CFLAGS=-O2 -g -Wall -W `pkg-config --cflags librtlsdr` -LIBS=`pkg-config --libs librtlsdr` -lpthread -lm +# Set NORTLSDR to compile without librtlsdr e.g. "make NORTLSDR=1" +ifndef NORTLSDR +ifeq ($(shell pkg-config --exists librtlsdr || echo "F"), F) +$(warning librtlsdr not found - please install it, or build with "NORTLSDR=1" to build with RTL SDR support.) +endif +RTLSDR_CFLAGS=$(shell pkg-config --cflags librtlsdr) +RTLSDR_LDFLAGS=$(shell pkg-config --libs librtlsdr) +else +RTLSDR_CFLAGS=-DNORTLSDR +endif + +CFLAGS=-O2 -g -Wall -W $(RTLSDR_CFLAGS) +LDFLAGS+=$(RTLSDR_LDFLAGS) -lpthread -lm CC=gcc diff --git a/dump1090.c b/dump1090.c index 60882fc73..d24b53e0e 100644 --- a/dump1090.c +++ b/dump1090.c @@ -188,6 +188,8 @@ void modesInit(void) { // Prepare error correction tables modesInitErrorInfo(); } + +#ifndef NORTLSDR // // =============================== RTLSDR handling ========================== // @@ -286,6 +288,8 @@ void rtlsdrCallback(unsigned char *buf, uint32_t len, void *ctx) { pthread_cond_signal(&Modes.data_cond); pthread_mutex_unlock(&Modes.data_mutex); } +#endif + // //========================================================================= // @@ -351,9 +355,11 @@ void *readerThreadEntryPoint(void *arg) { MODES_NOTUSED(arg); if (Modes.filename == NULL) { +#ifndef NORTLSDR rtlsdr_read_async(Modes.dev, rtlsdrCallback, NULL, MODES_ASYNC_BUF_NUMBER, MODES_ASYNC_BUF_SIZE); +#endif } else { readDataFromFile(); } @@ -595,6 +601,8 @@ void backgroundTasks(void) { } } } + +#ifndef NORTLSDR // //========================================================================= // @@ -657,6 +665,8 @@ int verbose_device_search(char *s) fprintf(stderr, "No matching devices found.\n"); return -1; } +#endif + // //========================================================================= // @@ -672,7 +682,11 @@ int main(int argc, char **argv) { int more = j+1 < argc; // There are more arguments if (!strcmp(argv[j],"--device-index") && more) { +#ifndef NORTLSDR Modes.dev_index = verbose_device_search(argv[++j]); +#else + assert(!"Compiled without librtlsdr support"); +#endif } else if (!strcmp(argv[j],"--gain") && more) { Modes.gain = (int) (atof(argv[++j])*10); // Gain is in tens of DBs } else if (!strcmp(argv[j],"--enable-agc")) { @@ -803,7 +817,11 @@ int main(int argc, char **argv) { if (Modes.net_only) { fprintf(stderr,"Net-only mode, no RTL device or file open.\n"); } else if (Modes.filename == NULL) { +#ifndef NORTLSDR modesInitRTLSDR(); +#else + assert(!"Compiled without librtlsdr support"); +#endif } else { if (Modes.filename[0] == '-' && Modes.filename[1] == '\0') { Modes.fd = STDIN_FILENO; @@ -886,9 +904,11 @@ int main(int argc, char **argv) { display_stats(); } - if (Modes.filename == NULL) { + if (Modes.filename == NULL && !Modes.net_only) { +#ifndef NORTLSDR rtlsdr_cancel_async(Modes.dev); // Cancel rtlsdr_read_async will cause data input thread to terminate cleanly rtlsdr_close(Modes.dev); +#endif } pthread_cond_destroy(&Modes.data_cond); // Thread cleanup pthread_mutex_destroy(&Modes.data_mutex); diff --git a/dump1090.h b/dump1090.h index 9ad4de037..c509dcbdc 100644 --- a/dump1090.h +++ b/dump1090.h @@ -57,7 +57,10 @@ #include #include #include + #include +#ifndef NORTLSDR #include "rtl-sdr.h" +#endif #include "anet.h" #else #include "winstubs.h" //Put everything Windows specific in here @@ -263,7 +266,9 @@ struct { // Internal state int dev_index; int gain; int enable_agc; +#ifndef NORTLSDR rtlsdr_dev_t *dev; +#endif int freq; int ppm_error; diff --git a/view1090.h b/view1090.h index 03ad96d11..bab6127eb 100644 --- a/view1090.h +++ b/view1090.h @@ -51,7 +51,10 @@ #include #include #include + #include +#ifndef NORTLSDR #include "rtl-sdr.h" +#endif #include "anet.h" #else #include "winstubs.h" //Put everything Windows specific in here From 13ff0ae546aa5e331ac651688a3d64a69bbcf57b Mon Sep 17 00:00:00 2001 From: Helge Titlestad Date: Mon, 21 Sep 2015 18:51:29 +0200 Subject: [PATCH 2/3] Add NORTLSDR info to README.md --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 3fdd396ed..8a85b56c0 100644 --- a/README.md +++ b/README.md @@ -27,6 +27,9 @@ Installation Type "make". +To compile without RTL SDR support (your binaries will only be useable for +network operations), run "make NORTLSDR=1" instead. + Normal usage --- From 1408cf3b3592a32e0782be9b12e28ee49351c619 Mon Sep 17 00:00:00 2001 From: Helge Titlestad Date: Mon, 21 Sep 2015 18:54:01 +0200 Subject: [PATCH 3/3] view1090 does not requires rtl-sdr.h --- view1090.h | 4 ---- 1 file changed, 4 deletions(-) diff --git a/view1090.h b/view1090.h index bab6127eb..a4125c392 100644 --- a/view1090.h +++ b/view1090.h @@ -51,10 +51,6 @@ #include #include #include - #include -#ifndef NORTLSDR - #include "rtl-sdr.h" -#endif #include "anet.h" #else #include "winstubs.h" //Put everything Windows specific in here