Makefiles:从一个目录获取.cpp,并将编译后的.o放在另一个目录中

发布于 2024-08-10 22:07:48 字数 1361 浏览 4 评论 0原文

我正在开发适用于移动设备(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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

左耳近心 2024-08-17 22:07:48

有不止一种方法可以做到这一点,但最简单的方法是在 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 
lt; $(CLIBS) -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 
lt $(CLIBS) -o $@
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文