Re: macro to print filename

"Michal Nazarewicz" <[email protected]> Wed, 01 Jun 2011 21:27:33 +0200
Newsgroups org.kernel.vger.linux-c-programming
Message-ID <op.vwewb7lm3l0zgt@mnazarewicz-glaptop>
On Wed, 01 Jun 2011 21:24:59 +0200, Aniruddha Bhattacharyya  
<[email protected]> wrote:
> From what I understood, Ratheesh wanted a compile time solution.
>
> My workaround will be to go for  a Makefile based compilation.
> 1)  "gcc -E yourfile.c"  will preprocess only. so __FILE__ will be  
> expanded .
>
> output file will be yourfile.c (with macro expanded)
>
> 2) then run your custom tool/bash script to trim the filepath to  
> filename.
> use awk tool maybe.
>
> 3) Do the final compile using Gcc

That sounds too complicated.  How about:

foo.o: foo.c
	gcc -DMY_FILE=$(basename $<) -o $@ $<

(Syntax might be wrong.)

-- 
Best regards,                                         _     _
.o. | Liege of Serenely Enlightened Majesty of      o' \,=./ `o
..o | Computer Science,  Michal "mina86" Nazarewicz    (o o)
ooo +-----<email/xmpp: [email protected]>-----ooO--(_)--Ooo--