GP32 Makefile Question...


Quo Vadis

Still Fresh
Joined
Feb 27, 2005
Messages
44
Hi all.

Sorry about this but I'm just putting my first project together and I'm not at all used to these makefile thingies. I have multiple .c and .h files but I can't work out how to amend Mr Mirko's makefile example to deal with multiple files.

I've checked through the examples and when I did find one that appeared to compile multiple files and copied the format it still didn't work.

Any pointers?

QV
 
Quo Vadis posted on Apr 5 2005 at 01:53 PM said:
I've checked through the examples and when I did find one that appeared to compile multiple files and copied the format it still didn't work.

Unfortunately, the format of makefiles is fairly complicated, doubly so if you're trying to modify someone else's make files for your own purposes.

As a reference, I'd highly recommend the O'Reilly Make book, followed by the GNU Make Documentation.

Try to understand what is happening in every step of the Makefile you're modifying, as it will make modifying it much easier. Then come back and post any specific questions you've got, with examples of the code from your Makefile.
 
Last edited by a moderator:
Hi,

Here is an example of the makefile (Mr.Mirkos) I use.

My main c file is called:
main.c

I also have:
second.h, second.c
third.h, third.c

This is how I compile all of the files into a program called 'myprog.fxe'

Code:
CC = arm-elf-gcc
LD = arm-elf-gcc
AS = arm-elf-as
AR = arm-elf-ar

NAME = My_prog_name
AUTHOR = Pea
PRG  = myprog
ICON = myprog.bmp
OBJS = main.o second.o third.o

LIBS      = -L../lib -lmirkoSDK -lm
CRT0      = ../lib/crt0.S
LNKSCRIPT = ../lib/lnkscript
INCLUDES  = -I../lib.src/include
CFLAGS    = $(INCLUDES) -O3 -s -mtune=arm9tdmi

all:	$(OBJS)
	$(CC) -c -o crt0.o $(CRT0)
	$(LD) -nostartfiles -s -Wall -Wl,-Map,Test.map  -T $(LNKSCRIPT) crt0.o -o $(PRG).elf $(OBJS) $(LIBS)
	arm-elf-objcopy -O binary $(PRG).elf $(PRG).bin
	b2fxec -a $(AUTHOR) -t $(NAME) $(PRG).bin $(PRG).fxe

As you can see, only edit the variables NAME, AUTHOR, PRG, ICON and OBJS:

OBJS:
This is a list of all the code files that you want to compile together. This relates directly to your question. Just list all the .c files here with a space between them, but rename them so that the .c is a .o - this will automatically search for a .c file with the same name (or a .S file, which is ASM) and compile it to a .o
I'm not sure if the order is important or not. I always have the main .c file first.
Also, as long as 'second.h' is #include'ed from within 'second.c', it will also be compiled in to your program

NAME:
This is the descriptive name that is inserted into the fxe, and displayed from within your launcher on the GP32. I don't think it can have spaces. It can be longer than 8 chars. e.g. This_is_my_program. (edit: Looks like it can have spaces if you surround with double quotes as in "This is my program")

AUTHOR:
Your name I guess. Not sure about spaces. (edit: Looks like it can have spaces if you surround with double quotes as in "Firstname lastname")

PRG:
The file name (without and extension) of your final fxe. Must be 8 chars or less.

ICON:
The name of a BMP icon 24x24 pixels in the standard palette that will be used as the icon for your fxe. If the icon can't be found, it will simply have the default icon (but it won't error or anything like that, so don't worry). This is a new variable I added, its not in the original.

EDIT:
Unfortunately, the format of makefiles is fairly complicated, doubly so if you're trying to modify someone else's make files for your own purposes.
Sorry unit3, but in this case, Mr.Mirko (or another author) has especially developed this makefile to be modifiable. I use it for all of my projects (except libMikMod) and it's great.

Hope it helps
 
Things are much better thanks but I'm getting a 'no rule to make target blah.c, needed by all' error. Any ideas how I can shift this one?
 
I use a similare makefile.. but the OBJS line gets pretty long... somebody knows how to add an implicit rule for them?
 
Yip, thats easy too, although it seems you still need at least one long line. Here is the libMikMod makefile so you can see what I mean. Notice how you can break the lines with a slash too:

Code:
CC = arm-elf-gcc
LD = arm-elf-gcc
AS = arm-elf-as
AR = arm-elf-ar

INCLUDES = -I../lib.src/include -Igp32 -Iinclude

