Merge branch 'master' of github.com:RfidResearchGroup/proxmark3
[RRG-proxmark3.git] / Makefile
blob77b7b9741f10036039e570da3b9e5db9ae400fe0
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 "+ cliparser - Generate cliparser TODO"
173 @echo "+ check - Run offline tests. Set CHECKARGS to pass arguments to the test script"
174 @echo "+ .../check - Run offline tests against specific target. See above."
175 @echo "+ miscchecks - Detect various encoding issues in source code"
176 @echo
177 @echo "+ udev - Sets udev rules on *nix"
178 @echo "+ accessrights - Ensure user belongs to correct group on *nix"
179 @echo
180 @echo "Possible platforms: try \"make PLATFORM=\" for more info, default is PM3RDV4"
181 @echo "To activate verbose mode, use make V=1"
183 client: client/all
185 bootrom: bootrom/all
187 # aliases fullimage = armsrc
189 fullimage: armsrc/all
191 fullimage/all: armsrc/all
193 fullimage/clean: armsrc/clean
195 fullimage/install: armsrc/install
197 fullimage/uninstall: armsrc/uninstall
199 recovery: recovery/all
201 mfkey: mfkey/all
203 nonce2key: nonce2key/all
205 mf_nonce_brute: mf_nonce_brute/all
207 fpga_compress: fpga_compress/all
209 hitag2crack: hitag2crack/all
211 newtarbin:
212 $(RM) proxmark3-$(platform)-bin.tar proxmark3-$(platform)-bin.tar.gz
213 @touch proxmark3-$(platform)-bin.tar
215 tarbin: newtarbin client/tarbin armsrc/tarbin bootrom/tarbin
216 $(info GEN proxmark3-$(platform)-bin.tar)
217 $(Q)$(GZIP) proxmark3-$(platform)-bin.tar
219 # detect if there were changes in the platform definitions, requiring a clean
220 cleanifplatformchanged:
221 ifeq ($(PLATFORM_CHANGED),true)
222 $(info [!] Platform definitions changed, cleaning bootrom/armsrc/recovery first...)
223 $(Q)$(MAKE) --no-print-directory -C bootrom clean
224 $(Q)$(MAKE) --no-print-directory -C armsrc clean
225 $(Q)$(MAKE) --no-print-directory -C recovery clean
226 $(Q)echo CACHED_PLATFORM=$(PLATFORM) > .Makefile.options.cache
227 $(Q)echo CACHED_PLATFORM_EXTRAS=$(PLATFORM_EXTRAS) >> .Makefile.options.cache
228 $(Q)echo CACHED_PLATFORM_DEFS=$(PLATFORM_DEFS) >> .Makefile.options.cache
229 endif
231 # configure system to ignore PM3 device as a modem (ModemManager blacklist, effective *only* if ModemManager is not using _strict_ policy)
232 # Read doc/md/ModemManager-Must-Be-Discarded.md for more info
233 udev:
234 sudo cp -rf driver/77-pm3-usb-device-blacklist.rules /etc/udev/rules.d/77-pm3-usb-device-blacklist.rules
235 sudo udevadm control --reload-rules
237 # configure system to add user to the dialout group
238 # you need to logout, relogin to get this access right correct.
239 # Finally, you might need to run the proxmark3 client under SUDO on some systems
240 accessrights:
241 ifneq ($(wildcard /etc/arch-release),) #If user is running ArchLinux
242 sudo usermod -aG uucp $(USER) #Use specific command and group
243 sudo usermod -aG bluetooth $(USER) #Use specific command and group
244 else
245 sudo adduser $(USER) dialout
246 sudo adduser $(USER) bluetooth
247 endif
249 # easy printing of MAKE VARIABLES
250 print-%: ; @echo $* = $($*)
252 style:
253 # Make sure astyle is installed
254 @which astyle >/dev/null || ( echo "Please install 'astyle' package first" ; exit 1 )
255 # Remove spaces & tabs at EOL, add LF at EOF if needed on *.c, *.h, *.cpp. *.lua, *.py, *.pl, Makefile, *.v
256 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" \) \) \
257 -exec perl -pi -e 's/[ \t]+$$//' {} \; \
258 -exec sh -c "tail -c1 {} | xxd -p | tail -1 | grep -q -v 0a$$" \; \
259 -exec sh -c "echo >> {}" \;
260 # Apply astyle on *.c, *.h, *.cpp
261 find . \( -not -path "./cov-int/*" -and \( -name "*.[ch]" -or \( -name "*.cpp" -and -not -name "*.moc.cpp" \) \) \) -exec astyle --formatted --mode=c --suffix=none \
262 --indent=spaces=4 --indent-switches \
263 --keep-one-line-blocks --max-instatement-indent=60 \
264 --style=google --pad-oper --unpad-paren --pad-header \
265 --align-pointer=name {} \;
266 # Update commands.md
267 [ -x client/proxmark3 ] && client/proxmark3 -m > doc/commands.md
269 # Detecting weird codepages and tabs.
270 ifeq ($(platform),Darwin)
271 miscchecks: TABSCMD=egrep -l '\t' {}
272 else
273 miscchecks: TABSCMD=grep -lP '\t' {}
274 endif
275 ifneq (,$(EDIT))
276 miscchecks: TABSCMD+= && vi {} -c ':set tabstop=4' -c ':set et|retab' -c ':wq'
277 endif
278 miscchecks:
279 # Make sure recode is installed
280 @which recode >/dev/null || ( echo "Please install 'recode' package first" ; exit 1 )
281 @echo "Files with suspicious chars:"
282 @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" \) \) \
283 -exec sh -c "cat {} |recode utf8.. >/dev/null || echo {}" \;
284 ifneq (,$(EDIT))
285 @echo "Files with tabs: (EDIT enabled, files will be rewritten!)"
286 else
287 @echo "Files with tabs: (rerun with EDIT=1 if you want to convert them with vim)"
288 endif
289 # to remove tabs within lines, one can try with: vi $file -c ':set tabstop=4' -c ':set et|retab' -c ':wq'
290 @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" \) \) \
291 -exec sh -c "$(TABSCMD)" \;
292 # @echo "Files with printf \\\\t:"
293 # @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" \) \
294 # -exec grep -lP '\\t' {} \;
296 release: VERSION="v4.$(shell git log --oneline master | wc -l)"
297 release:
298 $(if $(findstring master,$(shell git rev-parse --abbrev-ref HEAD)),,$(error "!!! you are not on master branch, aborting"))
299 $(if $(findstring dirty,$(shell git describe --dirty --always)),$(error "!!! you have pending changes, aborting"))
300 $(if $(RELEASE_NAME),,$(error "!!! missing RELEASE_NAME, aborting"))
301 # Preparing a commit for release tagging, to be reverted after tagging.
302 @echo "# - Release Tag: $(VERSION)"
303 @echo "# - Release Name: $(RELEASE_NAME)"
304 # - Removing -Werror...
305 @find . \( -path "./Makefile.defs" -or -path "./client/Makefile" -or -path "./common_arm/Makefile.common" -or -path "./tools/hitag2crack/*/Makefile" \) -exec sed -i 's/ -Werror//' {} \;
306 @find . \( -path "./client/deps/*.cmake" -or -path "./client/CMakeLists.txt" \) -exec sed -i 's/ -Werror//' {} \;
307 # - Changing banner...
308 @sed -i "s/^#define BANNERMSG3 .*/#define BANNERMSG3 \"Release $(VERSION) - $(RELEASE_NAME)\"/" client/src/proxmark3.c
309 @echo -n "# ";grep "^#define BANNERMSG3" client/src/proxmark3.c
310 # - Committing temporarily...
311 @git commit -a -m "Release $(VERSION) - $(RELEASE_NAME)"
312 # - Tagging temporarily...
313 @git tag -a -m "Release $(VERSION) - $(RELEASE_NAME)" $(VERSION)
314 # - Changing default version information based on new tag
315 @$(SH) tools/mkversion.sh > common/default_version.c.tmp && $(MV) common/default_version.c.tmp common/default_version.c
316 # - Removing mkversion calls
317 @sed -i 's#^.*\.\./tools/mkversion.sh.*|| #\t$$(Q)#' client/Makefile bootrom/Makefile armsrc/Makefile
318 @sed -i '/COMMAND/s/sh .*|| //' client/CMakeLists.txt
319 # - Deleting tag...
320 @git tag -d $(VERSION)
321 # - Amending commit...
322 @git commit -a --amend -m "Release $(VERSION) - $(RELEASE_NAME)"
323 # - Tagging again...
324 @git tag -a -m "Release $(VERSION) - $(RELEASE_NAME)" $(VERSION)
325 # - Reverting tagged commit...
326 @git revert --no-edit HEAD
327 @echo "==================================================================="
328 @echo "Done! You can now execute 'git push && git push origin $(VERSION)'"
330 # Dummy target to test for GNU make availability
331 _test: