help-make
[Top][All Lists]
Advanced

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

RE: foreach/ordering help


From: Randy W. Sims
Subject: RE: foreach/ordering help
Date: Sun, 3 Nov 2002 13:28:25 -0500

> -----Original Message-----
> From: Mark Therieau
> Sent: Saturday, November 02, 2002 5:00 PM
> To: address@hidden
> Subject: foreach/ordering help
> 
> I'm trying to create an output file that
> has one filename per line.  (I need to feed
> the filenames to the shell one at a time to
> avoid win32 command-line length issues when
> dealing with hundreds/thousands of files)
> 
> The makefile below doesn't work because the
> foreach is evaluated *before* the rm command is
> executed.  The result is that the "shell echo"
> commands run first to create "c.pfs" and then
> the rm deletes it every time.
> 
> Any ideas on a better way to get the rules to
> run in the desired order?
> 
> --------------------------------------------- 
> CSRCS = file1.c file2.c file999.c file1000.c
> c.pfs:
>       @rm -f $@
>       @$(foreach f,$(CSRCS),$(shell echo $(f) >> $@))
> --------------------------------------------- 
> 
> regards,
> markt
> 

I use the following to do something similar:

define WRITE_LINE
@ $(ECHO).$(2) >> $(1)

endef # keep blank line above

define OPEN_LDSCRIPT
@ $(ECHO).> $(1)
endef

# $1 filename, $2 command, $3 values
define WRITE_LDSCRIPT
@ $(ECHO).$(2)( >> $(1)
  $(foreach value,$(3),$(call WRITE_LINE,$(1),$(value)))
@ $(ECHO).); >> $(1)
@ $(ECHO).>> $(1)
endef

$(TARGET): LDSCRIPT=.\script-name.lds
$(TARGET): $(OBJS)
           $(call OPEN_LDSCRIPT,  $(LDSCRIPT))
           $(call WRITE_LDSCRIPT, $(LDSCRIPT), INPUT, $(OBJS))
           $(call WRITE_LDSCRIPT, $(LDSCRIPT), GROUP, $(LIBS))
           $(CC) $(LDFLAGS) -o $@ $(LDSCRIPT)
        -@ $(RM) $(LDSCRIPT)

HTH,
Randy.





reply via email to

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