help-make
[Top][All Lists]
Advanced

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

Hot to write pattern rules for suffix deletion


From: Stephen Touset
Subject: Hot to write pattern rules for suffix deletion
Date: Thu, 4 Jan 2024 16:08:01 -0800

Hello all,

I have a set of files in a project that need to be preprocessed through
`envsubst` to render their output. The targets of these templated files
are a mix of different file types, so they aren't rendered to files with
a consistent extension. Further, not all files with those target
extensions need to be rendered from templates. For example:

    a.yaml.envsubst    // a.yaml should be rendered from this
    b.json.envsubst    // b.json should be rendered from this
    c.json             // should not pass through a rendering step

I would like to express this in a make rule. Instinctually, I want to
reach for something like

    %: %.envsubst
        envsubst < $< > $@

Obviously this rule isn't correct. But I'm a bit at a loss for how to
express what I want through make rules. One approach that I considered
was using `$(shell find ...)` to get a list of these templates and
generate rules for each one. Unfortunately in my case, that would be
quite difficult because one file might go through *multiple*
preprocessing steps:

    d.json.envsubst.gz // d.json should be decompressed then rendered

So now I'd need to have some overcomplicated logic to write out the
resulting rules:

    d.json: d.json.envsubst
        ...

    d.json.envsubst: d.json.envsubst.gz
        ...

I'm happy to change the naming scheme of these files for a reasonable
solution, but I'm feeling a bit stuck by the combination that a) files
which should be rendered through `gzip -d` and `envsubst` don't have
consistent target suffixes, b) a final target might go through either or
both of these steps, and c) not every target requires rendering.

Any ideas?

--
Stephen Touset <stephen@touset.org>



reply via email to

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