Makefiles:从一个目录获取.cpp,并将编译后的.o放在另一个目录中
我正在为移动设备(WindowsMobile 6和Android)开发一个跨平台的2D引擎。我的Windows版本已经准备好了,但我仍然需要确保Android上也有相同的功能 我想要的是项目根目录中的一个Makefiles:从一个目录获取.cpp,并将编译后的.o放在另一个目录中,makefile,Makefile,我正在为移动设备(WindowsMobile 6和Android)开发一个跨平台的2D引擎。我的Windows版本已经准备好了,但我仍然需要确保Android上也有相同的功能 我想要的是项目根目录中的一个Makefile,以及项目本身和测试应用程序的几个Makefile Makefile ---Engine ------Makefile ------src ------bin ------intermediate ---Tests ------TestOne ---------Makefile
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
# 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 $@
但是,我无法让它检索.cpp,编译它们并将它们放在中间文件夹中
我已经查看了其他几个makefile
,但是没有一个做了我想做的事情
非常感谢您的帮助。实现这一点的方法不止一种,但最简单的方法是在TestOne中运行,使用Src/foo.cpp生成Intermediate/foo.o,使用Intermediate/foo.o生成test1,如下所示:
cd intermediate && rm -f *.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 ../$@
$(OBJECTS): Intermediate/%.o : Src/%.cpp
$(CC) $(CFLAGS) -I $(GLES_INCLUDES) -c $< $(CLIBS) -o $@
#这个makefile驻留在TestOne中,应该从那里运行。
include makeinclude#如果需要,调整makeinclude的路径。
PROG=bin/test1
SOURCES=$(通配符Src/*.cpp)
#因为main.cpp和start.cpp应该与其他
#源代码,没有必要单独列出它们
OBJECTS=$(patsubst Src/%.cpp,Intermediate/%.o,$(源代码))
全部:$(进度)
清洁:
rm-f中级/*.o箱/*
$(程序):$(对象)
$(LD)$(废话废话)$^-o../$@
$(对象):中间/%.o:Src/%.cpp
$(CC)$(CFLAGS)-I$(包括格尔斯)-c$<$(CLIBS)-o$@
谢谢这正是我需要的。我喜欢makefile(比VisualStudio的vcproj多得多),但它们的设置非常困难(我也喜欢它们,但它们有一些严重的缺点和很长的学习曲线…而且因为我没有实际测试这个,所以有一个bug。请稍等…请指定“make”标记而不是“makefile”。更多信息:嗯,我是这些方面的noob。:P