THRIFT-4717: fix up make clean with autoconf
diff --git a/test/Makefile.am b/test/Makefile.am
index 68f1986..84f1f25 100755
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -108,25 +108,32 @@
 	$(top_builddir)/compiler/cpp/thrift --gen html -r $(top_srcdir)/test/ThriftTest.thrift
 
 clean-local:
-	rm -rf $(top_srcdir)/test/gen-html
+	$(RM) -r $(top_srcdir)/test/gen-html/
+	find . -type d -name "__pycache__" | xargs rm -rf
+	find . -type f -name "*.pyc" | xargs rm -f
+
+dist-hook:
+	$(RM) -r $(distdir)/gen-html/
+	find $(distdir) -type d -name "__pycache__" | xargs rm -rf
+	find $(distdir) -type f -name "*.pyc" | xargs rm -f
 
 EXTRA_DIST = \
 	audit \
-	crossrunner \
-	keys \
 	c_glib \
 	cl \
 	cpp \
+	crossrunner \
 	dart \
 	erl \
 	hs \
+	keys \
 	lua \
 	ocaml \
 	perl \
 	php \
 	py \
-	py.twisted \
 	py.tornado \
+	py.twisted \
 	rb \
 	rs \
 	threads \
@@ -134,12 +141,14 @@
 	BrokenConstants.thrift \
 	ConstantsDemo.thrift \
 	DebugProtoTest.thrift \
-	DoubleConstantsTest.thrift \
 	DenseLinkingTest.thrift \
 	DocTest.thrift \
+	DoubleConstantsTest.thrift \
+	EnumContainersTest.thrift \
 	EnumTest.thrift \
 	FullCamelTest.thrift \
 	Include.thrift \
+	Int64Test.thrift \
 	JavaBeansTest.thrift \
 	JavaDeepCopyTest.thrift \
 	JavaTypes.thrift \
@@ -150,7 +159,6 @@
 	OptionalRequiredTest.thrift \
 	Recursive.thrift \
 	ReuseObjects.thrift \
-	EnumContainersTest.thrift \
 	SmallTest.thrift \
 	StressTest.thrift \
 	ThriftTest.thrift \
diff --git a/test/c_glib/Makefile.am b/test/c_glib/Makefile.am
index 4a03d29..01ab2ca 100755
--- a/test/c_glib/Makefile.am
+++ b/test/c_glib/Makefile.am
@@ -65,10 +65,18 @@
 AM_LDFLAGS = $(GLIB_LIBS) $(GOBJECT_LIBS) @GCOV_LDFLAGS@
 
 clean-local:
