Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

GNU Make has -B option that forces make to ignore existing targets. It allows to rebuild a target, but it also rebuilds all the dependency tree of the target. I wonder is there a way to force rebuilding a target without rebuilding its dependencies (using GNU Make options, settings in Makefile, compatible make-like software, etc.)?

Illustration of the problem:

$ 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 one can rm small; make small, but is there a built-in way?

like image 397
Kirill Bulygin Avatar asked Feb 09 '17 14:02

Kirill Bulygin


1 Answers

One way is to use the -o option for all targets you don't want to be remade:

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

EDIT

I think you're misreading the documentation for -B; it says:

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

Note, the all targets here; huge is certainly a target, and so if you use -B it will be remade.

However, I also misread your question a bit. I thought you wanted to rebuild small without rebuilding huge even though huge is new, but you're trying to get small to be rebuilt even though huge has not changed, right?

You definitely don't want to use -B. That option is not at all what you are looking for.

Normally people would do that by deleting small:

rm -f small
make small

It might be useful to have an option that forced a given target to be recreated, but that option doesn't exist.

You could use -W huge, but again this means you need to know the name of the prerequisite not just the target you want built.

like image 145
MadScientist Avatar answered Sep 30 '22 06:09

MadScientist