3

I'm working on a cross-platform 2D engine for mobile devices (Windows Mobile 6 and Android). My Windows version is pretty much ready, but I still need to make sure the same functionality is available on Android.

What I want is one Makefile in the root of the project and several Makefile's for the project itself and the test applications.

Makefile
---Engine
------Makefile
------src
------bin
------intermediate
---Tests
------TestOne
---------Makefile
---------src
---------bin
---------intermediate
------TestTwo
---------Makefile
---------src
---------bin
---------intermediate

I'm basing my attempts on the following Makefile:

 include ../makeinclude

 PROGS = test1
 SOURCES = $(wildcard *.cpp)

 # first compile main.o and start.o, then compile the rest
 OBJECTS = main.o start.o $(SOURCES:.cpp=.o)

 all: $(PROGS)

 clean:
    rm -f *.o src

 test1: $(OBJECTS)
    $(LD) --entry=_start --dynamic-linker system/bin/linker -nostdlib -rpath system/lib -rpath $(LIBS) -L $(LIBS) -lm -lc -lui -lGLESv1_CM $^ -o ../$@ 
    acpy ../$(PROGS)
 .cpp.o:
    $(CC) $(CFLAGS) -I $(GLES_INCLUDES) -c $*.cpp $(CLIBS)

However, I'm not very good with these things. What I want is for it to take the .cpp's that are in the src folder, compile them to .o and put them in the intermediate folder and, finally, compile the .o's to the compiled exe and put it in the bin folder.

I've managed to get clean to work like this:

cd intermediate && rm -f *.o

However, I can't get it to retrieve the .cpp's, compile them and put them in the intermediate folder.

I've looked at several other Makefiles, but none do the things I want to do.

Any help is appreciated.

P Shved
  • 96,026
  • 17
  • 121
  • 165
knight666
  • 1,599
  • 3
  • 22
  • 38
  • Please, specify "make" tag instead of "makefile". More info: http://meta.stackexchange.com/questions/24030/why-do-they-specify-makefile-tag-instead-of-make/26567#26567 – P Shved Nov 18 '09 at 06:45
  • Well, I *am* a noob concerning these things. :P – knight666 Nov 18 '09 at 13:41

1 Answers1

8

There's more than one way to do this, but the simplest is to run in TestOne, making Intermediate/foo.o out of Src/foo.cpp and test1 out of Intermediate/foo.o, like this:

# This makefile resides in TestOne, and should be run from there.

include makeinclude # Adjust the path to makeinclude, if need be.

PROG = bin/test1 
SOURCES = $(wildcard Src/*.cpp) 

# Since main.cpp and start.cpp should be in Src/ with the rest of
# the source code, there's no need to single them out
OBJECTS = $(patsubst Src/%.cpp,Intermediate/%.o,$(SOURCES))

all: $(PROG)

clean: 
    rm -f Intermediate/*.o bin/*

$(PROG): $(OBJECTS) 
    $(LD) $(BLAH_BLAH_BLAH) $^ -o ../$@  

$(OBJECTS): Intermediate/%.o : Src/%.cpp
    $(CC) $(CFLAGS) -I $(GLES_INCLUDES) -c $&lt $(CLIBS) -o $@
Beta
  • 96,650
  • 16
  • 149
  • 150
  • Thank you! :D This was exactly what I needed. I love makefile's (much more than Visual Studio's vcproj), but they can be so difficult to set up. :( – knight666 Nov 16 '09 at 21:54
  • I like them too, but they have some serious shortcomings and a long learning curve... and since I didn't actually test this, there's a bug. Hang on a sec... – Beta Nov 16 '09 at 22:12