help-make
[Top][All Lists]
Advanced

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

Re: Pattern rules with % matching empty string?


From: Kaz Kylheku (gmake)
Subject: Re: Pattern rules with % matching empty string?
Date: Fri, 24 Apr 2020 21:56:45 -0700
User-agent: Roundcube Webmail/0.9.2

On 2020-04-24 14:39, Paul Smith wrote:
On Fri, 2020-04-24 at 12:15 +0800, Glen Huang wrote:
remote-bin-host%: bin
        scp $< host$*:$<
        touch $@

to update files in remote hosts.

It works for remote-bin-host1, remote-bin-host2, etc, but not remote-
bin-host. It seems % won’t match empty string.

Another option is to match one extra character:

remote-bin-hos%: bin
        ...

There is a third option: choose your host naming scheme so
that all the names have a suffix.

And a fourth option: keep the host names inconsistent
(they are probably hard to change) but enumerate them
with consistently named stamp files (easy to control).

Use computed variable names to associate the two together:

  remote-bin-host%: bin
     scp $< $(host_$*):$<
     touch $@

Note the nesting $(host_$*).  The stem such as 1, 2, 3
is first interpolated into this to produce $(host_1),
$(host_2) and so on. These are variables, which get expanded
again. Make allows computed variable names without eval
having to be used. This effectively gives us an associative
data structure in which variables are keys. We somewhere
populate that:

  host_1 := alpha.localdomain
  host_2 := beta.othersite
  ...

Thus if the stamp file remote-bin-host1 is out of date
with respect to bin, then bin is scp-ed out to
alpha.localdomain:bin. Then the stamp file is touched.

Similarly for remote-bin-host2, bin is copied out to
beta.othersite.

Idea: instead of just touching the stamp file, we can write
the host name into it:

      echo $(host_$*) > $@

Then if someone wants a quick reminder what host is in
the stamp file, the answer is inside.




reply via email to

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