]> git.zerfleddert.de Git - proxmark3-svn/blob - client/Makefile
small refactoring
[proxmark3-svn] / client / Makefile
1 #-----------------------------------------------------------------------------
2 # This code is licensed to you under the terms of the GNU GPL, version 2 or,
3 # at your option, any later version. See the LICENSE.txt file for the text of
4 # the license.
5 #-----------------------------------------------------------------------------
6
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
14
15 ENV_LDFLAGS := $(LDFLAGS)
16 ENV_CFLAGS := $(CFLAGS)
17 VPATH = ../common ../zlib ../uart
18 OBJDIR = obj
19
20 LDLIBS = -L/opt/local/lib -L/usr/local/lib -lreadline -lpthread -lm
21 LUALIB = ../liblua/liblua.a
22 LDFLAGS = $(ENV_LDFLAGS)
23 CFLAGS = $(ENV_CFLAGS) -std=c99 -D_ISOC99_SOURCE -I. -I../include -I../common -I../zlib -I../uart -I/opt/local/include -I../liblua -Wall -g -O3
24 CXXFLAGS = -I../include -Wall -O3
25
26 LUAPLATFORM = generic
27 platform = $(shell uname)
28 ifneq (,$(findstring MINGW,$(platform)))
29 LUAPLATFORM = mingw
30 else
31 ifeq ($(platform),Darwin)
32 LUAPLATFORM = macosx
33 else
34 LUALIB += -ldl
35 LDLIBS += -ltermcap -lncurses
36 LUAPLATFORM = linux
37 endif
38 endif
39
40 # Check for correctly configured Qt5
41 QTINCLUDES = $(shell pkg-config --cflags Qt5Core Qt5Widgets 2>/dev/null)
42 QTLDLIBS = $(shell pkg-config --libs Qt5Core Qt5Widgets 2>/dev/null)
43 MOC = $(shell pkg-config --variable=host_bins Qt5Core)/moc
44 UIC = $(shell pkg-config --variable=host_bins Qt5Core)/uic
45 ifeq ($(QTINCLUDES), )
46 # if Qt5 not found check for correctly configured Qt4
47 QTINCLUDES = $(shell pkg-config --cflags QtCore QtGui 2>/dev/null)
48 QTLDLIBS = $(shell pkg-config --libs QtCore QtGui 2>/dev/null)
49 MOC = $(shell pkg-config --variable=moc_location QtCore)
50 UIC = $(shell pkg-config --variable=uic_location QtCore)
51 else
52 CXXFLAGS += -std=c++11 -fPIC
53 endif
54 ifeq ($(QTINCLUDES), )
55 # if both pkg-config commands failed, search in common places
56 ifneq ($(QTDIR), )
57 QTINCLUDES = -I$(QTDIR)/include -I$(QTDIR)/include/QtCore -I$(QTDIR)/include/QtGui
58 QTLDLIBS = -L$(QTDIR)/lib -lQtCore4 -lQtGui4
59 ifneq ($(wildcard $(QTDIR)/include/QtWidgets),)
60 QTINCLUDES += -I$(QTDIR)/include/QtWidgets
61 QTLDLIBS = -L$(QTDIR)/lib -lQt5Widgets -lQt5Gui -lQt5Core
62 CXXFLAGS += -std=c++11 -fPIC
63 endif
64 MOC = $(QTDIR)/bin/moc
65 UIC = $(QTDIR)/bin/uic
66 endif
67 endif
68
69
70 ifneq ($(QTLDLIBS), )
71 QTGUIOBJS = $(OBJDIR)/proxgui.o $(OBJDIR)/proxguiqt.o $(OBJDIR)/proxguiqt.moc.o
72 CFLAGS += -DHAVE_GUI
73 else
74 QTGUIOBJS = $(OBJDIR)/guidummy.o
75 endif
76
77 # Flags to generate temporary dependency files
78 DEPFLAGS = -MT $@ -MMD -MP -MF $(OBJDIR)/$*.Td
79 # make temporary to final dependeny files after successful compilation
80 POSTCOMPILE = $(MV) -f $(OBJDIR)/$*.Td $(OBJDIR)/$*.d
81
82 CORESRCS = uart_posix.c \
83 uart_win32.c \
84 util.c \
85 util_posix.c
86
87 CMDSRCS = crapto1/crapto1.c\
88 crapto1/crypto1.c\
89 polarssl/des.c \
90 polarssl/aes.c\
91 mfkey.c\
92 loclass/cipher.c \
93 loclass/cipherutils.c \
94 loclass/ikeys.c \
95 loclass/elite_crack.c\
96 loclass/fileutils.c\
97 whereami.c\
98 mifarehost.c\
99 parity.c\
100 crc.c \
101 crc16.c \
102 crc64.c \
103 iso14443crc.c \
104 iso15693tools.c \
105 data.c \
106 graph.c \
107 ui.c \
108 cmddata.c \
109 lfdemod.c \
110 emv/apduinfo.c\
111 cmdhf.c \
112 cmdhf14a.c \
113 cmdhf14b.c \
114 cmdhf15.c \
115 cmdhfepa.c \
116 cmdhflegic.c \
117 cmdhficlass.c \
118 cmdhfmf.c \
119 cmdhfmfu.c \
120 cmdhfmfhard.c \
121 hardnested/hardnested_bruteforce.c \
122 cmdhftopaz.c \
123 cmdhw.c \
124 cmdlf.c \
125 cmdlfawid.c \
126 cmdlfcotag.c\
127 cmdlfem4x.c \
128 cmdlffdx.c \
129 cmdlfgproxii.c \
130 cmdlfhid.c \
131 cmdlfhitag.c \
132 cmdlfio.c \
133 cmdlfindala.c \
134 cmdlfjablotron.c \
135 cmdlfnexwatch.c \
136 cmdlfnoralsy.c \
137 cmdlfparadox.c \
138 cmdlfpcf7931.c \
139 cmdlfpresco.c \
140 cmdlfpyramid.c \
141 cmdlfsecurakey.c \
142 cmdlft55xx.c \
143 cmdlfti.c \
144 cmdlfviking.c\
145 cmdlfvisa2000.c\
146 cmdlfpac.c\
147 cmdparser.c \
148 cmdmain.c \
149 scripting.c\
150 cmdscript.c\
151 pm3_binlib.c\
152 pm3_bitlib.c\
153 protocols.c\
154 sha1.c\
155 cmdcrc.c\
156 reveng/reveng.c\
157 reveng/cli.c\
158 reveng/bmpbit.c\
159 reveng/model.c\
160 reveng/poly.c\
161 reveng/getopt.c\
162
163 cpu_arch = $(shell uname -m)
164 ifneq ($(findstring 86, $(cpu_arch)), )
165 MULTIARCHSRCS = hardnested/hardnested_bf_core.c hardnested/hardnested_bitarray_core.c
166 endif
167 ifneq ($(findstring amd64, $(cpu_arch)), )
168 MULTIARCHSRCS = hardnested/hardnested_bf_core.c hardnested/hardnested_bitarray_core.c
169 endif
170 ifeq ($(MULTIARCHSRCS), )
171 CMDSRCS += hardnested/hardnested_bf_core.c hardnested/hardnested_bitarray_core.c
172 endif
173
174 ZLIBSRCS = deflate.c adler32.c trees.c zutil.c inflate.c inffast.c inftrees.c
175 ZLIBFLAGS = -DZ_SOLO -DZ_PREFIX -DNO_GZIP -DZLIB_PM3_TUNED
176 #-DDEBUG -Dverbose=1
177
178 QTGUISRCS = proxgui.cpp proxguiqt.cpp proxguiqt.moc.cpp guidummy.cpp
179
180 COREOBJS = $(CORESRCS:%.c=$(OBJDIR)/%.o)
181 CMDOBJS = $(CMDSRCS:%.c=$(OBJDIR)/%.o)
182 ZLIBOBJS = $(ZLIBSRCS:%.c=$(OBJDIR)/%.o)
183 MULTIARCHOBJS = $(MULTIARCHSRCS:%.c=$(OBJDIR)/%_NOSIMD.o) \
184 $(MULTIARCHSRCS:%.c=$(OBJDIR)/%_MMX.o) \
185 $(MULTIARCHSRCS:%.c=$(OBJDIR)/%_SSE2.o) \
186 $(MULTIARCHSRCS:%.c=$(OBJDIR)/%_AVX.o) \
187 $(MULTIARCHSRCS:%.c=$(OBJDIR)/%_AVX2.o)
188
189 GCC_VERSION := $(shell gcc --version | awk '/gcc/{print $$NF;}' | sed -e 's/\.\([0-9][0-9]\)/\1/g' -e 's/\.\([0-9]\)/0\1/g' -e 's/^[0-9]\{3,4\}$$/&00/')
190 CLANG_VERSION := $(shell gcc --version | awk '/Apple LLVM version/{print $$4;}' | sed -e 's/\.\([0-9][0-9]\)/\1/g' -e 's/\.\([0-9]\)/0\1/g' -e 's/^[0-9]\{3,4\}$$/&00/')
191 ifneq ($(CLANG_VERSION), )
192 SUPPORTS_AVX512 := $(shell [ $(CLANG_VERSION) -ge 80000 ] && echo "True" )
193 endif
194 ifneq ($(GCC_VERSION), )
195 SUPPORTS_AVX512 := $(shell [ $(GCC_VERSION) -ge 40900 ] && echo "True" )
196 endif
197 HARD_SWITCH_NOSIMD = -mno-mmx -mno-sse2 -mno-avx -mno-avx2
198 HARD_SWITCH_MMX = -mmmx -mno-sse2 -mno-avx -mno-avx2
199 HARD_SWITCH_SSE2 = -mmmx -msse2 -mno-avx -mno-avx2
200 HARD_SWITCH_AVX = -mmmx -msse2 -mavx -mno-avx2
201 HARD_SWITCH_AVX2 = -mmmx -msse2 -mavx -mavx2
202 HARD_SWITCH_AVX512 = -mmmx -msse2 -mavx -mavx2 -mavx512f
203 ifeq "$(SUPPORTS_AVX512)" "True"
204 HARD_SWITCH_NOSIMD += -mno-avx512f
205 HARD_SWITCH_MMX += -mno-avx512f
206 HARD_SWITCH_SSE2 += -mno-avx512f
207 HARD_SWITCH_AVX += -mno-avx512f
208 HARD_SWITCH_AVX2 += -mno-avx512f
209 MULTIARCHOBJS += $(MULTIARCHSRCS:%.c=$(OBJDIR)/%_AVX512.o)
210 endif
211
212 BINS = proxmark3 flasher fpga_compress
213 WINBINS = $(patsubst %, %.exe, $(BINS))
214 CLEAN = $(BINS) $(WINBINS) $(COREOBJS) $(CMDOBJS) $(ZLIBOBJS) $(QTGUIOBJS) $(MULTIARCHOBJS) $(OBJDIR)/*.o *.moc.cpp ui/ui_overlays.h
215
216 # need to assign dependancies to build these first...
217 all: lua_build $(BINS)
218
219 all-static: LDLIBS:=-static $(LDLIBS)
220 all-static: proxmark3 flasher fpga_compress
221
222 proxmark3: LDLIBS+=$(LUALIB) $(QTLDLIBS)
223 proxmark3: $(OBJDIR)/proxmark3.o $(COREOBJS) $(CMDOBJS) $(QTGUIOBJS) $(MULTIARCHOBJS) $(ZLIBOBJS) lualibs/usb_cmd.lua
224 $(LD) $(LDFLAGS) $(OBJDIR)/proxmark3.o $(COREOBJS) $(CMDOBJS) $(QTGUIOBJS) $(MULTIARCHOBJS) $(ZLIBOBJS) $(LDLIBS) -o $@
225
226 flasher: $(OBJDIR)/flash.o $(OBJDIR)/flasher.o $(COREOBJS)
227 $(LD) $(LDFLAGS) $^ $(LDLIBS) -o $@
228
229 fpga_compress: $(OBJDIR)/fpga_compress.o $(ZLIBOBJS)
230 $(LD) $(LDFLAGS) $(ZLIBFLAGS) $^ $(LDLIBS) -o $@
231
232 proxgui.cpp: ui/ui_overlays.h
233
234 proxguiqt.moc.cpp: proxguiqt.h
235 $(MOC) -o$@ $^
236
237 ui/ui_overlays.h: ui/overlays.ui
238 $(UIC) $^ > $@
239
240 lualibs/usb_cmd.lua: ../include/usb_cmd.h
241 awk -f usb_cmd_h2lua.awk $^ > $@
242
243 clean:
244 $(RM) $(CLEAN)
245 cd ../liblua && make clean
246
247 tarbin: $(BINS)
248 $(TAR) $(TARFLAGS) ../proxmark3-$(platform)-bin.tar $(BINS:%=client/%) $(WINBINS:%=client/%)
249
250 lua_build:
251 @echo Compiling liblua, using platform $(LUAPLATFORM)
252 cd ../liblua && make $(LUAPLATFORM)
253
254 .PHONY: all clean
255
256 $(OBJDIR)/%_NOSIMD.o : %.c $(OBJDIR)/%.d
257 $(CC) $(DEPFLAGS) $(CFLAGS) $(HARD_SWITCH_NOSIMD) -c -o $@ $<
258
259 $(OBJDIR)/%_MMX.o : %.c $(OBJDIR)/%.d
260 $(CC) $(DEPFLAGS) $(CFLAGS) $(HARD_SWITCH_MMX) -c -o $@ $<
261
262 $(OBJDIR)/%_SSE2.o : %.c $(OBJDIR)/%.d
263 $(CC) $(DEPFLAGS) $(CFLAGS) $(HARD_SWITCH_SSE2) -c -o $@ $<
264
265 $(OBJDIR)/%_AVX.o : %.c $(OBJDIR)/%.d
266 $(CC) $(DEPFLAGS) $(CFLAGS) $(HARD_SWITCH_AVX) -c -o $@ $<
267
268 $(OBJDIR)/%_AVX2.o : %.c $(OBJDIR)/%.d
269 $(CC) $(DEPFLAGS) $(CFLAGS) $(HARD_SWITCH_AVX2) -c -o $@ $<
270
271 $(OBJDIR)/%_AVX512.o : %.c $(OBJDIR)/%.d
272 $(CC) $(DEPFLAGS) $(CFLAGS) $(HARD_SWITCH_AVX512) -c -o $@ $<
273
274 %.o: %.c
275 $(OBJDIR)/%.o : %.c $(OBJDIR)/%.d
276 $(CC) $(DEPFLAGS) $(CFLAGS) $(ZLIBFLAGS) -c -o $@ $<
277 $(POSTCOMPILE)
278
279 %.o: %.cpp
280 $(OBJDIR)/%.o : %.cpp $(OBJDIR)/%.d
281 $(CXX) $(DEPFLAGS) $(CXXFLAGS) $(QTINCLUDES) -c -o $@ $<
282 $(POSTCOMPILE)
283
284
285 #$(CMDOBJS) $(COREOBJS): $(notdir $(%.c)) %.d
286 # $(CC) $(DEPFLAGS) $(CFLAGS) -c -o $@ $<
287 # $(POSTCOMPILE)
288
289 #$(ZLIBOBJS): $(notdir $(%.c)) %.d
290 # $(CC) $(DEPFLAGS) $(CFLAGS) $(ZLIBFLAGS) -c -o $@ $<
291 # $(POSTCOMPILE)
292
293 #$(QTGUIOBJS): $(notdir $(%.cpp)) %.d
294 # $(CXX) $(DEPFLAGS) $(CXXFLAGS) -c -o $@ $<
295 # $(POSTCOMPILE)
296
297 DEPENDENCY_FILES = $(patsubst %.c, $(OBJDIR)/%.d, $(CORESRCS) $(CMDSRCS) $(ZLIBSRCS) $(MULTIARCHSRCS)) \
298 $(patsubst %.cpp, $(OBJDIR)/%.d, $(QTGUISRCS)) \
299 $(OBJDIR)/proxmark3.d $(OBJDIR)/flash.d $(OBJDIR)/flasher.d $(OBJDIR)/fpga_compress.d
300
301 $(DEPENDENCY_FILES): ;
302 .PRECIOUS: $(DEPENDENCY_FILES)
303
304 -include $(DEPENDENCY_FILES)
305
Impressum, Datenschutz