如何在不放置任何物理依赖关系的情况下指定Makefile目标构建顺序? [英] How to specify Makefile target building order without put any physical dependencies?

查看:112
本文介绍了如何在不放置任何物理依赖关系的情况下指定Makefile目标构建顺序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在研究一个链接到.so(动态库)文件的C ++项目. 假设我有一个目标PROG,它需要链接到a.so,并且a.so也由我构建,在以下Makefile中指定.

I have been working on a C++ project that links to a .so(dynamic library) file. Let's assume that I have a target PROG which needs to link to a.so, and a.so is also built by me, specified in the following Makefile.

PROG_SRCS = prog.cpp
PROG_OBJS = $(PROG_SRCS: %.cpp:%.o)

all: PROG
PROG: $(PROG_OBJS) liba.so
    $(LINK.cpp) -o $@ $(PROG_OBJS) -la

LIBA_SRCS = liba/a.cpp
LIBA_OBJS = $(LIBA_SRCS: %.cpp:%.o)

liba.so: $(LIBA_OBJS)
    $(LINK.cpp) -shared -Wl.-soname,$@ -o $@ $^

我已经使用自动依赖性生成来使.cpp文件获得它们自己的依赖性 .h文件.而且prog.cpp包含a.h.

I have used auto-dependency-generation to get the .cpp files get their own dependency on the .h files. And prog.cpp includes a.h.

但是通过这种方式,一旦我更改了a.cpp,liba.so将被重制,那么PROG将成为 remake(relink),这不是我想要的.我只是更改liba.so的实现, 但没有任何接口定义.在更改a.h之后,PROG应该重新制作.

But by this way, once I change a.cpp, liba.so would be remake, then PROG would be remake(relink), which is not what I want. I just change the implementation of liba.so, but not any interface definitions. PROG should just remake after I change a.h.

我希望a.so应该在PROG构建之前就构建,但是a.so的更改不会导致PROG的构建.

I want to make that a.so should be built before PROG is built, but the changes of a.so would not incur the building of PROG.

下面的Makefile是我想出的方法,但有一点副作用 (生成一个临时文件).

The following Makefile is the method I figured out, but with a slightly side-effect (generate a temporary file).

ORDER = /tmp/.ORDER

all: PROG
PROG: $(PROG_OBJS) $(ORDER)
    $(LINK.cpp) -shared -Wl,-soname,$@ -o $@ $(PROG_OBJS) -la

$(ORDER): liba.so
    test -e $@ || touch $@

这样,每次liba.so重新制作时,$(ORDER)也会重新制作.但这只是感动 该文件(如果不存在).

In this way, every time liba.so gets remake, $(ORDER) gets remake too. But it only touch the file if it doesn't exist.

有没有办法指定这种依赖性而没有任何副作用,例如创建一个tmp文件.

Is there any way to specify this kind of dependency without any side-effect, e.g. creating a tmp file.

推荐答案

如果您愿意依赖GNU make的非便携式方面,则可以使用仅订购的先决条件

If you're willing to rely on non-portable aspects of GNU make, you can use order-only prerequisites order-only prerequisites for this. That's the only way to do it other than the stamp file method you've already discovered.

这篇关于如何在不放置任何物理依赖关系的情况下指定Makefile目标构建顺序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