GNU Make 有 -B
选项强制 make
忽略现有目标。它允许重建一个目标,但它也重建目标的所有依赖树。我想知道是否有一种方法可以强制重建目标而不重建其依赖项(使用 GNU Make 选项、Makefile 中的设置、兼容的类似 make
的软件等)?
问题说明:
$ mkdir test; cd test
$ unexpand -t4 >Makefile <<EOF
huge:
@echo "rebuilding huge"; date >huge
small: huge
@echo "rebuilding small"; sh -c 'cat huge; date' >small
EOF
$ make small
rebuilding huge
rebuilding small
$ ls
huge Makefile small
$ make small
make: 'small' is up to date.
$ make -B small
rebuilding huge # how to get rid of this line?
rebuilding small
$ make --version | head -n3
GNU Make 4.0
Built for x86_64-pc-linux-gnu
Copyright (C) 1988-2013 Free Software Foundation, Inc.
当然可以 rm small;变小
,但是有内置的方法吗?
最佳答案
一种方法是对您不想重新制作的所有目标使用 -o
选项:
-o FILE, --old-file=FILE, --assume-old=FILE Consider FILE to be very old and don't remake it.
编辑
我认为您误读了-B
的文档;它说:
-B, --always-make Unconditionally make all targets.
请注意,此处是所有目标; huge
肯定是一个目标,所以如果你使用 -B
它将被重新制作。
但是,我也有点误读了你的问题。我以为你想重建 small
而不是重建 huge
即使 huge
是新的,但你试图得到 small
将被重建,即使 巨大的
没有改变,对吧?
你绝对不想使用-B
。该选项根本不是您要找的。p>
通常人们会通过删除 small
来做到这一点:
rm -f small
make small
强制重新创建给定目标的选项可能很有用,但该选项不存在。
您可以使用 -W huge
,但这同样意味着您需要知道先决条件的名称,而不仅仅是您想要构建的目标。
关于linux - 有没有办法在不重建其依赖项的情况下强制重建目标(make -B)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42139227/