Is there a way to forcefully restore a target (make -B) without rebuilding its dependencies?

GNU Make has the -B , which causes make ignore existing targets. It allows you to restore the target, but also restores the entire dependency tree of the target. I wonder if there is a way to forcefully restore a target without rebuilding its dependencies (using the GNU Make options, settings in the Makefile, compatible make software, etc.)?

Problem Illustration:

 $ 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. 

Of course you can rm small; make small rm small; make small , but is there a built-in way?

+5
source share
5 answers

One way is to use the -o option for all purposes that you do not want to redo:

 -o FILE, --old-file=FILE, --assume-old=FILE Consider FILE to be very old and don't remake it. 

EDIT

I think you are reading the documentation for -B incorrectly; He says:

  -B, --always-make Unconditionally make all targets. 

Please note that all goals are here; huge is definitely the goal, so if you use -B it will be redone.

However, I am also reading your question incorrectly. I thought you want to rebuild small without restoring huge , although huge is new, but you are trying to restore small even if huge not changed, right?

You definitely do not want to use -B . This option is not at all what you are looking for.

Usually people do this by removing small :

 rm -f small make small 

It might be useful to have a parameter that made this target recreate, but this option does not exist.

You can use -W huge , but again, this means that you need to know the name of the premise, not just the goal you want to create.

+3
source

Will this help:

 touch huge; make small 

?

+3
source

File under a rather nasty hack:

 huge: @echo "rebuilding huge"; date >huge small: $(if $(filter just,${MAKECMDGOALS}),huge) @echo "rebuilding small"; sh -c 'cat huge; date' >small .PHONY: just just: ; 

Now you can

 $ make -B just small 
+2
source

Ok, so far I am using this partial solution:

 $ 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 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 
0
source

I am using something like this:

 remake() { for f in " $@ " do [ -f "$f" ] && rm -f "$f" done make " $@ " } 
0
source

Source: https://habr.com/ru/post/1264023/


All Articles