[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: suppress "target '*' given more than once in the same rule"
From: |
Cook, Malcolm |
Subject: |
RE: suppress "target '*' given more than once in the same rule" |
Date: |
Fri, 28 Jun 2024 16:44:39 +0000 |
> -----Original Message-----
> From: help-make-bounces+mec=stowers.org@gnu.org <help-make-
> bounces+mec=stowers.org@gnu.org> On Behalf Of Belliveau, Fran - 0666 -
> MITLL
> Sent: Tuesday, June 25, 2024 11:03 AM
> To: help-make@gnu.org
> Subject: suppress "target '*' given more than once in the same rule"
>
> I have a setup where I use include directives to access makefile content used
> by multiple “make” situations throughout a large project.
>
> As I try to replace a bunch of (heavily simplified) things like:
>
> FOO_DIR?=fd
> BAH_DIR?=bd
> ####
> $(FOO_DIR)/foo: $(F_HDRS)
> mkdir -p $(FOO_DIR)
> genF $@
>
> $(BAH_DIR)/foo: $(B_HDRS)
> mkdir -p $(BAH_DIR)
> genB $@
>
> with a something like
>
> ####
> $(FOO_DIR) $(BAH_DIR):
> mkdir -p $@
>
> $(FOO_DIR)/foo: $(HDRS) | $(FOO_DIR)
> gen $@
>
> $(BAH_DIR)/bah: $(B_HDRS) | $(BAH_DIR)
> genB $@
>
> I run into “make complaints” when multiple directory variables actually point
> to the same directory.
> This may just be a warning, but it looks like an error to those who do not
> know
> what is going on.
>
> I am wondering if there is a way to suppress this with a directive of some
> sort?
> Is there a function call I might be able to make like $(unique $(FOO_DIR)
> $(BAH_DIR)): ?
Sort removes duplicates also, so perhaps
$(sort $(FOO_DIR) $(BAH_DIR)):
However, you might consider entirely changing your approach to auto make any
directory, as follows:
.SECONDEXPANSION:
.SECONDARY: %/
%/:
## PURPOSE: auto make any directory!!! IT IS CONSIDERED A "BAD
## PRACTICE" (at least in some circles!) to have directories be
## themselves the direct precondition of a rule. However, it is VERY
## CONVENIENT, at least when directory paths (with trailing "/") are
## only used as *order-only* prerequisitive (e.g. introduced with a
## vertical bar "|") to rules that target files within them. Notably,
## when using .SECONDEXPANSION:, $${@D}/ can be used to idiomatically
## & generically refer to the current rule's directory.
mkdir -p $@
The result of your Makefile could then be written as:
FOO_DIR?=fd
BAH_DIR?=bd
$(FOO_DIR)/foo: $(HDRS) | $${@D}
gen $@
$(BAH_DIR)/bah: $(B_HDRS) | $${@D}
genB $@
It is not clear to if there are other useful abstractions to additionally be
factored out. Your example is short on detail. I can't guess what FOO and BAH
and their respective HDRS and gen procedure are doing, especially since neither
HDRS nor B_HDRS variables are used in the recipe.
>
>
> Francis Belliveau
> Consultant
> Lincoln Laboratory, Massachusetts Institute of Technology
> 244 Wood Street
> Lexington, MA 02421-6426
>
>