I mention avoiding targets because most developers don't notice, as I didn't, that the upper level makefile is included at the end so any targets should follow that inclusion. Given how little many devs no about Makefiles that little tidbit becomes difficult to debug.



Specifically any target added before the inclusion becomes the default target, unless the target starts with a '.'.



On 12/31/2023 10:13 PM, yfliu2008 wrote:
Bill,


Sorry that I just read your emails and tried what you told.


By using @echo directly, I saw "rule fired" printed out, just my other comamnd 
doesn't run yet, here is the part of my board level Makefile where I appended the 
double-colon rule:



...
include $(TOPDIR)/boards/Board.mk


.PHONY: clean


clean::
      @echo "rule fired" >&2
      $(call DELFILE romfs_boot.c)


It seems that the $(call DELFILE ...) command  doesn't run, but later I noticed that 
I missed a "," after DELFILE so after fixing that, it seems working now at my side.



Here my "clean::" target lives after the Board.mk inclusion, is this right? Do 
you still suggest not using any targets in the board level Makefile?



BTW, I am using config "canmv230/knsh" here. The upstream Makefile doesn't have the double-colon 
target yet, thus it won't clean the generated "romfs_boot.c" even if one run clean., but this isn't 
a big issue as I found most time rebuilt kernel can load user land apps in the ROMFS defined by an existing 
"romfs_boot.c".



Regards,
yf






Original
From:"Bill Rees"< redskyo...@icloud.com.INVALID &gt;;

Date:2024/1/1 10:49

To:"dev"< dev@nuttx.apache.org &gt;;

Subject:Re: Makefile vs Make.defs



Well I&nbsp; screwed up on this. The makefile actually runs before including
Board.mk which contains the real targets so the default target becomes
the one in the src/Makefile.

Fundamentally this Makefile should not contain any targets.

