English 中文(简体)
Makefiles: Get .cpp from one directory and put the compiled .o in another directory
原标题:
  • 时间:2009-11-16 06:11:28
  •  标签:
  • makefile

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.

最佳回答

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 $@
问题回答

暂无回答




相关问题
makefile: how to show line numbers for debugging?

Is there a way to have make display the line number where it declares an error? The -d switch doesn t seem to cut it. Updated: Example output: Reaping winning child 0x08aa8648 PID 9381 /bin/sh: ...

What is the reasoning behind the Makefile whitespace syntax?

I m revisiting Python after Michael Sparks s excellent walk through of Peter Norvig s Python spell checker at the SO DevDay in London. One of the points he highlighted was how clean Python is to look ...

Debugging GNU make

Is there a command line way in make to find out which of the prerequisites of a target is not updated?

How to add an all rule to this Makefile?

I want to just type make all and have the following Makefile do everything it s supposed to do: LEX = lex YACC = yacc CC = gcc calcu: y.tab.o lex.yy.o $(CC) -o calcu y.tab.o lex.yy.o -ly -lfl ...

How to discover number of *logical* cores on Mac OS X?

How can you tell, from the command line, how many cores are on the machine when you re running Mac OS X? On Linux, I use: x=$(awk /^processor/ {++n} END {print n+1} /proc/cpuinfo) It s not ...

Using extern in C doesn t work as expected

I have created two files: tunables.h #ifndef TUNABLES_H #define TUNABLES_H void tunables_load_conservative(); void tunables_load_aggressive(); extern int timer_x; #endif /*TUNABLES_H */ and ...

热门标签