Fix depfile detection for autotools
diff --git a/ninja.go b/ninja.go
index c255ef7..b678c23 100644
--- a/ninja.go
+++ b/ninja.go
@@ -81,6 +81,17 @@
 		return r, err
 	}
 
+	// A hack for Makefiles generated by automake.
+	mvCmd := "(mv -f " + r + " "
+	if i := strings.LastIndex(ss, mvCmd); i >= 0 {
+		rest := ss[i+len(mvCmd):]
+		ei := strings.IndexByte(rest, ')')
+		if ei < 0 {
+			panic(ss)
+		}
+		return rest[:ei], nil
+	}
+
 	// A hack for Android to get .P files instead of .d.
 	p := stripExt(r) + ".P"
 	if strings.Contains(ss, p) {
diff --git a/ninja_test.go b/ninja_test.go
index b9898df..ef03b97 100644
--- a/ninja_test.go
+++ b/ninja_test.go
@@ -115,6 +115,14 @@
 			in:   `gcc -c foo.P.c`,
 			want: ``,
 		},
+		{
+			in:   `(/bin/sh ./libtool  --tag=CXX   --mode=compile g++ -DHAVE_CONFIG_H -I. -I./src -I./src     -Wall -Wwrite-strings -Woverloaded-virtual -Wno-sign-compare  -DNO_FRAME_POINTER  -DNDEBUG -g -O2 -MT libglog_la-logging.lo -MD -MP -MF .deps/libglog_la-logging.Tpo -c -o libglog_la-logging.lo ` + "`" + `test -f 'src/logging.cc' || echo './'` + "`" + `src/logging.cc) && (mv -f .deps/libglog_la-logging.Tpo .deps/libglog_la-logging.Plo)`,
+			want: `.deps/libglog_la-logging.Plo`,
+		},
+		{
+			in:   `(g++ -DHAVE_CONFIG_H -I. -I./src  -I./src  -pthread     -Wall -Wwrite-strings -Woverloaded-virtual -Wno-sign-compare  -DNO_FRAME_POINTER  -g -O2 -MT signalhandler_unittest-signalhandler_unittest.o -MD -MP -MF .deps/signalhandler_unittest-signalhandler_unittest.Tpo -c -o signalhandler_unittest-signalhandler_unittest.o ` + "`" + `test -f 'src/signalhandler_unittest.cc' || echo './'` + "`" + `src/signalhandler_unittest.cc) && (mv -f .deps/signalhandler_unittest-signalhandler_unittest.Tpo .deps/signalhandler_unittest-signalhandler_unittest.Po)`,
+			want: `.deps/signalhandler_unittest-signalhandler_unittest.Po`,
+		},
 	} {
 		got, err := getDepfile(tc.in)
 		if got != tc.want {