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 troubles

#23540 - Darmstadium - Wed Jul 14, 2004 9:33 pm

I decided to start using gnu's make, but I'm having trouble getting it to work. First, my makefile:
Code:

CFLAGS = -c -O2
ASMFLAGS = -c
THUMB = -mthumb
ARM = -marm
THUMBANDARM = -mthumb-interwork

THUMBLIST_C:
THUMBLIST_CPP: bg.cpp collision.cpp enemies.cpp gba.cpp level.cpp source.cpp sprite.cpp
THUMBLIST_ASM:
ARMLIST_ASM:
BOTHLIST_ASM:

all: demo.gba

demo.gba: demo.elf
   objcopy -O binary demo.elf demo.gba

demo.elf: $(THUMBLIST_C) $(THUMBLIST_CPP) $(THUMBLIST_ASM) $(ARMLIST_ASM) $(BOTHLIST_ASM)
   $(CC) -o demo.elf $(THUMBLIST_C) $(THUMBLIST_CPP) $(THUMBLIST_ASM) $(ARMLIST_ASM) $(BOTHLIST_ASM)

$(THUMBLIST_C): %.o: %.c
   $(CC) $(CFLAGS) $(THUMB) $<

$(THUMBLIST_CPP): %.o: %.cpp
   path=c:\devkitadv\bin
   g++ $(CFLAGS) $(THUMB) $<

$(THUMBLIST_ASM): %.o: %.s
   $(CC) $(ASMFLAGS) $(THUMB) $<

$(ARMLIST_ASM): %.o: %.s
   $(CC) $(ASMFLAGS) $(ARM) $<

$(BOTHLIST_ASM): %.o: %.s
   $(CC) $(ASMFLAGS) $(THUMBANDARM) $<


when i try to run the script, make says "make: Nothing to be done for `THUMBLIST_C'." Why does it just stop?

thanks a lot

#23544 - poslundc - Wed Jul 14, 2004 11:06 pm

Makefiles process the first rule in the file. So "all" should be the first rule to appear.

Dan.

#23547 - col - Wed Jul 14, 2004 11:35 pm

I'm no expert, but it looks like you are telling make to make the .cpp files? and they are already made, so there is nothing to be done. You need to give make a list of object files that you want it to create.

try changing your list to somthing like:

THUMBLIST_CPP = bg.o collision.o enemies.o gba.o level.o source.o sprite.o

then put in rules to tell make how to use .cpp and .c files to make the .o files in the list files
Code:

%.o: %.c
   $(CC) $(CFLAGS) $(THUMB) $<

%.o: %.cpp
   path=c:\devkitadv\bin
        g++ $(CFLAGS) $(THUMB) $<


if you want to specify arm or thumb, one way is to add an intermediate suffix to the filename. So for arm you use .arm.cpp, and for thumb .thumb.cpp (i have thumb as default, so only specify arm)

then you put in some more rules like:
Code:

%.arm.o: %.arm.c
   $(CC) $(CFLAGS) $(ARM) $<

%.arm.o: %.arm.cpp
   path=c:\devkitadv\bin
        g++ $(CFLAGS) $(ARM) $<


I posted my makefile a while back - you should have a look at it, it is pretty much automatic - you just edit the directory list and library list, and a few other bits and pieces when you start a project and it does the rest - no editing required to add a new file to your project. just save the new file to one of the directories in the makefiles list. Also, it processes dependencies of headers as well as source files so you only rarely need to re-compile the whole project.

http://forum.gbadev.org/viewtopic.php?t=2004&start=12

cheers

Col