Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
496 views
in Technique[技术] by (71.8m points)

makefile - How can you make a % wildcard make rule phony?

I have the following wildcard "programming" make rule that uploads a binary to a device. This obviously does not produce a real file, so should be marked phony. However, how do you mark a % percent wildcard rule phony?

%-tangnano-prog: %-tangnano.fs
    openFPGALoader -b tangnano $^

.PHONY: %-tangnano-prog clean all

The phony rule does not give any error whatever you put there, so hard to tell if it worked. But I believe it did not:

$ touch blinky-tangnano-prog
$ make blinky-tangnano-prog
make: 'blinky-tangnano-prog' is up to date.

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Thee are basically two possibilities:

  1. You know in advance what %-tangnano-prog targets you can encounter. Just assign all their prefixes to a make variable, use make functions to compute the full target names and declare them as phony:

     P := blinky foo bar
     T := $(addsuffix -tangnano-prog,$(P))
    
     .PHONY: tangnano-prog $(T)
    
     tangnano-prog: $(T)
    
     %-tangnano-prog: %-tangnano.fs
         openFPGALoader -b tangnano $^
    
  2. You do not know in advance what targets you can encounter. Use the same Makefile but pass the list of target prefixes to build on the command line:

     $ make tangnano-prog P="blinky foo bar"
    

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...