On 12/31/2023 6:46 PM, Bill Rees wrote:
&gt;
&gt; &nbsp;&nbsp;&nbsp; Out of curiosity I followed your example and added a 
clean:: to a
&gt; src/Makefile. The target fired.
&gt;
&gt; :: git diff
&gt; diff --git a/boards/arm/efm32/efm32-g8xx-stk/src/Makefile
&gt; b/boards/arm/efm32/efm32-g8xx-stk/src/Makefile
&gt; index dc8bbbb938..79998ed009 100644
&gt; --- a/boards/arm/efm32/efm32-g8xx-stk/src/Makefile
&gt; +++ b/boards/arm/efm32/efm32-g8xx-stk/src/Makefile
&gt; @@ -28,4 +28,7 @@ else
&gt; &nbsp;CSRCS += efm32_userleds.c
&gt; &nbsp;endif
&gt;
&gt; +clean::
&gt; +&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; @echo "=====" &gt;&amp;2
&gt; +
&gt; &nbsp;include $(TOPDIR)/boards/Board.mk
&gt;
&gt; How does your setup differ from this? I had already built nuttx once.
&gt;
&gt; On 12/31/2023 12:33 PM, Bill Rees wrote:
&gt;&gt;
&gt;&gt; &nbsp;&nbsp;&nbsp; The command to your rule, clean:: does not need a 
shell process
&gt;&gt; wrapper.
&gt;&gt;
&gt;&gt; &nbsp;&nbsp;&nbsp; You don't need the $() to execute shell commands in 
the recipe
&gt;&gt; since make does that for you.
&gt;&gt;
&gt;&gt; &nbsp;&nbsp;&nbsp; Change the echo to simply: echo "board level clean" 
&gt;&amp;2
&gt;&gt;
&gt;&gt; &nbsp;&nbsp;&nbsp; The '&gt;&amp;2' directs the output of echo to the 
stderr file
&gt;&gt; descriptor for your process and should outwit most attempts to
&gt;&gt; capture output any recipe uses before hand. Running make can produce
&gt;&gt; so much output that many times its run silent which means your output
&gt;&gt; maybe suppressed.
&gt;&gt;
&gt;&gt; &nbsp;&nbsp;&nbsp; What board are you working on?
&gt;&gt;
&gt;&gt; On 12/30/2023 8:03 PM, yfliu2008 wrote:
&gt;&gt;&gt; Bill,
&gt;&gt;&gt;
&gt;&gt;&gt;
&gt;&gt;&gt; Thank you.
&gt;&gt;&gt;
&gt;&gt;&gt;
&gt;&gt;&gt; It seems that there is a "clean::" in "boards/Board.mk" which is
&gt;&gt;&gt; included by my board level Makefile.
&gt;&gt;&gt; The double-colon target thing sounds nice, so I added one to my
&gt;&gt;&gt; board level Makefile like below:
&gt;&gt;&gt;
&gt;&gt;&gt;
&gt;&gt;&gt; clean::
&gt;&gt;&gt;       $(echo "board level clean")
&gt;&gt;&gt;
&gt;&gt;&gt;
&gt;&gt;&gt; Then when I tried "make clean" under $(TOPDIR), there is no more
&gt;&gt;&gt; errors but the rule I added didn't fire.
&gt;&gt;&gt;
&gt;&gt;&gt;
&gt;&gt;&gt;
&gt;&gt;&gt;
&gt;&gt;&gt;
&gt;&gt;&gt;
&gt;&gt;&gt; I guess something else is still missing. The top level makefile
&gt;&gt;&gt; doesn't trigger my board level double-colon target.
&gt;&gt;&gt;
&gt;&gt;&gt;
&gt;&gt;&gt;
&gt;&gt;&gt; Regards,
&gt;&gt;&gt; yf
&gt;&gt;&gt;
&gt;&gt;&gt;
&gt;&gt;&gt;
&gt;&gt;&gt;
&gt;&gt;&gt; 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 Original
&gt;&gt;&gt;
&gt;&gt;&gt; From:"Bill Rees"< redskyo...@icloud.com.INVALID &gt;;
&gt;&gt;&gt;
&gt;&gt;&gt; Date:2023/12/31 9:51
&gt;&gt;&gt;
&gt;&gt;&gt; To:"dev"< dev@nuttx.apache.org &gt;;
&gt;&gt;&gt;
&gt;&gt;&gt; Subject:Re: Makefile vs Make.defs
&gt;&gt;&gt;
&gt;&gt;&gt;
&gt;&gt;&gt;
&gt;&gt;&gt; You're welcome.
&gt;&gt;&gt;
&gt;&gt;&gt; The error message is pointing out that you have two targets for 
clean.
&gt;&gt;&gt; One is clean: and the other is clean::
&gt;&gt;&gt;
&gt;&gt;&gt; You may be getting a clean target from an included makefile such 
as a
&gt;&gt;&gt; Make.def which may be in a directory up the path. Try issuing a 
grep
&gt;&gt;&gt; for
&gt;&gt;&gt; clean: to see what files contain it. Something like "grep -r 
clean.*:"
&gt;&gt;&gt; You may have to move a dir or two up the path.
&gt;&gt;&gt;
&gt;&gt;&gt; You may wish to try changing the syntax of your target to use the 
colon
&gt;&gt;&gt; syntax of the other. E.g. :: -- : or vice versa. Make allows 
multiple
&gt;&gt;&gt; instances of a target in some circumstances.
&gt;&gt;&gt;
&gt;&gt;&gt; Another way to get around this is to add the target as another 
name and
&gt;&gt;&gt; perform what you need to do. E.g. instead of clean use myclean:
&gt;&gt;&gt;
&gt;&gt;&gt; Please get back with your results.
&gt;&gt;&gt;
&gt;&gt;&gt; Bill
&gt;&gt;&gt;
&gt;&gt;&gt; On 12/30/2023 4:25 PM, yfliu2008 wrote:
&gt;&gt;&gt; &gt; Bill,
&gt;&gt;&gt; &gt;
&gt;&gt;&gt; &gt;
&gt;&gt;&gt; &gt; Thanks for the information.
&gt;&gt;&gt; &gt;
&gt;&gt;&gt; &gt;
&gt;&gt;&gt; &gt; So far I have been using make command at the $(TOPDIR) and the
&gt;&gt;&gt; contents in the board source&nbsp; folder (i.e. "boards/&gt;
&gt;&gt;&gt; &gt;
&gt;&gt;&gt; &gt; For example, I tried to add a "clean:" target in the Makefile
&gt;&gt;&gt; at board source folder, but got errors like:
&gt;&gt;&gt; &gt;
&gt;&gt;&gt; &gt;
&gt;&gt;&gt; &gt; yf@r7:uttx/nuttx$ make cleanMakefile:35: *** target file
&gt;&gt;&gt; 'clean' has both : and :: entries. &nbsp;Stop.
&gt;&gt;&gt; &gt; make[1]: *** [Makefile:230: clean] Error 2
&gt;&gt;&gt; &gt; make: *** [tools/Unix.mk:757: arch/risc-v/src_clean] Error 2
&gt;&gt;&gt; &gt;
&gt;&gt;&gt; &gt;
&gt;&gt;&gt; &gt;
&gt;&gt;&gt; &gt;
&gt;&gt;&gt; &gt;
&gt;&gt;&gt; &gt;
&gt;&gt;&gt; &gt;
&gt;&gt;&gt; &gt;
&gt;&gt;&gt; &gt;
&gt;&gt;&gt; &gt; I still lack understanding for the overall Makefile design, so
&gt;&gt;&gt; pointers to it are highly welcomed.
&gt;&gt;&gt; &gt;
&gt;&gt;&gt; &gt;
&gt;&gt;&gt; &gt; Regards,
&gt;&gt;&gt; &gt; yf
&gt;&gt;&gt; &gt;
&gt;&gt;&gt; &gt;
&gt;&gt;&gt; &gt;
&gt;&gt;&gt; &gt;
&gt;&gt;&gt; &gt; Original
&gt;&gt;&gt; &gt;
&gt;&gt;&gt; &gt;
&gt;&gt;&gt; &gt;
&gt;&gt;&gt; &gt; From:"Bill Rees"< redskyo...@icloud.com.INVALID &gt;;
&gt;&gt;&gt; &gt;
&gt;&gt;&gt; &gt; Date:2023/12/17 16:32
&gt;&gt;&gt; &gt;
&gt;&gt;&gt; &gt; To:"dev"< dev@nuttx.apache.org &gt;;
&gt;&gt;&gt; &gt;
&gt;&gt;&gt; &gt; Subject:Re: Makefile vs Make.defs
&gt;&gt;&gt; &gt;
&gt;&gt;&gt; &gt;
&gt;&gt;&gt; &gt;
&gt;&gt;&gt; &gt; Running make where Makefile exists runs that Makefile.
&gt;&gt;&gt; &gt;
&gt;&gt;&gt; &gt; Running make where you have a Make.defs won't do anything.
&gt;&gt;&gt; &gt;
&gt;&gt;&gt; &gt;
&gt;&gt;&gt; &gt; On 12/16/2023 8:55 PM, yfliu2008 wrote:
&gt;&gt;&gt; &gt; &gt; Hi,
&gt;&gt;&gt; &gt; &gt;
&gt;&gt;&gt; &gt; &gt;
&gt;&gt;&gt; &gt; &gt;
&gt;&gt;&gt; &gt; &gt;
&gt;&gt;&gt; &gt; &gt; It seems that some board source folder uses Makefile and
&gt;&gt;&gt; some uses Make.defs:
&gt;&gt;&gt; &gt; &gt;
&gt;&gt;&gt; &gt; &gt;
&gt;&gt;&gt; &gt; &gt;
&gt;&gt;&gt; &gt; &gt; boards/risc-v/hpm6750/hpm6750evk2/src/Makefile
&gt;&gt;&gt; &gt; &gt;
&gt;&gt;&gt; &gt; &gt;
&gt;&gt;&gt; &gt; &gt; boards/risc-v/qemu-rv/rv-virt/src/Makefile
&gt;&gt;&gt; &gt; &gt; boards/risc-v/mpfs/icicle/src/Make.defs
&gt;&gt;&gt; &gt; &gt;
&gt;&gt;&gt; &gt; &gt; boards/risc-v/esp32c6/esp32c6-devkit/src/Make.defs
&gt;&gt;&gt; &gt; &gt;
&gt;&gt;&gt; &gt; &gt; I am wondering what are the differences?
&gt;&gt;&gt; &gt; &gt;
&gt;&gt;&gt; &gt; &gt;
&gt;&gt;&gt; &gt; &gt;
&gt;&gt;&gt; &gt; &gt; Regards,
&gt;&gt;&gt; &gt; &gt; yf
&gt;&gt;
&gt;

Reply via email to