bug-make
[Top][All Lists]
Advanced

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

Re: make -t and directories


From: Paul Smith
Subject: Re: make -t and directories
Date: Sat, 11 Mar 2023 09:20:37 -0500
User-agent: Evolution 3.46.4 (by Flathub.org)

On Sat, 2023-03-11 at 01:54 +0100, Alejandro Colomar wrote:
> Let's say I have a build tree that has directories which are created
> during build.  The build system has some linters in a `lint` target,
> which touches files when it succeeds.  When I want to lint only a
> specific file, it's interesting to convince make(1) to touch all
> files, and then touch the source file I want to lint; a subsequent
> make(1) invocation will only lint the file I want.

To me that seems like not a good solution.  TBH I've never really
understood the use-case for the -t flag.  But basically what you're
saying here is that you're willing to rebuild your entire source tree
from scratch (because you've touched all the sources) just to run lint
on a specific file you want.  That doesn't seem like a good trade-off
to me.

Why don't you just add a special target for linting a specific file:

    lint-%:
            <lint> $*

and now if you want to run lint on foo.c you'd say "make lint-foo.c"?

> However, that only works if I've created all the directories, so I
> need to run `make -ij lint && make -t lint`.
> 
> How about using `mkdir -p` instead of touch(1) for nonexistent files?
> The effect would be the same, but it would allow such structures to
> work with this feature.  I don't foresee big issues with it (I don't
> imagine that some systems will depend on make -t creating regular
> empty files).

As Dmitry points out, that would be a disaster because lots of tools
will overwrite existing files without any problem, but no tools will
delete an existing directory.

The right way to handle this is to prefix your lines that you want to
be invoked even with -t, with a "+" operator.  That's one of the things
it's for.

>From the GNU Make manual:

https://www.gnu.org/software/make/manual/html_node/Instead-of-Execution.html

> The ‘-n’, ‘-t’, and ‘-q’ options do not affect recipe lines that
> begin with ‘+’ characters or contain the strings ‘$(MAKE)’ or
> ‘${MAKE}’. Note that only the line containing the ‘+’ character or
> the strings ‘$(MAKE)’ or ‘${MAKE}’ is run regardless of these
> options. Other lines in the same rule are not run unless they too
> begin with ‘+’ or contain ‘$(MAKE)’ or ‘${MAKE}’ (See How the MAKE
> Variable Works.)

Your example if you change your mkdir rule to:

  dir:
        +mkdir $@

instead then you get:

  $ make -t
  mkdir dir
  touch dir/file




reply via email to

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