That is very convenient, and a great improvement toward reduction in 
maintenance problems. 
As you say, my example is a bit short on detail. Mostly, I refuse to mix 
source-controlled items with generated items in the same directory. That 
simplifies repository “ignore” directives by saying “ignore: directory” rather 
than “ignore: *.o”; again, I am using generic repository syntax there, but I 
expect you get what I am saying. 

Thank you very much for the suggestion. 

Francis Belliveau 
Consultant 
Lincoln Laboratory, Massachusetts Institute of Technology 
244 Wood Street 
Lexington, MA 02421-6426 



From: Cook, Malcolm <m...@stowers.org>
Date: Friday, June 28, 2024 at 12:45
To: Belliveau, Fran - 0666 - MITLL <belliv...@ll.mit.edu>, help-make@gnu.org 
<help-make@gnu.org>
Subject: [EXT] RE: suppress "target '*' given more than once in the same rule" 

!-------------------------------------------------------------------|
This Message Is From an External Sender
This message came from outside the Laboratory.
|-------------------------------------------------------------------!


> -----Original Message-----
> From: help-make-bounces+mec=stowers....@gnu.org <help-make-
> bounces+mec=stowers....@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
> 
> 




Attachment: smime.p7s
Description: S/MIME cryptographic signature

Reply via email to