CFLAGS = $(INCLUDES) -O3 -s -DLITTLE_ENDIAN -DGP32 -mtune=arm9tdmi 
 
OBJS =$(LIBOBJS) $(DLOBJS) \
      drv_AF.o drv_aix.o drv_alsa.o drv_esd.o drv_hp.o drv_nos.o \
      drv_oss.o drv_pipe.o drv_raw.o drv_sam9407.o drv_sgi.o \
      drv_stdout.o drv_sun.o drv_ultra.o drv_wav.o drv_gp32.o \
      load_669.o load_amf.o load_dsm.o load_far.o load_gdm.o load_it.o  \
      load_imf.o load_m15.o load_med.o load_mod.o load_mtm.o load_okt.o \
      load_s3m.o load_stm.o load_stx.o load_ult.o load_uni.o load_xm.o \
      mmalloc.o mmerror.o mmio.o \
      mdriver.o mdreg.o mdulaw.o mloader.o mlreg.o mlutil.o mplayer.o \
      munitrk.o mwav.o npertab.o sloader.o virtch.o virtch2.o \
      virtch_common.o

all: libmikmod.a

libmikmod.a: $(OBJS) 
	$(AR) rcs $@ $(OBJS)

dl_hpux.o:	dlapi/dl_hpux.c \
  	/dlapi/dlfcn.h
	$(CC) $(CFLAGS) -c dlapi/dl_hpux.c
drv_AF.o:	drivers/drv_AF.c
	$(CC) $(CFLAGS) -c drivers/drv_AF.c
drv_aix.o:	drivers/drv_aix.c
	$(CC) $(CFLAGS) -c drivers/drv_aix.c
drv_alsa.o:	drivers/drv_alsa.c
	$(CC) $(CFLAGS) -c drivers/drv_alsa.c
drv_esd.o:	drivers/drv_esd.c
	$(CC) $(CFLAGS) -c drivers/drv_esd.c
drv_hp.o:	drivers/drv_hp.c
	$(CC) $(CFLAGS) -c drivers/drv_hp.c
drv_nos.o:	drivers/drv_nos.c
	$(CC) $(CFLAGS) -c drivers/drv_nos.c
drv_pipe.o:	drivers/drv_pipe.c
	$(CC) $(CFLAGS) -c drivers/drv_pipe.c
drv_oss.o:	drivers/drv_oss.c
	$(CC) $(CFLAGS) -c drivers/drv_oss.c
drv_raw.o:	drivers/drv_raw.c
	$(CC) $(CFLAGS) -c drivers/drv_raw.c
drv_sam9407.o:	drivers/drv_sam9407.c
	$(CC) $(CFLAGS) -c drivers/drv_sam9407.c
drv_sgi.o:	drivers/drv_sgi.c
	$(CC) $(CFLAGS) -c drivers/drv_sgi.c
drv_stdout.o:	drivers/drv_stdout.c
	$(CC) $(CFLAGS) -c drivers/drv_stdout.c
drv_sun.o:	drivers/drv_sun.c
	$(CC) $(CFLAGS) -c drivers/drv_sun.c
drv_ultra.o:	drivers/drv_ultra.c
	$(CC) $(CFLAGS) -c drivers/drv_ultra.c
drv_wav.o:	drivers/drv_wav.c
	$(CC) $(CFLAGS) -c drivers/drv_wav.c
drv_gp32.o:	drivers/drv_gp32.c
	$(CC) $(CFLAGS) -c drivers/drv_gp32.c

load_669.o:	loaders/load_669.c
	$(CC) $(CFLAGS) -c loaders/load_669.c
load_amf.o:	loaders/load_amf.c
	$(CC) $(CFLAGS) -c loaders/load_amf.c
load_dsm.o:	loaders/load_dsm.c
	$(CC) $(CFLAGS) -c loaders/load_dsm.c
load_far.o:	loaders/load_far.c
	$(CC) $(CFLAGS) -c loaders/load_far.c
load_gdm.o:	loaders/load_gdm.c
	$(CC) $(CFLAGS) -c loaders/load_gdm.c
load_it.o:	loaders/load_it.c
	$(CC) $(CFLAGS) -c loaders/load_it.c
load_imf.o:	loaders/load_imf.c
	$(CC) $(CFLAGS) -c loaders/load_imf.c
load_m15.o:	loaders/load_m15.c
	$(CC) $(CFLAGS) -c loaders/load_m15.c
