Use Makefile.am includes.  This gets rid of 110 lines of repetitive Makefile.am
cruft, yay!


git-svn-id: svn://svn.valgrind.org/valgrind/trunk@2641 a5019735-40e9-0310-863c-91ae7b9d1cf9
diff --git a/Makefile.all.am b/Makefile.all.am
new file mode 100644
index 0000000..d1b45fc
--- /dev/null
+++ b/Makefile.all.am
@@ -0,0 +1,8 @@
+
+## This file should be included by *every* Makefile.am, except those for docs/
+## and tests/ subdirectories.
+
+valdir = $(libdir)/valgrind
+inplacedir = $(top_builddir)/.in_place
+
+
diff --git a/Makefile.am b/Makefile.am
index 60252dd..00cd05d 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1,7 +1,9 @@
 
 AUTOMAKE_OPTIONS = foreign 1.6 dist-bzip2
 
-## include must be first for vg_skin.h
+include $(top_srcdir)/Makefile.all.am
+
+## include must be first for tool.h
 ## addrcheck must come after memcheck, for mac_*.o
 SUBDIRS = 	include coregrind . docs tests auxprogs \
 		memcheck \
@@ -13,13 +15,6 @@
 		lackey \
 		none
 
-AM_CPPFLAGS = 
-AM_CFLAGS = $(WERROR) -Winline -Wall -Wshadow -O -fomit-frame-pointer \
-		@PREFERRED_STACK_BOUNDARY@ -g
-
-valdir = $(libdir)/valgrind
-inplacedir = $(top_builddir)/.in_place
-
 SUPP_FILES = \
 	glibc-2.1.supp glibc-2.2.supp glibc-2.3.supp \
 	xfree-3.supp xfree-4.supp
@@ -44,7 +39,9 @@
 	ACKNOWLEDGEMENTS \
 	README_PACKAGERS \
 	README_MISSING_SYSCALL_OR_IOCTL TODO \
-	valgrind.spec.in valgrind.pc.in
+	valgrind.spec.in valgrind.pc.in \
+	Makefile.all.am Makefile.tool.am Makefile.core-AM_CPPFLAGS.am \
+	Makefile.tool-inplace.am
 
 install-exec-hook:
 	$(mkinstalldirs) $(DESTDIR)$(valdir)
diff --git a/Makefile.core-AM_CPPFLAGS.am b/Makefile.core-AM_CPPFLAGS.am
new file mode 100644
index 0000000..4a68b1a
--- /dev/null
+++ b/Makefile.core-AM_CPPFLAGS.am
@@ -0,0 +1,5 @@
+add_includes = -I$(top_builddir)/coregrind -I$(top_srcdir)/coregrind \
+		-I$(top_builddir)/include -I$(top_srcdir)/include
+
+AM_CPPFLAGS = $(add_includes)
+
diff --git a/Makefile.tool-inplace.am b/Makefile.tool-inplace.am
new file mode 100644
index 0000000..75d4991
--- /dev/null
+++ b/Makefile.tool-inplace.am
@@ -0,0 +1,4 @@
+all-local:
+	mkdir -p $(inplacedir)
+	-rm -f $(addprefix $(inplacedir)/,$(val_PROGRAMS))
+	ln -f -s $(addprefix ../$(subdir)/,$(val_PROGRAMS)) $(inplacedir)
diff --git a/Makefile.tool.am b/Makefile.tool.am
new file mode 100644
index 0000000..cdde4b8
--- /dev/null
+++ b/Makefile.tool.am
@@ -0,0 +1,16 @@
+
+include $(top_srcdir)/Makefile.all.am
+
+SUBDIRS = . tests docs
+
+## Need $(top_builddir)/include because tool.h is built from tool.h.base;
+## otherwise it will not work if builddir != srcdir.
+add_includes = -I$(top_builddir)/include -I$(top_srcdir)/include
+
+AM_CPPFLAGS = $(add_includes)
+AM_CFLAGS = $(WERROR) -Winline -Wall -Wshadow -O -fomit-frame-pointer \
+		@PREFERRED_STACK_BOUNDARY@ -g
+AM_CCASFLAGS = $(add_includes)
+
+include $(top_srcdir)/Makefile.tool-inplace.am
+	
diff --git a/addrcheck/Makefile.am b/addrcheck/Makefile.am
index df789a4..dba0a48 100644
--- a/addrcheck/Makefile.am
+++ b/addrcheck/Makefile.am
@@ -1,14 +1,7 @@
-
-SUBDIRS = . docs tests
+include $(top_srcdir)/Makefile.tool.am
 
 # include memcheck/ for mac_shared.h
