GNU Make有-B
选项,强制忽略现有目标。 它允许重build一个目标,但它也重build目标的所有依赖树。 我不知道有没有办法强制重build目标而不重build它的依赖关系(使用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; make small
rm small; make small
,但有一个内置的方式?
这将有助于:
touch huge; make 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
是新的,但你想尽量变small
,重建,即使huge
变化,对不对?
你绝对不想用-B
。 这个选项根本不是你要找的。
通常情况下,人们会删除small
:
rm -f small make small
有一个选项可以强制给定的目标被重新创建,但这个选项不存在。
你可以使用-W huge
,但这又意味着你需要知道的前提条件的名称,不只是你想要建立的目标。
文件在相当讨厌的黑客:
huge: @echo "rebuilding huge"; date >huge small: $(if $(filter just,${MAKECMDGOALS}),huge) @echo "rebuilding small"; sh -c 'cat huge; date' >small .PHONY: just just: ;
现在你可以
$ make -B just small
我使用这样的东西:
remake() { for f in "$@" do [ -f "$f" ] && rm -f "$f" done make "$@" }
那么,到目前为止我正在使用这个部分的解决方案
$ cat >~/bin/remake <<'EOF' #!/bin/sh # http://stackoverflow.com/questions/42139227 for f in "$@"; do if [ -f "$f" ]; then # Make the file very old; it's safer than removing. touch --date=@0 "$f" fi done make "$@" EOF $ chmod u+x ~/bin/remake $ # PATH="$HOME/bin:$PATH" in .bashrc $ remake --debug=b small GNU Make 4.0 Built for x86_64-pc-linux-gnu Copyright (C) 1988-2013 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Reading makefiles... Updating goal targets.... Prerequisite 'huge' is newer than target 'small'. Must remake target 'small'. rebuilding small