[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Lint for Makefiles
From: |
Kaz Kylheku (gmake) |
Subject: |
Re: Lint for Makefiles |
Date: |
Fri, 02 Apr 2021 08:27:50 -0700 |
User-agent: |
Roundcube Webmail/0.9.2 |
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
https://pubs.opengroup.org/onlinepubs/9699919799/utilities/make.html
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.
- Lint for Makefiles, Christian Hujer, 2021/04/02
- Re: Lint for Makefiles,
Kaz Kylheku (gmake) <=