🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.misc.discuss
Article #2265

Re: Static Patterns in Makefiles

#2265
From: John Zulauf
Date: Mon, 21 Dec 1998 00:00
78 lines
2928 bytes
This is a multi-part message in MIME format.
--------------A5FF5036FDB6F22A9AB700B0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

jimzat@iname.com wrote:

> I am trying to create a makefile which will do something based upon files in
> specific directories changing.
>
> When the following is used, the dependency list is not expanded.  Is there a
> way to make this work, or do I need to write explicit rules for foo.pak and
> bar.pak?
>
> PAK_DIRS = foo bar
>
> all: $(foreach dir, $(PAK_DIRS), $(dir).pak)
>
> $(foreach dir, $(PAK_DIRS), $(dir).pak) : %.pak : $(wildcard %/*.txt)
>     echo updated>$@
>
> JiMZ
>

Fear not -- while the expansion trick will not solve your problem look at the
attached makefile for a solution.

Summary.  For each of the .pak file we first create a PHONY rule that will
reinvoke make.  In the reinvocation we provide the "PAK_FILE" variable that
WILL be expanded in the creation of the rule for $(PAK_FILE).

It adds another N invocations of gmake, but I don't know how to do better
except perhaps by having rules to automatically create the make rules for each
directory and then relying on gmakes -- "if the included makefiles have changed
reload and rerun" facility.  I think that is less and and the complexity of
intermediate files.

Best success.

john


--
jzulauf@aw.sgi.com      805 884 7800     Alias|Wavefront, Santa Barbara
  An important corolary to "Never remember what you can look up," is
  "Never forget to remember what you don't remember, but must look up."



--------------A5FF5036FDB6F22A9AB700B0
Content-Type: text/plain; charset=us-ascii;
 name="make.jimz"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="make.jimz"

PAK_DIRS = foo bar
DIR_PAK  = $(foreach dir,$(PAK_DIRS),$(dir).pak)

.PHONY: jimz jimzClean

jimzClean :
	rm -f $(DIR_PAK)

jimz: $(DIR_PAK)
	@echo "$@:\n\t$^"

ifdef PAK_FILE
$(PAK_FILE) : $(wildcard $(patsubst %.pak,%,$(PAK_FILE))/*.txt)
	@echo "Updating $@\nFrom\t$^" 
	cat $^ > $@
else
.PHONY : $(DIR_PAK)
$(DIR_PAK) : %.pak :
	$(MAKE)  PAK_FILE="$@" $@
endif

--------------A5FF5036FDB6F22A9AB700B0--
Technical Details
Message-ID: <367E98B3.A05D071E@aw.sgi.com>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <75lp2j$7is$1@nnrp1.dejanews.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 11318c,e56f2d70afb650f
X-Google-Attributes: gid11318c,public
X-Google-Thread: 109f73,e56f2d70afb650f
X-Google-Attributes: gid109f73,public
X-Google-Thread: 1025b4,e56f2d70afb650f
X-Google-Attributes: gid1025b4,public
From: John Zulauf <jzulauf@aw.sgi.com>
Subject: Re: Static Patterns in Makefiles
Date: 1998/12/21
Message-ID: <367E98B3.A05D071E@aw.sgi.com>
X-Deja-AN: 424578107
References: <75lp2j$7is$1@nnrp1.dejanews.com>
X-Accept-Language: en
Content-Type: multipart/mixed; boundary="------------A5FF5036FDB6F22A9AB700B0"
Organization: Silicon Graphics, Inc.
Mime-Version: 1.0
Newsgroups: gnu.misc.discuss,gnu.gcc.help,gnu.utils.help