2009-11-16 82 views
3

我正在为移动设备(Windows Mobile 6和Android)设计跨平台2D引擎。我的Windows版本已经准备就绪,但我仍然需要确保Android上提供相同的功能。Makefiles:从一个目录获取.cpp,并将编译好的.o放到另一个目录中

我想要的是一个Makefile在项目的根和几个Makefile的项目本身和测试应用程序。

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

我立足于以下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 ../[email protected] 
    acpy ../$(PROGS) 
.cpp.o: 
    $(CC) $(CFLAGS) -I $(GLES_INCLUDES) -c $*.cpp $(CLIBS) 

不过,我不太会用这些东西。我想要的是将文件夹中的.cpp文件编译为.o文件,并将它们放在intermediate文件夹中,最后将.o文件编译为编译后的exe文件,并将其放入bin文件夹中。

我已经成功地得到清洁这样的工作:

cd intermediate && rm -f *.o 

但是,我不能让它检索的.cpp的,编译它们并把它们在intermediate文件夹中。

我看了其他几个Makefiles,但没有做我想做的事情。

任何帮助表示赞赏。

+0

请指定“make”标记而不是“makefile”。更多信息:http://meta.stackexchange.com/questions/24030/why-do-they-specify-makefile-tag-instead-of-make/26567#26567 – 2009-11-18 06:45:31

+0

嗯,我*是一个小白这些事情。 :P – knight666 2009-11-18 13:41:18

回答

8

有做到这一点的方法不止一种,但最简单的就是在TestOne运行,使得中级/ foo.o的出来的src/Foo.cpp中和test1的出中级/ foo.o的的,是这样的:

 
# 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 ../[email protected] 

$(OBJECTS): Intermediate/%.o : Src/%.cpp 
    $(CC) $(CFLAGS) -I $(GLES_INCLUDES) -c $< $(CLIBS) -o [email protected] 
+0

谢谢! :D 这正是我所需要的。我喜欢makefile(远远超过Visual Studio的vcproj),但它们可能非常难以设置。 :( – knight666 2009-11-16 21:54:37

+0

我也喜欢它们,但是它们有一些严重的缺点和很长的学习曲线......因为我没有真正测试过这个,所以有一个错误。 – Beta 2009-11-16 22:12:19

相关问题