maur keys
[RRG-proxmark3.git] / Makefile
blob4ba68b3ae0036a6d0a3ee259a8c0ed19b5052229
2 include Makefile.defs
3 -include Makefile.platform
4 -include .Makefile.options.cache
5 include common_arm/Makefile.hal
7 # preserve relative DESTDIR path for subdir makes
8 ifneq (,$(DESTDIR))
9 # realpath needs the directory to exist
10 $(shell $(MKDIR) $(DESTDIR))
11 MYDESTDIR:=$(realpath $(DESTDIR))
12 ifeq (,$(MYDESTDIR))
13 $(error Can't create $(DESTDIR))
14 endif
15 endif
17 all clean install uninstall check: %: client/% bootrom/% armsrc/% recovery/% mfkey/% nonce2key/% mf_nonce_brute/% fpga_compress/%
18 # hitag2crack toolsuite is not yet integrated in "all", it must be called explicitly: "make hitag2crack"
19 #all clean install uninstall check: %: hitag2crack/%
21 INSTALLTOOLS=pm3_eml2lower.sh pm3_eml2upper.sh pm3_mfdread.py pm3_mfd2eml.py pm3_eml2mfd.py findbits.py rfidtest.pl xorcheck.py
22 INSTALLSIMFW=sim011.bin sim011.sha512.txt
23 INSTALLSCRIPTS=pm3 pm3-flash pm3-flash-all pm3-flash-bootrom pm3-flash-fullimage
24 INSTALLSHARES=tools/jtag_openocd traces
25 INSTALLDOCS=doc/*.md doc/md
27 install: all common/install
29 common/install:
30 $(info [@] Installing common resources to $(MYDESTDIR)$(PREFIX)...)
31 ifneq (,$(INSTALLSCRIPTS))
32 $(Q)$(MKDIR) $(DESTDIR)$(PREFIX)$(PATHSEP)$(INSTALLBINRELPATH)
33 $(Q)$(CP) $(INSTALLSCRIPTS) $(DESTDIR)$(PREFIX)$(PATHSEP)$(INSTALLBINRELPATH)
34 endif
35 ifneq (,$(INSTALLSHARES))
36 $(Q)$(MKDIR) $(DESTDIR)$(PREFIX)$(PATHSEP)$(INSTALLSHARERELPATH)
37 $(Q)$(CP) $(INSTALLSHARES) $(DESTDIR)$(PREFIX)$(PATHSEP)$(INSTALLSHARERELPATH)
38 endif
39 ifneq (,$(INSTALLDOCS))
40 $(Q)$(MKDIR) $(DESTDIR)$(PREFIX)$(PATHSEP)$(INSTALLDOCSRELPATH)
41 $(Q)$(CP) $(INSTALLDOCS) $(DESTDIR)$(PREFIX)$(PATHSEP)$(INSTALLDOCSRELPATH)
42 endif
43 ifneq (,$(INSTALLTOOLS))
44 $(Q)$(MKDIR) $(DESTDIR)$(PREFIX)$(PATHSEP)$(INSTALLTOOLSRELPATH)
45 $(Q)$(CP) $(foreach tool,$(INSTALLTOOLS),tools/$(tool)) $(DESTDIR)$(PREFIX)$(PATHSEP)$(INSTALLTOOLSRELPATH)
46 endif
47 ifneq (,$(INSTALLSIMFW))
48 $(Q)$(MKDIR) $(DESTDIR)$(PREFIX)$(PATHSEP)$(INSTALLFWRELPATH)
49 $(Q)$(CP) $(foreach fw,$(INSTALLSIMFW),client/resources/$(fw)) $(DESTDIR)$(PREFIX)$(PATHSEP)$(INSTALLFWRELPATH)
50 endif
51 ifeq ($(platform),Linux)
52 $(Q)$(MKDIR) $(DESTDIR)$(UDEV_PREFIX)
53 $(Q)$(CP) driver/77-pm3-usb-device-blacklist.rules $(DESTDIR)$(UDEV_PREFIX)/77-pm3-usb-device-blacklist.rules
54 endif
56 uninstall: common/uninstall
58 common/uninstall:
59 $(info [@] Uninstalling common resources from $(MYDESTDIR)$(PREFIX)...)
60 ifneq (,$(INSTALLSCRIPTS))
61 $(Q)$(RM) $(foreach script,$(INSTALLSCRIPTS),$(DESTDIR)$(PREFIX)$(PATHSEP)$(INSTALLBINRELPATH)$(PATHSEP)$(notdir $(script)))
62 endif
63 ifneq (,$(INSTALLSHARES))
64 $(Q)$(RMDIR) $(foreach share,$(INSTALLSHARES),$(DESTDIR)$(PREFIX)$(PATHSEP)$(INSTALLSHARERELPATH)$(PATHSEP)$(notdir $(share)))
65 endif
66 ifneq (,$(INSTALLDOCS))
67 $(Q)$(RMDIR) $(foreach doc,$(INSTALLDOCS),$(DESTDIR)$(PREFIX)$(PATHSEP)$(INSTALLDOCSRELPATH)$(PATHSEP)$(notdir $(doc)))
68 $(Q)$(RMDIR_SOFT) $(DESTDIR)$(PREFIX)$(PATHSEP)$(INSTALLDOCSRELPATH)
69 endif
70 ifneq (,$(INSTALLTOOLS))
71 $(Q)$(RM) $(foreach tool,$(INSTALLTOOLS),$(DESTDIR)$(PREFIX)$(PATHSEP)$(INSTALLTOOLSRELPATH)$(PATHSEP)$(notdir $(tool)))
72 endif
73 $(Q)$(RMDIR_SOFT) $(DESTDIR)$(PREFIX)$(PATHSEP)$(INSTALLTOOLSRELPATH)
74 ifneq (,$(INSTALLSIMFW))
75 $(Q)$(RM) $(foreach fw,$(INSTALLSIMFW),$(DESTDIR)$(PREFIX)$(PATHSEP)$(INSTALLFWRELPATH)$(PATHSEP)$(notdir $(fw)))
76 endif
77 $(Q)$(RMDIR_SOFT) $(DESTDIR)$(PREFIX)$(PATHSEP)$(INSTALLFWRELPATH)
78 ifeq ($(platform),Linux)
79 $(Q)$(RM) $(DESTDIR)$(UDEV_PREFIX)/77-pm3-usb-device-blacklist.rules
80 endif
81 $(Q)$(RMDIR_SOFT) $(DESTDIR)$(PREFIX)$(PATHSEP)$(INSTALLSHARERELPATH)
83 # tests
84 mfkey/check: FORCE
85 $(info [*] CHECK $(patsubst %/check,%,$@))
86 $(Q)$(BASH) tools/pm3_tests.sh $(CHECKARGS) $(patsubst %/check,%,$@)
87 nonce2key/check: FORCE
88 $(info [*] CHECK $(patsubst %/check,%,$@))
89 $(Q)$(BASH) tools/pm3_tests.sh $(CHECKARGS) $(patsubst %/check,%,$@)
90 mf_nonce_brute/check: FORCE
91 $(info [*] CHECK $(patsubst %/check,%,$@))
92 $(Q)$(BASH) tools/pm3_tests.sh $(CHECKARGS) $(patsubst %/check,%,$@)
93 fpga_compress/check: FORCE
94 $(info [*] CHECK $(patsubst %/check,%,$@))
95 $(Q)$(BASH) tools/pm3_tests.sh $(CHECKARGS) $(patsubst %/check,%,$@)
96 bootrom/check: FORCE
97 $(info [*] CHECK $(patsubst %/check,%,$@))
98 $(Q)$(BASH) tools/pm3_tests.sh $(CHECKARGS) $(patsubst %/check,%,$@)
99 armsrc/check: FORCE
100 $(info [*] CHECK $(patsubst %/check,%,$@))
101 $(Q)$(BASH) tools/pm3_tests.sh $(CHECKARGS) $(patsubst %/check,%,$@)
102 client/check: FORCE
103 $(info [*] CHECK $(patsubst %/check,%,$@))
104 $(Q)$(BASH) tools/pm3_tests.sh $(CHECKARGS) $(patsubst %/check,%,$@)
105 recovery/check: FORCE
106 $(info [*] CHECK $(patsubst %/check,%,$@))
107 $(Q)$(BASH) tools/pm3_tests.sh $(CHECKARGS) $(patsubst %/check,%,$@)
108 hitag2crack/check: FORCE
109 $(info [*] CHECK $(patsubst %/check,%,$@))
110 $(Q)$(BASH) tools/pm3_tests.sh $(CHECKARGS) $(patsubst %/check,%,$@)
111 common/check: FORCE
112 $(info [*] CHECK $(patsubst %/check,%,$@))
113 $(Q)$(BASH) tools/pm3_tests.sh $(CHECKARGS) $(patsubst %/check,%,$@)
114 check: common/check
115 $(info [*] ALL CHECKS DONE)
117 mfkey/%: FORCE
118 $(info [*] MAKE $@)
119 $(Q)$(MAKE) --no-print-directory -C tools/mfkey $(patsubst mfkey/%,%,$@) DESTDIR=$(MYDESTDIR)
120 nonce2key/%: FORCE
121 $(info [*] MAKE $@)
122 $(Q)$(MAKE) --no-print-directory -C tools/nonce2key $(patsubst nonce2key/%,%,$@) DESTDIR=$(MYDESTDIR)
123 mf_nonce_brute/%: FORCE
124 $(info [*] MAKE $@)
125 $(Q)$(MAKE) --no-print-directory -C tools/mf_nonce_brute $(patsubst mf_nonce_brute/%,%,$@) DESTDIR=$(MYDESTDIR)
126 fpga_compress/%: FORCE
127 $(info [*] MAKE $@)
128 $(Q)$(MAKE) --no-print-directory -C tools/fpga_compress $(patsubst fpga_compress/%,%,$@) DESTDIR=$(MYDESTDIR)
129 bootrom/%: FORCE cleanifplatformchanged
130 $(info [*] MAKE $@)
131 $(Q)$(MAKE) --no-print-directory -C bootrom $(patsubst bootrom/%,%,$@) DESTDIR=$(MYDESTDIR)
132 armsrc/%: FORCE cleanifplatformchanged fpga_compress/%
133 $(info [*] MAKE $@)
134 $(Q)$(MAKE) --no-print-directory -C armsrc $(patsubst armsrc/%,%,$@) DESTDIR=$(MYDESTDIR)
135 client/%: FORCE
136 $(info [*] MAKE $@)
137 $(Q)$(MAKE) --no-print-directory -C client $(patsubst client/%,%,$@) DESTDIR=$(MYDESTDIR)
138 recovery/all: bootrom/all armsrc/all
139 recovery/install: bootrom/all armsrc/all
140 recovery/%: FORCE cleanifplatformchanged
141 $(info [*] MAKE $@)
142 $(Q)$(MAKE) --no-print-directory -C recovery $(patsubst recovery/%,%,$@) DESTDIR=$(MYDESTDIR)
143 hitag2crack/%: FORCE
144 $(info [*] MAKE $@)
145 $(Q)$(MAKE) --no-print-directory -C tools/hitag2crack $(patsubst hitag2crack/%,%,$@) DESTDIR=$(MYDESTDIR)
146 FORCE: # Dummy target to force remake in the subdirectories, even if files exist (this Makefile doesn't know about the prerequisites)
148 .PHONY: all clean install uninstall help _test bootrom fullimage recovery client mfkey nonce2key mf_nonce_brute hitag2crack style miscchecks release FORCE udev accessrights cleanifplatformchanged
150 help:
151 @echo "Multi-OS Makefile"
152 @echo
153 @echo "Possible targets:"
154 @echo "+ all - Make all targets: bootrom, fullimage and OS-specific host tools"
155 @echo "+ clean - Clean in all targets"
156 @echo "+ .../clean - Clean in specified target and its deps, e.g. bootrom/clean"
157 @echo "+ (un)install - Install/uninstall Proxmark files in the system, default to /usr/local/share,"
158 @echo " else provide a PREFIX. See Maintainers.md for more options"
159 @echo
160 @echo "+ bootrom - Make bootrom"
161 @echo "+ fullimage - Make armsrc fullimage (includes fpga)"
162 @echo "+ recovery - Make bootrom and fullimage files for JTAG flashing"
163 @echo
164 @echo "+ client - Make only the OS-specific host client"
165 @echo "+ mfkey - Make tools/mfkey"
166 @echo "+ nonce2key - Make tools/nonce2key"
167 @echo "+ mf_nonce_brute - Make tools/mf_nonce_brute"
168 @echo "+ hitag2crack - Make tools/hitag2crack"
169 @echo "+ fpga_compress - Make tools/fpga_compress"
170 @echo
171 @echo "+ style - Apply some automated source code formatting rules"
172 @echo "+ check - Run offline tests. Set CHECKARGS to pass arguments to the test script"
173 @echo "+ .../check - Run offline tests against specific target. See above."
174 @echo "+ miscchecks - Detect various encoding issues in source code"
175 @echo
176 @echo "+ udev - Sets udev rules on *nix"
177 @echo "+ accessrights - Ensure user belongs to correct group on *nix"
178 @echo
179 @echo "Possible platforms: try \"make PLATFORM=\" for more info, default is PM3RDV4"
180 @echo "To activate verbose mode, use make V=1"
182 client: client/all
184 bootrom: bootrom/all
186 # aliases fullimage = armsrc
188 fullimage: armsrc/all
190 fullimage/all: armsrc/all
192 fullimage/clean: armsrc/clean
194 fullimage/install: armsrc/install
196 fullimage/uninstall: armsrc/uninstall
198 recovery: recovery/all
200 mfkey: mfkey/all
202 nonce2key: nonce2key/all
204 mf_nonce_brute: mf_nonce_brute/all
206 fpga_compress: fpga_compress/all
208 hitag2crack: hitag2crack/all
210 newtarbin:
211 $(RM) proxmark3-$(platform)-bin.tar proxmark3-$(platform)-bin.tar.gz
212 @touch proxmark3-$(platform)-bin.tar
214 tarbin: newtarbin client/tarbin armsrc/tarbin bootrom/tarbin
215 $(info GEN proxmark3-$(platform)-bin.tar)
216 $(Q)$(GZIP) proxmark3-$(platform)-bin.tar
218 # detect if there were changes in the platform definitions, requiring a clean
219 cleanifplatformchanged:
220 ifeq ($(PLATFORM_CHANGED),true)
221 $(info [!] Platform definitions changed, cleaning bootrom/armsrc/recovery first...)
222 $(Q)$(MAKE) --no-print-directory -C bootrom clean
223 $(Q)$(MAKE) --no-print-directory -C armsrc clean
224 $(Q)$(MAKE) --no-print-directory -C recovery clean
225 $(Q)echo CACHED_PLATFORM=$(PLATFORM) > .Makefile.options.cache
226 $(Q)echo CACHED_PLATFORM_EXTRAS=$(PLATFORM_EXTRAS) >> .Makefile.options.cache
227 $(Q)echo CACHED_PLATFORM_DEFS=$(PLATFORM_DEFS) >> .Makefile.options.cache
228 endif
230 # configure system to ignore PM3 device as a modem (ModemManager blacklist, effective *only* if ModemManager is not using _strict_ policy)
231 # Read doc/md/ModemManager-Must-Be-Discarded.md for more info
232 udev:
233 sudo cp -rf driver/77-pm3-usb-device-blacklist.rules /etc/udev/rules.d/77-pm3-usb-device-blacklist.rules
234 sudo udevadm control --reload-rules
236 # configure system to add user to the dialout group
237 # you need to logout, relogin to get this access right correct.
238 # Finally, you might need to run the proxmark3 client under SUDO on some systems
239 accessrights:
240 ifneq ($(wildcard /etc/arch-release),) #If user is running ArchLinux
241 sudo usermod -aG uucp $(USER) #Use specific command and group
242 sudo usermod -aG bluetooth $(USER) #Use specific command and group
243 else
244 sudo adduser $(USER) dialout
245 sudo adduser $(USER) bluetooth
246 endif
248 # easy printing of MAKE VARIABLES
249 print-%: ; @echo $* = $($*)
251 style:
252 # Make sure astyle is installed
253 @which astyle >/dev/null || ( echo "Please install 'astyle' package first" ; exit 1 )
254 # Remove spaces & tabs at EOL, add LF at EOF if needed on *.c, *.h, *.cpp. *.lua, *.py, *.pl, Makefile, *.v, pm3
255 find . \( -not -path "./cov-int/*" -and -not -path "./fpga/xst/*" -and \( -name "*.[ch]" -or \( -name "*.cpp" -and -not -name "*.moc.cpp" \) -or -name "*.lua" -or -name "*.py" -or -name "*.pl" -or -name "Makefile" -or -name "*.v" -or -name "pm3" \) \) \
256 -exec perl -pi -e 's/[ \t]+$$//' {} \; \
257 -exec sh -c "tail -c1 {} | xxd -p | tail -1 | grep -q -v 0a$$" \; \
258 -exec sh -c "echo >> {}" \;
259 # Apply astyle on *.c, *.h, *.cpp
260 find . \( -not -path "./cov-int/*" -and \( \( -name "*.[ch]" -and -not -name "ui_overlays.h" \) -or \( -name "*.cpp" -and -not -name "*.moc.cpp" \) \) \) -exec astyle --formatted --mode=c --suffix=none \
261 --indent=spaces=4 --indent-switches \
262 --keep-one-line-blocks --max-instatement-indent=60 \
263 --style=google --pad-oper --unpad-paren --pad-header \
264 --align-pointer=name {} \;
265 # Update commands.md
266 [ -x client/proxmark3 ] && client/proxmark3 -m > doc/commands.md
267 # Make sure python3 is installed
268 @which python3 >/dev/null || ( echo "Please install 'python3' package first" ; exit 1 )
269 # Update commands.json
270 [ -x client/proxmark3 ] && client/proxmark3 --fulltext | python3 client/pyscripts/pm3_help2json.py - doc/commands.json
272 # Detecting weird codepages and tabs.
273 ifeq ($(platform),Darwin)
274 miscchecks: TABSCMD=egrep -l '\t' {}
275 else
276 miscchecks: TABSCMD=grep -lP '\t' {}
277 endif
278 ifneq (,$(EDIT))
279 miscchecks: TABSCMD+= && vi {} -c ':set tabstop=4' -c ':set et|retab' -c ':wq'
280 endif
281 miscchecks:
282 # Make sure recode is installed
283 @which recode >/dev/null || ( echo "Please install 'recode' package first" ; exit 1 )
284 @echo "Files with suspicious chars:"
285 @find . \( -not -path "./cov-int/*" -and -not -path "./client/deps/*" -and \( -name "*.[ch]" -or -name "*.cpp" -or -name "*.lua" -or -name "*.py" -or -name "*.pl" -or -name "Makefile" -or -name "*.v" -or -name "pm3" \) \) \
286 -exec sh -c "cat {} |recode utf8.. >/dev/null || echo {}" \;
287 ifneq (,$(EDIT))
288 @echo "Files with tabs: (EDIT enabled, files will be rewritten!)"
289 else
290 @echo "Files with tabs: (rerun with EDIT=1 if you want to convert them with vim)"
291 endif
292 # to remove tabs within lines, one can try with: vi $file -c ':set tabstop=4' -c ':set et|retab' -c ':wq'
293 @find . \( -not -path "./cov-int/*" -and -not -path "./client/deps/*" -and \( -name "*.[ch]" -or \( -name "*.cpp" -and -not -name "*.moc.cpp" \) -or -name "*.lua" -or -name "*.py" -or -name "*.pl" -or -name "*.md" -or -name "*.txt" -or -name "*.awk" -or -name "*.v" -or -name "pm3" \) \) \
294 -exec sh -c "$(TABSCMD)" \;
295 # @echo "Files with printf \\\\t:"
296 # @find . \( -name "*.[ch]" -or \( -name "*.cpp" -and -not -name "*.moc.cpp" \) -or -name "*.lua" -or -name "*.py" -or -name "*.pl" -or -name "*.md" -or -name "*.txt" -or -name "*.awk" -or -name "*.v" \) \
297 # -exec grep -lP '\\t' {} \;
299 release: VERSION="v4.$(shell git log --oneline master | wc -l)"
300 release:
301 $(if $(findstring master,$(shell git rev-parse --abbrev-ref HEAD)),,$(error "!!! you are not on master branch, aborting"))
302 $(if $(findstring dirty,$(shell git describe --dirty --always)),$(error "!!! you have pending changes, aborting"))
303 $(if $(RELEASE_NAME),,$(error "!!! missing RELEASE_NAME, aborting"))
304 # Preparing a commit for release tagging, to be reverted after tagging.
305 @echo "# - Release Tag: $(VERSION)"
306 @echo "# - Release Name: $(RELEASE_NAME)"
307 # - Removing -Werror...
308 @find . \( -path "./Makefile.defs" -or -path "./client/Makefile" -or -path "./common_arm/Makefile.common" -or -path "./tools/hitag2crack/*/Makefile" \) -exec sed -i 's/ -Werror//' {} \;
309 @find . \( -path "./client/deps/*.cmake" -or -path "./client/CMakeLists.txt" \) -exec sed -i 's/ -Werror//' {} \;
310 # - Changing banner...
311 @sed -i "s/^#define BANNERMSG3 .*/#define BANNERMSG3 \"Release $(VERSION) - $(RELEASE_NAME)\"/" client/src/proxmark3.c
312 @echo -n "# ";grep "^#define BANNERMSG3" client/src/proxmark3.c
313 # - Committing temporarily...
314 @git commit -a -m "Release $(VERSION) - $(RELEASE_NAME)"
315 # - Tagging temporarily...
316 @git tag -a -m "Release $(VERSION) - $(RELEASE_NAME)" $(VERSION)
317 # - Changing default version information based on new tag
318 @$(SH) tools/mkversion.sh > common/default_version_pm3.c.tmp && $(MV) common/default_version_pm3.c.tmp common/default_version_pm3.c
319 # - Removing mkversion calls
320 @sed -i 's#^.*\.\./tools/mkversion.sh.*|| #\t$$(Q)#' client/Makefile bootrom/Makefile armsrc/Makefile
321 @sed -i '/COMMAND/s/sh .*|| //' client/CMakeLists.txt
322 # - Deleting tag...
323 @git tag -d $(VERSION)
324 # - Amending commit...
325 @git commit -a --amend -m "Release $(VERSION) - $(RELEASE_NAME)"
326 # - Tagging again...
327 @git tag -a -m "Release $(VERSION) - $(RELEASE_NAME)" $(VERSION)
328 # - Reverting tagged commit...
329 @git revert --no-edit HEAD
330 @echo "==================================================================="
331 @echo "Done! You can now execute 'git push && git push origin $(VERSION)'"
333 # Dummy target to test for GNU make availability
334 _test: