[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Pattern rules with % matching empty string?
From: |
Philip Guenther |
Subject: |
Re: Pattern rules with % matching empty string? |
Date: |
Thu, 23 Apr 2020 23:41:49 -0900 |
On Thu, Apr 23, 2020 at 10:55 PM Glen Huang <address@hidden> wrote:
> I’m trying to do something like this:
>
> 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.
>
This is the documented behavior of pattern rules. To quote the info pages:
10.5 Defining and Redefining Pattern Rules
==========================================
You define an implicit rule by writing a "pattern rule". A pattern
rule looks like an ordinary rule, except that its target contains the
character `%' (exactly one of them). The target is considered a
pattern for matching file names; the `%' can match any nonempty
substring, while other characters match only themselves.
Note: "nonempty"
I tried mixing static and pattern rule like this to make it work:
>
> remote-bin-host remote-bin-host%: bin
> scp $< host$*:$<
> touch $@
>
> And make complains such mixture is deprecated.
>
Right, because pattern rules mean with multiple targets have a magic
meaning, making what they mean when mixed with non-pattern targets
ambiguous.
Is there a clean way to write it without splitting the rule and duplicating
> most of the receipt?
>
Put the commands for the rule in a variable and have two rules, one pattern
and one not, that both use the variable as their entire recipe.
Philip Guenther