diff --git a/configure b/configure
index fbd282414847a2ede455d4ab7d5b5f69ccd71f3a..dfbf4e1cd7671337944cb904d5f87bafddd8ec90 100755
--- a/configure
+++ b/configure
@@ -8875,11 +8875,8 @@ trap 'rm -fr `echo "GNUmakefile
 	src/backend/port/Makefile
 	src/backend/catalog/genbki.sh
 	src/backend/utils/Gen_fmgrtab.sh
-	src/bin/pg_dump/Makefile
-	src/bin/pg_version/Makefile
 	src/bin/pgtclsh/mkMakefile.tcldefs.sh
 	src/bin/pgtclsh/mkMakefile.tkdefs.sh
-	src/bin/psql/Makefile
 	src/include/version.h
 	src/interfaces/Makefile
 	src/interfaces/libpq/Makefile
@@ -8891,11 +8888,7 @@ trap 'rm -fr `echo "GNUmakefile
 	src/interfaces/libpgtcl/Makefile
 	src/interfaces/odbc/GNUmakefile
 	src/interfaces/python/GNUmakefile
-	src/pl/Makefile
-	src/pl/plpgsql/Makefile
-	src/pl/plpgsql/src/Makefile
 	src/pl/tcl/mkMakefile.tcldefs.sh
-	src/pl/plperl/GNUmakefile
 	src/test/regress/GNUmakefile
  src/include/config.h" | sed "s/:[^ ]*//g"` conftest*; exit 1' 1 2 15
 EOF