-	$(RM) gen-c_glib/*
+	$(RM) -r gen-c_glib/
+	$(RM) test_client
+	$(RM) test_server
+	$(RM) libtestcglib.la
+	find . -type f -iname "*.o" | xargs rm -f
+
+dist-hook:
+	$(RM) -r $(distdir)/gen-c_glib/
+	$(RM) $(distdir)/test_client
+	$(RM) $(distdir)/test_server
+	$(RM) $(distdir)/libtestcglib.la
+	find $(distdir) -type f -iname "*.o" | xargs rm -f
 
 EXTRA_DIST = \
-	src/test_client.c \
-	src/thrift_test_handler.c \
-	src/thrift_test_handler.h \
-	src/test_server.c
+	src
diff --git a/test/cpp/Makefile.am b/test/cpp/Makefile.am
index e8be80a..ebe715e 100755
--- a/test/cpp/Makefile.am
+++ b/test/cpp/Makefile.am
@@ -113,7 +113,7 @@
 AM_LDFLAGS = $(BOOST_LDFLAGS) $(LIBEVENT_LDFLAGS) $(ZLIB_LIBS)
 
 clean-local:
-	$(RM) gen-cpp/*
+	$(RM) -r gen-cpp/
 
 style-local:
 	$(CPPSTYLE_CMD)
diff --git a/test/dart/Makefile.am b/test/dart/Makefile.am
index 9750ec2..27fdc09 100644
--- a/test/dart/Makefile.am
+++ b/test/dart/Makefile.am
@@ -33,10 +33,20 @@
 check: stubs
 
 clean-local:
-	$(RM) -r gen-dart test_client/.pub
+	$(RM) -r gen-dart/ test_client/.pub
+	find . -type d -name ".dart_tool" | xargs $(RM) -r
 	find . -type d -name "packages" | xargs $(RM) -r
 	find . -type f -name ".packages" | xargs $(RM)
 	find . -type f -name "pubspec.lock" | xargs $(RM)
 
+dist-hook:
+	$(RM) -r $(distdir)/gen-dart/ $(distdir)/test_client/.pub
+	find $(distdir) -type d -name ".dart_tool" | xargs $(RM) -r
+	find $(distdir) -type d -name "packages" | xargs $(RM) -r
+	find $(distdir) -type f -name ".packages" | xargs $(RM)
+
 client: stubs
 	${DART} test_client/bin/main.dart
+
+EXTRA_DIST = \
+	test_client
diff --git a/test/erl/Makefile.am b/test/erl/Makefile.am
index ff25e89..81913ee 100644
--- a/test/erl/Makefile.am
+++ b/test/erl/Makefile.am
@@ -35,7 +35,17 @@
 precross: .generated
 	$(REBAR) compile
 
+maintainer-clean-local:
+	$(RM) -r ebin/
+
 clean:
-	rm -f .generated
-	rm -rf src/gen-erl
 	$(REBAR) clean
+	$(RM)    .generated
+	$(RM) -r .rebar/
+	$(RM) -r src/gen-erl/
+
+dist-hook:
+	$(RM)    $(distdir)/.generated
+	$(RM) -r $(distdir)/.rebar/
+	$(RM) -r $(distdir)/ebin/
+	$(RM) -r $(distdir)/src/gen-erl/
diff --git a/test/hs/Makefile.am b/test/hs/Makefile.am
index 1748906..817070d 100644
--- a/test/hs/Makefile.am
+++ b/test/hs/Makefile.am
@@ -30,9 +30,18 @@
 	sh run-test.sh Include
 
 clean-local:
-	$(RM) -r gen-hs
+	$(RM) -r gen-hs/
 	$(RM) *.hi
 	$(RM) *.o
+	$(RM) TestClient
+	$(RM) TestServer
+
+dist-hook:
+	$(RM) -r $(distdir)/gen-hs/
+	$(RM) $(distdir)/*.hi
+	$(RM) $(distdir)/*.o
+	$(RM) $(destdir)/TestClient
+	$(RM) $(destdir)/TestServer
 
 all-local: stubs
 	ghc -igen-hs TestServer.hs
diff --git a/test/lua/Makefile.am b/test/lua/Makefile.am
index ed8c5ae..b2683e1 100644
--- a/test/lua/Makefile.am
+++ b/test/lua/Makefile.am
@@ -28,4 +28,7 @@
 precross: stubs
 
 clean-local:
-	$(RM) -r gen-lua
+	$(RM) -r gen-lua/
+
+dist-hook:
+	$(RM) -r $(distdir)/gen-lua/
diff --git a/test/netcore/Makefile.am b/test/netcore/Makefile.am
index 376ffb7..2fff4ba 100644
--- a/test/netcore/Makefile.am
+++ b/test/netcore/Makefile.am
@@ -27,10 +27,19 @@
 
 clean-local:
 	$(RM) -r Client/bin
-	$(RM) -r Server/bin
 	$(RM) -r Client/obj
+	$(RM) -r Client/ThriftTest
+	$(RM) -r Server/bin
 	$(RM) -r Server/obj
-	$(RM) -r ThriftTest/ThriftTest
+	$(RM) -r Server/ThriftTest
+
+dist-hook:
+	$(RM) -r $(distdir)/Client/bin
+	$(RM) -r $(distdir)/Client/obj
+	$(RM) -r $(distdir)/Client/ThriftTest
+	$(RM) -r $(distdir)/Server/bin
+	$(RM) -r $(distdir)/Server/obj
+	$(RM) -r $(distdir)/Server/ThriftTest
 
 EXTRA_DIST = \
 	Client \
diff --git a/test/perl/Makefile.am b/test/perl/Makefile.am
index 165b9a7..1dbaf28 100644
--- a/test/perl/Makefile.am
+++ b/test/perl/Makefile.am
@@ -25,5 +25,7 @@
 check: stubs
 
 clean-local:
-	$(RM) -r gen-perl
+	$(RM) -r gen-perl/
 
+dist-hook:
+	$(RM) -r $(distdir)/gen-perl/
diff --git a/test/php/Makefile.am b/test/php/Makefile.am
index 72f7fc5..5c42321 100755
--- a/test/php/Makefile.am
+++ b/test/php/Makefile.am
@@ -33,7 +33,12 @@
 check: stubs php_ext_dir
 
 clean-local:
-	$(RM) -r gen-php gen-phpi gen-php-classmap php_ext_dir
+	$(RM) -r gen-*/
+	$(RM) -r php_ext_dir
+
+dist-hook:
+	$(RM) -r $(distdir)/gen-*/
+	$(RM) -r $(distdir)/php_ext_dir/
 
 client: stubs php_ext_dir
 	php TestClient.php
