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
+ifeq ($(SIM),)
+# Compile for terminal
+all: mtrfid mtserver mtkeys mtaio
else
-$(warning Compiling without RFID support)
+# Compile just simulator
+all: mtaio
endif
mtrfid_SRCS = signal_exit.c mt_rfid.c
mtrfid_LIBS = -lev -luFCoder-armhf
+mtrfid_DEFS = -DHAVE_RFID=1
mtserver_SRCS = signal_exit.c mt_server.c
mtserver_LIBS = -lev -lwebsockets
mtaio_LIBS = -lev -lwebsockets
mtaio_DEFS = -DNO_MAIN -DHAVE_RFID=$(if $(HAVE_RFID),1,0)
-ifeq ($(HAVE_RFID),yes)
+ifeq ($(SIM),)
mtaio_SRCS += mt_rfid.c
mtaio_LIBS += -luFCoder-armhf
-endif
+else
+mtaio_SRCS += mt_sim.c
+mtaio_DEFS += -DSIM=1 -Ilibwebsockets/include -Llibwebsockets/lib -g
+mtaio_LIBS += -lz $(shell pkg-config --libs openssl)
+
+libwebsockets/CMakeLists.txt:
+ git submodule update --init libwebsockets
-all: mtserver mtkeys mtaio
+libwebsockets/CMakeCache.txt: libwebsockets/CMakeLists.txt
+ cd libwebsockets && cmake -DLWS_WITH_LIBEV=ON -DLWS_WITH_SHARED=OFF -DLWS_WITHOUT_TESTAPPS=ON .
+
+libwebsockets/lib/libwebsockets.a: libwebsockets/CMakeCache.txt
+ cd libwebsockets && cmake --build .
+
+mt_server.c: libwebsockets/lib/libwebsockets.a
+endif
.PHONY: clean
rm -rf $(OUTPUT_DIR)
.SECONDEXPANSION:
-mt%: $$($$@_SRCS)
+mtserver mtkeys mtaio mtrfid: $$($$@_SRCS)
mkdir -p $(OUTPUT_DIR)
$(CC) $(CFLAGS) $($@_DEFS) -o $(OUTPUT_DIR)/$@ $^ $($@_LIBS)