Makefiles:从一个目录中获取.cpp并将已编译的.o放在另一个目录中 [英] Makefiles: Get .cpp from one directory and put the compiled .o in another directory
问题描述
我正在为移动设备(Windows Mobile 6和Android)开发跨平台的2D引擎.我的Windows版本已经准备好了,但是我仍然需要确保Android上可以使用相同的功能.
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.
我想要的是项目根目录中的一个Makefile
,以及项目本身和测试应用程序中的多个Makefile
.
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
我将基于以下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
文件夹.
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.
我已经努力工作:
cd intermediate && rm -f *.o
但是,我无法获取它来检索.cpp文件,对其进行编译并将其放入intermediate
文件夹中.
However, I can't get it to retrieve the .cpp's, compile them and put them in the intermediate
folder.
我看过其他几个Makefiles
,但没有一个我想做的事情.
I've looked at several other Makefiles
, but none do the things I want to do.
感谢您的帮助.
推荐答案
有多种方法可以执行此操作,但最简单的方法是在TestOne中运行,使Intermediate/foo.o脱离Src/foo.cpp和test1出Intermediate/foo.o,像这样:
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 $< $(CLIBS) -o $@
这篇关于Makefiles:从一个目录中获取.cpp并将已编译的.o放在另一个目录中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!