Skip to content

Commit fb9acd4

Browse files
authored
Update/cleanup Makefiles (#265)
- add new target "make mfkey" to build mfkey32 and mfkey64 - include above when "make all" - fix Qt detection for Kali Linux - create and use dependency files when building client - create client/lualibs/usb_cmd.lua from include/usb_cmd.h when building client - add Windows *.exe files with "make tarbin" - For the time being don't include Makefile.common in Makefile and client/Makefile - set com3 as default flashing port for Windows (including mingw) - remove static targets snooper and cli. Remove their sources as well.
1 parent b642ce7 commit fb9acd4

File tree

8 files changed

+274
-322
lines changed

8 files changed

+274
-322
lines changed

Makefile

+32-7
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,40 @@
1-
include common/Makefile.common
2-
1+
GZIP=gzip
2+
# Windows' echo echos its input verbatim, on Posix there is some
3+
# amount of shell command line parsing going on. echo "" on
4+
# Windows yields literal "", on Linux yields an empty line
5+
ifeq ($(shell echo ""),)
6+
# This is probably a proper system, so we can use uname
7+
DELETE=rm -rf
8+
FLASH_TOOL=client/flasher
9+
platform=$(shell uname)
10+
ifneq (,$(findstring MINGW,$(platform)))
11+
FLASH_PORT=com3
12+
PATHSEP=\\#
13+
else
314
FLASH_PORT=/dev/ttyACM0
15+
PATHSEP=/
16+
endif
17+
else
18+
# Assume that we are running on native Windows
19+
DELETE=del /q
20+
FLASH_TOOL=client/flasher.exe
21+
platform=Windows
22+
FLASH_PORT=com3
23+
PATHSEP=\\#
24+
endif
425

5-
all clean: %: client/% bootrom/% armsrc/% recovery/%
26+
all clean: %: client/% bootrom/% armsrc/% recovery/% mfkey/%
627

728
bootrom/%: FORCE
8-
$(MAKE) -C bootrom $(patsubst bootrom/%,%,$@)
29+
$(MAKE) -C bootrom $(patsubst bootrom/%, %, $@)
930
armsrc/%: FORCE
10-
$(MAKE) -C armsrc $(patsubst armsrc/%,%,$@)
31+
$(MAKE) -C armsrc $(patsubst armsrc/%, %, $@)
1132
client/%: FORCE
12-
$(MAKE) -C client $(patsubst client/%,%,$@)
33+
$(MAKE) -C client $(patsubst client/%, %, $@)
1334
recovery/%: FORCE
14-
$(MAKE) -C recovery $(patsubst recovery/%,%,$@)
35+
$(MAKE) -C recovery $(patsubst recovery/%, %, $@)
36+
mfkey/%: FORCE
37+
$(MAKE) -C tools/mfkey $(patsubst mfkey/%, %, $@)
1538
FORCE: # Dummy target to force remake in the subdirectories, even if files exist (this Makefile doesn't know about the prerequisites)
1639

1740
.PHONY: all clean help _test flash-bootrom flash-os flash-all FORCE
@@ -28,6 +51,8 @@ help:
2851

2952
client: client/all
3053

54+
mfkey: mfkey/all
55+
3156
flash-bootrom: bootrom/obj/bootrom.elf $(FLASH_TOOL)
3257
$(FLASH_TOOL) $(FLASH_PORT) -b $(subst /,$(PATHSEP),$<)
3358

client/Makefile

+82-47
Original file line numberDiff line numberDiff line change
@@ -3,58 +3,68 @@
33
# at your option, any later version. See the LICENSE.txt file for the text of
44
# the license.
55
#-----------------------------------------------------------------------------
6-
include ../common/Makefile.common
76

7+
CC = gcc
8+
CXX = g++
9+
LD = g++
10+
TAR = tar
11+
TARFLAGS = -C .. --ignore-failed-read -rvf
12+
RM = rm -f
13+
MV = mv
814

9-
CC=gcc
10-
CXX=g++
1115
#COMMON_FLAGS = -m32
1216
VPATH = ../common ../zlib
1317
OBJDIR = obj
1418

1519
LDLIBS = -L/opt/local/lib -L/usr/local/lib -lreadline -lpthread -lm
1620
LUALIB = ../liblua/liblua.a
1721
LDFLAGS = $(COMMON_FLAGS)
18-
CFLAGS = -std=c99 -D_ISOC99_SOURCE -I. -I../include -I../common -I../tools -I../zlib -I/opt/local/include -I../liblua -Wall $(COMMON_FLAGS) -g -O4
22+
CFLAGS = -std=c99 -D_ISOC99_SOURCE -I. -I../include -I../common -I../zlib -I/opt/local/include -I../liblua -Wall $(COMMON_FLAGS) -g -O4
1923
LUAPLATFORM = generic
2024

25+
platform = $(shell uname)
2126
ifneq (,$(findstring MINGW,$(platform)))
2227
CXXFLAGS = -I$(QTDIR)/include -I$(QTDIR)/include/QtCore -I$(QTDIR)/include/QtGui
23-
MOC = $(QTDIR)/bin/moc
24-
LUAPLATFORM = mingw
2528
ifneq ($(wildcard $(QTDIR)/include/QtWidgets),)
2629
CXXFLAGS += -I$(QTDIR)/include/QtWidgets
2730
QTLDLIBS = -L$(QTDIR)/lib -lQt5Core -lQt5Gui -lQt5Widgets
2831
else
2932
QTLDLIBS = -L$(QTDIR)/lib -lQtCore4 -lQtGui4
3033
endif
31-
else ifeq ($(platform),Darwin)
32-
CXXFLAGS = $(shell pkg-config --cflags QtCore QtGui 2>/dev/null) -Wall -O4
33-
QTLDLIBS = $(shell pkg-config --libs QtCore QtGui 2>/dev/null)
34-
MOC = $(shell pkg-config --variable=moc_location QtCore)
35-
LUAPLATFORM = macosx
34+
MOC = $(QTDIR)/bin/moc
35+
LUAPLATFORM = mingw
3636
else
37-
CXXFLAGS = $(shell pkg-config --cflags QtCore QtGui 2>/dev/null) -Wall -O4
38-
QTLDLIBS = $(shell pkg-config --libs QtCore QtGui 2>/dev/null)
39-
LUALIB += -ldl
40-
LDLIBS += -ltermcap -lncurses
41-
MOC = $(shell pkg-config --variable=moc_location QtCore)
42-
# 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.
43-
#MOC = /usr/lib/x86_64-linux-gnu/qt4/bin/moc
44-
LUAPLATFORM = linux
37+
CXXFLAGS = $(shell pkg-config --cflags Qt5Core Qt5Widgets 2>/dev/null) -Wall -O4
38+
QTLDLIBS = $(shell pkg-config --libs Qt5Core Qt5Widgets 2>/dev/null)
39+
MOC = $(shell pkg-config --variable=host_bins Qt5Core)/moc
40+
ifeq ($(QTLDLIBS), )
41+
CXXFLAGS = $(shell pkg-config --cflags QtCore QtGui 2>/dev/null) -Wall -O4
42+
QTLDLIBS = $(shell pkg-config --libs QtCore QtGui 2>/dev/null)
43+
MOC = $(shell pkg-config --variable=moc_location QtCore)
44+
endif
45+
ifeq ($(platform),Darwin)
46+
LUAPLATFORM = macosx
47+
else
48+
LUALIB += -ldl
49+
LDLIBS += -ltermcap -lncurses
50+
LUAPLATFORM = linux
51+
endif
4552
endif
4653

4754
ifneq ($(QTLDLIBS),)
48-
QTGUI = $(OBJDIR)/proxgui.o $(OBJDIR)/proxguiqt.o $(OBJDIR)/proxguiqt.moc.o
55+
QTGUIOBJS = $(OBJDIR)/proxgui.o $(OBJDIR)/proxguiqt.o $(OBJDIR)/proxguiqt.moc.o
4956
CFLAGS += -DHAVE_GUI
50-
LINK.o = $(LINK.cpp)
5157
else
52-
QTGUI = guidummy.o
58+
QTGUIOBJS = $(OBJDIR)/guidummy.o
5359
endif
5460

55-
CORESRCS = uart.c \
56-
util.c \
61+
# Flags to generate temporary dependency files
62+
DEPFLAGS = -MT $@ -MMD -MP -MF $(OBJDIR)/$*.Td
63+
# make temporary to final dependeny files after successful compilation
64+
POSTCOMPILE = $(MV) -f $(OBJDIR)/$*.Td $(OBJDIR)/$*.d
5765

66+
CORESRCS = uart.c \
67+
util.c
5868

5969
CMDSRCS = crapto1/crapto1.c\
6070
crapto1/crypto1.c\
@@ -129,57 +139,82 @@ CMDSRCS = crapto1/crapto1.c\
129139
reveng/getopt.c\
130140

131141
ZLIBSRCS = deflate.c adler32.c trees.c zutil.c inflate.c inffast.c inftrees.c
132-
ZLIB_FLAGS = -DZ_SOLO -DZ_PREFIX -DNO_GZIP -DZLIB_PM3_TUNED
142+
ZLIBFLAGS = -DZ_SOLO -DZ_PREFIX -DNO_GZIP -DZLIB_PM3_TUNED
133143
#-DDEBUG -Dverbose=1
134144

145+
QTGUISRCS = proxgui.cpp proxguiqt.cpp proxguiqt.moc.cpp guidummy.cpp
135146

136147
COREOBJS = $(CORESRCS:%.c=$(OBJDIR)/%.o)
137148
CMDOBJS = $(CMDSRCS:%.c=$(OBJDIR)/%.o)
138149
ZLIBOBJS = $(ZLIBSRCS:%.c=$(OBJDIR)/%.o)
139150

140-
RM = rm -f
141-
BINS = proxmark3 flasher fpga_compress #snooper cli
142-
CLEAN = cli cli.exe flasher flasher.exe proxmark3 proxmark3.exe fpga_compress fpga_compress.exe snooper snooper.exe $(CMDOBJS) $(OBJDIR)/*.o *.o *.moc.cpp
151+
BINS = proxmark3 flasher fpga_compress
152+
WINBINS = $(patsubst %, %.exe, $(BINS))
153+
CLEAN = $(BINS) $(WINBINS) $(COREOBJS) $(CMDOBJS) $(ZLIBOBJS) $(QTGUIOBJS) $(OBJDIR)/*.o *.moc.cpp
143154

144-
all: lua_build $(BINS)
155+
all: lua_build $(BINS)
145156

146157
all-static: LDLIBS:=-static $(LDLIBS)
147-
all-static: snooper cli flasher fpga_compress
158+
all-static: proxmark3 flasher fpga_compress
148159

149160
proxmark3: LDLIBS+=$(LUALIB) $(QTLDLIBS)
150-
proxmark3: $(OBJDIR)/proxmark3.o $(COREOBJS) $(CMDOBJS) $(QTGUI)
151-
$(CXX) $(CXXFLAGS) $^ $(LDLIBS) -o $@
152-
153-
snooper: $(OBJDIR)/snooper.o $(COREOBJS) $(CMDOBJS) $(OBJDIR)/guidummy.o
154-
$(CXX) $(CXXFLAGS) $^ $(LDLIBS) -o $@
155-
156-
cli: $(OBJDIR)/cli.o $(COREOBJS) $(CMDOBJS) $(OBJDIR)/guidummy.o
157-
$(CXX) $(CXXFLAGS) $^ $(LDLIBS) -o $@
161+
proxmark3: $(OBJDIR)/proxmark3.o $(COREOBJS) $(CMDOBJS) $(QTGUIOBJS) lualibs/usb_cmd.lua
162+
$(LD) $(LDFLAGS) $(OBJDIR)/proxmark3.o $(COREOBJS) $(CMDOBJS) $(QTGUIOBJS) $(LDLIBS) -o $@
158163

159164
flasher: $(OBJDIR)/flash.o $(OBJDIR)/flasher.o $(COREOBJS)
160-
$(CXX) $(CXXFLAGS) $^ $(LDLIBS) -o $@
165+
$(LD) $(LDFLAGS) $^ $(LDLIBS) -o $@
161166

162167
fpga_compress: $(OBJDIR)/fpga_compress.o $(ZLIBOBJS)
163-
$(CXX) $(CXXFLAGS) $(ZLIB_FLAGS) $^ $(LDLIBS) -o $@
164-
165-
$(OBJDIR)/%.o: %.c
166-
$(CC) $(CFLAGS) $(ZLIB_FLAGS) -c -o $@ $<
167-
168-
$(OBJDIR)/%.o: %.cpp
169-
$(CXX) $(CXXFLAGS) -c -o $@ $<
168+
$(LD) $(LDFLAGS) $(ZLIBFLAGS) $^ $(LDLIBS) -o $@
170169

171170
proxguiqt.moc.cpp: proxguiqt.h
172171
$(MOC) -o$@ $^
173172

173+
lualibs/usb_cmd.lua: ../include/usb_cmd.h
174+
awk -f usb_cmd_h2lua.awk $^ > $@
175+
174176
clean:
175177
$(RM) $(CLEAN)
176178
cd ../liblua && make clean
177179

178180
tarbin: $(BINS)
179-
$(TAR) $(TARFLAGS) ../proxmark3-$(platform)-bin.tar $(BINS:%=client/%)
181+
$(TAR) $(TARFLAGS) ../proxmark3-$(platform)-bin.tar $(BINS:%=client/%) $(WINBINS:%=client/%)
180182

181183
lua_build:
182184
@echo Compiling liblua, using platform $(LUAPLATFORM)
183185
cd ../liblua && make $(LUAPLATFORM)
184186

185187
.PHONY: all clean
188+
189+
%.o: %.c
190+
$(OBJDIR)/%.o : %.c $(OBJDIR)/%.d
191+
$(CC) $(DEPFLAGS) $(CFLAGS) $(ZLIBFLAGS) -c -o $@ $<
192+
$(POSTCOMPILE)
193+
194+
%.o: %.cpp
195+
$(OBJDIR)/%.o : %.cpp $(OBJDIR)/%.d
196+
$(CXX) $(DEPFLAGS) $(CXXFLAGS) -c -o $@ $<
197+
$(POSTCOMPILE)
198+
199+
200+
#$(CMDOBJS) $(COREOBJS): $(notdir $(%.c)) %.d
201+
# $(CC) $(DEPFLAGS) $(CFLAGS) -c -o $@ $<
202+
# $(POSTCOMPILE)
203+
204+
#$(ZLIBOBJS): $(notdir $(%.c)) %.d
205+
# $(CC) $(DEPFLAGS) $(CFLAGS) $(ZLIBFLAGS) -c -o $@ $<
206+
# $(POSTCOMPILE)
207+
208+
#$(QTGUIOBJS): $(notdir $(%.cpp)) %.d
209+
# $(CXX) $(DEPFLAGS) $(CXXFLAGS) -c -o $@ $<
210+
# $(POSTCOMPILE)
211+
212+
DEPENDENCY_FILES = $(patsubst %.c, $(OBJDIR)/%.d, $(CORESRCS) $(CMDSRCS) $(ZLIBSRCS)) \
213+
$(patsubst %.cpp, $(OBJDIR)/%.d, $(QTGUISRCS)) \
214+
$(OBJDIR)/proxmark3.d $(OBJDIR)/flash.d $(OBJDIR)/flasher.d $(OBJDIR)/fpga_compress.d
215+
216+
$(DEPENDENCY_FILES): ;
217+
.PRECIOUS: $(DEPENDENCY_FILES)
218+
219+
-include $(DEPENDENCY_FILES)
220+

client/cli.c

-58
This file was deleted.

client/guidummy.c client/guidummy.cpp

+6-6
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
#include <stdio.h>
1212

13-
void ShowGraphWindow(void)
13+
extern "C" void ShowGraphWindow(void)
1414
{
1515
static int warned = 0;
1616

@@ -20,8 +20,8 @@ void ShowGraphWindow(void)
2020
}
2121
}
2222

23-
void HideGraphWindow(void) {}
24-
void RepaintGraphWindow(void) {}
25-
void MainGraphics() {}
26-
void InitGraphics(int argc, char **argv) {}
27-
void ExitGraphics(void) {}
23+
extern "C" void HideGraphWindow(void) {}
24+
extern "C" void RepaintGraphWindow(void) {}
25+
extern "C" void MainGraphics() {}
26+
extern "C" void InitGraphics(int argc, char **argv) {}
27+
extern "C" void ExitGraphics(void) {}

0 commit comments

Comments
 (0)