mozilla

Revision 78835 of Makefiles - Best practices and suggestions

  • Revision slug: How_Mozilla's_build_system_works/Makefiles_-_Best_practices_and_suggestions
  • Revision title: Makefiles - Best practices and suggestions
  • Revision id: 78835
  • Created:
  • Creator: Joey Armstrong
  • Is current revision? No
  • Comment 20 words added, 5 words removed

Revision Content

  • Always include dependencies when creating a target
    • Initial make call should always be the workhorse: build, generate, deploy, install, etc.
    • All subsequent make calls must become a NOP unless sources or dependencies change or have been removed.
    • Incorrect dependencies will contribute to wasted cycles and can contribute to circular dependencies.
  • Directory dependencies
    • Do not use directories as a dependency for generated targets.  Any activity within a directory will alter inodes forcing targets to always be stale.
    • Parallel make: include a .done timestamp dependency to synchronize threaded calls on directory creation.
# Transient directory for storing timestamps
TS=.ts

#####################################################
## Extra dep needed to synchronize parallel execution
#####################################################
$(TS): $(TS)/.done
$(TS)/.done:
  
$(MKDIR) -p $(dir $@)
  
touch $@

GARBAGE_DIRS += $(TS)

 

  • Wrapper check/unit tests with a ENABLE_TESTS conditional so tests can be disabled on demand.
ifdef ENABLE_TESTS 
ifeq ($(NULL),$(filter WINNT OS2,$(OS_ARCH)))
DIRS += test
endif # WIN
endif # ENABLE_TESTS > >

Revision Source

<ul> <li>Always include dependencies when creating a target <ul> <li>Initial make call should always be the workhorse: build, generate, deploy, install, etc.</li> <li>All subsequent make calls must become a NOP unless sources or dependencies change or have been removed.</li> <li>Incorrect dependencies will contribute to wasted cycles and can contribute to circular dependencies.</li> </ul> </li> <li>Directory dependencies <ul> <li>Do not use directories as a dependency for generated targets.  Any activity within a directory will alter inodes forcing targets to always be stale.</li> <li>Parallel make: include a .done timestamp dependency to synchronize threaded calls on directory creation.</li> </ul> </li>
</ul>
<pre><span style="color:#008800;"># Transient directory for storing timestamps<br>TS=.ts<br><br>#####################################################<br></span><span style="color:#008800;">## Extra dep needed to synchronize parallel execution<br></span><span style="color:#008800;">#####################################################<br></span><span style="color:#008800;">$(TS): $(TS)/.done<br></span><span style="color:#008800;">$(TS)/.done:<br>  </span><span style="color:#008800;">$(MKDIR) -p $(dir $@)<br>  </span><span style="color:#008800;">touch $@ <br><br>GARBAGE_DIRS += $(TS)<br></span></pre>
<p> </p>
<ul> <li>Wrapper check/unit tests with a ENABLE_TESTS conditional so tests can be disabled on demand.</li>
</ul>
<pre class="bz_comment_text" id="comment_text_6"><span class="quote">ifdef ENABLE_TESTS <br>    ifeq ($(NULL),$(filter WINNT OS2,$(OS_ARCH)))<br>        DIRS += test <br>    endif # WIN<br>endif # ENABLE_TESTS &gt; &gt; </span>
</pre>
Revert to this revision