<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <meta content="text/html; charset=ISO-8859-1"
      http-equiv="Content-Type">
  </head>
  <body bgcolor="#ffffff" text="#000000">
    Yes, but only when setting MAKEFLAGS from within a Makefile.&nbsp; It
    appears the rules do not apply when MAKEFLAGS is set by the invoking
    shell.&nbsp; (And actually, current GNU make handles parallel execution
    differently on Linux, using a job server that all make subprocesses
    use to coordinate execution -- the documentation below is from
    1998.)<br>
    <br>
    If you still don't believe :)&nbsp; try putting the following in a
    Makefile and running MAKEFLAGS=j3 make<br>
    <br>
    all: r1 r2 r3<br>
    r1 r2 r3:<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; echo rule $@; sleep 5<br>
    <br>
    -Mike<br>
    <br>
    On 09/09/2011 02:55 PM, Jean-Christophe Fillion-Robin wrote:
    <blockquote
cite="mid:CANLz8R6vTqK3MwS8eNHgMr0SPbZ143ZBd3iMMjecC4orB3Y_5g@mail.gmail.com"
      type="cite">Reading through make documentation, seems setting -jx
      to MAKEFLAGS is a no-op.<br>
      <br>
      <i>"The <samp>`-j'</samp> option is a special case (see section <a
          moz-do-not-send="true"
