help-make
[Top][All Lists]
Advanced

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

Re: Flexible include (was: Re: adding functions to function.c


From: Alessandro Vesely
Subject: Re: Flexible include (was: Re: adding functions to function.c
Date: Tue, 18 Jan 2005 16:35:38 +0100

Boris Kolpackov wrote:
> 
> Alessandro Vesely <address@hidden> writes:
> 
> > [...]
> >
> > Would it be a feasible and useful to have a delayed include? I mean
> > to consider the include-file as a regular target but only include it
> > after it has been either rebuilt or diagnosed up to date.
> 
> I don't see what exactly you are trying to achieve. Maybe you could
> create a small example that shows your problem.

I've tried to make a simple example, but failed... :-(

I've written the two files attached below, wich mix a basic dependency
as explained in <http://make.paulandlesley.org/autodep.html#basic> and
a source generation utility. The result doesn't fail the way I wanted,
but has some strange behaviour and is sensitive to the order that C
sources are given in the first line of the Makefile.

One of these days I'll try a better example...

Curiously, `gmake -n' builds the example whilst just `gmake' starts
in infinite loop because generator.P is not considered precious
(perhaps included files deserve this feature by default). The infinite
loop does not happen on a clean 3.80 I built on Unix back in 2002.
SRCS = generator.c generated.c
.SUFFIXES:

COMPILE = $(CC) -o$@ $<
%.exe : %.c %.P
        $(COMPILE)

MAKEDEPEND = gcc -M $(CPPFLAGS) -o $*.d $<
%.P : %.c
        $(MAKEDEPEND)
        sed 's/\($*\)\.o[ :]*/\1.exe $@ : /g' < $*.d > $@; \
        rm -f $*.d; [ -s $@ ] || rm -f $@

include $(SRCS:.c=.P)

.PHONY: all
all: generated.exe

generated.c : generator.exe
        ./$< stdio.h > $@

.PHONY: clean
clean:
        rm -f $(SRCS:.c=.P) $(SRCS:.c=.exe) generated.c
#include <stdio.h>
int main(int argc, char *argv[])
{
   int i;
   for (i = 1; i < argc; ++i)
      printf("#include <%s>\n", argv[i]);
   puts("int main()\n"
      "{\n"
      "   puts(\"Hello world!\\n\");\n"
      "   return 0;\n"
      "}\n");
   return 0;
}

reply via email to

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