Makefiles:从一个目录获取.cpp,并将编译后的.o放在另一个目录中
我正在开发适用于移动设备(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 到编译好的 exe 中并将其放入 bin
文件夹中。
我已经成功地像这样干净地工作:
cd intermediate && rm -f *.o
但是,我无法让它检索 .cpp、编译它们并将它们放入 intermediate
文件夹中。
我查看了其他几个 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
有不止一种方法可以做到这一点,但最简单的方法是在 TestOne 中运行,从 Src/foo.cpp 中生成 Intermediate/foo.o,并从 Intermediate/foo.o 中生成 test1,如下所示:
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: