How should this be placed in a makefile?

Investigation into how Linux on the PS3 might lead to homebrew development.

Moderators: cheriff, emoon

Post Reply
User avatar
vivi
Posts: 7
Joined: Wed Jul 08, 2009 8:31 am

How should this be placed in a makefile?

Post by vivi »

Hi, this compiles and works fine, but I'm not sure how to put this into a Makefile.

Code: Select all

spu-gcc-4.3 spe_example.c -o spe_example;
embedspu test_handle spe_example spe_example_csf.o;
gcc ppe_example.c spe_example_csf.o -lspe2 -o example;
Here is my attempt so far

Code: Select all

CC=gcc
CFLAGS=-g -Wall
SPUGCC=spu-gcc-4.3

example: ppe_example.c spe_example_csf.o
    $(CC) $(CFLAGS) ppe_example.c spe_example_csf.o -lspe2 -o example
    embedspu test_handle spe_example spe_example_csf.o

spe_example: spe_example.c
    $(SPUGCC) spe_example.c -o spe_example        

clean:
    rm -rf spe_example_csf.o example spe_example
With regards to it's background, It's just some test code using all the cores on the PS3

http://www.ibm.com/developerworks/library/pa-libspe2/

(Ignore the differences, much to my annoyance i found that Debian has different naming conventions from what was written in the guide.)

Thanks!
jimparis
Posts: 1145
Joined: Fri Jun 10, 2005 4:21 am
Location: Boston

Post by jimparis »

this three step process

Code: Select all

spu-gcc-4.3 spe_example.c -o spe_example
embedspu test_handle spe_example spe_example_csf.o
gcc ppe_example.c spe_example_csf.o -lspe2 -o example;
would be expressed in a Makefile as three dependency rules:

Code: Select all

all:
        example

spe_example: spe_example.c
        spu-gcc-4.3 spe_example.c -o spe_example

spe_example_csf.o: spe_example
        embedspu test_handle spe_example spe_example_csf.o

example: ppe_example.c spe_example_csf.o
        gcc ppe_example.c spe_example_csf.o -lspe2 -o example
User avatar
vivi
Posts: 7
Joined: Wed Jul 08, 2009 8:31 am

Post by vivi »

hmm, recieving error 127 when i try to use that makefile. I'm baffled, does anyone have any more attempts. Placing the commands

Code: Select all

spu-gcc-4.3 spe_example.c -o spe_example
embedspu test_handle spe_example spe_example_csf.o
gcc ppe_example.c spe_example_csf.o -lspe2 -o example; 
in an sh file feels and seems sloppy, so i would really like to be able to find out how it is placed in a makefile. Thanks for your help so far jimparis ^^
J.F.
Posts: 2906
Joined: Sun Feb 22, 2004 11:41 am

Post by J.F. »

The makefile shown IS the proper way to do it. You just need to figure out what the error is... probably a whitespace problem. Make doesn't like leading spaces - only leading tabs are allowed. Look for any lines that start with one or more spaces and replace them with tabs.
jimparis
Posts: 1145
Joined: Fri Jun 10, 2005 4:21 am
Location: Boston

Post by jimparis »

Sorry, that first rule should be

Code: Select all

all: example
not

Code: Select all

all:
        example
Also, what JF said.
User avatar
vivi
Posts: 7
Joined: Wed Jul 08, 2009 8:31 am

Post by vivi »

Came back to it later and and solved it after reading more about creating makefiles and playing around. I think that the problem was that the makefiles suggested were in reverse. Here is the working copy which includes am extra spe program. Thanks for the help :)

Code: Select all

CC = gcc -Wall
SPU-GCC = spu-gcc-4.3
ESPU = embedspu
DEBUG = -ggdb3

example: ppe_example.c spe_example_csf.o spe_example_csf2.o
	$(CC) ppe_example.c spe_example_csf.o spe_example_csf2.o -lspe2 -o example

spe_example_csf2.o: spe_example2
	$(ESPU) test_handle_2 spe_example2 spe_example_csf2.o
	
spe_example_csf.o: spe_example
	$(ESPU) test_handle spe_example spe_example_csf.o	

spe_example2: 
	$(SPU-GCC) spe_example2.c -o spe_example2

spe_example: 
	$(SPU-GCC) spe_example.c -o spe_example

clean:
	rm spe_example spe_example2 spe_example_csf2.o spe_example_csf.o example

  
jimparis
Posts: 1145
Joined: Fri Jun 10, 2005 4:21 am
Location: Boston

Post by jimparis »

The rule order doesn't actually if the Makefile expresses all of the dependencies correctly. Yours is almost correct, but you forgot to list spu_example.c as a dependency of spu_example. Similarly for spu_example2.
User avatar
vivi
Posts: 7
Joined: Wed Jul 08, 2009 8:31 am

Post by vivi »

Ah, yeah should have wrote the dependancies. It still compiled without them though. Is including the source files as dependencies just to make it easier for the human programmer?
jimparis
Posts: 1145
Joined: Fri Jun 10, 2005 4:21 am
Location: Boston

Post by jimparis »

Including all dependencies is done so that "make" works correctly. As you noticed, without proper dependencies, it can fail if (for example) the rules are in a different order.
Post Reply