Re: Conditional broken line in recipe

Bahman Movaqar <[email protected]>
Newsgroups gmane.comp.gnu.make.general
Message-ID <[email protected]>
On Sun, 2023-09-03 at 01:00 +0200, Alejandro Colomar wrote:
> Hi!
> 
> Is something like this possible?
> 
> target:
>         foo \
> ifeq (...)
>         | bar \
> endif
>         | baz

I'm afraid not.  The way I approach similar situations is this pattern:


<code>

ifeq (...)

define target._conditional-piece
bar
endef

else

define target._conditional-piece
baz
endef

endif

###

target:
	foo \
	| $(target._conditional-piece)

</code>


The main advantage IMO is for debugging; ie when your run `make -pnr
target' the output contains only the version of `target._conditional-
piece` which you'd be interested in based on the condition.  Much in
the same vein as your pseudo-code.

Additionally, I find this easier to adapt than converting all to
.ONESHELL.  YMMV

--
Bahman
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.