Makefile: display firmware size
[RRG-proxmark3.git] / client / Makefile
blobf7a59ed3fe6e0cbe1dc6946ade2c73bad81bc58f
1 #-----------------------------------------------------------------------------
2 # Copyright (C) Proxmark3 contributors. See AUTHORS.md for details.
4 # This program is free software: you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation, either version 3 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # See LICENSE.txt for the text of the license.
15 #-----------------------------------------------------------------------------
17 ifeq ($(PLTNAME),)
18 -include ../Makefile.platform
19 -include ../.Makefile.options.cache
20 ifneq ($(PLATFORM), $(CACHED_PLATFORM))
21 $(error platform definitions have been changed, please "make clean" at the root of the project)
22 endif
23 endif
24 include ../Makefile.defs
26 ifeq ($(PLATFORM),PM3ICOPYX)
27 INCLUDES += -DICOPYX
28 endif
30 INSTALLBIN = proxmark3
31 INSTALLSHARE = cmdscripts lualibs luascripts pyscripts resources dictionaries
33 VPATH = ../common src
34 vpath %.dic dictionaries
35 OBJDIR = obj
37 ifeq ($(USE_BREW),1)
38 INCLUDES += -I$(BREW_PREFIX)/include
39 LDLIBS += -L$(BREW_PREFIX)/lib
40 PKG_CONFIG_ENV := PKG_CONFIG_PATH=$(BREW_PREFIX)/lib/pkgconfig:$(BREW_PREFIX)/opt/qt@5/lib/pkgconfig:$(BREW_PREFIX)/opt/qt@5/lib/pkgconfig
41 endif
43 ifeq ($(USE_MACPORTS),1)
44 INCLUDES += -I$(MACPORTS_PREFIX)/include
45 LDLIBS += -L$(MACPORTS_PREFIX)/lib
46 PKG_CONFIG_ENV := PKG_CONFIG_PATH=$(MACPORTS_PREFIX)/lib/pkgconfig
47 endif
50 PM3INCLUDES =
52 ###################
53 # local libraries #
54 ###################
56 ## Amiibo
57 AMIIBOLIBPATH = ./deps/amiitool
58 AMIIBOLIBINC = -I$(AMIIBOLIBPATH)
59 AMIIBOLIB = $(AMIIBOLIBPATH)/libamiibo.a
60 AMIIBOLIBLD =
62 ## Cliparser / Argtable3
63 CLIPARSERLIBPATH = ./deps/cliparser
64 CLIPARSERLIBINC = -I$(CLIPARSERLIBPATH)
65 CLIPARSERLIB = $(CLIPARSERLIBPATH)/libcliparser.a
66 CLIPARSERLIBLD =
68 ## Hardnested
69 HARDNESTEDLIBPATH = ./deps/hardnested
70 HARDNESTEDLIBINC = -I$(HARDNESTEDLIBPATH)
71 HARDNESTEDLIB = $(HARDNESTEDLIBPATH)/libhardnested.a
72 HARDNESTEDLIBLD =
74 ## ID48
75 ID48LIBPATH = ./deps/id48
76 ID48LIBINC = -I$(ID48LIBPATH)
77 ID48LIB = $(ID48LIBPATH)/libid48.a
78 ID48LIBLD =
80 ## Jansson
81 JANSSONLIBPATH = ./deps/jansson
82 JANSSONLIBINC = -I$(JANSSONLIBPATH)
83 JANSSONLIB = $(JANSSONLIBPATH)/libjansson.a
84 JANSSONLIBLD =
86 ## Linenoise
87 # Can be used if Readline is unavailable or explicitely disabled
88 # Requires to be unpacked, see deps/get_linenoise.sh
89 LINENOISELIBPATH = ./deps/linenoise
90 LINENOISELIBINC = -I$(LINENOISELIBPATH)
91 LINENOISELIB = $(LINENOISELIBPATH)/liblinenoise.a
92 LINENOISELIBLD =
94 ## Lua
95 LUALIBPATH = ./deps/liblua
96 LUALIBINC = -I$(LUALIBPATH)
97 LUALIB = $(LUALIBPATH)/liblua.a
98 LUALIBLD =
99 LUAPLATFORM = generic
100 ifneq (,$(findstring MINGW,$(platform)))
101 LUAPLATFORM = mingw
102 else
103 ifeq ($(platform),Darwin)
104 LUAPLATFORM = macosx
105 else
106 LUALIBLD += -ldl
107 LUAPLATFORM = linux
108 endif
109 endif
111 ## Winsock2
112 ifneq (,$(findstring MINGW,$(platform)))
113 LDLIBS += -lws2_32
114 endif
116 ## Reveng
117 REVENGLIBPATH = ./deps/reveng
118 REVENGLIBINC = -I$(REVENGLIBPATH)
119 REVENGLIB = $(REVENGLIBPATH)/libreveng.a
120 REVENGLIBLD =
122 ## Tinycbor
123 TINYCBORLIBPATH = ./deps/tinycbor
124 TINYCBORLIBINC = -I$(TINYCBORLIBPATH)
125 TINYCBORLIB = $(TINYCBORLIBPATH)/tinycbor.a
126 TINYCBORLIBLD =
128 ## Whereami
129 WHEREAMILIBPATH = ./deps/whereami
130 WHEREAMILIBINC = -I$(WHEREAMILIBPATH)
131 WHEREAMILIB = $(WHEREAMILIBPATH)/libwhereami.a
132 WHEREAMILIBLD =
134 ##########################
135 # common local libraries #
136 ##########################
138 ## mbed TLS
139 MBEDTLSLIBPATH = ../common/mbedtls
140 MBEDTLSLIBINC = -I$(MBEDTLSLIBPATH)
141 MBEDTLSLIB = $(OBJDIR)/libmbedtls.a
142 MBEDTLSLIBCLIENTRELPATH = ../../client
144 ########################################################
145 # optional system libraries to replace local libraries #
146 ########################################################
148 ## Amiibo
149 # not distributed as system library
150 STATICLIBS += $(AMIIBOLIB)
151 LDLIBS += $(AMIIBOLIBLD)
152 PM3INCLUDES += $(AMIIBOLIBINC)
154 ## Cliparser / Argtable3
155 # not distributed as system library
156 STATICLIBS += $(CLIPARSERLIB)
157 LDLIBS += $(CLIPARSERLIBLD)
158 PM3INCLUDES += $(CLIPARSERLIBINC)
160 ## Hardnested
161 # not distributed as system library
162 STATICLIBS += $(HARDNESTEDLIB)
163 LDLIBS +=$(HARDNESTEDLIBLD)
164 PM3INCLUDES += $(HARDNESTEDLIBINC)
166 ## ID48
167 # not distributed as system library
168 STATICLIBS += $(ID48LIB)
169 LDLIBS += $(ID48LIBLD)
170 PM3INCLUDES += $(ID48LIBINC)
172 ## Linenoise
173 # wait to see if Readline is available
175 ## Lua
176 ifneq ($(SKIPLUASYSTEM),1)
177 ifdef MACPORTS_PREFIX
178 LUAINCLUDES = $(shell $(PKG_CONFIG_ENV) pkg-config --cflags lua-5.4 2>/dev/null)
179 LUALDLIBS = $(shell $(PKG_CONFIG_ENV) pkg-config --libs lua-5.4 2>/dev/null)
180 else
181 LUAINCLUDES = $(shell $(PKG_CONFIG_ENV) pkg-config --cflags lua5.4 2>/dev/null)
182 LUALDLIBS = $(shell $(PKG_CONFIG_ENV) pkg-config --libs lua5.4 2>/dev/null)
183 endif
184 ifneq ($(LUALDLIBS),)
185 LUALIB =
186 LUALIBLD = $(LUALDLIBS)
187 LUALIBINC = $(LUAINCLUDES)
188 LUA_FOUND = 1
189 endif
190 endif
191 STATICLIBS += $(LUALIB)
192 LDLIBS += $(LUALIBLD)
193 PM3INCLUDES += $(LUALIBINC)
195 ## Jansson
196 # Jansson section needs to be after Lua to avoid interferences on macOS if a locally incompatible Lua was available, see PR 1155
197 ifneq ($(SKIPJANSSONSYSTEM),1)
198 JANSSONINCLUDES = $(shell $(PKG_CONFIG_ENV) pkg-config --cflags jansson 2>/dev/null)
199 JANSSONLDLIBS = $(shell $(PKG_CONFIG_ENV) pkg-config --libs jansson 2>/dev/null)
200 ifneq ($(JANSSONLDLIBS),)
201 JANSSONLIB =
202 JANSSONLIBLD = $(JANSSONLDLIBS)
203 JANSSONLIBINC = $(JANSSONINCLUDES)
204 JANSSON_FOUND = 1
205 endif
206 endif
207 STATICLIBS += $(JANSSONLIB)
208 LDLIBS += $(JANSSONLIBLD)
209 PM3INCLUDES += $(JANSSONLIBINC)
211 ## mbed TLS
212 # system library cannot be used because it is compiled by default without CMAC support
213 STATICLIBS += $(MBEDTLSLIB)
214 LDLIBS += $(MBEDTLSLIBLD)
215 PM3INCLUDES += $(MBEDTLSLIBINC)
217 ## Reveng
218 # not distributed as system library
219 STATICLIBS += $(REVENGLIB)
220 LDLIBS += $(REVENGLIBLD)
221 PM3INCLUDES += $(REVENGLIBINC)
223 ## Tinycbor
224 # not distributed as system library
225 STATICLIBS += $(TINYCBORLIB)
226 LDLIBS += $(TINYCBORLIBLD)
227 PM3INCLUDES += $(TINYCBORLIBINC)
229 ## Whereami
230 ifneq ($(SKIPWHEREAMISYSTEM),1)
231 ifneq (,$(wildcard /usr/include/whereami.h))
232 WHEREAMILIB =
233 WHEREAMILIBLD = -lwhereami
234 WHEREAMILIBINC =
235 WHEREAMI_FOUND = 1
236 endif
237 endif
238 STATICLIBS += $(WHEREAMILIB)
239 LDLIBS += $(WHEREAMILIBLD)
240 PM3INCLUDES += $(WHEREAMILIBINC)
242 ####################
243 # system libraries #
244 ####################
246 ## Atomic
247 # RPi Zero gcc requires -latomic
248 # but MacOSX /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld
249 # doesn't recognize option --as-needed
250 ifneq ($(platform),Darwin)
251 LDLIBS += -Wl,--as-needed -latomic -Wl,--no-as-needed
252 endif
254 ## BZIP2
255 LDLIBS += -lbz2
257 ## LZ4
258 LDLIBS += -llz4
260 ## Bluez (optional)
261 ifneq ($(SKIPBT),1)
262 BTINCLUDES = $(shell $(PKG_CONFIG_ENV) pkg-config --cflags bluez 2>/dev/null)
263 BTLDLIBS = $(shell $(PKG_CONFIG_ENV) pkg-config --libs bluez 2>/dev/null)
264 ifneq ($(BTLDLIBS),)
265 BTLIBLD = $(BTLDLIBS)
266 BTLIBINC = $(BTINCLUDES)
267 BT_FOUND = 1
268 endif
269 endif
270 LDLIBS += $(BTLIBLD)
271 PM3INCLUDES += $(BTLIBINC)
273 ## Math
274 LDLIBS += -lm
276 ## Pthread
277 # Some have no pthread, e.g. termux
278 ifneq ($(SKIPPTHREAD),1)
279 LDLIBS += -lpthread
280 endif
282 ## Python3 (optional)
283 ifneq ($(SKIPPYTHON),1)
284 # since python3.8, applications willing to embed python must use -embed:
285 PYTHONINCLUDES = $(shell $(PKG_CONFIG_ENV) pkg-config --cflags $(PYTHON3_PKGCONFIG)-embed 2>/dev/null)
286 PYTHONLDLIBS = $(shell $(PKG_CONFIG_ENV) pkg-config --libs $(PYTHON3_PKGCONFIG)-embed 2>/dev/null)
287 ifneq ($(PYTHONLDLIBS),)
288 PYTHONLIBLD = $(PYTHONLDLIBS)
289 PYTHONLIBINC = $(subst -I,-isystem ,$(PYTHONINCLUDES))
290 PYTHON_FOUND = 1
291 else
292 PYTHONINCLUDES = $(shell $(PKG_CONFIG_ENV) pkg-config --cflags $(PYTHON3_PKGCONFIG) 2>/dev/null)
293 PYTHONLDLIBS = $(shell $(PKG_CONFIG_ENV) pkg-config --libs $(PYTHON3_PKGCONFIG) 2>/dev/null)
294 ifneq ($(PYTHONLDLIBS),)
295 PYTHONLIBLD = $(PYTHONLDLIBS)
296 PYTHONLIBINC = $(subst -I,-isystem ,$(PYTHONINCLUDES))
297 PYTHON_FOUND = 1
298 endif
299 endif
300 endif
301 LDLIBS += $(PYTHONLIBLD)
302 PM3INCLUDES += $(PYTHONLIBINC)
304 ## QT5 (or QT4 fallback) (optional)
305 ifneq ($(SKIPQT),1)
306 # Check for correctly configured Qt5
307 QTINCLUDES = $(shell $(PKG_CONFIG_ENV) pkg-config --cflags Qt5Core Qt5Widgets 2>/dev/null)
308 QTLDLIBS = $(shell $(PKG_CONFIG_ENV) pkg-config --libs Qt5Core Qt5Widgets 2>/dev/null)
309 MOC = $(shell $(PKG_CONFIG_ENV) pkg-config --variable=host_bins Qt5Core)/moc
310 UIC = $(shell $(PKG_CONFIG_ENV) pkg-config --variable=host_bins Qt5Core)/uic
311 QMAKE = $(shell $(PKG_CONFIG_ENV) pkg-config --variable=host_bins Qt5Core)/qmake
312 ifneq ($(QTLDLIBS),)
313 QT5_FOUND = 1
314 else
315 # if Qt5 not found check for correctly configured Qt4
316 QTINCLUDES = $(shell $(PKG_CONFIG_ENV) pkg-config --cflags QtCore QtGui 2>/dev/null)
317 QTLDLIBS = $(shell $(PKG_CONFIG_ENV) pkg-config --libs QtCore QtGui 2>/dev/null)
318 MOC = $(shell $(PKG_CONFIG_ENV) pkg-config --variable=moc_location QtCore)
319 UIC = $(shell $(PKG_CONFIG_ENV) pkg-config --variable=uic_location QtCore)
320 QMAKE = $(shell $(PKG_CONFIG_ENV) pkg-config --variable=exec_prefix QtCore)/bin/qmake
321 endif
322 ifeq ($(QTLDLIBS),)
323 # if both pkg-config commands failed, search in common places
324 ifneq ($(QTDIR),)
325 ifneq ($(wildcard $(QTDIR)/include/QtWidgets),)
326 # QT5
327 QTINCLUDES = -I$(QTDIR)/include -I$(QTDIR)/include/QtCore -I$(QTDIR)/include/QtGui -I$(QTDIR)/include/QtWidgets
328 QTLDLIBS = -L$(QTDIR)/lib -lQt5Core -lQt5Gui -lQt5Widgets
329 QT5_FOUND = 1
330 else
331 # QT4
332 QTINCLUDES = -I$(QTDIR)/include -I$(QTDIR)/include/QtCore -I$(QTDIR)/include/QtGui
333 QTLDLIBS = -L$(QTDIR)/lib -lQtCore4 -lQtGui4
334 endif
335 MOC = $(QTDIR)/bin/moc
336 UIC = $(QTDIR)/bin/uic
337 QMAKE = $(QTDIR)/bin/qmake
338 endif
339 endif
340 ifneq ($(QTLDLIBS),)
341 QT_FOUND = 1
342 endif
343 endif
344 LDLIBS += $(QTLDLIBS)
345 CXXINCLUDES += $(QTINCLUDES)
347 ## GD (optional)
348 ifneq ($(SKIPGD),1)
349 GDINCLUDES = $(shell $(PKG_CONFIG_ENV) pkg-config --cflags gdlib 2>/dev/null)
350 GDLDLIBS = $(shell $(PKG_CONFIG_ENV) pkg-config --libs gdlib 2>/dev/null)
351 ifneq ($(GDLDLIBS),)
352 LDLIBS += $(GDLDLIBS)
353 PM3INCLUDES += $(GDINCLUDES)
354 GD_FOUND = 1
355 endif
356 endif
358 ## Readline
359 ifneq ($(SKIPREADLINE),1)
360 ifeq ($(USE_BREW),1)
361 LDLIBS += -L$(BREW_PREFIX)/opt/readline/lib
362 PM3INCLUDES += -I$(BREW_PREFIX)/opt/readline/include
363 endif
365 ifeq ($(USE_MACPORTS),1)
366 PM3INCLUDES += -I$(MACPORTS_PREFIX)/include/readline
367 endif
369 LDLIBS += -lreadline
370 READLINE_FOUND = 1
371 else
372 ## Linenoise
373 ifneq ($(SKIPLINENOISE),1)
374 ifneq (,$(wildcard $(LINENOISELIBPATH)))
375 STATICLIBS += $(LINENOISELIB)
376 LDLIBS += $(LINENOISELIBLD)
377 PM3INCLUDES += $(LINENOISELIBINC)
378 LINENOISE_LOCAL_FOUND = 1
379 endif
380 endif
381 endif
383 ########
384 # SWIG #
385 ########
387 ifneq ("$(wildcard src/pm3_luawrap.c)","")
388 SWIG_LUA_FOUND = 1
389 endif
390 ifeq ($(PYTHON_FOUND),1)
391 ifneq ("$(wildcard src/pm3_pywrap.c)","")
392 SWIG_PYTHON_FOUND = 1
393 endif
394 endif
396 #######################################################################################################
397 # clang doesn't like this params
398 #MYCFLAGS += --param max-completely-peeled-insns=1000 --param max-completely-peel-times=10000
399 MYCFLAGS += -O3
401 CFLAGS ?= $(DEFCFLAGS)
402 CFLAGS += $(MYDEFS) $(MYCFLAGS) $(MYINCLUDES)
404 # We cannot just use CFLAGS+=... because it has impact on sub-makes if CFLAGS is defined in env:
405 PM3CFLAGS = $(CFLAGS)
406 PM3CFLAGS += -I./src -I./include -I../include -I../common -I../common_fpga $(PM3INCLUDES) $(INCLUDES)
407 # WIP Testing
408 #PM3CFLAGS += -std=c11 -pedantic
410 PREFIX ?= /usr/local
411 ifneq (,$(findstring MINGW,$(platform)))
412 # Mingw uses by default Microsoft printf, we want the GNU printf (e.g. for %z)
413 # and setting _ISOC99_SOURCE sets internally __USE_MINGW_ANSI_STDIO=1
414 # FTR __USE_MINGW_ANSI_STDIO seems deprecated in Mingw32
415 # but not Mingw64 https://fr.osdn.net/projects/mingw/lists/archive/users/2019-January/000199.html
416 PM3CFLAGS += -D_ISOC99_SOURCE
417 PM3CFLAGS += -mno-ms-bitfields -fexec-charset=cp850
418 endif
420 ifeq ($(READLINE_FOUND),1)
421 PM3CFLAGS += -DHAVE_READLINE
422 endif
424 ifeq ($(LINENOISE_LOCAL_FOUND),1)
425 PM3CFLAGS += -DHAVE_LINENOISE
426 endif
428 ifeq ($(BT_FOUND),1)
429 PM3CFLAGS += -DHAVE_BLUEZ
430 endif
432 ifeq ($(PYTHON_FOUND),1)
433 PM3CFLAGS += -DHAVE_PYTHON
434 endif
436 ifeq ($(GD_FOUND),1)
437 PM3CFLAGS += -DHAVE_GD
438 endif
440 ifeq ($(SWIG_LUA_FOUND),1)
441 PM3CFLAGS += -DHAVE_LUA_SWIG
442 endif
443 ifeq ($(SWIG_PYTHON_FOUND),1)
444 PM3CFLAGS += -DHAVE_PYTHON_SWIG
445 endif
447 PM3CFLAGS += -DHAVE_SNPRINTF
449 CXXFLAGS ?= -Wall -Werror
450 CXXFLAGS += $(MYDEFS) $(MYCXXFLAGS) $(MYINCLUDES)
452 PM3CXXFLAGS = $(CXXFLAGS)
453 PM3CXXFLAGS += -I../include -I./include
455 ifeq ($(QT_FOUND),1)
456 PM3CFLAGS += -DHAVE_GUI
457 PM3CXXFLAGS += -DQT_NO_DEBUG
458 ifeq ($(QT5_FOUND),1)
459 # On OSX Qt5 is claiming for a C++11 compiler (gnu++14 works too, but if nothing it fails)
460 PM3CXXFLAGS += -fPIC -std=c++11
461 endif
462 endif
464 PM3CXXFLAGS += -DHAVE_SNPRINTF
466 LDFLAGS ?= $(DEFLDFLAGS)
467 LDFLAGS += $(MYLDFLAGS)
469 PM3LDFLAGS = $(LDFLAGS)
470 ifeq ($(platform),Darwin)
471 ifeq ($(shell uname -p),arm64)
472 # The platform is iOS
473 PM3LDFLAGS += -framework Foundation -framework UIKit
474 else
475 # M* macOS devices return arm
476 PM3LDFLAGS += -framework Foundation -framework AppKit
477 endif
478 endif
480 ###################
481 # printing status #
482 ###################
484 $(info ===================================================================)
485 $(info Version info: $(shell ../tools/mkversion.sh --short 2>/dev/null))
486 $(info Client platform: $(platform))
488 ifeq ($(SKIPQT),1)
489 $(info GUI support: skipped)
490 else
491 ifeq ($(QT_FOUND),1)
492 ifeq ($(QT5_FOUND),1)
493 $(info GUI support: QT5 found, enabled ($(shell QT_SELECT=5 $(QMAKE) -v 2>/dev/null|grep -o 'Qt version.*')))
494 else
495 $(info GUI support: QT4 found, enabled ($(shell QT_SELECT=4 $(QMAKE) -v 2>/dev/null|grep -o 'Qt version.*')))
496 endif
497 else
498 $(info GUI support: QT not found, disabled)
499 endif
500 endif
502 ifeq ($(SKIPBT),1)
503 $(info native BT support: skipped)
504 else
505 ifeq ($(BT_FOUND),1)
506 $(info native BT support: Bluez found, enabled)
507 else
508 $(info native BT support: Bluez not found, disabled)
509 endif
510 endif
512 ifeq ($(SKIPJANSSONSYSTEM),1)
513 $(info Jansson library: local library forced)
514 else ifeq ($(JANSSON_FOUND),1)
515 $(info Jansson library: system library found)
516 else
517 $(info Jansson library: system library not found, using local library)
518 endif
520 ifeq ($(SKIPLUASYSTEM),1)
521 $(info Lua library: local library forced)
522 else
523 ifeq ($(LUA_FOUND),1)
524 $(info Lua library: system library found)
525 else
526 $(info Lua library: system library not found, using local library)
527 endif
528 endif
530 ifeq ($(SKIPPYTHON),1)
531 $(info Python3 library: skipped)
532 else
533 ifeq ($(PYTHON_FOUND),1)
534 $(info Python3 library: Python3 v$(shell $(PKG_CONFIG_ENV) pkg-config --modversion $(PYTHON3_PKGCONFIG)) found, enabled)
535 else
536 $(info Python3 library: Python3 not found, disabled)
537 endif
538 endif
540 ifeq ($(SKIPGD),1)
541 $(info GD library: skipped)
542 else
543 ifeq ($(GD_FOUND),1)
544 $(info GD library: GD v$(shell $(PKG_CONFIG_ENV) pkg-config --modversion gdlib) found, enabled)
545 else
546 $(info GD library: GD not found, disabled)
547 endif
548 endif
550 ifeq ($(SKIPREADLINE),1)
551 $(info Readline library: skipped)
552 else
553 ifeq ($(READLINE_FOUND),1)
554 $(info Readline library: enabled)
555 else
556 $(info Readline library: Readline not found, disabled)
557 endif
558 endif
560 ifneq ($(READLINE_FOUND),1)
561 ifeq ($(SKIPLINENOISE),1)
562 $(info Linenoise library: skipped)
563 else
564 ifeq ($(LINENOISE_LOCAL_FOUND),1)
565 $(info Linenoise library: enabled)
566 else
567 $(info Linenoise library: Linenoise not found, disabled)
568 endif
569 endif
570 endif
572 ifeq ($(SKIPWHEREAMISYSTEM),1)
573 $(info Whereami library: local library forced)
574 else
575 ifeq ($(WHEREAMI_FOUND),1)
576 $(info Whereami library: system library found)
577 else
578 $(info Whereami library: system library not found, using local library)
579 endif
580 endif
582 ifeq ($(SWIG_LUA_FOUND),1)
583 $(info Lua SWIG: wrapper found)
584 endif
585 ifeq ($(SWIG_PYTHON_FOUND),1)
586 $(info Python SWIG: wrapper found)
587 endif
589 $(info compiler version: $(shell $(CC) --version|head -n 1))
590 $(info ===================================================================)
592 ################
593 # dependencies #
594 ################
596 # Flags to generate temporary dependency files
597 DEPFLAGS = -MT $@ -MMD -MP -MF $(OBJDIR)/$*.Td
598 # make temporary to final dependency files after successful compilation
599 POSTCOMPILE = $(MV) -f $(OBJDIR)/$*.Td $(OBJDIR)/$*.d && $(TOUCH) $@
601 ################
602 # enumerations #
603 ################
605 SRCS = mifare/aiddesfire.c \
606 aidsearch.c \
607 atrs.c \
608 cmdanalyse.c \
609 cmdcrc.c \
610 cmddata.c \
611 cmdflashmem.c \
612 cmdflashmemspiffs.c \
613 cmdhf.c \
614 cmdhf14a.c \
615 cmdhf14b.c \
616 cmdhf15.c \
617 cmdhfcryptorf.c \
618 cmdhfepa.c \
619 cmdhfemrtd.c \
620 cmdhffelica.c \
621 cmdhffido.c \
622 cmdhffudan.c \
623 cmdhfgallagher.c \
624 cmdhfksx6924.c \
625 cmdhfcipurse.c \
626 cmdhficlass.c \
627 cmdhfict.c \
628 cmdhflegic.c \
629 cmdhfjooki.c \
630 cmdhflist.c \
631 cmdhflto.c \
632 cmdhfmf.c \
633 cmdhfmfdes.c \
634 cmdhfmfhard.c \
635 cmdhfmfu.c \
636 cmdhfmfp.c \
637 cmdhfntag424.c \
638 cmdhfseos.c \
639 cmdhfst.c \
640 cmdhfst25ta.c \
641 cmdhftesla.c \
642 cmdhfthinfilm.c \
643 cmdhftopaz.c \
644 cmdhftexkom.c \
645 cmdhfvas.c \
646 cmdhfxerox.c \
647 cmdhw.c \
648 cmdlf.c \
649 cmdlfawid.c \
650 cmdlfcotag.c \
651 cmdlfdestron.c \
652 cmdlfem.c \
653 cmdlfem410x.c \
654 cmdlfem4x05.c \
655 cmdlfem4x50.c \
656 cmdlfem4x70.c \
657 cmdlffdxb.c \
658 cmdlfguard.c \
659 cmdlfgallagher.c \
660 cmdlfhid.c \
661 cmdlfhitag.c \
662 cmdlfhitaghts.c \
663 cmdlfidteck.c \
664 cmdlfindala.c \
665 cmdlfio.c \
666 cmdlfjablotron.c \
667 cmdlfkeri.c \
668 cmdlfmotorola.c \
669 cmdlfnedap.c \
670 cmdlfnexwatch.c \
671 cmdlfnoralsy.c \
672 cmdlfpac.c \
673 cmdlfparadox.c \
674 cmdlfpcf7931.c \
675 cmdlfpresco.c \
676 cmdlfpyramid.c \
677 cmdlfsecurakey.c \
678 cmdlft55xx.c \
679 cmdlfti.c \
680 cmdlfviking.c \
681 cmdlfvisa2000.c \
682 cmdlfzx8211.c \
683 cmdmain.c \
684 cmdnfc.c \
685 cmdparser.c \
686 cmdpiv.c \
687 cmdscript.c \
688 cmdsmartcard.c \
689 cmdtrace.c \
690 cmdusart.c \
691 cmdwiegand.c \
692 comms.c \
693 crypto/asn1dump.c \
694 crypto/asn1utils.c\
695 crypto/libpcrypto.c\
696 emv/cmdemv.c \
697 emv/crypto.c\
698 emv/crypto_polarssl.c\
699 emv/dol.c \
700 emv/emv_pk.c\
701 emv/emv_pki.c\
702 emv/emv_pki_priv.c\
703 emv/emv_roca.c \
704 emv/emv_tags.c \
705 emv/emvcore.c \
706 emv/emvjson.c\
707 emv/tlv.c \
708 emv/test/crypto_test.c\
709 emv/test/cryptotest.c\
710 emv/test/cda_test.c\
711 emv/test/dda_test.c\
712 emv/test/sda_test.c\
713 fido/additional_ca.c \
714 fido/cose.c \
715 fido/cbortools.c \
716 fido/fidocore.c \
717 ksx6924/ksx6924core.c \
718 cipurse/cipursecore.c \
719 cipurse/cipursecrypto.c \
720 cipurse/cipursetest.c \
721 fileutils.c \
722 flash.c \
723 generator.c \
724 graph.c \
725 jansson_path.c \
726 iso4217.c \
727 iso7816/apduinfo.c \
728 iso7816/iso7816core.c \
729 loclass/cipher.c \
730 loclass/cipherutils.c \
731 loclass/elite_crack.c \
732 loclass/ikeys.c \
733 lua_bitlib.c \
734 mifare/lrpcrypto.c \
735 mifare/desfirecrypto.c \
736 mifare/desfirecore.c \
737 mifare/desfiresecurechan.c \
738 mifare/desfiretest.c \
739 mifare/gallaghercore.c \
740 mifare/mad.c \
741 mifare/mfkey.c \
742 mifare/mifare4.c \
743 mifare/mifaredefault.c \
744 mifare/mifarehost.c \
745 mifare/gen4.c \
746 nfc/ndef.c \
747 pm3.c \
748 pm3_binlib.c \
749 pm3_bitlib.c \
750 preferences.c \
751 pm3line.c \
752 proxmark3.c \
753 scandir.c \
754 uart/ringbuffer.c \
755 uart/uart_common.c \
756 uart/uart_posix.c \
757 uart/uart_win32.c \
758 scripting.c \
759 ui.c \
760 util.c \
761 version_pm3.c \
762 wiegand_formats.c \
763 wiegand_formatutils.c
765 # common
766 SRCS += bucketsort.c \
767 bruteforce.c \
768 cardhelper.c \
769 crapto1/crapto1.c \
770 crapto1/crypto1.c \
771 crc.c \
772 crc16.c \
773 crc32.c \
774 crc64.c \
775 commonutil.c \
776 hitag2/hitag2_crypto.c \
777 iso15693tools.c \
778 legic_prng.c \
779 lfdemod.c \
780 util_posix.c
782 ifeq ($(GD_FOUND),1)
783 # electronic shelf labels
784 SRCS += imgutils.c \
785 cmdhfwaveshare.c
786 endif
788 # swig
790 SWIGSRCS =
791 ifeq ($(SWIG_LUA_FOUND),1)
792 SWIGSRCS += pm3_luawrap.c
793 endif
794 ifeq ($(SWIG_PYTHON_FOUND),1)
795 SWIGSRCS += pm3_pywrap.c
796 endif
798 # gui
799 ifeq ($(QT_FOUND),1)
800 CXXSRCS = proxgui.cpp proxguiqt.cpp proxguiqt.moc.cpp
801 else
802 CXXSRCS = guidummy.cpp
803 endif
805 # OS X
806 ifeq ($(platform),Darwin)
807 OBJCSRCS = util_darwin.m
808 endif
810 OBJS = $(SRCS:%.c=$(OBJDIR)/%.o)
811 OBJS += $(SWIGSRCS:%.c=$(OBJDIR)/%.o)
812 OBJS += $(CXXSRCS:%.cpp=$(OBJDIR)/%.o)
813 OBJS += $(OBJCSRCS:%.m=$(OBJDIR)/%.o)
815 BINS = proxmark3
817 CLEAN = $(BINS) src/version_pm3.c src/*.moc.cpp src/ui/ui_overlays.h src/ui/ui_image.h lualibs/pm3_cmd.lua lualibs/mfc_default_keys.lua
818 # transition: cleaning also old path stuff
819 CLEAN += flasher *.moc.cpp ui/ui_overlays.h ui/ui_image.h
821 ###########
822 # targets #
823 ###########
825 # need to assign dependancies to build these first...
826 all: $(BINS)
828 all-static: LDLIBS:=-static $(LDLIBS)
829 all-static: $(BINS)
831 proxmark3: $(OBJS) $(STATICLIBS) lualibs/pm3_cmd.lua lualibs/mfc_default_keys.lua
832 $(info [=] CXX $@)
833 # $(Q)$(CXX) $(PM3LDFLAGS) $(OBJS) $(STATICLIBS) $(LDLIBS) -o $@
834 $(Q)$(CXX) $(PM3CFLAGS) $(PM3LDFLAGS) $(OBJS) $(STATICLIBS) $(LDLIBS) -o $@
836 src/proxgui.cpp: src/ui/ui_overlays.h src/ui/ui_image.h
838 src/proxguiqt.cpp: src/proxguiqt.h
840 src/proxguiqt.moc.cpp: src/proxguiqt.h
841 $(info [-] MOC $@)
842 $(Q)$(MOC) -o$@ $^
844 src/proxguiqt.h: src/ui/ui_overlays.h src/ui/ui_image.h
846 src/ui/ui_overlays.h: src/ui/overlays.ui
847 $(info [-] UIC $@)
848 $(Q)$(UIC) $^ > $@
850 src/ui/ui_image.h: src/ui/image.ui
851 $(info [-] UIC $@)
852 $(Q)$(UIC) $^ > $@
854 lualibs/pm3_cmd.lua: ../include/pm3_cmd.h
855 $(info [=] GEN $@)
856 $(Q)awk -f pm3_cmd_h2lua.awk $^ > $@
858 lualibs/mfc_default_keys.lua : mfc_default_keys.dic
859 $(info [=] GEN $@)
860 $(Q)awk -f default_keys_dic2lua.awk $^ > $@
862 clean:
863 $(Q)$(RM) $(CLEAN)
864 $(Q)$(RMDIR) $(OBJDIR)
865 $(Q)$(MAKE) --no-print-directory -C $(AMIIBOLIBPATH) clean
866 $(Q)$(MAKE) --no-print-directory -C $(CLIPARSERLIBPATH) clean
867 $(Q)$(MAKE) --no-print-directory -C $(HARDNESTEDLIBPATH) clean
868 $(Q)$(MAKE) --no-print-directory -C $(ID48LIBPATH) clean
869 $(Q)$(MAKE) --no-print-directory -C $(JANSSONLIBPATH) clean
870 ifeq ($(LINENOISE_LOCAL_FOUND), 1)
871 $(Q)$(MAKE) --no-print-directory -C $(LINENOISELIBPATH) clean
872 endif
873 $(Q)$(MAKE) --no-print-directory -C $(LUALIBPATH) clean
874 $(Q)$(MAKE) --no-print-directory -C $(REVENGLIBPATH) clean
875 $(Q)$(MAKE) --no-print-directory -C $(TINYCBORLIBPATH) clean
876 $(Q)$(MAKE) --no-print-directory -C $(WHEREAMILIBPATH) clean
877 @# Just in case someone compiled within these dirs:
878 $(Q)$(MAKE) --no-print-directory -C $(MBEDTLSLIBPATH) clean
880 install: all
881 $(info [@] Installing client to $(DESTDIR)$(PREFIX)...)
882 ifneq (,$(INSTALLBIN))
883 $(Q)$(INSTALLSUDO) $(MKDIR) $(DESTDIR)$(PREFIX)$(PATHSEP)$(INSTALLBINRELPATH)
884 $(Q)$(INSTALLSUDO) $(CP) $(INSTALLBIN) $(DESTDIR)$(PREFIX)$(PATHSEP)$(INSTALLBINRELPATH)
885 endif
886 ifneq (,$(INSTALLSHARE))
887 $(Q)$(INSTALLSUDO) $(MKDIR) $(DESTDIR)$(PREFIX)$(PATHSEP)$(INSTALLSHARERELPATH)
888 $(Q)$(INSTALLSUDO) $(CP) $(INSTALLSHARE) $(DESTDIR)$(PREFIX)$(PATHSEP)$(INSTALLSHARERELPATH)
889 endif
890 @true
892 uninstall:
893 $(info [@] Uninstalling client from $(DESTDIR)$(PREFIX)...)
894 ifneq (,$(INSTALLBIN))
895 $(Q)$(INSTALLSUDO) $(RM) $(foreach tool,$(INSTALLBIN),$(DESTDIR)$(PREFIX)$(PATHSEP)$(INSTALLBINRELPATH)$(PATHSEP)$(notdir $(tool)))
896 endif
897 ifneq (,$(INSTALLSHARE))
898 $(Q)$(INSTALLSUDO) $(RMDIR) $(foreach tool,$(INSTALLSHARE),$(DESTDIR)$(PREFIX)$(PATHSEP)$(INSTALLSHARERELPATH)$(PATHSEP)$(notdir $(tool)))
899 endif
900 @true
902 tarbin: $(BINS)
903 $(info [=] TAR ../proxmark3-$(platform)-bin.tar)
904 $(Q)$(TAR) $(TARFLAGS) ../proxmark3-$(platform)-bin.tar $(BINS:%=client/%) $(WINBINS:%=client/%)
906 ###########################
907 # local libraries targets #
908 ###########################
909 $(AMIIBOLIB): .FORCE
910 $(info [*] MAKE $@)
911 $(Q)$(MAKE) --no-print-directory -C $(AMIIBOLIBPATH) all
913 $(CLIPARSERLIB): .FORCE
914 $(info [*] MAKE $@)
915 $(Q)$(MAKE) --no-print-directory -C $(CLIPARSERLIBPATH) all
917 $(HARDNESTEDLIB): .FORCE
918 $(info [*] MAKE $@)
919 $(Q)$(MAKE) --no-print-directory -C $(HARDNESTEDLIBPATH) all
921 $(ID48LIB): .FORCE
922 $(info [*] MAKE $@)
923 $(Q)$(MAKE) --no-print-directory -C $(ID48LIBPATH) all
925 $(JANSSONLIB): .FORCE
926 ifneq ($(JANSSON_FOUND),1)
927 $(info [*] MAKE $@)
928 $(Q)$(MAKE) --no-print-directory -C $(JANSSONLIBPATH) all
929 endif
931 $(LINENOISELIB): .FORCE
932 ifeq ($(LINENOISE_LOCAL_FOUND), 1)
933 $(info [*] MAKE $@)
934 $(Q)$(MAKE) --no-print-directory -C $(LINENOISELIBPATH) all
935 endif
937 $(LUALIB): .FORCE
938 ifneq ($(LUA_FOUND),1)
939 $(info [*] MAKE $@ for $(LUAPLATFORM))
940 $(Q)$(MAKE) --no-print-directory -C $(LUALIBPATH) $(LUAPLATFORM)
941 endif
943 $(MBEDTLSLIB): .FORCE
944 $(info [*] MAKE $@)
945 $(Q)$(MAKE) --no-print-directory -C $(MBEDTLSLIBPATH) OBJDIR=$(MBEDTLSLIBCLIENTRELPATH)/$(OBJDIR)/mbedtls BINDIR=$(MBEDTLSLIBCLIENTRELPATH)/$(OBJDIR) all
947 $(REVENGLIB): .FORCE
948 $(info [*] MAKE $@)
949 $(Q)$(MAKE) --no-print-directory -C $(REVENGLIBPATH) all
951 $(TINYCBORLIB): .FORCE
952 $(info [*] MAKE $@)
953 $(Q)$(MAKE) --no-print-directory -C $(TINYCBORLIBPATH) all
955 $(WHEREAMILIB): .FORCE
956 ifneq ($(WHEREAMI_FOUND),1)
957 $(info [*] MAKE $@)
958 $(Q)$(MAKE) --no-print-directory -C $(WHEREAMILIBPATH) all
959 endif
961 ########
962 # SWIG #
963 ########
965 src/pm3_luawrap.c: pm3.i
966 $(info [=] GEN $@)
967 $(Q)$(SWIG) -lua -o $@ $<
969 src/pm3_pywrap.c: pm3.i
970 $(info [=] GEN $@)
971 $(Q)$(SWIG) -python -o $@ $<
973 ########
974 # misc #
975 ########
977 .PHONY: all clean install uninstall tarbin .FORCE
979 # version_pm3.c should be checked on every compilation
980 src/version_pm3.c: default_version_pm3.c .FORCE
981 $(info [=] CHECK $@)
982 $(Q)$(SH) ../tools/mkversion.sh $@ || $(CP) $< $@
984 # easy printing of MAKE VARIABLES
985 print-%: ; @echo $* = $($*)
987 # SWIG files emit a number of warnings, we've to ignore them
988 %wrap.o: %wrap.c
989 $(OBJDIR)/%wrap.o : %wrap.c $(OBJDIR)/%.d
990 $(info [-] CC $<)
991 $(Q)$(MKDIR) $(dir $@)
992 $(Q)$(CC) $(DEPFLAGS) $(PM3CFLAGS) -Wno-missing-prototypes -Wno-missing-declarations -Wno-missing-field-initializers -c -o $@ $<
993 $(Q)$(POSTCOMPILE)
995 %.o: %.c
996 $(OBJDIR)/%.o : %.c $(OBJDIR)/%.d
997 $(info [-] CC $<)
998 $(Q)$(MKDIR) $(dir $@)
999 $(Q)$(CC) $(DEPFLAGS) $(PM3CFLAGS) -c -o $@ $<
1000 $(Q)$(POSTCOMPILE)
1002 %.o: %.cpp
1003 $(OBJDIR)/%.o : %.cpp $(OBJDIR)/%.d
1004 $(info [-] CXX $<)
1005 $(Q)$(MKDIR) $(dir $@)
1006 $(Q)$(CXX) $(DEPFLAGS) $(PM3CXXFLAGS) $(CXXINCLUDES) -c -o $@ $<
1007 $(Q)$(POSTCOMPILE)
1009 %.o: %.m
1010 $(OBJDIR)/%.o : %.m $(OBJDIR)/%.d
1011 $(info [-] CC $<)
1012 $(Q)$(MKDIR) $(dir $@)
1013 $(Q)$(CC) $(DEPFLAGS) $(PM3CFLAGS) -c -o $@ $<
1014 $(Q)$(POSTCOMPILE)
1016 DEPENDENCY_FILES = $(patsubst %.c, $(OBJDIR)/%.d, $(SRCS)) \
1017 $(patsubst %wrap.c, $(OBJDIR)/%.d, $(SWIGSRCS)) \
1018 $(patsubst %.cpp, $(OBJDIR)/%.d, $(CXXSRCS)) \
1019 $(patsubst %.m, $(OBJDIR)/%.d, $(OBJCSRCS))
1021 $(DEPENDENCY_FILES): ;
1022 .PRECIOUS: $(DEPENDENCY_FILES)
1024 -include $(DEPENDENCY_FILES)