Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 11 Nov 2022 17:43:32 +0300
From:      Gleb Popov <arrowd@freebsd.org>
To:        =?UTF-8?Q?T=C4=B3l_Coosemans?= <tijl@freebsd.org>
Cc:        FreeBSD ports list <freebsd-ports@freebsd.org>
Subject:   Re: Temporary variables in make .for loops
Message-ID:  <CALH631k_5KAYrMgfgRxybooWNGFaur3N%2Bxm=ShWZaHoF3arrGQ@mail.gmail.com>
In-Reply-To: <20221111145635.045da586@FreeBSD.org>
References:  <CALH631=xg5-cRPwZs-DXBW0LqycN4%2BrP8w5ziQ-ncqdwq%2BPPMw@mail.gmail.com> <20221111145635.045da586@FreeBSD.org>

next in thread | previous in thread | raw e-mail | index | archive | help
On Fri, Nov 11, 2022 at 4:56 PM T=C4=B3l Coosemans <tijl@freebsd.org> wrote=
:
>
> On Fri, 11 Nov 2022 15:41:51 +0300 Gleb Popov <arrowd@freebsd.org> wrote:
> > Hello fellow porters.
> >
> > My variable modifiers are growing and become too incomprehensible, so
> > here is the question I wanted to ask long ago:
> >
> > How do I make and use a temporary variable in the .for loop?
> >
> > This is what I have in Mk/Uses/cabal.mk:
> >
> > .  for package in ${_use_cabal}
> > _PKG_GROUP=3D        ${package:C/[\.-]//g}
> >
> > MASTER_SITES+=3D    https://hackage.haskell.org/package/:${package:C/[\=
.-]//g}
> > .  endfor
> >
> > I'd like to write ${_PKG_GROUP} instead of repeating that regexp
> > incantation, but due to specifics of .for operation it doesn't work.
> > Using :=3D with _PKG_GROUP also doesn't fix the problem.
> >
> > Now I need to add another regexp substitution to every expression
> > inside this loop and it'll become even less readable than before.
> >
> > Is there a clean solution to this problem?
>
> You could use a nested .for loop:
>
> .  for package in ${_use_cabal}
> .    for pkg_group pkg_norev rev in \
>         ${package:C/[.-]//g} ${packa...} ${packa...}
>
> You can drop the backslash by the way.

That's a really neat trick, thanks!



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CALH631k_5KAYrMgfgRxybooWNGFaur3N%2Bxm=ShWZaHoF3arrGQ>