Makefile: If target name contains colon (:)

cross-posted from: https://lemmy.ml/post/3229278

Suppose I've got a simple #Makefile w/ a few URLs that I'd like to process as dynamic targets.

For example here is a not working snippet:

.DEFAULT_GOAL := all

#####
URLS  = https://foo.example.com
URLS += https://bar.example.com
URLS += https://www.example.org

#####
% :
	@echo the url is $(*)

#####
.PHONY : all
all : $(URLS)

It fails w/

*** target pattern contains no '%'

I believe that's b/c of the character : being part of URLS which confuses Make after expansion (order o

As a workaround, I've removed https:// from all URLs. For example this works:

URLS = foo.example.com
URLS += bar.example.com

I know Make generally doesn't play well w/ targets w/ space or colon in the name but I wonder if the above is the best I can do. What do you think?

31 points · 6 comments · view on lemmy.world

6 Comments

pnutzh4x0r@lemmy.ndlug.org · 8 pts · 3y (4 replies)

You can escape the :

URLS  = https\://foo.example.com
URLS += https\://bar.example.com
URLS += https\://www.example.org
bahmanm@lemmy.ml · 5 pts · 3y

Ah...this explains why it works: https://savannah.gnu.org/bugs/?712#comment16

It's a new feature \o/

#TIL

bahmanm@mastodon.social · 1 pts · 3y (2 replies)

@pnutzh4x0r @bahmanm@lemmy.ml I'm not at my desk now but I doubt it will work. Make has no notion of escaping as far as I know.

pnutzh4x0r@lemmy.ndlug.org · 1 pts · 3y (1 reply)

I just tried it with GNU make 4.3 and it worked.

bahmanm@lemmy.ml · 2 pts · 3y

Oh, it works 🎉 Thank you!

For posterity here's a complete example:

foo\:bar :
	@echo $(@)

and then

$ make foo:bar
foo:bar

Though, TBH, I don't understand how this works 🤦‍♂️ I need to look into Make docs.

jlsalvador@lemmy.ml · 2 pts · 3y

I didn't try yet: https://www.cmcrossroads.com/article/gnu-make-escaping-walk-wild-side

colon := :
$(colon) := :
url := https$(:)//something