我正在为移动设备(Windows Mobile 6 和 Android)开发一个跨平台的 2D 引擎。我的 Windows 版本已经准备就绪,但我仍然需要确保在 Android 上提供相同的功能。
我想要的是项目根目录中的一个 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 ../$@
acpy ../$(PROGS)
.cpp.o:
$(CC) $(CFLAGS) -I $(GLES_INCLUDES) -c $*.cpp $(CLIBS)
但是,我对这些东西不是很好。我想要的是它获取 src
文件夹中的 .cpp,将它们编译为 .o 并将它们放在 intermediate
文件夹中,最后编译.o's 到编译好的 exe 并放在 bin
文件夹中。
我已经设法像这样工作了:
cd intermediate && rm -f *.o
但是,我无法用它来检索 .cpp,编译它们并将它们放在 intermediate
文件夹中。
我查看了其他几个 Makefile
,但没有一个能做我想做的事情。
感谢任何帮助。
最佳答案
这样做的方法不止一种,但最简单的方法是在 TestOne 中运行,将 Src/foo.cpp 中的 Intermediate/foo.o 和 Intermediate/foo.o 中的 test1 制作出来,如下所示:
# 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 $< $(CLIBS) -o $@
关于Makefiles : Get . cpp 从一个目录并将编译的 .o 放在另一个目录中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1740379/