@@ -9066,11 +9059,8 @@ CONFIG_FILES=\${CONFIG_FILES-"GNUmakefile
 	src/backend/port/Makefile
 	src/backend/catalog/genbki.sh
 	src/backend/utils/Gen_fmgrtab.sh
-	src/bin/pg_dump/Makefile
-	src/bin/pg_version/Makefile
 	src/bin/pgtclsh/mkMakefile.tcldefs.sh
 	src/bin/pgtclsh/mkMakefile.tkdefs.sh
-	src/bin/psql/Makefile
 	src/include/version.h
 	src/interfaces/Makefile
 	src/interfaces/libpq/Makefile
@@ -9082,11 +9072,7 @@ CONFIG_FILES=\${CONFIG_FILES-"GNUmakefile
 	src/interfaces/libpgtcl/Makefile
 	src/interfaces/odbc/GNUmakefile
 	src/interfaces/python/GNUmakefile
-	src/pl/Makefile
-	src/pl/plpgsql/Makefile
-	src/pl/plpgsql/src/Makefile
 	src/pl/tcl/mkMakefile.tcldefs.sh
-	src/pl/plperl/GNUmakefile
 	src/test/regress/GNUmakefile
 "}
 EOF
diff --git a/configure.in b/configure.in
index 30996b2610f3a443e385a55cef6af197b87f6c52..7aeac7a11e5f88d0f37925e2ef3d4091112157be 100644
--- a/configure.in
+++ b/configure.in
@@ -1193,11 +1193,8 @@ AC_OUTPUT(
 	src/backend/port/Makefile
 	src/backend/catalog/genbki.sh
 	src/backend/utils/Gen_fmgrtab.sh
-	src/bin/pg_dump/Makefile
-	src/bin/pg_version/Makefile
 	src/bin/pgtclsh/mkMakefile.tcldefs.sh
 	src/bin/pgtclsh/mkMakefile.tkdefs.sh
-	src/bin/psql/Makefile
 	src/include/version.h
 	src/interfaces/Makefile
 	src/interfaces/libpq/Makefile
@@ -1209,10 +1206,6 @@ AC_OUTPUT(
 	src/interfaces/libpgtcl/Makefile
 	src/interfaces/odbc/GNUmakefile
 	src/interfaces/python/GNUmakefile
-	src/pl/Makefile
-	src/pl/plpgsql/Makefile
-	src/pl/plpgsql/src/Makefile
 	src/pl/tcl/mkMakefile.tcldefs.sh
-	src/pl/plperl/GNUmakefile
 	src/test/regress/GNUmakefile
 )
diff --git a/src/GNUmakefile.in b/src/GNUmakefile.in
index 1471a06a238d0330852afe2d031f8e106e7163c7..24f115b3e9dd59dcfd932c873aaeb986f51e7c42 100644
--- a/src/GNUmakefile.in
+++ b/src/GNUmakefile.in
@@ -7,7 +7,7 @@
 #
 #
 # IDENTIFICATION
-#    $Header: /cvsroot/pgsql/src/Attic/GNUmakefile.in,v 1.52 2000/06/10 18:01:36 petere Exp $
+#    $Header: /cvsroot/pgsql/src/Attic/GNUmakefile.in,v 1.53 2000/06/27 00:30:48 petere Exp $
 #
 #-------------------------------------------------------------------------
 
@@ -50,18 +50,15 @@ clean:
 	$(MAKE) -C ../contrib/spi clean
 
 # Not all subdirectories have a make distclean target yet
-distclean:
+distclean maintainer-clean:
 	-$(MAKE) -C utils clean
 	-$(MAKE) -C backend clean
 	rm -f backend/port/Makefile backend/catalog/genbki.sh \
 		backend/utils/Gen_fmgrtab.sh \
 		backend/port/tas.s backend/port/dynloader.c
 	-$(MAKE) -C interfaces distclean
-	-$(MAKE) -C bin clean
-	rm -f bin/pg_dump/Makefile bin/pg_version/Makefile \
-		bin/psql/Makefile bin/pgtclsh/mkMakefile.tcldefs.sh \
-		bin/pgtclsh/mkMakefile.tkdefs.sh
-	-$(MAKE) -C pl distclean
+	-$(MAKE) -C bin $@
+	-$(MAKE) -C pl $@
 	-$(MAKE) -C test clean
 	rm -f test/regress/GNUmakefile
 	-$(MAKE) -C ../contrib/spi clean
diff --git a/src/Makefile.global.in b/src/Makefile.global.in
index 8dc303e4e601649c1e2afdc86d2b57c637028f32..7d2209c9e7566215ca03e51d94981031bfe36d9e 100644
--- a/src/Makefile.global.in
+++ b/src/Makefile.global.in
@@ -7,7 +7,7 @@
 #
 #
 # IDENTIFICATION
-#    $Header: /cvsroot/pgsql/src/Makefile.global.in,v 1.80 2000/06/19 16:58:35 petere Exp $
+#    $Header: /cvsroot/pgsql/src/Makefile.global.in,v 1.81 2000/06/27 00:30:48 petere Exp $
 #
 # NOTES
 #    Essentially all Postgres make files include this file and use the
@@ -35,6 +35,17 @@
 #
 #-------------------------------------------------------------------------
 
+ifndef SRCDIR
+# This should be changed once we have separate build dirs.
+top_srcdir = $(top_builddir)
+ifeq ($(top_builddir), $(top_srcdir))
+srcdir = .
+else
+srcdir = $(top_srcdir)/$(subdir)
+endif
+VPATH = $(srcdir)
+SRCDIR = $(top_builddir)/src
+endif
 
 ##############################################################################
 #
@@ -61,33 +72,29 @@ LIBPQ= -L$(LIBPQDIR) -lpq
 LIBPGTCL= -L$(LIBPGTCLDIR) -lpgtcl
 LIBPGEASY= -L$(LIBPGEASYDIR) -lpgeasy
 
-# For convenience, POSTGRESDIR is where BINDIR, and LIBDIR
-# and other target destinations are rooted.  Of course, each of these is
-# changable separately.
-POSTGRESDIR= @prefix@
-
-# Where the postgres executables live (changeable by just putting them
-# somewhere else and putting that directory in your shell PATH)
-BINDIR= $(POSTGRESDIR)/bin
-
-# Where libpq.a gets installed.  You must put it where your loader will
-# look for it if you wish to use the -lpq convention.  Otherwise you
-# can just put the absolute pathname to the library at the end of your
-# command line.
-LIBDIR= $(POSTGRESDIR)/lib
-
-# Where the database templates are stored
-#
-TEMPLATEDIR= $(POSTGRESDIR)/lib
-
-# Where the man pages (suitable for use with "man") get installed.
+# installation directories
+
+prefix = @prefix@
+exec_prefix = @exec_prefix@
+bindir = @bindir@
+sbindir = @sbindir@
+libexecdir = @libexecdir@
+datadir = @datadir@
+sysconfdir = @sysconfdir@
+sharedstatedir = @sharedstatedir@
+localstatedir = @localstatedir@
+libdir = @libdir@
+includedir = @includedir@
+
+# old variable names for installation directories
+
+POSTGRESDIR= $(prefix)
+BINDIR= $(bindir)
+LIBDIR= $(libdir)
+TEMPLATEDIR= $(libdir)
 POSTMANDIR= $(POSTGRESDIR)/man
-
-# Where the formatted documents (e.g., the reference manual) get installed.
 POSTDOCDIR= $(POSTGRESDIR)/doc
-
-# Where the header files necessary to build frontend programs get installed.
-HEADERDIR= $(POSTGRESDIR)/include
+HEADERDIR= $(includedir)
 
 
 ##############################################################################
@@ -105,6 +112,8 @@ ENFORCE_ALIGNMENT= true
 #PROFILE= -p -non_shared
 
 
+with_perl = @with_perl@
+
 #
 # Please do not edit USE_TCL and USE_TK by hand.
 #
@@ -125,13 +134,21 @@ MULTIBYTE=@MULTIBYTE@
 #
 # For many ports, INSTALL is overridden below.
 INSTALL= @INSTALL@
-RANLIB= @RANLIB@
 
+INSTALL_PROGRAM = @INSTALL_PROGRAM@
+INSTALL_SCRIPT = @INSTALL_SCRIPT@
+INSTALL_DATA = @INSTALL_DATA@
+INSTALL_SHLIB = @INSTALL_SHLIB@
+
+mkinstalldirs = @mkinstalldirs@
+
+# don't use these any more
 INSTLOPTS= @INSTLOPTS@
 INSTL_EXE_OPTS= @INSTL_EXE_OPTS@
 INSTL_LIB_OPTS= @INSTL_LIB_OPTS@
 INSTL_SHLIB_OPTS= @INSTL_SHLIB_OPTS@
 
+RANLIB= @RANLIB@
 
 #-------------------------------------------------------------
 # See the subdirectory template for default settings for these
@@ -154,6 +171,8 @@ DLSUFFIX= @DLSUFFIX@
 LN_S= @LN_S@
 TAR= @tar@
 GZCAT= @GZCAT@
+PERL = @PERL@
+
 
 ##############################################################################
 #
@@ -238,3 +257,13 @@ ifdef PROFILE
    CFLAGS+= $(PROFILE)
    LDFLAGS+= $(PROFILE)
 endif
+
+
+# substitute implementations of the C library
+STRERROR = @STRERROR@
+STRERROR2 = @STRERROR2@
+SNPRINTF = @SNPRINTF@
+STRDUP = @STRDUP@
+
+.DEFAULT: all
+.PHONY: all install installdirs uninstall dep depend clean distclean maintainer-clean
diff --git a/src/bin/Makefile b/src/bin/Makefile
index 9aaec4509177fc5a35bf7f106b9e6b3de9f3cbb4..6e2ac0694488cb888730b71d0d2387ba45b4a8dc 100644
--- a/src/bin/Makefile
+++ b/src/bin/Makefile
@@ -1,30 +1,27 @@
 #-------------------------------------------------------------------------
 #
-# Makefile
-#    Makefile for src/bin (client programs)
+# Makefile for src/bin (client programs)
 #
 # Copyright (c) 1994, Regents of the University of California
 #
-#
-# IDENTIFICATION
-#    $Header: /cvsroot/pgsql/src/bin/Makefile,v 1.25 2000/01/20 21:51:02 petere Exp $
+# $Header: /cvsroot/pgsql/src/bin/Makefile,v 1.26 2000/06/27 00:30:49 petere Exp $
 #
 #-------------------------------------------------------------------------
 
-SRCDIR= ..
+subdir = src/bin
+top_builddir = ../..
 include ../Makefile.global
 
-DIRS = pg_id pg_version psql pg_dump pg_passwd \
- 	scripts initdb initlocation ipcclean \
-	pg_ctl
+DIRS := initdb initlocation ipcclean pg_ctl pg_dump pg_id \
+	pg_passwd pg_version psql scripts
+
+ALLDIRS := $(DIRS) pg_encoding pgaccess pgtclsh
 
 ifdef MULTIBYTE
 DIRS += pg_encoding
 endif
 
-#
 # TCL/TK programs
-#
 ifeq ($(USE_TCL), true)
 ifeq ($(USE_TK), true)
 	DIRS += pgaccess
@@ -32,5 +29,11 @@ endif
 	DIRS += pgtclsh
 endif
 
-.DEFAULT all:
-	for i in $(DIRS); do $(MAKE) -C $$i $@; done
+all install installdirs uninstall depend:
+	@for dir in $(DIRS); do $(MAKE) -C $$dir $@ || exit 1; done
+
+clean:
+	@for dir in $(DIRS); do $(MAKE) -C $$dir $@; done
+
+distclean maintainer-clean:
+	@for dir in $(ALLDIRS); do $(MAKE) -C $$dir $@; done
diff --git a/src/bin/initdb/Makefile b/src/bin/initdb/Makefile
index f2c81a9cc918903413a19afd25ca9f4748fe0601..0224abec6ec36891ae186d0fd96eb30bb9a1d1c4 100644
--- a/src/bin/initdb/Makefile
+++ b/src/bin/initdb/Makefile
@@ -1,28 +1,30 @@
 #-------------------------------------------------------------------------
 #
-# Makefile.inc--
-#    Makefile for bin/initdb
+# Makefile for src/bin/initdb
 #
 # Copyright (c) 1994, Regents of the University of California
 #
-#
-# IDENTIFICATION
-#    $Header: /cvsroot/pgsql/src/bin/initdb/Makefile,v 1.17 2000/02/16 21:25:59 momjian Exp $
+# $Header: /cvsroot/pgsql/src/bin/initdb/Makefile,v 1.18 2000/06/27 00:30:53 petere Exp $
 #
 #-------------------------------------------------------------------------
 
-SRCDIR= ../..
+subdir = src/bin/initdb
+top_builddir = ../../..
 include ../../Makefile.global
 
 all: initdb
 
 initdb: initdb.sh
-	sed -e 's/__MULTIBYTE__/$(MULTIBYTE)/g' < initdb.sh > initdb
+	sed -e 's/__MULTIBYTE__/$(MULTIBYTE)/g' < $< > $@
 
-install: initdb
-	$(INSTALL) $(INSTL_EXE_OPTS) $+ $(BINDIR)/$+
+install: all installdirs
+	$(INSTALL_SCRIPT) initdb $(bindir)/initdb
 
-clean:
-	rm -f initdb
+installdirs:
+	$(mkinstalldirs) $(bindir)
 
-dep depend:
+uninstall:
+	rm -f $(bindir)/initdb
+
+clean distclean maintainer-clean:
+	rm -f initdb
diff --git a/src/bin/initlocation/Makefile b/src/bin/initlocation/Makefile
index 410bba1c64e3c997f95a10a37b57108cd2df3bf8..ca811c03e3b308d5d681bbe4074c419afd5e4341 100644
--- a/src/bin/initlocation/Makefile
+++ b/src/bin/initlocation/Makefile
@@ -1,28 +1,30 @@
 #-------------------------------------------------------------------------
 #
-# Makefile.inc--
-#    Makefile for bin/initlocation
+# Makefile for src/bin/initlocation
 #
 # Copyright (c) 1994, Regents of the University of California
 #
-#
-# IDENTIFICATION
-#    $Header: /cvsroot/pgsql/src/bin/initlocation/Attic/Makefile,v 1.8 1999/12/08 10:29:43 momjian Exp $
+# $Header: /cvsroot/pgsql/src/bin/initlocation/Attic/Makefile,v 1.9 2000/06/27 00:31:00 petere Exp $
 #
 #-------------------------------------------------------------------------
 
-SRCDIR= ../..
+subdir = src/bin/initlocation
+top_builddir = ../../..
 include ../../Makefile.global
 
 all: initlocation
 
 initlocation: initlocation.sh
-	cp -p initlocation.sh initlocation
+	cp $< $@
 
-install: initlocation
-	$(INSTALL) $(INSTL_EXE_OPTS) $+ $(BINDIR)
+install: all installdirs
+	$(INSTALL_SCRIPT) initlocation $(bindir)/initlocation
 
-clean:
-	rm -f initlocation
+installdirs:
+	$(mkinstalldirs) $(bindir)
 
-dep depend:
+uninstall:
+	rm -f $(bindir)/initlocation
+
+clean distclean maintainer-clean:
+	rm -f initlocation
diff --git a/src/bin/ipcclean/Makefile b/src/bin/ipcclean/Makefile
index 2f741a0dc2e48df117317bf4caae05e8a243f2df..152fba5b02ac39ba4ec47567bf5594c188e7b5e1 100644
--- a/src/bin/ipcclean/Makefile
+++ b/src/bin/ipcclean/Makefile
@@ -1,16 +1,15 @@
 #-------------------------------------------------------------------------
 #
-# Makefile for bin/ipcclean
+# Makefile for src/bin/ipcclean
 #
 # Copyright (c) 1994, Regents of the University of California
 #
-#
-# IDENTIFICATION
-#    $Header: /cvsroot/pgsql/src/bin/ipcclean/Attic/Makefile,v 1.10 2000/04/14 23:43:43 petere Exp $
+# $Header: /cvsroot/pgsql/src/bin/ipcclean/Attic/Makefile,v 1.11 2000/06/27 00:31:05 petere Exp $
 #
 #-------------------------------------------------------------------------
 
-SRCDIR= ../..
+subdir = src/bin/ipcclean
+top_builddir = ../../..
 include ../../Makefile.global
 
 all: ipcclean
@@ -18,10 +17,14 @@ all: ipcclean
 ipcclean: ipcclean.sh
 	cp $< $@
 
-install: ipcclean
-	$(INSTALL) $(INSTL_EXE_OPTS) $^ $(BINDIR)
+install: all installdirs
+	$(INSTALL_SCRIPT) ipcclean $(bindir)/ipcclean
 
-clean:
-	rm -f ipcclean
+installdirs:
+	$(mkinstalldirs) $(bindir)
 
-dep depend:
+uninstall:
+	rm -f $(bindir)/ipcclean
+
+clean distclean maintainer-clean:
+	rm -f ipcclean
diff --git a/src/bin/pg_ctl/Makefile b/src/bin/pg_ctl/Makefile
index a0095749aa9e6a0271d32ead83951f04197bdbc5..a08751ee877bee96b1ee3eff8acfba13bf71fe94 100644
--- a/src/bin/pg_ctl/Makefile
+++ b/src/bin/pg_ctl/Makefile
@@ -1,28 +1,30 @@
 #-------------------------------------------------------------------------
 #
-# Makefile.inc--
-#    Makefile for bin/pg_ctl
+# Makefile for src/bin/pg_ctl
 #
 # Copyright (c) 1999, PostgreSQL Global Development Group
 #
-#
-# IDENTIFICATION
-#    $Header: /cvsroot/pgsql/src/bin/pg_ctl/Makefile,v 1.5 2000/06/04 01:44:36 petere Exp $
+# $Header: /cvsroot/pgsql/src/bin/pg_ctl/Makefile,v 1.6 2000/06/27 00:31:08 petere Exp $
 #
 #-------------------------------------------------------------------------
 
-SRCDIR= ../..
+subdir = src/bin/pg_ctl
+top_builddir = ../../..
 include ../../Makefile.global
 
 all: pg_ctl
 
 pg_ctl: pg_ctl.sh
-	cat pg_ctl.sh > pg_ctl
+	cp $< $@
 
-install: pg_ctl
-	$(INSTALL) $(INSTL_EXE_OPTS) $+ $(BINDIR)
+install: all installdirs
+	$(INSTALL_SCRIPT) pg_ctl $(bindir)/pg_ctl
 
-clean:
-	rm -f pg_ctl
+installdirs:
+	$(mkinstalldirs) $(bindir)
 
-dep depend:
+uninstall:
+	rm -f $(bindir)/pg_ctl
+
+clean distclean maintainer-clean:
+	rm -f pg_ctl
diff --git a/src/bin/pg_dump/Makefile b/src/bin/pg_dump/Makefile
new file mode 100644
index 0000000000000000000000000000000000000000..cf621027cdde7652f7519f59ac5d38aa81ed4c72
--- /dev/null
+++ b/src/bin/pg_dump/Makefile
@@ -0,0 +1,51 @@
+#-------------------------------------------------------------------------
+#
+# Makefile for src/bin/pg_dump
+#
+# Copyright (c) 1994, Regents of the University of California
+#
+# $Header: /cvsroot/pgsql/src/bin/pg_dump/Makefile,v 1.15 2000/06/27 00:31:12 petere Exp $
+#
+#-------------------------------------------------------------------------
+
+subdir = src/bin/pg_dump
+top_builddir = ../../..
+include ../../Makefile.global
+
+OBJS= pg_dump.o common.o $(STRDUP)
+
+CFLAGS+= -I$(LIBPQDIR)
+
+
+all: submake pg_dump$(X)
+
+pg_dump$(X): $(OBJS) $(LIBPQDIR)/libpq.a
+	$(CC) $(CFLAGS) -o $@ $(OBJS) $(LIBPQ) $(LDFLAGS)
+
+../../utils/strdup.o:
+	$(MAKE) -C ../../utils strdup.o
+
+.PHONY: submake
+submake:
+	$(MAKE) -C $(LIBPQDIR) libpq.a
+
+install: all installdirs
+	$(INSTALL_PROGRAM) pg_dump$(X) $(bindir)/pg_dump$(X)
+	$(INSTALL_SCRIPT) pg_dumpall $(bindir)/pg_dumpall
+	$(INSTALL_SCRIPT) pg_upgrade $(bindir)/pg_upgrade
+
+installdirs:
+	$(mkinstalldirs) $(bindir)
+
+uninstall:
+	rm -f $(addprefix $(bindir)/, pg_dump$(X) pg_dumpall pg_upgrade)
+
+depend dep:
+	$(CC) -MM $(CFLAGS) *.c >depend
+
+clean distclean maintainer-clean:
+	rm -f pg_dump$(X) $(OBJS) 
+
+ifeq (depend,$(wildcard depend))
+include depend
+endif
diff --git a/src/bin/pg_dump/Makefile.in b/src/bin/pg_dump/Makefile.in
deleted file mode 100644
index aa7ed69555094513194e74b352de3d769ea1e217..0000000000000000000000000000000000000000
--- a/src/bin/pg_dump/Makefile.in
+++ /dev/null
@@ -1,47 +0,0 @@
-#-------------------------------------------------------------------------
-#
-# Makefile.inc--
-#    Makefile for bin/pg_dump
-#
-# Copyright (c) 1994, Regents of the University of California
-#
-#
-# IDENTIFICATION
-#    $Header: /cvsroot/pgsql/src/bin/pg_dump/Attic/Makefile.in,v 1.14 2000/06/17 00:09:44 petere Exp $
-#
-#-------------------------------------------------------------------------
-
-SRCDIR= ../..
-include ../../Makefile.global
-
-OBJS= pg_dump.o common.o @STRDUP@
-
-CFLAGS+= -I$(LIBPQDIR)
-
-
-all: submake pg_dump
-
-pg_dump: $(OBJS) $(LIBPQDIR)/libpq.a
-	$(CC) $(CFLAGS) -o pg_dump $(OBJS) $(LIBPQ) $(LDFLAGS)
-
-../../utils/strdup.o:
-	$(MAKE) -C ../../utils strdup.o
-
-.PHONY: submake
-submake:
-	$(MAKE) -C $(LIBPQDIR) libpq.a
-
-install: pg_dump
-	$(INSTALL) $(INSTL_EXE_OPTS) pg_dump$(X) $(BINDIR)/pg_dump$(X)
-	$(INSTALL) $(INSTL_EXE_OPTS) pg_dumpall $(BINDIR)/pg_dumpall
-	$(INSTALL) $(INSTL_EXE_OPTS) pg_upgrade $(BINDIR)/pg_upgrade
-
-depend dep:
-	$(CC) -MM $(CFLAGS) *.c >depend
-
-clean: 
-	rm -f pg_dump$(X) $(OBJS) 
-
-ifeq (depend,$(wildcard depend))
-include depend
-endif
diff --git a/src/bin/pg_encoding/Makefile b/src/bin/pg_encoding/Makefile
index 5db546a9cf186d6808ac696bf2ad79a3c46dfc38..179a3f43da6c1cd6ca2d8f82b16182af90cce971 100644
--- a/src/bin/pg_encoding/Makefile
+++ b/src/bin/pg_encoding/Makefile
@@ -1,37 +1,42 @@
 #-------------------------------------------------------------------------
 #
-#    Makefile for bin/pg_encoding
+# Makefile for src/bin/pg_encoding
 #
-# Copyright (c) 1998, PostgreSQL development group
+# Copyright (c) 1998, PostgreSQL Global Development Group
 #
-#
-# IDENTIFICATION
-#    $Header: /cvsroot/pgsql/src/bin/pg_encoding/Attic/Makefile,v 1.7 2000/05/29 05:45:44 tgl Exp $
+# $Header: /cvsroot/pgsql/src/bin/pg_encoding/Attic/Makefile,v 1.8 2000/06/27 00:31:17 petere Exp $
 #
 #-------------------------------------------------------------------------
 
-SRCDIR= ../..
-include $(SRCDIR)/Makefile.global
+subdir = src/bin/pg_encoding
+top_builddir = ../../..
+include ../../Makefile.global
 
 OBJS= pg_encoding.o
 
-all: submake pg_encoding
+all: submake pg_encoding$(X)
 
-pg_encoding: $(OBJS)
-	$(CC) -o pg_encoding $(OBJS) $(LIBPQ) $(LDFLAGS) $(CFLAGS)
+pg_encoding$(X): $(OBJS)
+	$(CC) -o $@ $(OBJS) $(LIBPQ) $(LDFLAGS) $(CFLAGS)
 
 .PHONY: submake
 
 submake:
 	$(MAKE) -C $(LIBPQDIR) libpq.a
 
-install: pg_encoding
-	$(INSTALL) $(INSTL_EXE_OPTS) pg_encoding$(X) $(BINDIR)/pg_encoding$(X)
+install: all installdirs
+	$(INSTALL_PROGRAM) pg_encoding$(X) $(bindir)/pg_encoding$(X)
+
+installdirs:
+	$(mkinstalldirs) $(bindir)
+
+uninstall:
+	rm -f $(bindir)/pg_encoding$(X)
 
 depend dep:
 	$(CC) -MM $(CFLAGS) *.c >depend
 
-clean: 
+clean distclean maintainer-clean:
 	rm -f pg_encoding$(X) pg_encoding.o
 
 ifeq (depend,$(wildcard depend))
diff --git a/src/bin/pg_id/Makefile b/src/bin/pg_id/Makefile
index 713eb299611a9b4f0b98f368b6a749d433e16a53..dd74d83e13b2270ede537d46fb8190e7cce053de 100644
--- a/src/bin/pg_id/Makefile
+++ b/src/bin/pg_id/Makefile
@@ -1,32 +1,36 @@
 #-------------------------------------------------------------------------
 #
-# Makefile
-#    Makefile for bin/pg_id
+# Makefile for src/bin/pg_id
 #
 # Copyright (C) 2000 by PostgreSQL Global Development Team
 #
-# $Header: /cvsroot/pgsql/src/bin/pg_id/Attic/Makefile,v 1.16 2000/03/31 14:14:32 momjian Exp $
+# $Header: /cvsroot/pgsql/src/bin/pg_id/Attic/Makefile,v 1.17 2000/06/27 00:31:20 petere Exp $
 #
 #-------------------------------------------------------------------------
 
-SRCDIR= ../..
+subdir = src/bin/pg_id
+top_builddir = ../../..
 include ../../Makefile.global
 
-OBJS= pg_id.o
+all: pg_id$(X)
 
-all: pg_id
+pg_id$(X): pg_id.o
+	$(CC) -o $@ $^ $(LDFLAGS)
 
-pg_id: $(OBJS)
-	$(CC) -o pg_id $(OBJS) $(LDFLAGS)
+install: all installdirs
+	$(INSTALL_PROGRAM) pg_id$(X) $(bindir)/pg_id$(X)
 
-install: pg_id
-	$(INSTALL) $(INSTL_EXE_OPTS) pg_id$(X) $(BINDIR)/pg_id$(X)
+installdirs:
+	$(mkinstalldirs) $(bindir)
+
+uninstall:
+	rm -f $(bindir)/pg_id$(X)
 
 depend dep:
 	$(CC) -MM $(CFLAGS) *.c >depend
 
-clean:
-	rm -f pg_id$(X) $(OBJS)
+clean distclean maintainer-clean:
+	rm -f pg_id$(X) pg_id.o
 
 ifeq (depend,$(wildcard depend))
 include depend
diff --git a/src/bin/pg_passwd/Makefile b/src/bin/pg_passwd/Makefile
index f6c15053c9ac216dd68df80fbabdd954bfd433cb..aef4f1a56a4c43b6039f71251b7a217a2c195a49 100644
--- a/src/bin/pg_passwd/Makefile
+++ b/src/bin/pg_passwd/Makefile
@@ -1,31 +1,30 @@
-#-------------------------------------------------------------------------
 #
-# Makefile
-#    Makefile for bin/pg_passwd
-#-------------------------------------------------------------------------
+# Makefile for src/bin/pg_passwd
+#
 
-SRCDIR= ../..
+subdir = src/bin/pg_passwd
+top_builddir = ../../..
 include ../../Makefile.global
 
-OBJS= pg_passwd.o
+all: pg_passwd$(X)
 
-all: pg_passwd
+pg_passwd$(X): pg_passwd.o
+	$(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS)
 
-pg_passwd: $(OBJS)
-	$(CC) $(CFLAGS) -o pg_passwd $(OBJS) $(LDFLAGS)
+install: all installdirs
+	$(INSTALL_PROGRAM) pg_passwd$(X) $(bindir)/pg_passwd$(X)
 
-install: pg_passwd
-	$(INSTALL) $(INSTL_EXE_OPTS) pg_passwd$(X) $(BINDIR)/pg_passwd$(X)
+installdirs:
+	$(mkinstalldirs) $(bindir)
 
-.PHONY: submake
-submake:
-	$(MAKE) -C $(LIBPQDIR) libpq.a
+uninstall:
+	rm -f $(bindir)/pg_passwd$(X)
 
 depend dep:
 	$(CC) -MM $(CFLAGS) *.c >depend
 
-clean:
-	rm -f pg_passwd$(X) $(OBJS)
+clean distclean maintainer-clean:
+	rm -f pg_passwd$(X) pg_passwd.o
 
 ifeq (depend,$(wildcard depend))
 include depend
diff --git a/src/bin/pg_version/Makefile b/src/bin/pg_version/Makefile
new file mode 100644
index 0000000000000000000000000000000000000000..373031fc9fb798ffd840fc35400aac87751ead2e
--- /dev/null
+++ b/src/bin/pg_version/Makefile
@@ -0,0 +1,43 @@
+#-------------------------------------------------------------------------
+#
+# Makefile for src/bin/pg_version
+#
+# Portions Copyright (c) 1996-2000, PostgreSQL, Inc
+# Portions Copyright (c) 1994, Regents of the University of California
+#
+# $Header: /cvsroot/pgsql/src/bin/pg_version/Attic/Makefile,v 1.7 2000/06/27 00:31:29 petere Exp $
+#
+#-------------------------------------------------------------------------
+
+subdir = src/bin/pg_version
+top_builddir = ../../..
+include ../../Makefile.global
+
+OBJS= pg_version.o $(top_builddir)/src/utils/version.o $(STRERROR2)
+
+all: pg_version$(X)
+
+pg_version$(X): $(OBJS)
+	$(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS)
+
+$(top_builddir)/src/utils/version.o: $(top_srcdir)/src/utils/version.c $(top_builddir)/src/include/version.h
+	$(MAKE) -C $(top_builddir)/src/utils version.o
+
+install: all installdirs
+	$(INSTALL_PROGRAM) pg_version$(X) $(bindir)/pg_version$(X)
+
+installdirs:
+	$(mkinstalldirs) $(bindir)
+
+uninstall:
+	rm -f $(bindir)/pg_version$(X)
+
+depend dep:
+	$(CC) -MM $(CFLAGS) *.c >depend
+
+clean distclean maintainer-clean:
+	rm -f pg_version$(X) pg_version.o
+
+ifeq (depend,$(wildcard depend))
+include depend
+endif
diff --git a/src/bin/pg_version/Makefile.in b/src/bin/pg_version/Makefile.in
deleted file mode 100644
index 38d67a5e1c50cdccae87ed581ed05a7c23a4c49c..0000000000000000000000000000000000000000
--- a/src/bin/pg_version/Makefile.in
+++ /dev/null
@@ -1,38 +0,0 @@
-#-------------------------------------------------------------------------
-#
-# Makefile.in--
-#    Makefile for bin/pg_version
-#
-# Portions Copyright (c) 1996-2000, PostgreSQL, Inc
-# Portions Copyright (c) 1994, Regents of the University of California
-#
-# IDENTIFICATION
-#    $Header: /cvsroot/pgsql/src/bin/pg_version/Attic/Makefile.in,v 1.9 2000/05/29 05:45:46 tgl Exp $
-#
-#-------------------------------------------------------------------------
-
-SRCDIR= ../..
-include $(SRCDIR)/Makefile.global
-
-OBJS= pg_version.o $(SRCDIR)/utils/version.o @STRERROR2@
-
-all: pg_version
-
-pg_version: $(OBJS)
-	$(CC) $(CFLAGS) -o pg_version $(OBJS) $(LDFLAGS)
-
-$(SRCDIR)/utils/version.o: $(SRCDIR)/utils/version.c $(SRCDIR)/include/version.h
-	$(MAKE) -C $(SRCDIR)/utils version.o
-
-install: pg_version
-	$(INSTALL) $(INSTL_EXE_OPTS) pg_version$(X) $(BINDIR)/pg_version$(X)
-
-depend dep:
-	$(CC) -MM $(CFLAGS) *.c >depend
-
-clean: 
-	rm -f pg_version$(X) pg_version.o
-
-ifeq (depend,$(wildcard depend))
-include depend
-endif
diff --git a/src/bin/pgaccess/Makefile b/src/bin/pgaccess/Makefile
index 9bc53196f0260966f5d3cb0bbd0e3abf347bc152..58b7f2b0530d35d23d6a3404e703691d53f081d8 100644
--- a/src/bin/pgaccess/Makefile
+++ b/src/bin/pgaccess/Makefile
@@ -1,37 +1,38 @@
 #-------------------------------------------------------------------------
 #
-# Makefile
-#    Makefile for pgaccess
+# Makefile for src/bin/pgaccess
 #
 # Copyright (c) 1994, Regents of the University of California
 #
-# IDENTIFICATION
-#    $Header: /cvsroot/pgsql/src/bin/pgaccess/Attic/Makefile,v 1.8 1999/12/16 01:25:10 momjian Exp $
+# $Header: /cvsroot/pgsql/src/bin/pgaccess/Attic/Makefile,v 1.9 2000/06/27 00:31:34 petere Exp $
 #
 #-------------------------------------------------------------------------
 
-SRCDIR= ../..
-include $(SRCDIR)/Makefile.global
+subdir = src/bin/pgaccess
+top_builddir = ../../..
+include ../../Makefile.global
+
+pgaccessdir = $(datadir)/pgaccess
 
 all: pgaccess
 
 pgaccess: pgaccess.sh
-	sed -e 's;__wish__;$(WISH);' pgaccess.sh |	\
-	sed -e 's;__POSTGRESDIR__;$(POSTGRESDIR);' 	\
-			> pgaccess
-
-install:
-	$(INSTALL) $(INSTL_EXE_OPTS) pgaccess $(BINDIR)/pgaccess
-	-@if [ ! -d $(POSTGRESDIR)/pgaccess ]; then mkdir $(POSTGRESDIR)/pgaccess; fi
-	$(INSTALL) $(INSTL_EXE_OPTS) main.tcl $(POSTGRESDIR)/pgaccess
-	-@if [ ! -d $(POSTGRESDIR)/pgaccess/lib ]; then mkdir $(POSTGRESDIR)/pgaccess/lib; fi
-	$(INSTALL) $(INSTLOPTS) lib/*.tcl $(POSTGRESDIR)/pgaccess/lib
-	-@if [ ! -d $(POSTGRESDIR)/pgaccess/lib/help ]; then mkdir $(POSTGRESDIR)/pgaccess/lib/help; fi
-	$(INSTALL) $(INSTLOPTS) lib/help/*.hlp $(POSTGRESDIR)/pgaccess/lib/help
-	-@if [ ! -d $(POSTGRESDIR)/pgaccess/lib/languages ]; then mkdir $(POSTGRESDIR)/pgaccess/lib/languages; fi
-	$(INSTALL) $(INSTLOPTS) lib/languages/[a-z]* $(POSTGRESDIR)/pgaccess/lib/languages
-	-@if [ ! -d $(POSTGRESDIR)/pgaccess/images ]; then mkdir $(POSTGRESDIR)/pgaccess/images; fi
-	$(INSTALL) $(INSTLOPTS) images/*.gif $(POSTGRESDIR)/pgaccess/images
-
-clean:
+	sed -e 's,__wish__,$(WISH),' -e 's,__PGACCESSHOME__,$(pgaccessdir),' < $< > $@
+
+install: all installdirs
+	$(INSTALL_SCRIPT) pgaccess $(bindir)/pgaccess
+	$(INSTALL_SCRIPT) main.tcl $(pgaccessdir)
+	$(INSTALL_DATA) lib/*.tcl $(pgaccessdir)/lib
+	$(INSTALL_DATA) lib/help/*.hlp $(pgaccessdir)/lib/help
+	$(INSTALL_DATA) lib/languages/[a-z]* $(pgaccessdir)/lib/languages
+	$(INSTALL_DATA) images/*.gif $(pgaccessdir)/images
+
+installdirs:
+	$(mkinstalldirs) $(bindir) $(pgaccessdir)/lib/help $(pgaccessdir)/lib/languages $(pgaccessdir)/images
+
+uninstall:
+	rm -f $(bindir)/pgaccess
+	rm -rf $(pgaccessdir)
+
+clean distclean maintainer-clean:
 	rm -f pgaccess
diff --git a/src/bin/pgaccess/pgaccess.sh b/src/bin/pgaccess/pgaccess.sh
index 88b40a1149f767f97b7013b011c900295b2bc046..c41cf53cce0126bd1332b479378a8e7ebc57cc51 100755
--- a/src/bin/pgaccess/pgaccess.sh
+++ b/src/bin/pgaccess/pgaccess.sh
@@ -1,10 +1,9 @@
-#!/bin/sh
+#! /bin/sh
 
 PATH_TO_WISH=__wish__
-PGACCESS_HOME=__POSTGRESDIR__/pgaccess
+PGACCESS_HOME=__PGACCESSHOME__
 
 export PATH_TO_WISH
 export PGACCESS_HOME
 
 exec ${PATH_TO_WISH} ${PGACCESS_HOME}/main.tcl "$@"
-
diff --git a/src/bin/pgtclsh/Makefile b/src/bin/pgtclsh/Makefile
index 95f3a3b6a6b6969ae45b50b5ba2b3c5715055056..0aeb56a73425b303d87a1d86f43ddbd000dd61cf 100644
--- a/src/bin/pgtclsh/Makefile
+++ b/src/bin/pgtclsh/Makefile
@@ -1,17 +1,16 @@
 #-------------------------------------------------------------------------
 #
-# Makefile
-#    Makefile for a tclsh workalike with pgtcl commands installed
+# Makefile for src/bin/pgtclsh
+# (a tclsh workalike with pgtcl commands installed)
 #
 # Copyright (c) 1994, Regents of the University of California
 #
-#
-# IDENTIFICATION
-#    $Header: /cvsroot/pgsql/src/bin/pgtclsh/Attic/Makefile,v 1.27 2000/06/17 00:09:47 petere Exp $
+# $Header: /cvsroot/pgsql/src/bin/pgtclsh/Attic/Makefile,v 1.28 2000/06/27 00:31:40 petere Exp $
 #
 #-------------------------------------------------------------------------
 
-SRCDIR= ../..
+subdir = src/bin/pgtclsh
+top_builddir = ../../..
 include ../../Makefile.global
 
 #
@@ -26,42 +25,55 @@ CFLAGS+= $(X_CFLAGS) -I$(LIBPGTCLDIR)
 
 
 # If we are here then TCL is available
-PGMS = pgtclsh
-INSTPGMS = install_tcl
+PROGRAMS = pgtclsh
 
 # Add TK targets if TK is available
 ifeq ($(USE_TK), true)
-PGMS += pgtksh
-INSTPGMS += install_tk
+PROGRAMS += pgtksh
 endif
 
-all: $(PGMS)
+all: submake $(PROGRAMS)
 
 pgtclsh: pgtclAppInit.o
-	$(CC) $(CFLAGS) $(TCL_DEFS) -o $@ pgtclAppInit.o \
+	$(CC) $(CFLAGS) $(TCL_DEFS) -o $@ $< \
 	  $(LIBPGTCL) $(LIBPQ) $(TCL_LIB_SPEC) $(TCL_LIBS) $(LDFLAGS)
 
 pgtksh: pgtkAppInit.o
-	$(CC) $(CFLAGS) $(TK_DEFS) -o $@ pgtkAppInit.o \
+	$(CC) $(CFLAGS) $(TK_DEFS) -o $@ $< \
 	  $(LIBPGTCL) $(LIBPQ) $(X_LIBS) $(TK_LIB_SPEC) $(TK_LIBS) \
 	  $(TCL_LIB_SPEC) $(X11_LIBS) $(LDFLAGS)
 
-install: $(INSTPGMS)
+.PHONY: submake
+submake:
+	$(MAKE) -C $(LIBPGTCLDIR) all
+
+install: all installdirs
+	$(INSTALL_PROGRAM) pgtclsh $(bindir)/pgtclsh
+ifeq ($(USE_TK), true)
+	$(INSTALL_PROGRAM) pgtksh $(bindir)/pgtksh
+endif
 
-install_tcl: pgtclsh
-	$(INSTALL) $(INSTL_EXE_OPTS) pgtclsh $(BINDIR)/pgtclsh
+installdirs:
+	$(mkinstalldirs) $(bindir)
 
-install_tk: pgtksh
-	$(INSTALL) $(INSTL_EXE_OPTS) pgtksh $(BINDIR)/pgtksh
+uninstall:
+	rm -f $(bindir)/pgtclsh $(bindir)/pgtksh
 
 Makefile.tcldefs: mkMakefile.tcldefs.sh
-	/bin/sh ./mkMakefile.tcldefs.sh
+	$(SHELL) $<
 
 Makefile.tkdefs: mkMakefile.tkdefs.sh
-	/bin/sh ./mkMakefile.tkdefs.sh
+	$(SHELL) $<
+
+mkMakefile.tcldefs.sh mkMakefile.tkdefs.sh: $(top_builddir)/config.status
+mkMakefile.tcldefs.sh mkMakefile.tkdefs.sh: % : %.in
+	cd $(top_builddir) && CONFIG_FILES=$(subdir)/$@ CONFIG_HEADERS= ./config.status
 
 clean:
-	rm -f *.o Makefile.t*defs pgtclsh pgtksh
+	rm -f *.o Makefile.tcldefs Makefile.tkdefs pgtclsh pgtksh
+
+distclean maintainer-clean: clean
+	rm -f mkMakefile.tcldefs.sh mkMakefile.tkdefs.sh
 
 dep depend:
 	$(CC) -MM $(CFLAGS) *.c > depend
diff --git a/src/bin/psql/Makefile b/src/bin/psql/Makefile
new file mode 100644
index 0000000000000000000000000000000000000000..f318e10f2213e26751bb49e19beb54b1c88e2a98
--- /dev/null
+++ b/src/bin/psql/Makefile
@@ -0,0 +1,88 @@
+#-------------------------------------------------------------------------
+#
+# Makefile for src/bin/psql
+#
+# Copyright (c) 1994, Regents of the University of California
+#
+# $Header: /cvsroot/pgsql/src/bin/psql/Makefile,v 1.21 2000/06/27 00:31:41 petere Exp $
+#
+#-------------------------------------------------------------------------
+
+subdir = src/bin/psql
+top_builddir = ../../..
+include ../../Makefile.global
+
+REFDOCDIR= $(top_srcdir)/doc/src/sgml/ref
+
+CFLAGS+= -I$(LIBPQDIR)
+
+OBJS=command.o common.o help.o input.o stringutils.o mainloop.o \
+	copy.o startup.o prompt.o variables.o large_obj.o print.o describe.o \
+	tab-complete.o
+
+all: submake psql$(X)
+
+ifdef STRDUP
+OBJS+=$(top_builddir)/src/utils/strdup.o
+
+$(top_builddir)/src/utils/strdup.o:
+	$(MAKE) -C $(top_builddir)/src/utils strdup.o
+endif
+
+# Move these to the utils directory?
+
+ifdef STRERROR
+OBJS+=$(top_builddir)/src/backend/port/strerror.o
+
+$(top_builddir)/src/backend/port/strerror.o:
+	$(MAKE) -C $(top_builddir)/src/backend/port strerror.o
+endif
+
+ifdef SNPRINTF
+OBJS+=$(top_builddir)/src/backend/port/snprintf.o
+
+$(top_builddir)/src/backend/port/snprintf.o:
+	$(MAKE) -C $(top_builddir)/src/backend/port snprintf.o
+endif
+
+# End of hacks for picking up backend 'port' modules
+
+psql$(X): $(OBJS) $(LIBPQDIR)/libpq.a
+	$(CC) $(CFLAGS) -o $@ $(OBJS) $(LIBPQ) $(LDFLAGS)
+
+help.o: $(srcdir)/sql_help.h
+
+ifdef PERL
+$(srcdir)/sql_help.h: create_help.pl $(wildcard $(REFDOCDIR)/*.sgml)
+	$(PERL) $< $(REFDOCDIR) $@
+else
+$(srcdir)/sql_help.h:
+	@echo "*** Perl is needed to build psql help."
+endif
+
+.PHONY: submake
+
+submake:
+	$(MAKE) -C $(LIBPQDIR) libpq.a
+
+install: all installdirs
+	$(INSTALL_PROGRAM) psql$(X) $(bindir)/psql$(X)
+
+installdirs:
+	$(mkinstalldirs) $(bindir)
+
+uninstall:
+	rm -f $(bindir)/psql$(X)
+
+depend dep:
+	$(CC) -MM -MG $(CFLAGS) *.c >depend
+
+clean distclean:
+	rm -f psql$(X) $(OBJS)
+
+maintainer-clean: distclean
+	rm -f sql_help.h
+
+ifeq (depend,$(wildcard depend))
+include depend
+endif
diff --git a/src/bin/psql/Makefile.in b/src/bin/psql/Makefile.in
deleted file mode 100644
index 9aa56bed6d914085be08068eb851acc70712f6a5..0000000000000000000000000000000000000000
--- a/src/bin/psql/Makefile.in
+++ /dev/null
@@ -1,89 +0,0 @@
-#-------------------------------------------------------------------------
-#
-# Makefile.in--
-#    Makefile for bin/psql
-#
-# Copyright (c) 1994, Regents of the University of California
-#
-#
-# IDENTIFICATION
-#    $Header: /cvsroot/pgsql/src/bin/psql/Attic/Makefile.in,v 1.26 2000/06/17 00:09:51 petere Exp $
-#
-#-------------------------------------------------------------------------
-
-SRCDIR= ../..
-include $(SRCDIR)/Makefile.global
-
-DOCDIR= $(SRCDIR)/../doc/src/sgml/ref
-PERL = @PERL@
-
-CFLAGS+= -I$(LIBPQDIR)
-
-OBJS=command.o common.o help.o input.o stringutils.o mainloop.o \
-	copy.o startup.o prompt.o variables.o large_obj.o print.o describe.o \
-	tab-complete.o
-
-all: submake psql
-
-ifneq (@STRDUP@,)
-OBJS+=$(SRCDIR)/utils/strdup.o
-
-$(SRCDIR)/utils/strdup.o:
-	$(MAKE) -C $(SRCDIR)/utils strdup.o
-endif
-
-# Move these to the utils directory?
-
-ifneq (@STRERROR@,)
-OBJS+=$(SRCDIR)/backend/port/strerror.o
-
-$(SRCDIR)/backend/port/strerror.o:
-	$(MAKE) -C $(SRCDIR)/backend/port strerror.o
-endif
-
-ifneq (@SNPRINTF@,)
-OBJS+=$(SRCDIR)/backend/port/snprintf.o
-
-$(SRCDIR)/backend/port/snprintf.o:
-	$(MAKE) -C $(SRCDIR)/backend/port snprintf.o
-endif
-
-# End of hacks for picking up backend 'port' modules
-
-psql: $(OBJS) $(LIBPQDIR)/libpq.a
-	$(CC) $(CFLAGS) -o psql $(OBJS) $(LIBPQ) $(LDFLAGS)
-
-help.o: sql_help.h
-
-ifneq ($(strip $(PERL)),) 
-sql_help.h: $(wildcard $(DOCDIR)/*.sgml) create_help.pl
-	$(PERL) create_help.pl $(DOCDIR) sql_help.h 
-else
-sql_help.h:
-	@echo "*** Perl is needed to build psql help."
-endif
-
-.PHONY: submake
-
-submake:
-	$(MAKE) -C $(LIBPQDIR) libpq.a
-
-install: psql
-	$(INSTALL) $(INSTL_EXE_OPTS) psql$(X) $(BINDIR)/psql$(X)
-
-depend dep:
-	$(CC) -MM -MG $(CFLAGS) *.c >depend
-
-clean: 
-	rm -f psql$(X) $(OBJS)
-
-# Some people might get in trouble if they do a make clean and the
-# sql_help.h is gone, for it needs the docs in the right place to be
-# regenerated. -- (pe)
-
-maintainer-clean: clean
-	rm -f sql_help.h
-
-ifeq (depend,$(wildcard depend))
-include depend
-endif
diff --git a/src/bin/psql/create_help.pl b/src/bin/psql/create_help.pl
index 875ff843837a9441e2f64566c1638af7ac174ad5..9e71e5bfa566c7ec9cfbb08821a5f8ae80f472ba 100644
--- a/src/bin/psql/create_help.pl
+++ b/src/bin/psql/create_help.pl
@@ -5,7 +5,7 @@
 #
 # Copyright 2000 by PostgreSQL Global Development Group
 #
-# $Header: /cvsroot/pgsql/src/bin/psql/create_help.pl,v 1.6 2000/04/16 18:07:22 tgl Exp $
+# $Header: /cvsroot/pgsql/src/bin/psql/create_help.pl,v 1.7 2000/06/27 00:31:41 petere Exp $
 #################################################################
 
 #
@@ -22,7 +22,14 @@
 $docdir = $ARGV[0] || die "$0: missing required argument: docdir\n";
 $outputfile = $ARGV[1] || die "$0: missing required argument: output file\n";
 
-$define = $outputfile;
+if ($outputfile =~ m!.*/([^/]+)$!) {
+    $outputfilebasename = $1;
+}
+else {
+    $outputfilebasename = $outputfile;
+}
+
+$define = $outputfilebasename;
 $define =~ tr/a-z/A-Z/;
 $define =~ s/\W/_/g;
 
@@ -33,12 +40,11 @@ open(OUT, ">$outputfile")
 
 print OUT
 "/*
- * *** Do not change this file. It is machine-generated. ***
+ * *** Do not change this file by hand. It is automatically
+ * *** generated from the DocBook documentation.
  *
- * This file was generated by
- *     $^X $0 $outputfile
- * from the DocBook documentation in
- *     $docdir
+ * generated by
+ *     $^X $0 @ARGV
  *
  */
 
@@ -108,7 +114,7 @@ foreach $file (sort readdir DIR) {
         $count++;
     }
     else {
-	print STDERR "$0: parsing file '$file' failed at or near line $. (N='$cmdname' D='$cmddesc')\n";
+	print STDERR "$0: parsing file '$file' failed (N='$cmdname' D='$cmddesc')\n";
     }
 }
 
diff --git a/src/bin/scripts/Makefile b/src/bin/scripts/Makefile
index 0e91744358bf9212a587c5ec006e343bc7c22787..7426db49eb8847f6855099fb5e6de5c9161d3c0a 100644
--- a/src/bin/scripts/Makefile
+++ b/src/bin/scripts/Makefile
@@ -1,40 +1,32 @@
 #-------------------------------------------------------------------------
 #
-# Makefile.inc--
-#    Makefile for bin/scripts
+# Makefile for src/bin/scripts
 #
 # Copyright (c) 1994, Regents of the University of California
 #
-#
-# IDENTIFICATION
-#    $Header: /cvsroot/pgsql/src/bin/scripts/Makefile,v 1.4 1999/12/16 01:25:11 momjian Exp $
+# $Header: /cvsroot/pgsql/src/bin/scripts/Makefile,v 1.5 2000/06/27 00:31:44 petere Exp $
 #
 #-------------------------------------------------------------------------
 
-.SUFFIXES:
-
-SRCDIR=../..
+subdir = src/bin/scripts
+top_builddir = ../../..
 include ../../Makefile.global
 
-SCRIPTS=createdb dropdb createuser dropuser createlang droplang vacuumdb
+SCRIPTS := createdb dropdb createuser dropuser createlang droplang vacuumdb
 
 all: $(SCRIPTS)
 
-createdb:
-dropdb:
-createuser:
-dropuser:
-
 createlang: createlang.sh
-	sed -e 's/__DLSUFFIX__/$(DLSUFFIX)/' createlang.sh > createlang
-droplang:
+	sed -e 's/__DLSUFFIX__/$(DLSUFFIX)/' $< > $@
 
-vacuumdb:
+install: all installdirs
+	$(INSTALL_SCRIPT) $(SCRIPTS) $(bindir)
 
-install: $(SCRIPTS)
-	for i in $+; do $(INSTALL) $(INSTL_EXE_OPTS) $$i $(BINDIR); done
+installdirs:
+	$(mkinstalldirs) $(bindir)
 
-clean:
-	rm -f createlang
+uninstall:
+	rm -f $(addprefix $(bindir)/, $(SCRIPTS))
 
-dep depend:
+clean distclean maintainer-clean:
+	rm -f createlang
diff --git a/src/pl/Makefile b/src/pl/Makefile
new file mode 100644
index 0000000000000000000000000000000000000000..100722105b33f2a0e749f9b5dda7384fbfb13e45
--- /dev/null
+++ b/src/pl/Makefile
@@ -0,0 +1,36 @@
+#-------------------------------------------------------------------------
+#
+# Makefile for src/pl (procedural languages)
+#
+# Copyright (c) 1994, Regents of the University of California
+#
+# $Header: /cvsroot/pgsql/src/pl/Makefile,v 1.9 2000/06/27 00:31:48 petere Exp $
+#
+#-------------------------------------------------------------------------
+
+subdir = src/pl
+top_builddir = ../..
+include ../Makefile.global
+
+DIRS := plpgsql
+
+ifeq ($(USE_TCL), true)
+DIRS += tcl
+endif
+
+# Disabled because it doesn't work
+#ifeq ($(with_perl), yes)
+#	$(MAKE) -C plperl $@
+#endif
+
+ALLDIRS := plpgsql tcl plperl
+
+
+all install installdirs uninstall depend:
+	@for dir in $(DIRS); do $(MAKE) -C $$dir $@ || exit 1; done
+
+clean:
+	@for dir in $(DIRS); do $(MAKE) -C $$dir $@; done
+
+distclean maintainer-clean:
+	@for dir in $(ALLDIRS); do $(MAKE) -C $$dir $@; done
diff --git a/src/pl/Makefile.in b/src/pl/Makefile.in
deleted file mode 100644
index 1a5a067dc8d890f94bd97f44184a4d3c995d66f6..0000000000000000000000000000000000000000
--- a/src/pl/Makefile.in
+++ /dev/null
@@ -1,51 +0,0 @@
-#-------------------------------------------------------------------------
-#
-# Makefile for src/pl (procedural languages)
-#
-# Copyright (c) 1994, Regents of the University of California
-#
-# $Header: /cvsroot/pgsql/src/pl/Attic/Makefile.in,v 1.2 2000/06/20 16:40:04 petere Exp $
-#
-#-------------------------------------------------------------------------
-
-srcdir = @srcdir@
-VPATH = @srcdir@
-
-top_srcdir = @top_srcdir@
-top_builddir = ../..
-subdir = src/pl
-
-
-with_perl = @with_perl@
-USE_TCL = @USE_TCL@
-
-
-all install clean:
-	$(MAKE) -C plpgsql $@
-ifeq ($(USE_TCL), true)
-	$(MAKE) -C tcl $@
-endif
-# Disabled because it doesn't work
-#ifeq ($(with_perl), yes)
-#	$(MAKE) -C plperl $@
-#endif
-
-
-distclean maintainer-clean:
-	-$(MAKE) -C plpgsql $@
-ifeq ($(USE_TCL), true)
-	$(MAKE) -C tcl clean
-endif
-	rm -f tcl/mkMakefile.tcldefs.sh
-	-$(MAKE) -C plperl $@
-	rm -f Makefile
-
-
-.PHONY: all install clean distclean maintainer-clean
-
-
-Makefile: Makefile.in $(top_builddir)/config.status
-	cd $(top_builddir) && CONFIG_FILES=$(subdir)/$@ CONFIG_HEADERS= ./config.status
-
-$(top_builddir)/config.status: $(top_srcdir)/configure
-	cd $(top_builddir) && ./config.status --recheck
diff --git a/src/pl/plperl/GNUmakefile b/src/pl/plperl/GNUmakefile
new file mode 100644
index 0000000000000000000000000000000000000000..0e34b2e3d7c41a6723bb8b3149cfd51a9f8be39e
--- /dev/null
+++ b/src/pl/plperl/GNUmakefile
@@ -0,0 +1,28 @@
+# $Header: /cvsroot/pgsql/src/pl/plperl/GNUmakefile,v 1.1 2000/06/27 00:31:49 petere Exp $
+
+subdir = src/pl/plperl
+top_builddir = ../../..
+include ../../Makefile.global
+
+plperl_installdir = $(libdir)
+
+
+all: Makefile
+	$(MAKE) -f $< all
+
+Makefile: Makefile.PL
+	@plperl_installdir='$(plperl_installdir)' \
+	  EXTRA_INCLUDES='-I$(top_srcdir)/src/include $(INCLUDES)' \
+	  $(PERL) $< POLLUTE=1
+
+install: all installdirs
+	$(MAKE) -f $< install
+
+installdirs:
+	$(mkinstalldirs) $(plperl_installdir)
+
+uninstall:
+	rm -f $(libdir)/plperl$(DLSUFFIX)
+
+clean distclean maintainer-clean:
+	-[ -f Makefile ] && $(MAKE) -f Makefile realclean
diff --git a/src/pl/plperl/GNUmakefile.in b/src/pl/plperl/GNUmakefile.in
deleted file mode 100644
index 5ac85ce835bf2a79cbd6d68b478cbc5d5325bdac..0000000000000000000000000000000000000000
--- a/src/pl/plperl/GNUmakefile.in
+++ /dev/null
@@ -1,40 +0,0 @@
-# $Header: /cvsroot/pgsql/src/pl/plperl/Attic/GNUmakefile.in,v 1.2 2000/06/17 00:10:21 petere Exp $
-
-srcdir = @srcdir@
-VPATH = @srcdir@
-
-top_srcdir = @top_srcdir@
-top_builddir = ../../..
-
-prefix = @prefix@
-exec_prefix = @exec_prefix@
-libdir = @libdir@
-
-plperl_installdir = $(libdir)
-
-mkinstalldirs = @mkinstalldirs@
-PERL = @PERL@
-INCLUDES = @INCLUDES@
-
-all: Makefile
-	$(MAKE) -f $< all
-
-Makefile: Makefile.PL
-	@plperl_installdir='$(plperl_installdir)' \
-	  EXTRA_INCLUDES='-I$(top_srcdir)/src/include $(INCLUDES)' \
-	  $(PERL) $< POLLUTE=1
-
-install: Makefile installdirs
-	$(MAKE) -f $< install
-
-installdirs:
-	$(mkinstalldirs) $(plperl_installdir)
-
-clean:
-	-[ -f Makefile ] && $(MAKE) -f Makefile realclean
-
-distclean maintainer-clean: clean
-	rm -f GNUmakefile
-
-
-.PHONY: all install installdirs clean distclean maintainer-clean
diff --git a/src/pl/plpgsql/Makefile b/src/pl/plpgsql/Makefile
new file mode 100644
index 0000000000000000000000000000000000000000..2c6848622563d76a6cc5d41c041fc206f90330cf
--- /dev/null
+++ b/src/pl/plpgsql/Makefile
@@ -0,0 +1,19 @@
+#-------------------------------------------------------------------------
+#
+# Makefile for src/pl/plpgsql (PostgreSQL's SQL procedural language)
+#
+# Copyright (c) 1994, Regents of the University of California
+#
+# $Header: /cvsroot/pgsql/src/pl/plpgsql/Makefile,v 1.3 2000/06/27 00:31:56 petere Exp $
+#
+#-------------------------------------------------------------------------
+
+subdir = src/pl/plpgsql
+top_builddir = ../../..
+include ../../Makefile.global
+
+all install installdirs uninstall:
+	$(MAKE) -C src $@
+
+clean distclean maintainer-clean:
+	-$(MAKE) -C src $@
diff --git a/src/pl/plpgsql/Makefile.in b/src/pl/plpgsql/Makefile.in
deleted file mode 100644
index 422a02c20e016bb2d3aa67019a25a052aa09d3cd..0000000000000000000000000000000000000000
--- a/src/pl/plpgsql/Makefile.in
+++ /dev/null
@@ -1,34 +0,0 @@
-#-------------------------------------------------------------------------
-#
-# Makefile for src/pl/plpgsql (PostgreSQL's SQL procedural language)
-#
-# Copyright (c) 1994, Regents of the University of California
-#
-# $Header: /cvsroot/pgsql/src/pl/plpgsql/Attic/Makefile.in,v 1.1 2000/06/20 16:40:07 petere Exp $
-#
-#-------------------------------------------------------------------------
-
-srcdir = @srcdir@
-VPATH = @srcdir@
-
-top_srcdir = @top_srcdir@
-top_builddir = ../../..
-subdir = src/pl/plpgsql
-
-
-.DEFAULT all install clean:
-	$(MAKE) -C src $@
-
-distclean maintainer-clean:
-	-$(MAKE) -C src $@
-	rm -f Makefile
-
-
-.PHONY: all install clean distclean maintainer-clean
-
-
-Makefile: Makefile.in $(top_builddir)/config.status
-	cd $(top_builddir) && CONFIG_FILES=$(subdir)/$@ CONFIG_HEADERS= ./config.status
-
-$(top_builddir)/config.status: $(top_srcdir)/configure
-	cd $(top_builddir) && ./config.status --recheck
diff --git a/src/pl/plpgsql/src/Makefile.in b/src/pl/plpgsql/src/Makefile
similarity index 58%
rename from src/pl/plpgsql/src/Makefile.in
rename to src/pl/plpgsql/src/Makefile
index 27cc8a8b71e494b3c7669c1425d46bd3a9390561..4abc335ee413bbf0cda9c6f69948b9c8a6b4b5b6 100644
--- a/src/pl/plpgsql/src/Makefile.in
+++ b/src/pl/plpgsql/src/Makefile
@@ -2,42 +2,25 @@
 #
 # Makefile for the plpgsql shared object
 #
-# $Header: /cvsroot/pgsql/src/pl/plpgsql/src/Attic/Makefile.in,v 1.26 2000/06/20 16:40:10 petere Exp $
+# $Header: /cvsroot/pgsql/src/pl/plpgsql/src/Makefile,v 1.3 2000/06/27 00:32:01 petere Exp $
 #
 #-------------------------------------------------------------------------
 
-srcdir = @srcdir@
-VPATH = @srcdir@
-
-top_srcdir = @top_srcdir@
-top_builddir = ../../../..
 subdir = src/pl/plpgsql/src
-
-
-INSTALL = @INSTALL@
-INSTALL_SHLIB = @INSTALL_SHLIB@
-mkinstalldirs = @mkinstalldirs@
-prefix = @prefix@
-exec_prefix = @exec_prefix@
-libdir = @libdir@
-
+top_builddir = ../../../..
+include $(top_builddir)/src/Makefile.global
 
 # Shared library parameters
 NAME= plpgsql
 SO_MAJOR_VERSION= 1
 SO_MINOR_VERSION= 0
-DLSUFFIX = @DLSUFFIX@
-
-SRCDIR = $(top_srcdir)/src
-include $(SRCDIR)/Makefile.global
-
 
 CPPFLAGS += -I$(srcdir)
 
-OBJS=	pl_parse.o pl_handler.o pl_comp.o pl_exec.o pl_funcs.o
+OBJS = pl_parse.o pl_handler.o pl_comp.o pl_exec.o pl_funcs.o
 
-# Shared library stuff, also default 'all' target
-include $(SRCDIR)/Makefile.shlib
+# Shared library stuff, also default `all' target
+include $(top_srcdir)/src/Makefile.shlib
 
 
 # In order to use Makefile.shlib, we allow it to build a static
@@ -46,8 +29,8 @@ include $(SRCDIR)/Makefile.shlib
 # call it that when installed, however, so we ignore the install-shlib
 # rule and do this instead:
 
-install: installdirs $(shlib)
-ifneq ($(shlib),)
+install: installdirs all
+ifdef shlib
 	$(INSTALL_SHLIB) $(shlib) $(libdir)/plpgsql$(DLSUFFIX)
 else
 	@echo "*****"; \
@@ -58,9 +41,12 @@ endif
 installdirs:
 	$(mkinstalldirs) $(libdir)
 
-pl_handler.o pl_comp.o pl_exec.o pl_funcs.o: plpgsql.h pl.tab.h
+uninstall:
+	rm -f $(libdir)/plpgsql$(DLSUFFIX)
 
-pl_parse.o: pl_gram.c pl_scan.c plpgsql.h
+pl_handler.o pl_comp.o pl_exec.o pl_funcs.o: plpgsql.h $(srcdir)/pl.tab.h
+
+pl_parse.o: $(srcdir)/pl_gram.c $(srcdir)/pl_scan.c plpgsql.h
 	$(CC) -c $(CPPFLAGS) $(CFLAGS) -o $@ $<
 
 # Note: Since the yacc and lex files are shipped in the distribution,
@@ -82,25 +68,8 @@ mklang.sql: mklang.sql.in
 	sed -e 's%__libdir__%$(libdir)%g' -e 's%__DLSUFFIX__%$(DLSUFFIX)%g' < $< > $@
 
 
-clean: clean-shlib
+clean distclean: clean-shlib
 	rm -f lib$(NAME).a *.o y.tab.c y.tab.h lex.yy.c mklang.sql
 
-distclean: clean
-	rm -f Makefile
-
 maintainer-clean: clean
 	rm -f $(srcdir)/pl_gram.c $(srcdir)/pl.tab.h $(srcdir)/pl_scan.c
-	rm -f Makefile
-
-
-.PHONY: all install installdirs clean distclean maintainer-clean
-
-
-Makefile: Makefile.in $(top_builddir)/config.status
-	cd $(top_builddir) && CONFIG_FILES=$(subdir)/$@ CONFIG_HEADERS= ./config.status
-
-$(top_builddir)/src/Makefile.global: $(top_srcdir)/src/Makefile.global.in $(top_builddir)/config.status
-	cd $(top_builddir) && CONFIG_FILES=src/Makefile.global CONFIG_HEADERS= ./config.status
-
-$(top_builddir)/config.status: $(top_srcdir)/configure
-	cd $(top_builddir) && ./config.status --recheck
diff --git a/src/pl/tcl/Makefile b/src/pl/tcl/Makefile
index b58d4944b1a45ff39cc971ed5861d26f32ddff68..44b7a390acd061a07b687a6989c935a98414ad51 100644
--- a/src/pl/tcl/Makefile
+++ b/src/pl/tcl/Makefile
@@ -1,34 +1,23 @@
 #-------------------------------------------------------------------------
 #
-# Makefile
-#    Makefile for the pltcl shared object
+# Makefile for the pltcl shared object
 #
-# IDENTIFICATION
-#    $Header: /cvsroot/pgsql/src/pl/tcl/Makefile,v 1.17 2000/06/17 00:10:25 petere Exp $
+# $Header: /cvsroot/pgsql/src/pl/tcl/Makefile,v 1.18 2000/06/27 00:32:06 petere Exp $
 #
 #-------------------------------------------------------------------------
 
-#
-# Tell make where the postgresql sources live
-#
-SRCDIR= ../../../src
-include $(SRCDIR)/Makefile.global
+subdir = src/pl/tcl
+top_builddir = ../../..
+include ../../Makefile.global
 
-#
-# Include definitions from the tclConfig.sh file
-# NOTE: GNU make will make this file automatically if it doesn't exist,
-# using the make rule that appears below.  Cute, eh?
-#
 include Makefile.tcldefs
 
-#
-# Find out whether Tcl was built as a shared library --- if not,
-# we can't link a shared library that depends on it, and have to
-# forget about building pltcl.
-# In Tcl 8, tclConfig.sh sets TCL_SHARED_BUILD for us, but in
-# older Tcl releases it doesn't.  In that case we guess based on
-# the name of the Tcl library.
-#
+# Find out whether Tcl was built as a shared library --- if not, we
+# can't link a shared library that depends on it, and have to forget
+# about building pltcl. In Tcl 8, tclConfig.sh sets TCL_SHARED_BUILD
+# for us, but in older Tcl releases it doesn't. In that case we guess
+# based on the name of the Tcl library.
+
 ifndef TCL_SHARED_BUILD
 ifneq (,$(findstring $(DLSUFFIX),$(TCL_LIB_FILE)))
 TCL_SHARED_BUILD=1
@@ -38,14 +27,13 @@ endif
 endif
 
 
-# Change following to how shared library that contains
-# references to libtcl must get built on your system.
-# Since these definitions come from the tclConfig.sh script,
-# they should work if the shared build of tcl was successful
-# on this system.  However, tclConfig.sh lies to us a little bit
-# (at least in versions 7.6 through 8.0.4) --- it doesn't mention -lc
-# in TCL_LIBS, but you still need it on systems that want to hear about
-# dependent libraries...
+# Change following to how shared library that contains references to
+# libtcl must get built on your system. Since these definitions come
+# from the tclConfig.sh script, they should work if the shared build
+# of tcl was successful on this system. However, tclConfig.sh lies to
+# us a little bit (at least in versions 7.6 through 8.0.4) --- it
+# doesn't mention -lc in TCL_LIBS, but you still need it on systems
+# that want to hear about dependent libraries...
 
 ifneq ($(TCL_SHLIB_LD_LIBS),)
 # link command for a shared lib must mention shared libs it uses
@@ -55,28 +43,30 @@ else
 SHLIB_EXTRA_LIBS=
 endif
 
-%$(TCL_SHLIB_SUFFIX):	%.o
+%$(TCL_SHLIB_SUFFIX): %.o
 	$(TCL_SHLIB_LD) -o $@ $< $(TCL_LIB_SPEC) $(SHLIB_EXTRA_LIBS)
 
 
 CC = $(TCL_CC)
 
-# Since we are using Tcl's choice of C compiler, which might not be the
-# same one selected for Postgres, do NOT use CFLAGS from Makefile.global.
-# Instead use TCL's CFLAGS plus necessary -I directives.
+# Since we are using Tcl's choice of C compiler, which might not be
+# the same one selected for Postgres, do NOT use CFLAGS from
+# Makefile.global. Instead use TCL's CFLAGS plus necessary -I
+# directives.
 
-# Can choose either TCL_CFLAGS_OPTIMIZE or TCL_CFLAGS_DEBUG here, as needed
+# Can choose either TCL_CFLAGS_OPTIMIZE or TCL_CFLAGS_DEBUG here, as
+# needed
 CFLAGS= $(TCL_CFLAGS_OPTIMIZE)
 
 CFLAGS+= $(TCL_SHLIB_CFLAGS) $(TCL_DEFS)
 
-CFLAGS+= -I$(SRCDIR)/include $(INCLUDES)
-        
-#
-# Uncomment the following to enable the unknown command lookup
-# on the first of all calls to the call handler. See the doc
-# in the modules directory about details.
-#
+CFLAGS+= -I$(top_srcdir)/src/include $(INCLUDES)
+
+
+# Uncomment the following to enable the unknown command lookup on the
+# first of all calls to the call handler. See the doc in the modules
+# directory about details.
+
 #CFLAGS+= -DPLTCL_UNKNOWN_SUPPORT
 
 
@@ -95,42 +85,39 @@ INFILES+= $(DLOBJS:.o=$(EXPSUFF))
 endif
 
 
-ifeq ($(TCL_SHARED_BUILD),1)
+# Provide dummy targets for the case where we can't build the shared library.
+
+ifeq ($(TCL_SHARED_BUILD), 1)
 
-#
-# Build the shared lib
-#
 all: $(INFILES)
 
-install: all
-	$(INSTALL) $(INSTL_SHLIB_OPTS) $(DLOBJS) $(LIBDIR)/$(DLOBJS)
+install: all installdirs
+	$(INSTALL_SHLIB) $(DLOBJS) $(libdir)/$(DLOBJS)
 
-else
+installdirs:
+	$(mkinstalldirs) $(libdir)
 
-#
-# Oops, can't build it
-#
-all:
-	@echo "Cannot build pltcl because Tcl is not a shared library; skipping it."
+uninstall:
+	rm -f $(libdir)/$(DLOBJS)
 
-install:
-	@echo "Cannot build pltcl because Tcl is not a shared library; skipping it."
+else
 
+all install:
+	@echo "*****"; \
+	 echo "* Cannot build pltcl because Tcl is not a shared library; skipping it."; \
+	 echo "*****"
 endif
 
-#
-# Make targets that are still valid when we can't build pltcl
-# should be below here.
-#
 
 Makefile.tcldefs: mkMakefile.tcldefs.sh
-	/bin/sh ./mkMakefile.tcldefs.sh
+	$(SHELL) $<
+
+mkMakefile.tcldefs.sh: mkMakefile.tcldefs.sh.in $(top_builddir)/config.status
+	cd $(top_builddir) && CONFIG_FILES=$(subdir)/$@ CONFIG_HEADERS= ./config.status
+
 
-#
-# Clean 
-#
 clean:
-	rm -f $(INFILES) *.o
-	rm -f Makefile.tcldefs
+	rm -f $(INFILES) *.o Makefile.tcldefs
 
-dep depend:
+distclean maintainer-clean: clean
+	rm -f mkMakefile.tcldefs.sh