]> rtime.felk.cvut.cz Git - coffee/mt-apps.git/commitdiff
Autodetect RFID support and allow compiling without it
authorMichal Sojka <michal.sojka@cvut.cz>
Mon, 6 Aug 2018 11:45:47 +0000 (13:45 +0200)
committerMichal Sojka <michal.sojka@cvut.cz>
Mon, 6 Aug 2018 11:47:48 +0000 (13:47 +0200)
Makefile
mt_rfid.h

index 470e9a1d6b490c2b39d8aef5c1e758922c3e4452..6cad9192f275f9ee14d52be9bff78ee94279e78f 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,5 +1,15 @@
 OUTPUT_DIR    = build
 
+CFLAGS       = -Ilibwebsockets/include -Llibwebsockets/lib
+can_compile   = $(shell set -x; if echo '$(1)' | $(CC) $(CFLAGS) -c -xc - -o /dev/null >/dev/null 2>&1; then echo yes; fi)
+HAVE_RFID    := $(call can_compile,\#include <uFCoder.h>)
+
+ifeq ($(HAVE_RFID),yes)
+all: mtrfid
+else
+$(warning Compiling without RFID support)
+endif
+
 mtrfid_SRCS   = signal_exit.c mt_rfid.c
 mtrfid_LIBS   = -lev -luFCoder-armhf
 
@@ -9,11 +19,16 @@ mtserver_LIBS = -lev -lwebsockets
 mtkeys_SRCS   = signal_exit.c mt_keys.c
 mtkeys_LIBS   = -lev
 
-mtaio_SRCS    = signal_exit.c mt_rfid.c mt_keys.c mt_server.c mt_aio.c
-mtaio_LIBS    = -lev -luFCoder-armhf -lwebsockets
-mtaio_DEFS    = -DNO_MAIN
+mtaio_SRCS    = signal_exit.c mt_keys.c mt_server.c mt_aio.c
+mtaio_LIBS    = -lev -lwebsockets
+mtaio_DEFS    = -DNO_MAIN -DHAVE_RFID=$(if $(HAVE_RFID),1,0)
+
+ifeq ($(HAVE_RFID),yes)
+mtaio_SRCS += mt_rfid.c
+mtaio_LIBS += -luFCoder-armhf
+endif
 
-all: mtrfid mtserver mtkeys mtaio
+all: mtserver mtkeys mtaio
 
 .PHONY: clean
 
index fad9390290dd02e027eacc07f371a038d7e81ffd..10ea402276230e12c43869356c8f3ffc7ee0a3a0 100644 (file)
--- a/mt_rfid.h
+++ b/mt_rfid.h
@@ -3,14 +3,6 @@
 
 #include <ev.h>
 
-// reader open parameters, see uFR manual
-#define UFR_READER_TYPE     1       // uFR type (1Mbps)
-#define UFR_PORT_INTERFACE  1       // serial; auto->ftdi->FAIL
-#define UFR_PORT_NAME       "/dev/ttyUSB0" // reader device
-#define UFR_ASYNC_BAUD_RATE 1000000 // 1Mbps, otherwise UFR_COMMUNICATION_BREAK
-
-#define UFR_BEEP // define this to annoy people
-
 typedef struct ev_io_ufr {
     ev_io w;           // fd watcher
     char uid_data[24]; // store uid here (uid is 10 bytes max)
@@ -23,6 +15,16 @@ typedef struct mt_rfid_t {
     int fd;      // print JSON output here
 } mt_rfid_t;
 
+#if HAVE_RFID
+
+// reader open parameters, see uFR manual
+#define UFR_READER_TYPE     1       // uFR type (1Mbps)
+#define UFR_PORT_INTERFACE  1       // serial; auto->ftdi->FAIL
+#define UFR_PORT_NAME       "/dev/ttyUSB0" // reader device
+#define UFR_ASYNC_BAUD_RATE 1000000 // 1Mbps, otherwise UFR_COMMUNICATION_BREAK
+
+#define UFR_BEEP // define this to annoy people
+
 // connect to the reader, add self to loop and make it write to fd
 // return 0 on success, negative number otherwise
 int mt_rfid_init(mt_rfid_t *self, struct ev_loop *loop, int fd);
@@ -30,4 +32,11 @@ int mt_rfid_init(mt_rfid_t *self, struct ev_loop *loop, int fd);
 // disconnect from reader
 void mt_rfid_deinit(mt_rfid_t *self);
 
+#else
+
+#define mt_rfid_init(self, loop, fd) 0
+#define mt_rfid_deinit(self) 0
+
+#endif /* HAVE_RFID */
+
 #endif