Change Makefile to better track what to do
authorLukáš Jiřiště <jiriste@icpf.cas.cz>
Wed, 23 Oct 2024 09:13:40 +0000 (11:13 +0200)
committerLukáš Jiřiště <jiriste@icpf.cas.cz>
Wed, 23 Oct 2024 09:13:40 +0000 (11:13 +0200)
Normally the object files and executable are used for tracking but
arduino-cli does not generate any files inside the working directory.
The changes use dotfiles .compile and .upload to keep track of what
needs to be done.
In addition to the dotfiles compile and upload rules were added, that
force the action.

Makefile

index a71422612399e69c76311903e644327e51f6b1c7..b952ff968540850432d59ea140e398a897fc63b2 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,3 +1,4 @@
+RM := rm -rf
 
 MAINCMD := arduino-cli compile --upload --verify
 
@@ -19,9 +20,21 @@ NAME := Servomatic
 
 all : $(NAME)
 
-$(NAME) : $(SRCS)
-       $(MAINCMD) $<
-       touch $(NAME)
+$(NAME) : .upload
+
+.upload : .compile
+       $(MAKE) upload
+       touch .upload
+
+upload : .compile
+       arduino-cli upload --port $(PORT) --verify
+
+.compile : $(SRCS)
+       $(MAKE) compile
+       touch .compile
+
+compile : $(SRCS)
+       arduino-cli compile --fqbn $(FQBN) $<
 
 verbose : .verbose
 
@@ -34,7 +47,7 @@ re : fclean
 clean :
 
 fclean : clean
-       $(RM) $(NAME)
+       $(RM) .compile .upload
 
 .% :
        if [ ! -f $@ ]; then touch $@ && $(MAKE) re; fi