title: Building Makefile using bazel
body: <p>I am trying to build Makefile of a submodule in a bazel project. I see that bazel does provide genrule to execute bash command. I am facing two issues currently -</p>
  
  <p><strong>1. How to cd into a directory before executing command, something like -</strong></p>
  
  <pre><code>genrule(
      name = "hello-make",
      srcs = ["hello"] + glob(["hello/**"]),
      outs = ["hello/main"],
      cmd = "(cd $(location :hello) &amp;&amp; make)",
  )
  </code></pre>
  
  <p><strong>2. How do I update update submodule before executing genrule?</strong> </p>
  
  <p>Adding <code>cmd = "(git submodule init &amp;&amp; git submodule update)"</code> gives <code>fatal: Not a git repository (or any of the parent directories): .git</code></p>
  
  <p>Step to reproduce:</p>
  
  <ol>
  <li><code>git clone git@github.com:bazelbuild/examples.git</code></li>
  <li><code>cd examples/ &amp;&amp; git submodule add git@github.com:mucsi96/cpp-hello-world.git cpp-tutorial/stage1/main/hello</code></li>
  <li><code>cd cpp-tutorial/stage1/ &amp;&amp;  bazel build //main:hello-world</code></li>
  </ol>
  
  <p>After this step I want to add a rule that allows me init, update and make the hello submodule.</p>
  
  <p>Is there a better way to build <code>git@github.com:mucsi96/cpp-hello-world.git</code> than creating it as a submodule of <code>git clone git@github.com:bazelbuild/examples.git</code>?</p>
  
  <p>The actual projects are more complex and creating a BUILD file for cpp-hello-world.git is not feasible.</p>