load_med.o:	loaders/load_med.c
	$(CC) $(CFLAGS) -c loaders/load_med.c
load_mod.o:	loaders/load_mod.c
	$(CC) $(CFLAGS) -c loaders/load_mod.c
load_mtm.o:	loaders/load_mtm.c
	$(CC) $(CFLAGS) -c loaders/load_mtm.c
load_okt.o:	loaders/load_okt.c
	$(CC) $(CFLAGS) -c loaders/load_okt.c
load_s3m.o:	loaders/load_s3m.c
	$(CC) $(CFLAGS) -c loaders/load_s3m.c
load_stm.o:	loaders/load_stm.c
	$(CC) $(CFLAGS) -c loaders/load_stm.c
load_stx.o:	loaders/load_stx.c
	$(CC) $(CFLAGS) -c loaders/load_stx.c
load_ult.o:	loaders/load_ult.c
	$(CC) $(CFLAGS) -c loaders/load_ult.c
load_uni.o:	loaders/load_uni.c
	$(CC) $(CFLAGS) -c loaders/load_uni.c
load_xm.o:	loaders/load_xm.c
	$(CC) $(CFLAGS) -c loaders/load_xm.c

mmalloc.o:	mmio/mmalloc.c
	$(CC) $(CFLAGS) -c mmio/mmalloc.c
mmerror.o:	mmio/mmerror.c
	$(CC) $(CFLAGS) -c mmio/mmerror.c
mmio.o:  mmio/mmio.c
	$(CC) $(CFLAGS) -c mmio/mmio.c

mdriver.o:	playercode/mdriver.c
	$(CC) $(CFLAGS) -c playercode/mdriver.c
mdreg.o:	playercode/mdreg.c
	$(CC) $(CFLAGS) -c playercode/mdreg.c
mdulaw.o:	playercode/mdulaw.c
	$(CC) $(CFLAGS) -c playercode/mdulaw.c
mloader.o:	playercode/mloader.c
	$(CC) $(CFLAGS) -c playercode/mloader.c
mlreg.o:	playercode/mlreg.c
	$(CC) $(CFLAGS) -c playercode/mlreg.c
mlutil.o:	playercode/mlutil.c
	$(CC) $(CFLAGS) -c playercode/mlutil.c
mplayer.o:	playercode/mplayer.c
	$(CC) $(CFLAGS) -c playercode/mplayer.c
munitrk.o:	playercode/munitrk.c
	$(CC) $(CFLAGS) -c playercode/munitrk.c
mwav.o:  playercode/mwav.c
	$(CC) $(CFLAGS) -c playercode/mwav.c
npertab.o:	playercode/npertab.c
	$(CC) $(CFLAGS) -c playercode/npertab.c
sloader.o:	playercode/sloader.c
	$(CC) $(CFLAGS) -c playercode/sloader.c
virtch.o:	playercode/virtch.c playercode/virtch_common.c \
  	include/mikmod.h include/mikmod_internals.h
	$(CC) $(CFLAGS) -c playercode/virtch.c
virtch2.o:	playercode/virtch2.c playercode/virtch_common.c \
  	include/mikmod.h include/mikmod_internals.h
	$(CC) $(CFLAGS) -c playercode/virtch2.c
virtch_common.o:	playercode/virtch_common.c \
  	include/mikmod.h include/mikmod_internals.h
	$(CC) $(CFLAGS) -c playercode/virtch_common.c

strcasecmp.o:	posix/strcasecmp.c
	$(CC) $(CFLAGS) -c posix/strcasecmp.c
strdup.o:	posix/strdup.c
	$(CC) $(CFLAGS) -c posix/strdup.c
strstr.o:	posix/strstr.c
	$(CC) $(CFLAGS) -c posix/strstr.c

What this means, is if you type:

make

The make command looks for the rule for 'all', so it is the same as typing:

make all

It then looks up the rule for 'make all' in the makefile, which (if you loook above) simply gives you:

all: libmikmod.a

So then it looks up the rule to build 'libmikmod.a' (which is the same as typing 'make libmikmod.a' in the first place), which gives you:

libmikmod.a: $(OBJS)
$(AR) rcs $@ $(OBJS)

So you can see that the loooong OBJS list is still needed because ALL of those files are needed to build libmikmod.a - I don't know of any ways to get around this. It will now step through each of the items in OBJS, and attempt to find the rule to make each of these files. e.g. the first one would be:

make drv_AF.o

etc.

Hope it helps
 
Back
Top