bug-make
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Colons in targets (and prerequisites)


From: Alejandro Colomar
Subject: Colons in targets (and prerequisites)
Date: Wed, 26 Apr 2023 01:02:14 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.9.1

Hi!

I found a lot of manual pages have '::' in them, and would like to be
able to work with them with Makefiles.  I've been testing a little bit,
and I think I got some consistent mental model of how GNU Make handles
colons in pathnames.

I'd like you to confirm if this is solid, and I can rely on Make not
having regressions in this regard in the future, or if it's completely
unsupported and likely to break.

Also, I find some minor inconveniences that I don't know if they could be
solved, or if that would require changing important logic.

I posted an answer in StackOverflow about it:
<https://stackoverflow.com/a/76096683/6872717>


$ tree
.
├── Makefile
├── dst
│   ├── a
│   ├── b
│   └── c
└── src
    └── :


$ cat Makefile
SRC := $(shell find src -type f | sed 's,:,\\:,')
DST_a := $(patsubst src/%,dst/a/%,$(SRC))
DST_b := $(patsubst src/%,dst/b/%,$(SRC))
DST_c := $(patsubst src/%,dst/c/%,$(SRC))

.PHONY: a
a: $(DST_a);

$(DST_a): $(SRC)
    touch $@

.SECONDEXPANSION:

.PHONY: b
b: $(DST_b);

$(DST_b): $(SRC)
    touch $@

.PHONY: c
c: $(DST_c);

$(DST_c): $$(SRC)
    touch $@



And then I can run the targets:

$ make a
touch dst/a/:

$ make b
touch dst/b/:

$ make c
make: *** No rule to make target 'src/\:', needed by 'dst/c/:'.  Stop.


So, it seems we only need to transform ':' into '\:' in the variables
(the sed(1) call is for that).  Then, it's all fine, with one caveat:

Okay, the third one didn't work, but I can live with it if I just need to
avoid second-expanding variables with escaped colons.  That was the minor
inconvenience that would be nice to fix, but not really disturbing.


$ tree
.
├── Makefile
├── dst
│   ├── a
│   │   └── :
│   ├── b
│   │   └── :
│   └── c
└── src
    └── :


Thanks,
Alex

-- 
<http://www.alejandro-colomar.es/>
GPG key fingerprint: A9348594CE31283A826FBDD8D57633D441E25BB5

Attachment: OpenPGP_signature
Description: OpenPGP digital signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]