title: make clean failed in windows
body: <p>I want to use mingw to compile my C language project.</p>
  <p>I found the command of <code>make all</code> succeeded, however <code>make clean</code> failed.  There are only two files in my test project: <code>test.c</code> and <code>Makefile.mak</code>.</p>
  <p><code>test.c</code>:</p>
  <pre><code>#include &lt;stdio.h&gt;
  
  int main()
  {
      printf(&quot;Hello world\n&quot;);
      while (1);
  
      return 0;
  }
  </code></pre>
  <p><code>Makefile.mak</code>:</p>
  <pre><code>all: test.o
      gcc test.o -o test.exe
  
  test.o: test.c
      gcc -c test.c
  
  clean:
      @echo &quot;clean project&quot;
      -rm test *.o
      @echo &quot;clean completed&quot;
  .PHONY: clean
  </code></pre>
  <p>When I ran <code>make all -f Makefile.mak</code>, it succeeded and generated the expected <code>test.exe</code>, and I also can run the executable. However, when I run <code>make clean -f Makefile.mak</code>, it failed, the error is:</p>
  <pre><code>&quot;clean project&quot;
  rm test *.o
  process_begin: CreateProcess(NULL, rm test *.o, ...) failed.
  make (e=2):
  Makefile.mak:8: recipe for target 'clean' failed
  make: [clean] Error 2 (ignored)
  &quot;clean completed&quot;
  </code></pre>
  <p><a href="https://i.stack.imgur.com/PgKa5.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/PgKa5.jpg" alt="" /></a></p>
  <p>Why?</p>
  <p><strong>EDIT:</strong></p>
  <p>The following link enlightened me:
  <a href="https://stackoverflow.com/questions/19928965/mingw-makefile-with-or-without-msys-del-vs-rm">MinGW makefile with or without MSYS (del vs rm)</a></p>
  <ol>
  <li>I added the workaround code mentioned in the above link in my <code>makefile</code>:</li>
  </ol>
  <pre><code>ifeq ($(OS),Windows_NT) 
  RM = del /Q /F
  CP = copy /Y
  ifdef ComSpec
  SHELL := $(ComSpec)
  endif
  ifdef COMSPEC
  SHELL := $(COMSPEC)
  endif
  else
  RM = rm -rf
  CP = cp -f
  endif
  
  all: test.o
      gcc test.o -o test.exe
  
  test.o: test.c
      gcc -c test.c
  
  clean:
      @echo &quot;clean project&quot;
      -$(RM) test.exe *.o
      @echo &quot;clean completed&quot;
  .PHONY: clean
  </code></pre>
  <p>It works:</p>
  <pre><code>&quot;clean project&quot;
  del /Q /F test.exe *.o
  &quot;clean completed&quot;
  </code></pre>
  <ol start="2">
  <li>This reminds me that it may be because current environment doesn't support <code>rm</code> command, so I add my <code>msys</code> install path into environment path, then it works:</li>
  </ol>
  <pre><code>clean project
  rm test.exe *.o
  clean completed
  </code></pre>