Add initial work for generating .gitignore on the fly.

Needs polishing.

Signed-off-by: Garrett Cooper <yanegomi@gmail.com>
diff --git a/Makefile b/Makefile
index 94a9684..2f9f622 100644
--- a/Makefile
+++ b/Makefile
@@ -1,7 +1,8 @@
 #
 #    Top-level Makefile for LTP. See INSTALL for more info.
 #
-#    Copyright (C) 2009, Cisco Systems Inc.
+#    Copyright (C) 2009-2010, Cisco Systems Inc.
+#    Copyright (C) 2010-2011, Linux Test Project.
 #
 #    This program is free software; you can redistribute it and/or modify
 #    it under the terms of the GNU General Public License as published by
@@ -29,6 +30,7 @@
 
 include $(top_srcdir)/include/mk/env_pre.mk
 include $(top_srcdir)/include/mk/automake.mk
+include $(top_srcdir)/include/mk/gitignore.mk
 
 .SUFFIXES:
 .SUFFIXES: .am .default .h .in .m4 .mk
diff --git a/include/mk/env_pre.mk b/include/mk/env_pre.mk
index 662458c..f1584a8 100644
--- a/include/mk/env_pre.mk
+++ b/include/mk/env_pre.mk
@@ -95,7 +95,7 @@
 endif
 
 # autotools, *clean, and help don't require config.mk, features.mk, etc...
-ifeq ($(filter autotools %clean help,$(MAKECMDGOALS)),)
+ifeq ($(filter autotools %clean .gitignore gitignore.% help,$(MAKECMDGOALS)),)
 
 include $(abs_top_builddir)/include/mk/config.mk
 include $(abs_top_builddir)/include/mk/features.mk
diff --git a/include/mk/gitignore.mk b/include/mk/gitignore.mk
new file mode 100644
index 0000000..b9932fb
--- /dev/null
+++ b/include/mk/gitignore.mk
@@ -0,0 +1,51 @@
+#
+#    gitignore generation include Makefile.
+#
+#    Copyright (C) 2011, Linux Test Project.
+#
+#    This program is free software; you can redistribute it and/or modify
+#    it under the terms of the GNU General Public License as published by
+#    the Free Software Foundation; either version 2 of the License, or
+#    (at your option) any later version.
+#
+#    This program is distributed in the hope that it will be useful,
+#    but WITHOUT ANY WARRANTY; without even the implied warranty of
+#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#    GNU General Public License for more details.
+#
+#    You should have received a copy of the GNU General Public License along
+#    with this program; if not, write to the Free Software Foundation, Inc.,
+#    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Garrett Cooper, January 2011
+#
+
+CLEAN_TARGETS+=		gitignore_clean
+
+BEFORE:=		.gitignore-before
+
+AFTER:=			.gitignore-after
+
+IGNORE_DIR_EXPR:=	egrep -v "^$$(echo "$(AUTOCONFED_SUBDIRS)" | tr " " "|")"
+
+# NOTE: The underscore is used in place of a dash to avoid implicit rule
+# evaluation in top-level Makefile.
+.PHONY: gitignore_clean
+gitignore_clean:
+	$(RM) -f $(BEFORE) $(AFTER) 
+
+$(BEFORE):
+	$(MAKE) distclean
+	$(MAKE) ac-maintainer-clean
+	find . | $(IGNORE_DIR_EXPR) > $@
+
+$(AFTER):
+	$(MAKE) autotools
+	./configure --prefix=/dev/null
+	$(MAKE) all
+	find . | $(IGNORE_DIR_EXPR) > $@
+	# Set everything in autoconf land back to a sane state.
+	$(MAKE) distclean
+
+.gitignore: | $(BEFORE) $(AFTER) 
+	diff -u $(BEFORE) $(AFTER) | grep '^+' | sed -e 's,^\+,,g' > $@
diff --git a/testcases/realtime/Makefile b/testcases/realtime/Makefile
index 8808100..7bb6523 100644
--- a/testcases/realtime/Makefile
+++ b/testcases/realtime/Makefile
@@ -33,9 +33,10 @@
 #
 # NOTE (garrcoop): this criterium should be in-sync with include/mk/env_pre.mk
 # (minus help as that's only invoked in the top-level Makefile).
-ifeq ($(filter autotools %clean,$(MAKECMDGOALS)),)
+ifeq ($(filter autotools %clean .gitignore gitignore.%,$(MAKECMDGOALS)),)
 include $(abs_srcdir)/config.mk
 endif
+include $(top_srcdir)/include/mk/gitignore.mk
 
 LIBDIR			:= lib
 FILTER_OUT_DIRS		:= $(LIBDIR) m4