help-make
[Top][All Lists]
Advanced

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

Re: Automatic build time inclusion


From: Der Herr Hofrat
Subject: Re: Automatic build time inclusion
Date: Thu, 2 Mar 2006 05:02:29 +0100 (CET)

> On Sun, Feb 12, 2006 at 09:23:43PM +0100, Martin Willers wrote:
> > 
> > program: $(OBJECTS)
> >         echo "const char build_time[] = \"`date`\";" > build.c
> >         $(CC) -c build.c
> >         $(CC) -o $@ $(OBJECTS) build.o
> > 
> > However, with this approach, I have to use an explicit
> > compiler call to compile build.c - it would be nicer if I could
> > let a pattern rule force compilation of build.c.
> > 
> > Is there a better way to do this?
> 
> Wouldn't this do?
> 
>   build.c : $(OBJECTS)
>       echo "const char build_time[] = \"`date`\";" > build.c
> 
> 
>   program: $(OBJECTS) build.o
>       $(CC) -o $@ $(OBJECTS) build.o
>
no need for an intermediate file for something like that.

address@hidden:/tmp# cat Makefile
all: hello

NOW := $(shell date -u "+%Y/%m/%d %H:%M")
CFLAGS    += -DBUILDTIME='"$(NOW)"'
hello: hello.c
address@hidden:/tmp# cat hello.c
#include <stdio.h>
main(){
        printf("\n"BUILDTIME"\n");
        return 0;
}
address@hidden:/tmp# make
cc -DBUILDTIME='"2006/02/25 15:16"'    hello.c   -o hello
address@hidden:/tmp# ./hello

2006/02/25 15:16
address@hidden:/tmp#

hofrat




reply via email to

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