Variables in GNU Make: Simple and Recursive
www.bahmanm.com
external-link
There are two major flavours of variables in GNU Make: "simple" and "recursive".

cross-posted from: https://lemmy.ml/post/4908824

There are two major flavours of variables in GNU Make: ā€œsimpleā€ and ā€œrecursiveā€.

While simple variables are quite simple and easy to understand, they can be limiting at times. On the other hand, recursive variables are powerful yet tricky.

ā€¦

There is exactly one rule to recall when using recursive variablesā€¦

šŸ§  The value of a recursive variable is computed every time it is expanded.

JoYo
link
fedilink
0ā€¢1Y

itā€™s that illegal?

bahmanm
creator
link
fedilink
1ā€¢1Y

Uh, Iā€™m not sure I understand what you mean.

JoYo
link
fedilink
0ā€¢1Y

RMS notoriously fought against variables in make

bahmanm
creator
link
fedilink
2ā€¢1Y

I think I understand where RMS was coming from RE ā€œrecursive variablesā€. As I wrote in my blog:

Recursive variables are quite powerful as they introduce a pinch of imperative programming into the otherwise totally declarative nature of a Makefile.

They extend the capabilities of Make quite substantially. But like any other powerful tool, one needs to use them sparsely and responsibly or end up w/ a complex and hard to debug Makefile.

In my experience, most of the times I can avoid using recursive variables and instead lay out the rules and prerequisites in a way that does the same. However, occasionally, Iā€™d have to resort to them and Iā€™m thankful that RMS didnā€™t win and they exist in GNU Make today šŸ˜… IMO purist solutions have a tendency to turn out impractical.

General Programming Discussion
!programming@lemmy.ml

    A general programming discussion community.

    Rules:

    1. Be civil.
    2. Please start discussions that spark conversation

    Other communities

    Systems

    Functional Programming

    Also related

    • 0 users online
    • 6 users / day
    • 7 users / week
    • 21 users / month
    • 111 users / 6 months
    • 1 subscriber
    • 326 Posts
    • 596 Comments
    • Modlog