From 355319e36aab6360d67f29a7a446c00e3b054e66 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Sat, 1 Jun 2019 01:37:02 +0200 Subject: [PATCH] Automate make clean when platform definitions are changed --- .gitignore | 2 ++ Makefile | 21 +++++++++++++++++---- armsrc/Makefile | 6 ++++++ common/Makefile.hal | 9 +++++++++ 4 files changed, 34 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index 32f879cc7..bad050e8f 100644 --- a/.gitignore +++ b/.gitignore @@ -24,6 +24,8 @@ version.c # new build file for add-ons. Makefile.platform +# Cache for detecting platform def changes +.Makefile.options.cache !client/hardnested/*.bin !client/hardnested/tables/*.z diff --git a/Makefile b/Makefile index 7dbdd9453..1b27be069 100644 --- a/Makefile +++ b/Makefile @@ -25,6 +25,7 @@ endif ifeq ($(PLATFORM),) -include Makefile.platform + -include .Makefile.options.cache ifeq ($(PLATFORM),) PLATFORM=PM3RDV4 else @@ -54,17 +55,17 @@ mfkey/%: FORCE $(MAKE) -C tools/mfkey $(patsubst mfkey/%,%,$@) nonce2key/%: FORCE $(MAKE) -C tools/nonce2key $(patsubst nonce2key/%,%,$@) -bootrom/%: FORCE +bootrom/%: FORCE cleanifplatformchanged $(MAKE) -C bootrom $(patsubst bootrom/%,%,$@) -armsrc/%: FORCE +armsrc/%: FORCE cleanifplatformchanged $(MAKE) -C armsrc $(patsubst armsrc/%,%,$@) client/%: FORCE $(MAKE) -C client $(patsubst client/%,%,$@) -recovery/%: FORCE bootrom/% armsrc/% +recovery/%: FORCE cleanifplatformchanged bootrom/% armsrc/% $(MAKE) -C recovery $(patsubst recovery/%,%,$@) FORCE: # Dummy target to force remake in the subdirectories, even if files exist (this Makefile doesn't know about the prerequisites) -.PHONY: all clean help _test bootrom flash-bootrom os flash-os flash-all recovery client mfkey nounce2key style checks FORCE udev accessrights +.PHONY: all clean help _test bootrom flash-bootrom os flash-os flash-all recovery client mfkey nounce2key style checks FORCE udev accessrights cleanifplatformchanged help: @echo "Multi-OS Makefile" @@ -117,6 +118,18 @@ newtarbin: tarbin: newtarbin client/tarbin armsrc/tarbin bootrom/tarbin $(GZIP) proxmark3-$(platform)-bin.tar +# detect if there were changes in the platform definitions, requiring a clean +cleanifplatformchanged: +ifeq ($(PLATFORM_CHANGED), true) + echo "Platform definitions changed, cleaning bootrom/armsrc/recovery first..." + $(MAKE) -C bootrom clean + $(MAKE) -C armsrc clean + $(MAKE) -C recovery clean + @echo CACHED_PLATFORM=$(PLATFORM) > .Makefile.options.cache + @echo CACHED_PLATFORM_EXTRAS=$(PLATFORM_EXTRAS) >> .Makefile.options.cache + @echo CACHED_PLATFORM_DEFS=$(PLATFORM_DEFS) >> .Makefile.options.cache +endif + # configure system to ignore PM3 device as a modem (ModemManager blacklist, effective *only* if ModemManager is not using _strict_ policy) # Read doc/md/ModemManager-Must-Be-Discarded.md for more info udev: diff --git a/armsrc/Makefile b/armsrc/Makefile index a364bd187..e7788776a 100644 --- a/armsrc/Makefile +++ b/armsrc/Makefile @@ -11,6 +11,7 @@ APP_INCLUDES = apps.h # This Makefile might have been called directly, not via the root Makefile, so: ifeq ($(PLTNAME),) -include ../Makefile.platform + -include ../.Makefile.options.cache ifeq ($(PLATFORM),) PLATFORM=PM3RDV4 else @@ -30,6 +31,11 @@ ifeq ($(PLTNAME),) $(info Included options: $(PLATFORM_DEFS_INFO)) $(info Standalone mode: $(PLATFORM_DEFS_INFO_STANDALONE)) $(info ===================================================================) + +# detect if there were changes in the platform definitions, requiring a clean +ifeq ($(PLATFORM_CHANGED), true) + $(error platform definitions have been changed, please "make clean" at the root of the project) +endif endif #remove one of the following defines and comment out the relevant line diff --git a/common/Makefile.hal b/common/Makefile.hal index 9b687b7f4..98ad81da0 100644 --- a/common/Makefile.hal +++ b/common/Makefile.hal @@ -163,3 +163,12 @@ export MCU export PLATFORM_DEFS export PLATFORM_DEFS_INFO export PLATFORM_DEFS_INFO_STANDALONE + +PLATFORM_CHANGED=false +ifneq ($(PLATFORM), $(CACHED_PLATFORM)) + PLATFORM_CHANGED=true +else ifneq ($(PLATFORM_EXTRAS), $(CACHED_PLATFORM_EXTRAS)) + PLATFORM_CHANGED=true +else ifneq ($(PLATFORM_DEFS), $(CACHED_PLATFORM_DEFS)) + PLATFORM_CHANGED=true +endif