There have been multiple accounts created with the sole purpose of posting advertisement posts or replies containing unsolicited advertising.

Accounts which solely post advertisements, or persistently post them may be terminated.

Makefile: If target name contains colon (:)

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

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

For example here is a not working snippet:


<span style="color:#323232;">.DEFAULT_GOAL := all
</span><span style="color:#323232;">
</span><span style="color:#323232;">#####
</span><span style="color:#323232;">URLS  = https://foo.example.com
</span><span style="color:#323232;">URLS += https://bar.example.com
</span><span style="color:#323232;">URLS += https://www.example.org
</span><span style="color:#323232;">
</span><span style="color:#323232;">#####
</span><span style="color:#323232;">% :
</span><span style="color:#323232;">	@echo the url is $(*)
</span><span style="color:#323232;">
</span><span style="color:#323232;">#####
</span><span style="color:#323232;">.PHONY : all
</span><span style="color:#323232;">all : $(URLS)
</span>

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:


<span style="color:#323232;">URLS = foo.example.com
</span><span style="color:#323232;">URLS += bar.example.com
</span>

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?

jlsalvador ,

I didn’t try yet: cmcrossroads.com/…/gnu-make-escaping-walk-wild-si…


<span style="color:#323232;">colon := :
</span><span style="color:#323232;">$(colon) := :
</span><span style="color:#323232;">url := https$(:)//something
</span>
pnutzh4x0r ,
@pnutzh4x0r@lemmy.ndlug.org avatar

You can escape the :


<span style="color:#323232;">URLS  = https://foo.example.com
</span><span style="color:#323232;">URLS += https://bar.example.com
</span><span style="color:#323232;">URLS += https://www.example.org
</span>
bahmanm ,
@bahmanm@mastodon.social avatar

@pnutzh4x0r @bahmanm 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 ,
@pnutzh4x0r@lemmy.ndlug.org avatar

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

bahmanm OP ,
@bahmanm@lemmy.ml avatar

Oh, it works 🎉 Thank you!

For posterity here’s a complete example:


<span style="color:#323232;">foo:bar :
</span><span style="color:#323232;">	@echo $(@)
</span>

and then


<span style="color:#323232;">$ make foo:bar
</span><span style="color:#323232;">foo:bar
</span>

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

bahmanm OP ,
@bahmanm@lemmy.ml avatar

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

It’s a new feature \o/

  • All
  • Subscribed
  • Moderated
  • Favorites
  • [email protected]
  • random
  • lifeLocal
  • goranko
  • All magazines