-WINCC=c:\mingw\bin\gcc
-
-#COMMON_FLAGS = -m32
-
-LDLIBS = -L/opt/local/lib -L/usr/local/lib -lusb -lreadline -lpthread
-LDFLAGS = $(COMMON_FLAGS)
-CFLAGS = -I. -I/opt/local/include -Wall -Wno-unused-function $(COMMON_FLAGS)
-
-WINLIBS = -lgdi32 -lsetupapi
-CXXFLAGS = $(shell pkg-config --cflags QtCore QtGui 2>/dev/null) -Wall
-QTLDLIBS = $(shell pkg-config --libs QtCore QtGui 2>/dev/null)
-
-ifeq ($(shell echo ""),)
-
-ifeq ($(shell uname),Darwin)
-CXXFLAGS = -I/Library/Frameworks/QtGui.framework/Versions/Current/Headers -I/Library/Frameworks/QtCore.framework/Versions/Current/Headers
-QTLDLIBS = -framework QtGui -framework QtCore
-MOC = moc
+#-----------------------------------------------------------------------------
+# This code is licensed to you under the terms of the GNU GPL, version 2 or,
+# at your option, any later version. See the LICENSE.txt file for the text of
+# the license.
+#-----------------------------------------------------------------------------
+include ../common/Makefile.common
+
+CC = gcc
+CXX = g++
+COMMON_FLAGS += -std=c99 -O3 -mpopcnt -march=native -g
+
+#VPATH = ../common ../zlib
+OBJDIR = obj
+
+LDLIBS = -L/opt/local/lib -L/usr/local/lib -lreadline -lpthread -lm
+LUALIB = ../liblua/liblua.a
+#LDFLAGS = $(COMMON_FLAGS)
+CFLAGS = $(COMMON_FLAGS) -I. -I../include -I../common -I../zlib -I/opt/local/include -I../liblua -Wall
+LUAPLATFORM = generic
+
+ifneq (,$(findstring MINGW,$(platform)))
+ LDLIBS += -L/mingw/lib -lgdi32
+ CFLAGS += -I/mingw/include -D__USE_MINGW_ANSI_STDIO=1
+ CXXFLAGS = -I$(QTDIR)/include -I$(QTDIR)/include/QtCore -I$(QTDIR)/include/QtGui
+ MOC = $(QTDIR)/bin/moc
+ LUAPLATFORM = mingw
+ ifneq ($(wildcard $(QTDIR)/include/QtWidgets),)
+ CXXFLAGS += -I$(QTDIR)/include/QtWidgets
+ QTLDLIBS = -L$(QTDIR)/lib -lQt5Core -lQt5Gui -lQt5Widgets
+ else
+ QTLDLIBS = -L$(QTDIR)/lib -lQtCore4 -lQtGui4
+ endif
+
+ # QT version, 4 or 5
+ qtplatform = $(shell $(MOC) -v)
+ ifneq (, $(findstring moc 5,$(qtplatform)))
+ CXXFLAGS = -I$(QTDIR)/include -I$(QTDIR)/include/QtCore -I$(QTDIR)/include/QtGui -I$(QTDIR)/include/QtWidgets -I/mingw/include
+ QTLDLIBS = -L$(QTDIR)/lib -lQt5Core -lQt5Gui -lQt5Widgets
+ else
+ CXXFLAGS = -I$(QTDIR)/include -I$(QTDIR)/include/QtCore -I$(QTDIR)/include/QtGui
+ QTLDLIBS = -L$(QTDIR)/lib -lQtCore4 -lQtGui4
+ endif
+
+else ifeq ($(platform),Darwin)
+
+ # OS X, QT5 detection needs this.
+ export PKG_CONFIG_PATH=/usr/local/Cellar/qt5/5.6.1-1/lib/pkgconfig/
+
+ CXXFLAGS = $(shell pkg-config --cflags QtCore QtGui 2>/dev/null) -Wall -O3
+ QTLDLIBS = $(shell pkg-config --libs QtCore QtGui 2>/dev/null)
+ MOC = $(shell pkg-config --variable=moc_location QtCore)
+
+ # QT version, 4 or 5
+ qtplatform = $(shell $(MOC) -v)
+ ifneq (, $(findstring moc 5,$(qtplatform)))
+ # use this if you have QT5 installed.
+ CFLAGS += -I/usr/include/malloc/ -I/usr/local/opt/readline/include -I/usr/local/opt/qt5/include
+ LDLIBS = -L/usr/local/opt/readline/lib -L/usr/local/opt/qt5/lib -lreadline -lpthread -lm
+ else
+ # Assuming you have QT4 installed.
+ CFLAGS += -I/usr/include/malloc/ -I/usr/local/opt/readline/include
+ LDLIBS = -L/usr/local/opt/readline/lib -lreadline -lpthread -lm
+ endif
+
+ LUAPLATFORM = macosx
+else
+ CXXFLAGS = $(shell pkg-config --cflags QtCore QtGui 2>/dev/null) -Wall -O3
+ QTLDLIBS = $(shell pkg-config --libs QtCore QtGui 2>/dev/null)
+ LUALIB += -ldl
+ LDLIBS += -ltermcap -lncurses
+ MOC = $(shell pkg-config --variable=moc_location QtCore)
+ # Below is a variant you can use if you have problems compiling with QT5 on ubuntu. see http://www.proxmark.org/forum/viewtopic.php?id=1661 for more info.
+ #MOC = /usr/lib/x86_64-linux-gnu/qt4/bin/moc
+ LUAPLATFORM = linux