title: sed -i command for in-place editing to work with both GNU sed and BSD/OSX
body: <p>I've got a makefile (developed for <code>gmake</code> on Linux) that I'm attempting to port to MacOS, but it seems like <code>sed</code> doesn't want to cooperate. What I do is use <code>GCC</code> to autogenerate dependency files, and then tweak them a bit using <code>sed</code>. The relevant portion of the <code>makefile</code>:</p>
  
  <pre class="lang-bash prettyprint-override"><code>$(OBJ_DIR)/%.d: $(SRC_DIR)/%.cpp
    $(CPPC) -MM -MD $&lt; -o $@
    sed -i 's|\(.*\)\.o:|$(OBJ_DIR)/\1.o $(OBJ_DIR)/\1.d $(TEST_OBJ_DIR)/\1_utest.o:|' $@
  </code></pre>
  
  <p>While this runs with no trouble under GNU/Linux, I get errors like the following when attempting to build on MacOS:</p>
  
  <pre class="lang-bash prettyprint-override"><code>sed: 1: "test/obj/equipmentConta ...": undefined label 'est/obj/equipmentContainer_utest.d'
  sed: 1: "test/obj/dice_utest.d": undefined label 'est/obj/dice_utest.d'
  sed: 1: "test/obj/color-string_u ...": undefined label 'est/obj/color-string_utest.d'
  </code></pre>
  
  <p>It would seem like <code>sed</code> is chopping off a character, but I can't see the solution.</p>