diff --git a/test/py.tornado/Makefile.am b/test/py.tornado/Makefile.am
index a8e680a..e962f0c 100644
--- a/test/py.tornado/Makefile.am
+++ b/test/py.tornado/Makefile.am
@@ -27,4 +27,12 @@
 	./test_suite.py
 
 clean-local:
-	$(RM) -r gen-py.tornado
+	$(RM) -r build
+	find . -type f \( -iname "*.pyc" \) | xargs rm -f
+	find . -type d \( -iname "__pycache__" -or -iname "_trial_temp" \) | xargs rm -rf
+	$(RM) -r gen-py*/
+
+dist-hook:
+	find $(distdir) -type f \( -iname "*.pyc" \) | xargs rm -f
+	find $(distdir) -type d \( -iname "__pycache__" -or -iname "_trial_temp" \) | xargs rm -rf
+	$(RM) -r $(distdir)/gen-py*/
diff --git a/test/py.twisted/Makefile.am b/test/py.twisted/Makefile.am
index d11908c..dee8e2f 100644
--- a/test/py.twisted/Makefile.am
+++ b/test/py.twisted/Makefile.am
@@ -27,4 +27,12 @@
 	$(TRIAL) ./test_suite.py
 
 clean-local:
-	$(RM) -r gen-py.twisted
+	$(RM) -r build
+	find . -type f \( -iname "*.pyc" \) | xargs rm -f
+	find . -type d \( -iname "__pycache__" -or -iname "_trial_temp" \) | xargs rm -rf
+	$(RM) -r gen-py*/
+
+dist-hook:
+	find $(distdir) -type f \( -iname "*.pyc" \) | xargs rm -f
+	find $(distdir) -type d \( -iname "__pycache__" -or -iname "_trial_temp" \) | xargs rm -rf
+	$(RM) -r $(distdir)/gen-py*/
diff --git a/test/py/Makefile.am b/test/py/Makefile.am
index 8296200..9433e59 100644
--- a/test/py/Makefile.am
+++ b/test/py/Makefile.am
@@ -94,4 +94,12 @@
 	$(THRIFT) --gen py:dynamic,slots -out gen-py-dynamicslots $<
 
 clean-local:
-	$(RM) -r gen-py gen-py-slots gen-py-default gen-py-oldstyle gen-py-no_utf8strings gen-py-dynamic gen-py-dynamicslots
+	$(RM) -r build
+	find . -type f \( -iname "*.pyc" \) | xargs rm -f
+	find . -type d \( -iname "__pycache__" -or -iname "_trial_temp" \) | xargs rm -rf
+	$(RM) -r gen-py*/
+
+dist-hook:
+	find $(distdir) -type f \( -iname "*.pyc" \) | xargs rm -f
+	find $(distdir) -type d \( -iname "__pycache__" -or -iname "_trial_temp" \) | xargs rm -rf
+	$(RM) -r $(distdir)/gen-py*/
diff --git a/test/rb/Makefile.am b/test/rb/Makefile.am
index cfdc149..3910934 100644
--- a/test/rb/Makefile.am
+++ b/test/rb/Makefile.am
@@ -30,3 +30,8 @@
 	$(BUNDLER) exec $(RUBY) -I. test_suite.rb
 endif
 
+clean-local:
+	$(RM) -r gen-rb/
+
+dist-hook:
+	$(RM) -r $(distdir)/gen-rb/
diff --git a/test/rs/Makefile.am b/test/rs/Makefile.am
index 54905b4..4b061ea 100644
--- a/test/rs/Makefile.am
+++ b/test/rs/Makefile.am
@@ -34,7 +34,7 @@
 
 EXTRA_DIST = \
 	Cargo.toml \
-        src/lib.rs \
+	src/lib.rs \
 	src/bin/test_server.rs \
 	src/bin/test_client.rs