href="http://theory.uwinnipeg.ca/localfiles/infofiles/make/make_47.html#SEC46">Parallel
          Execution</a>).
        If you set it to some numeric value, <samp>`-j 1'</samp> is
        always put into
        <code>MAKEFLAGS</code> instead of the value you specified. This
        is because if
        the <samp>`-j'</samp> option were passed down to sub-<code>make</code>s,
        you would
        get many more jobs running in parallel than you asked for. If
        you give
        <samp>`-j'</samp> with no numeric argument, meaning to run as
        many jobs as
        possible in parallel, this is passed down, since multiple
        infinities are
        no more than one.
        "</i><br>
      <br>
      Source: <a moz-do-not-send="true"
        href="http://theory.uwinnipeg.ca/localfiles/infofiles/make/make_53.html">http://theory.uwinnipeg.ca/localfiles/infofiles/make/make_53.html</a><br>
      <br>
      Jc<br>
      <br>
      <div class="gmail_quote">On Fri, Sep 9, 2011 at 3:37 PM, Mike
        Wittman <span dir="ltr">&lt;<a moz-do-not-send="true"
            href="mailto:michael.wittman@headwave.com">michael.wittman@headwave.com</a>&gt;</span>
        wrote:<br>
        <blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt
          0.8ex; border-left: 1px solid rgb(204, 204, 204);
          padding-left: 1ex;">
          <div bgcolor="#ffffff" text="#000000"> If you are building on
            Linux, try<br>
            &nbsp;&nbsp;&nbsp; MAKEFLAGS=j8 make distcheck<br>
            <br>
            I have successfully used the MAKEFLAGS environment variable
            to propagate parallel build invocations through scripts that
            invoke make with fixed options.<br>
            <br>
            -Mike
            <div>
              <div class="h5"><br>
                <br>
                On 09/09/2011 09:21 AM, Clifford Yapp wrote: </div>
            </div>
            <blockquote type="cite">
              <div>
                <div class="h5">I can finally give a good concrete case
                  where I might need to do this (or need some other very
                  clever solution).<br>
                  <br>
                  I have created a distcheck command for BRL-CAD that
                  has a lot of responsibilities, including doing a
                  complete configure and build of BRL-CAD from a source
                  archive expanded from a CPack tarball.&nbsp; The distcheck
                  rule uses cmake to fire off the build (this is to try
                  and be future proof against using other tools than
                  Make to do a distcheck) but I need to pass the
                  parallel build setting -j from Make down to the
                  ${CMAKE_COMMAND} build launched by the distcheck rule,
                  and there doesn't seem to be any way to do it.<br>
                  <br>
                  This is the subset of the distcheck rule (somewhat
                  edited for clarity):<br>
                  <br>
                  &nbsp;&nbsp; ADD_CUSTOM_TARGET(distcheck<br>
                  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; COMMAND ${CMAKE_COMMAND} -E echo "Stage 1:&nbsp;
                  Create source tgz, tbz2 and zip archives from toplevel
                  archive."<br>
                  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; COMMAND cpack --config
                  ${CMAKE_CURRENT_BINARY_DIR}/CPackSourceConfig.cmake<br>
                  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; COMMAND ${CMAKE_COMMAND} -E echo "Stage 2:&nbsp;
                  Expand tgz archive and prepare to build from archive
                  sources."<br>
                  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; COMMAND ${CMAKE_COMMAND} -E tar xvzf
                  ${CPACK_SOURCE_PACKAGE_FILE_NAME}.tar.gz<br>
                  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; COMMAND ${CMAKE_COMMAND} -E make_directory
                  _${CPACK_SOURCE_PACKAGE_FILE_NAME}-build<br>
                  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; COMMAND ${CMAKE_COMMAND} -E make_directory
                  _${CPACK_SOURCE_PACKAGE_FILE_NAME}-install<br>
                  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; COMMAND ${CMAKE_COMMAND} -E chdir
                  _${CPACK_SOURCE_PACKAGE_FILE_NAME}-build
                  ${CMAKE_COMMAND} ../${CPACK_SOURCE_PACKAGE_FILE_NAME}
-DCMAKE_INSTALL_PREFIX=${CMAKE_CURRENT_BINARY_DIR}/_${CPACK_SOURCE_PACKAGE_FILE_NAME}-install<br>
                  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; COMMAND ${CMAKE_COMMAND} -E echo "Stage 3:&nbsp;
                  Compile using source from tgz archive."<br>
                  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; COMMAND ${CMAKE_COMMAND} --build
                  _${CPACK_SOURCE_PACKAGE_FILE_NAME}-build<br>
                  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; )<br>
                  <br>
                  This can be successfully fired off by "make
                  distcheck", which is the desired behavior.&nbsp; However,
                  the --build option doesn't respect (naturally) any -jN
                  options fed to make, since they aren't specified at
                  CMake time when the distcheck Makefile target is being
                  generated.&nbsp; <br>
                  <br>
                  Perversely enough, if I'm understanding the issue
                  correctly I won't be able to use the -jN value itself
                  in any case, even if the Makefile can be taught to do
                  something smart: <a moz-do-not-send="true"
href="http://old.nabble.com/MAKEFLAGS-var-does-not-show-%22-j%22-param-----td15983337.html"
                    target="_blank">http://old.nabble.com/MAKEFLAGS-var-does-not-show-%22-j%22-param-----td15983337.html</a><br>
                  <br>
                  The best idea I can come up with so far is for the
                  CMake generated Makefile to write out a variable
                  containing some CPU related variable (e.g. make CPUS=8
                  and write the value of $(CPUS) to
                  CMakeFiles/make_cpu_flag or some such) and then
                  convert the distcheck commands above into a series of
                  EXECUTE_PROCESS lines in a rundistcheck.cmake file
                  that is launched by the distcheck rule with a
                  ${CMAKE_COMMAND}.&nbsp; In rundistcheck.cmake, I can check
                  for the presence of the make_cpu_flag file and if
                  found add the -j parallel flag to the --build line
                  before running it.&nbsp; That will mean a parallel
                  distcheck will have to use a different make syntax
                  than the standard make -j, but at least it would be
                  something.&nbsp; Unfortunately, that means I still need the
                  Makefile to let me know what was passed in up front,
                  which means tweaking the CMake generated output
                  somehow (not really sure how yet).<br>
                  <br>
                  Does anybody else have a mechanism for passing
                  parallel build instructions from make down to child
                  ${CMAKE_COMMAND} --build instances?<br>
                  <br>
                  Cheers,<br>
                  CY<br>
                  <br>
                  <br>
                  <div class="gmail_quote">On Wed, Feb 2, 2011 at 4:32
                    PM, Michael Hertling <span dir="ltr">&lt;<a
                        moz-do-not-send="true"
                        href="mailto:mhertling@online.de"
                        target="_blank">mhertling@online.de</a>&gt;</span>
                    wrote:<br>
                    <blockquote class="gmail_quote" style="margin: 0pt
                      0pt 0pt 0.8ex; border-left: 1px solid rgb(204,
                      204, 204); padding-left: 1ex;">
                      <div>
                        <div>On 02/02/2011 03:34 PM, Clifford Yapp
                          wrote:<br>
                          &gt; Is there any way to customize the
                          Makefile output from CMake to<br>
                          &gt; include user-defined lines (say,
                          something like "#include<br>
                          &gt; Makefile.inc") at the end of each Make
                          file?<br>
                        </div>
                      </div>
                    </blockquote>
                    <div><br>
                      &nbsp;[snip]<br>
                      &nbsp;</div>
                    <blockquote class="gmail_quote" style="margin: 0pt
                      0pt 0pt 0.8ex; border-left: 1px solid rgb(204,
                      204, 204); padding-left: 1ex;">However, this
                      approach is neither portable nor clean<br>
                      nor &lt;your-expectation-here&gt;, so I would ask
                      Eric's questions, too. ;)<br>
                      <br>
                      Regards,<br>
                      <br>
                      Michael<br>
                    </blockquote>
                  </div>
                  <br>
                </div>
              </div>
              <pre><fieldset></fieldset>
_______________________________________________
Powered by <a moz-do-not-send="true" href="http://www.kitware.com" target="_blank">www.kitware.com</a><div class="im">

Visit other Kitware open-source projects at <a moz-do-not-send="true" href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a>

Please keep messages on-topic and check the CMake FAQ at: <a moz-do-not-send="true" href="http://www.cmake.org/Wiki/CMake_FAQ" target="_blank">http://www.cmake.org/Wiki/CMake_FAQ</a>

Follow this link to subscribe/unsubscribe:
<a moz-do-not-send="true" href="http://www.cmake.org/mailman/listinfo/cmake" target="_blank">http://www.cmake.org/mailman/listinfo/cmake</a></div></pre>
            </blockquote>
            <br>
          </div>
          <br>
          _______________________________________________<br>
          Powered by <a moz-do-not-send="true"
            href="http://www.kitware.com" target="_blank">www.kitware.com</a><br>
          <br>
          Visit other Kitware open-source projects at <a
            moz-do-not-send="true"
            href="http://www.kitware.com/opensource/opensource.html"
            target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
          <br>
          Please keep messages on-topic and check the CMake FAQ at: <a
            moz-do-not-send="true"
            href="http://www.cmake.org/Wiki/CMake_FAQ" target="_blank">http://www.cmake.org/Wiki/CMake_FAQ</a><br>
          <br>
          Follow this link to subscribe/unsubscribe:<br>
          <a moz-do-not-send="true"
            href="http://www.cmake.org/mailman/listinfo/cmake"
            target="_blank">http://www.cmake.org/mailman/listinfo/cmake</a><br>
        </blockquote>
      </div>
      <br>
      <br clear="all">
      <br>
      -- <br>
      +1 919 869 8849<br>
      <br>
    </blockquote>
    <br>
  </body>
</html>