gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

Coding > Makefile question

#71903 - gauauu - Wed Feb 15, 2006 6:46 am

In my makefile, I am wanting to do something like:

Code:

AUTOGFX = gfx/hud.c gfx/stuff.c

...

$(AUTOGFX) : ..?..
     perl myGfxConverter.pl file=$@


Now, where the ..?.. is, I'd like to put set a dependancy that each AUTOGFX file is dependant on the associated .png file (gfx/png/hud.png). I'm not sure how to specify this, though.

A few notes: in the gfx/ directory, there are other C/object files that won't be automatically generated, so I can't use a directory wildcard. I specifically want to define the files manually like I am doing.

I tried something like:
Code:

$(AUTOGFX) : $(patsubst gfx/%.c,gfx/png/%.png,$@)
     perl myGfxConverter.pl file=$@

but the $@ only doesn't seem to work in the dependancy section for some reason (unless I'm doing something blatantly stupid?) It's not that it complains of not being able to find the dependant file...it just doesn't seem to know that it needs to rebuild my AUTOGFX files when the png changes.

And if I do something like
Code:

$(AUTOGFX) : $(patsubst gfx/%.c,gfx/png/%.png,$(AUTOGFX))
     perl myGfxConverter.pl file=$@


Then each C source file will have to be rebuilt every time one of the png's get changed, right?

Also, I know that generally it's bad to put gfx in C files. I'm doing it anyway because of how my converter perl scripts work. The makefile question is the same whether it's C or assembly files.

Thanks!

#71947 - kashiwa - Wed Feb 15, 2006 2:55 pm

I am doing in this way.

Code:

BMPFILES   = \
   Resource/sprMyShip.bmp \
   Resource/sprMyShot.bmp \
   Resource/sprOption.bmp \
   ...
CFILES   = \
   $(BMPFILES:.bmp=.c) \
   ...

.SUFFIXES: .s .c .o .a .d .bmp .pal

.bmp.c: $(BMPFILES)
   @echo converting $<
   @perl tools/bmp2c.pl $<


I feel troublesome to have to write the file name in makefile when adding a new resource. ;(