[bug #59243] Overcomplicated example of automatic dependency configuration

2020-10-09 Thread Paul D. Smith
Follow-up Comment #2, bug #59243 (project make):

Regarding rm: this is needed in case the .d file is not writable for some
reason.

As mentioned by Martin, the suggested replacement -MM doesn't work for all
compilers.

I do agree that this code is still too obscure.

Really this entire section should be rewritten to include the "modern" method
of dependency tracking, described here:
http://make.mad-scientist.net/papers/advanced-auto-dependency-generation/

It does lose us our big example for the usefulness of rebuilding included
makefiles though :)

___

Reply to this item at:

  

___
  Message sent via Savannah
  https://savannah.gnu.org/




[bug #59243] Overcomplicated example of automatic dependency configuration

2020-10-09 Thread Martin Dorey
Follow-up Comment #1, bug #59243 (project make):

Given set -o pipefail isn't on by default even where supported, the OP
neglects the benefit of set -e in preventing the existing dependency file from
being truncated to empty if something goes wrong with the compiler step.  Even
the original example does not meet my standard for being production quality
because it doesn't take into account what happens if two builds run at the
same time or the user hits Ctrl-C after the truncation but before the sed. 
Scrambled, and particularly truncated, dependency files stop later rebuilds
from being triggered when they should be, leading to hours of frustrating
debugging, lost trust in the build system and a culture of wasting time with
"make clean" and rebuilds.  Atomic replacement with mv FTW.

Finding the example in context, at
https://www.gnu.org/software/make/manual/make.html#Automatic-Prerequisites, I
see there is already prose discussing the set -e, explaining the cryptic sed,
and suggesting the -MM change that the OP slipped in.  I too might have
plunged in and spent minutes trying to understand it, only to kick myself when
I spotted the explanation later.  With its two code snippets, the explanation
is too large to have before the example.  I don't see a case to answer here.

___

Reply to this item at:

  

___
  Message sent via Savannah
  https://savannah.gnu.org/




[bug #59243] Overcomplicated example of automatic dependency configuration

2020-10-09 Thread anonymous
URL:
  

 Summary: Overcomplicated example of automatic dependency
configuration
 Project: make
Submitted by: None
Submitted on: Fri 09 Oct 2020 03:49:50 PM UTC
Severity: 3 - Normal
  Item Group: Documentation
  Status: None
 Privacy: Public
 Assigned to: None
 Open/Closed: Open
 Discussion Lock: Any
   Component Version: None
Operating System: None
   Fixed Release: None
   Triage Status: None

___

Details:

In section 4.14, the example of the pattern rule is unnecessarily
complicated:

%.d: %.c
@set -e; rm -f $@; \
 $(CC) -M $(CPPFLAGS) $< > $@.; \
 sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@. > $@; \
 rm -f $@.

The first rm command is redundant as redirecting the output of the sed command
with ">" will replace it anyway. Instead of creating another temporary file
with "$@.", one can simply pipe the preprocessor output to sed input,
making the second rm unnecessary as well. If a file must be created for some
reason, why confuse beginners with "$@." instead of just "$@.temp". The
sed is also overengineered as is.

This example provides the same functionality:

%.d: %.c
@printf "$@ " > $@
@$(CC) $(CPPFLAGS) -MM $< >> $@

However, instead of spending 30 minutes to understand it, the developer only
needs 5, as this example would be much clearer.




___

Reply to this item at:

  

___
  Message sent via Savannah
  https://savannah.gnu.org/