[Top][All Lists]

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

Re: Using grep inside makefile for loop

From: Luke Shumaker
Subject: Re: Using grep inside makefile for loop
Date: Mon, 17 Jan 2011 15:18:43 -0500

On Mon, 2011-01-17 at 10:28 -0800, givemecode wrote:
> I saw this question was posted but never answered on this forum. Hopefully
> this can be done:
> I have code in a makefile that creates a new file called "allheaders.h"
> which includes ALL the headers, and is intended to verify they compile:
> allheaders.h $(HEADER)
>     @for f in $(HEADER) ; do echo "#include \""$$f"\"" >> $@ ; done
> where HEADER is just a bunch of header files inside the include directory:
> HEADER = include/a.h
> HEADER += include/b.h
> HEADER += include/c.h
> ...
> How do I do something similar to grep in the for loop, so as not to include
> the "include/" part of the header rule?
> For instance, I currently have this inside my allheaders.h file:
> #include "include/a.h"
> #include "include/b.h"
> #include "include/c/h"
> ....
> but I want just:
> #include "a.h"
> #include "b.h"
> ...
> they are essential the same but I would like it to be the second list.
> thanks!!

I'm not sure what you want exactly.  I reference to grep, the tool would
be sed, but I'm not sure that's waht you actually want.  Does this do
what you want?:

allheaders.h: $(HEADER)
        @for f in $(patsubst include/%,%,$(HEADER)); do \
                echo "#include \"$$f\""; \
        done > '$@'

This could be done using sed, but doing it inside make is more
efficient, and a bit simpler.  Also, you were over-complicating shell
quotation.  Also, you can capture the output of the entire for loop, so
it only has to open allheaders.h for writing once.

~ LukeShu

reply via email to

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