help-make
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Dependencies for clean rule


From: Christian Hujer
Subject: Re: Dependencies for clean rule
Date: Wed, 17 Jul 2019 16:47:21 +0530

Hello Erik,


While I have no direct answer for you, I have a few tips about cleaning.

1. Use double-colon rules.
https://www.gnu.org/software/make/manual/make.html#Double_002dColon
They can be combined, so you could have:
Makefile1:
.PHONY: clean
clean::
$(RM) somefile
-include Makefile2

Makefile2:
.PHONY: clean
clean::
$(RM) someOtherFile

2. Use $(RM) instead of rm
For removing files, use $(RM). It is more portable, and it expands to rm
-f, not just rm.
So you don't have to worry about files that do not exist.

3. Exit Hook + Recursive Make
If cleanup is a MUST, don't provide separate rules.
Instead, use recursive make and a more powerful shell.
For example, if the cleanup is about cleaning up after tests, I use the
following pattern.
In the example, I need a docker container to be started for the test, and I
don't want to keep the container running after the tests.
But that can be anything, replace docker with whatever you want/need in
your context.

export SHELL:=/bin/bash
export SHELLOPTS:=$(if $(SHELLOPTS),$(SHELLOPTS):)pipefail:errexit

.ONESHELL:

.PHONY: test
## Runs all tests.
test:
function tearDown {
    docker stop test-image
}
trap tearDown EXIT
docker run --name test-image …
$(MAKE) testImpl


See also my StackOverflow answer:
https://stackoverflow.com/questions/28597794/how-can-i-clean-up-after-an-error-in-a-makefile/52159940#52159940


Best regards,
Christian



On Tue, Jul 16, 2019 at 1:26 AM Erik Rull <address@hidden> wrote:

> Hi all,
>
> I have several targets that depend on each other.
> For cleaning them up, I have to take care that the clean dependencies are
> just
> the other way round.
>
> e.g.
>
> a: b c
> b: d e
> c:
> d:
> e:
>
> If I want to make a the dependencies assert that the build order is
> correct.
> If I want to make "clean" e.g. c, I should clean a first.
>
> Is there a way to find the "reverse-order" of the dependencies? Of course,
> I
> could manually write the clean-rule-dependencies, but that would be too
> easy
> (and generate additional errors when the number of targets and
> dependencies are
> bigger).
>
> Maybe someone solved that already, I did not yet find a smooth solution
> for that.
>
> Thanks in advance.
>
> Best regards,
>
> Erik
>
> _______________________________________________
> Help-make mailing list
> address@hidden
> https://lists.gnu.org/mailman/listinfo/help-make
>


-- 
Christian Hujer
E: address@hidden
T: @christianhujer
+91 77 2003 6661 (while in India)
+49 162 4124108 (while in Germany)
+44 7871 912444 (while in UK)


reply via email to

[Prev in Thread] Current Thread [Next in Thread]