[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Conditional broken line in recipe
From: |
Alejandro Colomar |
Subject: |
Re: Conditional broken line in recipe |
Date: |
Sun, 3 Sep 2023 14:57:49 +0200 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.13.1 |
On 2023-09-03 14:38, Paul Smith wrote:
> On Sun, 2023-09-03 at 13:14 +0200, Alejandro Colomar wrote:
>>> You need to put the ifdef outside the recipe:
>>
>> That would hurt readability a little bit.
>
> IMO a make preprocessor statement inside a recipe is a code smell and I
> would find the "outside the recipe" version simpler to understand, but
> of course this is a personal taste thing.
>
The rule is something like this:
target: source
sed 's/%date%/$(shell date)/' <$< |
ifneq ($(VERSION),)
sed 's/%version%/$(VERSION)/' |
endif
cp -T /dev/stdin $@
I could first copy and then edit in-place, to avoid needing .ONESHELL:
target: source
cp -T $< $@
sed -i 's/%date%/$(shell date)/' $@
ifneq ($(VERSION),)
sed -i 's/%version%/$(VERSION)/' $@
endif
But I don't like this as much; it's probably quite inefficient.
Then I could split this rule into intermediate targets, and make the
dependencies variable depending on $(VERSION). Something like
ifeq ($(VERSION),)
target: target-version
target-version: target-date
else
target: target-date
endif
target-date: source
sed 's/%date%/$(shell date)/' <$< >$@
target-version:
sed 's/%version%/$(VERSION)/' <$< >$@
target:
cp -T $< $@
It's more work, but would keep it at 1 canned recipe per rule, which
should be the normal thing. I might do this. It felt a bit overkill,
but I don't know.
Cheers,
Alex
--
<http://www.alejandro-colomar.es/>
GPG key fingerprint: A9348594CE31283A826FBDD8D57633D441E25BB5
OpenPGP_signature
Description: OpenPGP digital signature
Re: Conditional broken line in recipe, Paul Smith, 2023/09/02
Re: Conditional broken line in recipe, Bahman Movaqar, 2023/09/03