Makefile (case insensitive targets)

when using a makefile, I want the following to be possible:

make clean make Clean make CLean make CLEan make CLEAn make ... 

and everyone should do the same in my makefile.
(i.e. I don’t want the targets to be case sensitive)

Of course, I could write everything, possibly like this:

 .PHONY clean Clean CLean CLEan CLEAn ... clean Clean CLean CLEan CLEAn ...: $(DELETE_STUFF) 

but I think you can understand why this is undesirable.
I know that β€œmake” has a built-in macro called MAKECMDGOALS, which will be equal to the type that you type after you type make.

 for example, running 'make clean all backup' $(MAKECMDGOALS) = "clean all backup" 

I tried to do this at the top of my makefile:

 MAKECMDGOALS:= $(shell echo $(MAKECMDGOALS) | tr "[:upper:]" "[:lower:]") 

it changes the variable to all lowercase letters, but it will still only invoke the rule for the target.

I even tried to redefine it as follows:

 override MAKECMDGOALS:= $(shell echo $(MAKECMDGOALS) | tr "[:upper:]" "[:lower:]") 

in the hope that this will be done earlier, but will not be successful.

I was going to create such a goal:

 $(MAKECMDGOALS): MAKECMDGOALS:= $(shell echo $(MAKECMDGOALS) | tr "[:upper:]" "[:lower:]") #BUT I CAN'T CALL OTHER TARGETS FROM THE SHELL 

I know this is a stupid detail to make a fuss about, but of course there must be a right way?

+4
source share
2 answers

Raw but effective:

 %: $(MAKE) $(shell echo $@ | tr "[:upper:]" "[:lower:]") clean: delete_stuff 
+6
source

You can generate your goals, for example, using a shell (at least in GNU Make):

 SHELL := /bin/bash clean_insensitive := $(shell echo {C,c}{L,l}{E,e}{A,a}{N,n}) $(clean_insensitive) : rm *.o 

Another solution would be to write a wrapper that will contain string arguments and invoke make, accepting only string objects.

+5
source

Source: https://habr.com/ru/post/1379745/


All Articles