Makefile :在单独的目录树中构建
我的项目(一种解释性语言)有一个由多个文件组成的标准库,每个文件都将构建到一个 .so 动态库中,解释器将根据用户请求(使用导入指令)加载该库。 每个源文件都位于代表其“命名空间”的子目录中,例如:
构建过程必须创建一个“build”目录,然后当每个文件编译时必须在“build”目录中创建其名称空间目录,例如,在编译时,
std/io/network/tcp.cc
他运行 mkdir 命令,
mkdir -p build/std/io/network
Makefile 片段是:
STDSRC=stdlib/std/hashing/md5.cc \
stdlib/std/hashing/crc32.cc \
stdlib/std/hashing/sha1.cc \
stdlib/std/hashing/sha2.cc \
stdlib/std/io/network/http.cc \
stdlib/std/io/network/tcp.cc \
stdlib/std/io/network/smtp.cc \
stdlib/std/io/file.cc \
stdlib/std/io/console.cc \
stdlib/std/io/xml.cc \
stdlib/std/type/reflection.cc \
stdlib/std/type/string.cc \
stdlib/std/type/matrix.cc \
stdlib/std/type/array.cc \
stdlib/std/type/map.cc \
stdlib/std/type/type.cc \
stdlib/std/type/binary.cc \
stdlib/std/encoding.cc \
stdlib/std/os/dll.cc \
stdlib/std/os/time.cc \
stdlib/std/os/threads.cc \
stdlib/std/os/process.cc \
stdlib/std/pcre.cc \
stdlib/std/math.cc
STDOBJ=$(STDSRC:.cc=.so)
all: stdlib
stdlib: $(STDOBJ)
.cc.so:
mkdir -p `dirname $< | sed -e 's/stdlib/stdlib\/build/'`
$(CXX) $< -o `dirname $< | sed -e 's/stdlib/stdlib\/build/'`/`basename $< .cc`.so $(CFLAGS) $(LDFLAGS)
我有两个问题:
1 - 问题是 make 命令,我真的不知道为什么,不会检查文件是否被修改,并且无论如何都会在所有文件上启动构建过程,所以如果我只需要构建一个文件,我必须全部构建它们或使用命令:
make path/to/single/file.so
有什么方法可以解决这个问题吗?
2 - 有什么方法可以以“更干净”的方式做到这一点,而不必分发所有带有源代码的构建目录?
谢谢
My project (an interpreted language) has a standard library composed by multiple files, each of them will be built into an .so dynamic library that the interpreter will load upon user request (with an import directive).
Each source file is located into a subdirectory representing its "namespace", for instance :
The build process has to create a "build" directory, then when each file is compiling has to create its namespace directory inside the "build" one, for instance, when compiling
std/io/network/tcp.cc
he run an mkdir command with
mkdir -p build/std/io/network
The Makefile snippet is :
STDSRC=stdlib/std/hashing/md5.cc \
stdlib/std/hashing/crc32.cc \
stdlib/std/hashing/sha1.cc \
stdlib/std/hashing/sha2.cc \
stdlib/std/io/network/http.cc \
stdlib/std/io/network/tcp.cc \
stdlib/std/io/network/smtp.cc \
stdlib/std/io/file.cc \
stdlib/std/io/console.cc \
stdlib/std/io/xml.cc \
stdlib/std/type/reflection.cc \
stdlib/std/type/string.cc \
stdlib/std/type/matrix.cc \
stdlib/std/type/array.cc \
stdlib/std/type/map.cc \
stdlib/std/type/type.cc \
stdlib/std/type/binary.cc \
stdlib/std/encoding.cc \
stdlib/std/os/dll.cc \
stdlib/std/os/time.cc \
stdlib/std/os/threads.cc \
stdlib/std/os/process.cc \
stdlib/std/pcre.cc \
stdlib/std/math.cc
STDOBJ=$(STDSRC:.cc=.so)
all: stdlib
stdlib: $(STDOBJ)
.cc.so:
mkdir -p `dirname lt; | sed -e 's/stdlib/stdlib\/build/'`
$(CXX) lt; -o `dirname lt; | sed -e 's/stdlib/stdlib\/build/'`/`basename lt; .cc`.so $(CFLAGS) $(LDFLAGS)
I have two questions :
1 - The problem is that the make command, i really don't know why, doesn't check if a file was modified and launch the build process on ALL the files no matter what, so if i need to build only one file, i have to build them all or use the command :
make path/to/single/file.so
Is there any way to solve this?
2 - Any way to do this in a "cleaner" way without have to distribute all the build directories with sources?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对于1),问题是规则的目标(stdlib/something.so)并不完全是规则所创建的(build/something.so),因此Make始终认为它必须创建目标。这应该可以解决它(我正在使用 GNUMake):
对于 2)我不确定你的意思。如果您想要您描述的构建目录结构,这就可以了。
For 1) the problem is that the target of your rule (stdlib/something.so) is not exactly what the rule makes (build/something.so), so Make always thinks it must make the target. This should fix it (I am using GNUMake):
For 2) I'm not sure what you mean. If you want the build directory structure you describe, this will do it.