-AM_CPPFLAGS = -I$(top_builddir)/include -I$(top_srcdir)/include \
-		-I$(top_srcdir)/memcheck
-AM_CFLAGS = $(WERROR) -Winline -Wall -Wshadow -O -fomit-frame-pointer \
-		@PREFERRED_STACK_BOUNDARY@ -g
-
-valdir = $(libdir)/valgrind
-inplacedir = $(top_builddir)/.in_place
+AM_CPPFLAGS += -I$(top_srcdir)/memcheck
 
 val_PROGRAMS = vgskin_addrcheck.so vgpreload_addrcheck.so
 
@@ -28,7 +21,3 @@
 	../memcheck/mac_replace_strmem.o
 vgpreload_addrcheck_so_LDFLAGS = -shared -Wl,-z,interpose,-z,initfirst
 
-all-local:
-	mkdir -p $(inplacedir)
-	-rm -f $(addprefix $(inplacedir)/,$(val_PROGRAMS))
-	ln -f -s $(addprefix $(top_builddir)/$(subdir)/,$(val_PROGRAMS)) $(inplacedir)
diff --git a/auxprogs/Makefile.am b/auxprogs/Makefile.am
index bd46a41..1e31292 100644
--- a/auxprogs/Makefile.am
+++ b/auxprogs/Makefile.am
@@ -1,12 +1,9 @@
+include $(top_srcdir)/Makefile.all.am
+include $(top_srcdir)/Makefile.core-AM_CPPFLAGS.am
 
-SUBDIRS = . 
-
-AM_CPPFLAGS = -I$(top_builddir)/include -I$(top_srcdir)/include \
-		-I$(top_builddir)/coregrind -I$(top_srcdir)/coregrind
 AM_CFLAGS = $(WERROR) -Winline -Wall -O -g
 
 bin_PROGRAMS = valgrind-listener
 
-valgrind_listener_SOURCES = \
-	valgrind-listener.c
+valgrind_listener_SOURCES = valgrind-listener.c
 
diff --git a/cachegrind/Makefile.am b/cachegrind/Makefile.am
index f1735bd..2840067 100644
--- a/cachegrind/Makefile.am
+++ b/cachegrind/Makefile.am
@@ -1,12 +1,4 @@
-
-SUBDIRS = . docs tests
-
-AM_CPPFLAGS = -I$(top_builddir)/include -I$(top_srcdir)/include
-AM_CFLAGS = $(WERROR) -Winline -Wall -Wshadow -O -fomit-frame-pointer \
-		@PREFERRED_STACK_BOUNDARY@ -g
-
-valdir = $(libdir)/valgrind
-inplacedir = $(top_builddir)/.in_place
+include $(top_srcdir)/Makefile.tool.am
 
 bin_SCRIPTS = cg_annotate
 
@@ -17,7 +9,3 @@
 vgskin_cachegrind_so_SOURCES = cg_main.c
 vgskin_cachegrind_so_LDFLAGS = -shared
 
-all-local:
-	mkdir -p $(inplacedir)
-	-rm -f $(inplacedir)/$(val_PROGRAMS)
-	ln -f -s $(top_builddir)/$(subdir)/$(val_PROGRAMS) $(inplacedir)/$(val_PROGRAMS)
diff --git a/corecheck/Makefile.am b/corecheck/Makefile.am
index b790a83..9e4c37b 100644
--- a/corecheck/Makefile.am
+++ b/corecheck/Makefile.am
@@ -1,19 +1,7 @@
-
-SUBDIRS = . tests docs
-
-AM_CPPFLAGS = -I$(top_builddir)/include -I$(top_srcdir)/include
-AM_CFLAGS = $(WERROR) -Winline -Wall -Wshadow -O -fomit-frame-pointer \
-		@PREFERRED_STACK_BOUNDARY@ -g
-
-valdir = $(libdir)/valgrind
-inplacedir = $(top_builddir)/.in_place
+include $(top_srcdir)/Makefile.tool.am
 
 val_PROGRAMS = vgskin_corecheck.so
 
 vgskin_corecheck_so_SOURCES = cc_main.c
 vgskin_corecheck_so_LDFLAGS = -shared
 
-all-local:
-	mkdir -p $(inplacedir)
-	-rm -f $(inplacedir)/$(val_PROGRAMS)
-	ln -f -s $(top_builddir)/$(subdir)/$(val_PROGRAMS) $(inplacedir)/$(val_PROGRAMS)
diff --git a/coregrind/Makefile.am b/coregrind/Makefile.am
index adfb629..b869647 100644
--- a/coregrind/Makefile.am
+++ b/coregrind/Makefile.am
@@ -1,13 +1,10 @@
+include $(top_srcdir)/Makefile.all.am
+include $(top_srcdir)/Makefile.core-AM_CPPFLAGS.am
 
 SUBDIRS = x86 demangle . docs
 
