[Top][All Lists]

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

Re: Lint for Makefiles

From: Christian Hujer
Subject: Re: Lint for Makefiles
Date: Sat, 3 Apr 2021 00:20:31 +0530

Hey Kaz,

thanks for pointing that out.
I was primarily interested in GNU Makefiles only, but it's always good
to have a broader perspective to make the tool more useful for others.

If I'm not mistaken, `$(RM)` doesn't always expand to `rm -f` but to
something else like `delete/nolog` on VMS for example.
See line 457.
So, there are two portability scenarios:
* If the `Makefile` shall be portable to other make implementations,
using `rm -f` directly or having `RM` defined as `RM?=rm -f` is the
* If the `Makefile` is a GNUMakefile that shall run on VMS as well,
`$(RM)` should be used, and a definition.
Both scenarios can be combined.

I take this as feedback to improve the check.
In POSIX mode, the check would only ensure that `rm -f` is used instead of `rm`.
In Portability mode, the check would ensure that `$(RM)` is used
instead of `rm` or `rm -f`.
If both, POSIX and Portability, are asked for, the check would ensure
that `$(RM)` is used and `RM` is defined with a conditional variable

I've put this as an issue on the project:

Thanks again for the feedback.

Best regards,

On Fri, Apr 2, 2021 at 8:57 PM Kaz Kylheku (gmake)
<> wrote:
> On 2021-04-02 00:55, Christian Hujer wrote:
> > Hello everyone.
> >
> > I was looking for a Lint-like tool for Makefiles.
> > The ones I could find either seemed abandoned (like mint) or had a
> > broken build (checkmake) and other fundamental flaws (not operating on
> > included Makefiles).
> > I hope to get some responses on this list here for more tools that
> > people have created.
> > Because I couldn't find one that works for me, I created one.
> >
> > The first two checks implemented are, which isn't much but at least a
> > start:
> > • Report direct usage of `rm` (should use `$(RM)` instead).
> Note that POSIX doesn't specify any RM variable.
> Look for the "Default Rules" section here
> > This one
> > was the reason for writing this tool, a dev had used rm instead of
> > $(RM) in clean, causing it to fail on consecutive runs.
> The actual bug was not using "rm -f". I see that RM gives you that:
>    $ make -p | grep '^RM ='
>    RM = rm -f
> Since this is nonstandard though, it would behoove you to define it
> yourself, or at least weakly with ?=
>    RM ?= rm -f
> Unless you are sure that your Makefile is strictly GNU Make.
> Aliases for common utilities that are quite portable, and are not
> toolchain components don't make a whole lot of sense, IMHO.
> If we are cross-compiling, the build machine's "rm" should work just
> fine for removing something in a build directory, or even target
> sysroot; we have no reason to be putting a cross toolchain prefix
> onto rm or anything like that.
> If it was the case that some versions of "rm" don't have the "-f"
> option (and it is implied), yet other versions of "rm" require
> it, then the abstraction would be valuable.
> But "rm" and "rm -f" are standardized by POSIX, like make itself.
> A Makefile that uses "rm -f ..." in a recipe line can be
> entirely POSIX conforming.

Christian Hujer
Nelkinda Software Craft Pvt Ltd
📧 Christian Hujer | 🐦 @nelkinda | 🌐
☏ 🇮🇳 ✆ +91 77 2003 6661

reply via email to

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