-add_includes = -I$(srcdir)/demangle -I$(top_builddir)/include \
-		-I$(top_srcdir)/include -I$(srcdir)/x86
-
-valdir = $(libdir)/valgrind
-inplacedir = $(top_builddir)/.in_place
-
-AM_CPPFLAGS = $(add_includes) -DVG_LIBDIR="\"$(valdir)"\" \
+AM_CPPFLAGS += -DVG_LIBDIR="\"$(valdir)"\" -I$(srcdir)/demangle \
+		-I$(srcdir)/x86 \
 		-DKICKSTART_BASE=$(KICKSTART_BASE)
 AM_CFLAGS = $(WERROR) -Winline -Wall -Wshadow -O -fno-omit-frame-pointer \
 		@PREFERRED_STACK_BOUNDARY@ -g -DELFSZ=32
diff --git a/coregrind/demangle/Makefile.am b/coregrind/demangle/Makefile.am
index b1956c4..9aa1b3a 100644
--- a/coregrind/demangle/Makefile.am
+++ b/coregrind/demangle/Makefile.am
@@ -1,6 +1,6 @@
+include $(top_srcdir)/Makefile.all.am
+include $(top_srcdir)/Makefile.core-AM_CPPFLAGS.am
 
-AM_CPPFLAGS = -I$(top_builddir)/coregrind -I$(top_srcdir)/coregrind \
-              -I$(top_builddir)/include -I$(top_srcdir)/include
 AM_CFLAGS = $(WERROR) -Winline -Wall -Wshadow -O -fomit-frame-pointer -g
 
 noinst_HEADERS = \
@@ -14,6 +14,7 @@
 libdemangle_a_SOURCES = \
 	cp-demangle.c cplus-dem.c dyn-string.c safe-ctype.c
 
+## Ignore harmless warnings for these ones
 cp-demangle.o: CFLAGS += -Wno-unused -Wno-shadow 
 cplus-dem.o: CFLAGS += -Wno-unused
 
diff --git a/helgrind/Makefile.am b/helgrind/Makefile.am
index 05b4ea4..68aa37f 100644
--- a/helgrind/Makefile.am
+++ b/helgrind/Makefile.am
@@ -1,12 +1,4 @@
-
-SUBDIRS = . docs tests
-
-AM_CPPFLAGS = -I$(top_builddir)/include -I$(top_srcdir)/include
-AM_CFLAGS = $(WERROR) -Winline -Wall -Wshadow -O -fomit-frame-pointer \
-		@PREFERRED_STACK_BOUNDARY@ -g
-
-valdir = $(libdir)/valgrind
-inplacedir = $(top_builddir)/.in_place
+include $(top_srcdir)/Makefile.tool.am
 
 val_PROGRAMS = vgskin_helgrind.so vgpreload_helgrind.so
 
@@ -22,7 +14,3 @@
 
 hginclude_HEADERS = helgrind.h
 
-all-local:
-	mkdir -p $(inplacedir)
-	-rm -f $(addprefix $(inplacedir)/,$(val_PROGRAMS))
-	ln -f -s $(addprefix $(top_builddir)/$(subdir)/,$(val_PROGRAMS)) $(inplacedir)
diff --git a/lackey/Makefile.am b/lackey/Makefile.am
index 7bbc4f2..a21574b 100644
--- a/lackey/Makefile.am
+++ b/lackey/Makefile.am
@@ -1,20 +1,7 @@
-
-SUBDIRS = . docs tests
-
-AM_CPPFLAGS = -I$(top_builddir)/include -I$(top_srcdir)/include
-AM_CFLAGS = $(WERROR) -Winline -Wall -Wshadow -O -fomit-frame-pointer \
-		@PREFERRED_STACK_BOUNDARY@ -g
-
-valdir = $(libdir)/valgrind
-inplacedir = $(top_builddir)/.in_place
+include $(top_srcdir)/Makefile.tool.am
 
 val_PROGRAMS = vgskin_lackey.so
 
 vgskin_lackey_so_SOURCES = lk_main.c
 vgskin_lackey_so_LDFLAGS = -shared
 
-
-all-local:
-	mkdir -p $(inplacedir)
-	-rm -f $(inplacedir)/$(val_PROGRAMS)
-	ln -f -s $(top_builddir)/$(subdir)/$(val_PROGRAMS) $(inplacedir)/$(val_PROGRAMS)
diff --git a/massif/Makefile.am b/massif/Makefile.am
index bc26161..620c4f1 100644
--- a/massif/Makefile.am
+++ b/massif/Makefile.am
@@ -1,12 +1,6 @@
+include $(top_srcdir)/Makefile.tool.am
 
-SUBDIRS = . tests docs hp2ps
-
-AM_CPPFLAGS = -I$(top_builddir)/include -I$(top_srcdir)/include
-AM_CFLAGS = $(WERROR) -Winline -Wall -Wshadow -O -fomit-frame-pointer \
-		@PREFERRED_STACK_BOUNDARY@ -g
-
-valdir = $(libdir)/valgrind
-inplacedir = $(top_builddir)/.in_place
+SUBDIRS += hp2ps
 
 val_PROGRAMS = vgskin_massif.so vgpreload_massif.so
 
@@ -18,7 +12,3 @@
 vgpreload_massif_so_DEPENDENCIES = $(top_builddir)/coregrind/vg_replace_malloc.o
 vgpreload_massif_so_LDFLAGS = -shared -Wl,-z,interpose,-z,initfirst
 
-all-local:
-	mkdir -p $(inplacedir)
-	-rm -f $(addprefix $(inplacedir)/,$(val_PROGRAMS))
-	ln -f -s $(addprefix $(top_builddir)/$(subdir)/,$(val_PROGRAMS)) $(inplacedir)
diff --git a/massif/hp2ps/Makefile.am b/massif/hp2ps/Makefile.am
index 58e39a3..1f51006 100644
--- a/massif/hp2ps/Makefile.am
+++ b/massif/hp2ps/Makefile.am
@@ -1,11 +1,6 @@
+include $(top_srcdir)/Makefile.all.am
 
-valdir = $(libdir)/valgrind
-inplacedir = $(top_builddir)/.in_place
-
-AM_CPPFLAGS = $(add_includes)
-AM_CFLAGS = $(WERROR) -Winline -Wall -Wshadow -O -fno-omit-frame-pointer \
-                @PREFERRED_STACK_BOUNDARY@ -g
-AM_CCASFLAGS = $(add_includes)
+AM_CFLAGS = $(WERROR) -Winline -Wall -Wshadow -O -g
 
 val_PROGRAMS = hp2ps 
 
@@ -59,8 +54,5 @@
        TraceElement.h \
        Utilities.h
 
-all-local:
-	mkdir -p $(inplacedir)
-	-rm -f $(addprefix $(inplacedir)/,$(val_PROGRAMS))
-	ln -f -s $(addprefix ../$(subdir)/,$(val_PROGRAMS)) $(inplacedir)
+include $(top_srcdir)/Makefile.tool-inplace.am
 
diff --git a/memcheck/Makefile.am b/memcheck/Makefile.am
index e46a5be..a19a906 100644
--- a/memcheck/Makefile.am
+++ b/memcheck/Makefile.am
@@ -1,15 +1,7 @@
+include $(top_srcdir)/Makefile.tool.am
 
-SUBDIRS = . tests docs
-
-all_includes = -I$(top_builddir)/include -I$(top_srcdir)/include
-
-AM_CPPFLAGS = $(all_includes)
-AM_CFLAGS = $(WERROR) -Winline -Wall -Wshadow -O2 -fomit-frame-pointer \
-		@PREFERRED_STACK_BOUNDARY@ -g
-AM_CCASFLAGS = $(all_includes)
-
-valdir = $(libdir)/valgrind
-inplacedir = $(top_builddir)/.in_place
+## Build Memcheck at a higher optimisation level
+AM_CFLAGS += -O2
 
 val_PROGRAMS = vgskin_memcheck.so vgpreload_memcheck.so
 
@@ -43,7 +35,3 @@
 
 mac_replace_strmem.o: CFLAGS += -fno-omit-frame-pointer
 
-all-local:
-	mkdir -p $(inplacedir)
-	-rm -f $(addprefix $(inplacedir)/,$(val_PROGRAMS))
-	ln -f -s $(addprefix $(top_builddir)/$(subdir)/,$(val_PROGRAMS)) $(inplacedir)
diff --git a/none/Makefile.am b/none/Makefile.am
index f27ec45..a4fc9e6 100644
--- a/none/Makefile.am
+++ b/none/Makefile.am
@@ -1,19 +1,7 @@
-
-SUBDIRS = . docs tests
-
-AM_CPPFLAGS = -I$(top_builddir)/include -I$(top_srcdir)/include
-AM_CFLAGS = $(WERROR) -Winline -Wall -Wshadow -O -fomit-frame-pointer \
-		@PREFERRED_STACK_BOUNDARY@ -g
-
-valdir = $(libdir)/valgrind
-inplacedir = $(top_builddir)/.in_place
+include $(top_srcdir)/Makefile.tool.am
 
 val_PROGRAMS = vgskin_none.so
 
 vgskin_none_so_SOURCES 	 = nl_main.c
 vgskin_none_so_LDFLAGS   = -shared
 
-all-local:
-	mkdir -p $(inplacedir)
-	-rm -f $(inplacedir)/$(val_PROGRAMS)
-	ln -f -s $(top_builddir)/$(subdir)/$(val_PROGRAMS) $(inplacedir)/$(val_PROGRAMS)