diff --git a/Makefile.am b/Makefile.am
index 3273a8b..b0592a2 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -9,7 +9,7 @@
 
 AUTOMAKE_OPTIONS = foreign
 
-SUBDIRS = xtra/png2c branding i18n plugins.d pgadmin xtra pkg
+SUBDIRS = branding i18n plugins.d xtra pgadmin pkg
 
 EXTRA_DIST = \
 	$(top_srcdir)/BUGS \
@@ -101,4 +101,4 @@ endif
 all: doc
 
 clean-local:
-	rm -rf docs/en_US/_build
+	rm -rf $(top_srcdir)/docs/en_US/_build
diff --git a/configure.ac.in b/configure.ac.in
index 1d5a748..46a93fd 100644
--- a/configure.ac.in
+++ b/configure.ac.in
@@ -6,7 +6,7 @@ AC_CONFIG_AUX_DIR(config)
 AC_CONFIG_SRCDIR([pgadmin/pgAdmin3.cpp])
 AC_CONFIG_HEADERS([config.h])
 AC_CANONICAL_HOST
-AM_INIT_AUTOMAKE([tar-ustar subdir-objects])
+AM_INIT_AUTOMAKE([tar-ustar])
 AC_PREFIX_DEFAULT([/usr/local/pgadmin3])
 
 # Checks for programs.
diff --git a/pgadmin/Makefile.am b/pgadmin/Makefile.am
index 6195b96..8b243c9 100644
--- a/pgadmin/Makefile.am
+++ b/pgadmin/Makefile.am
@@ -119,13 +119,13 @@ endif
 # Convert images to an embeddable format
 BUILT_SOURCES = $(patsubst %.png,%.pngc,$(wildcard $(top_srcdir)/pgadmin/include/images/*.png))
 
-$(top_srcdir)/xtra/png2c/png2c:
-	(cd $(top_srcdir)/xtra/png2c && $(MAKE) $(AM_MAKEFLAGS) png2c)
+$(top_builddir)/xtra/png2c/png2c:
+	(cd $(top_builddir)/xtra/png2c && $(MAKE) $(AM_MAKEFLAGS) png2c)
 
-$(BUILT_SOURCES): $(top_srcdir)/xtra/png2c/png2c
+$(BUILT_SOURCES): $(top_builddir)/xtra/png2c/png2c
 
 %.pngc: %.png
-	$(top_srcdir)/xtra/png2c/png2c $< $@
+	$(top_builddir)/xtra/png2c/png2c $< $@
 
 clean-local:
 	rm -f include/images/*.pngc
diff --git a/xtra/Makefile.am b/xtra/Makefile.am
index b00c635..6afbbdf 100644
--- a/xtra/Makefile.am
+++ b/xtra/Makefile.am
@@ -10,3 +10,7 @@
 DIST_SUBDIRS = png2c pgscript wx-build
 SUBDIRS = wx-build
 
+clean:
+	for dir in $(DIST_SUBDIRS); do \
+		$(MAKE) -C $$dir $(AM_MAKEFLAGS) clean || exit 1; \
+	done;
diff --git a/xtra/pgscript/Makefile.am b/xtra/pgscript/Makefile.am
index f44b76f..e46946f 100644
--- a/xtra/pgscript/Makefile.am
+++ b/xtra/pgscript/Makefile.am
@@ -11,5 +11,5 @@ SUBDIRS = lib bin test
 
 EXTRA_DIST =
 
-include $(srcdir)/doc/module.mk
-include $(srcdir)/file/module.mk
+include doc/module.mk
+include file/module.mk
diff --git a/xtra/pgscript/bin/Makefile.am b/xtra/pgscript/bin/Makefile.am
index e0a30cf..36bc991 100644
--- a/xtra/pgscript/bin/Makefile.am
+++ b/xtra/pgscript/bin/Makefile.am
@@ -13,7 +13,7 @@ pgScript_SOURCES = \
 	pgsMain.cpp
 
 pgScript_LDADD += \
-	$(srcdir)/../lib/libpgs.a
+	$(builddir)/../lib/libpgs.a
 
 if SUN_CXX
   __CXXFLAGS=""
@@ -21,7 +21,7 @@ else
   __CXXFLAGS=-Wall -Wno-non-virtual-dtor -fno-strict-aliasing
 endif
 
-AM_CXXFLAGS = $(__CXXFLAGS) -I$(srcdir)/../../../pgadmin/include -DPGSCLI -DPGADMIN3_H
-AM_CFLAGS = $(__CFLAGS) -I$(srcdir)/../../../pgadmin/include -DPGSCLI -DPGADMIN3_H
+AM_CXXFLAGS = $(__CXXFLAGS) -I$(top_srcdir)/pgadmin/include -DPGSCLI -DPGADMIN3_H
+AM_CFLAGS = $(__CFLAGS) -I$(top_srcdir)/pgadmin/include -DPGSCLI -DPGADMIN3_H
 
 # dist_man_MANS = pgScript.1
diff --git a/xtra/pgscript/lib/Makefile.am b/xtra/pgscript/lib/Makefile.am
index 64662eb..e158732 100644
--- a/xtra/pgscript/lib/Makefile.am
+++ b/xtra/pgscript/lib/Makefile.am
@@ -7,9 +7,11 @@
 # Makefile - Makefile for *nix systems
 ##############################################################################
 
+AUTOMAKE_OPTIONS = foreign subdir-objects no-dependencies
+OBJEXT=pgso
 noinst_LIBRARIES = libpgs.a
 
-nodist_libpgs_a_SOURCES = ../../../pgadmin/utils/sysLogger.cpp \
+libpgs_a_SOURCES = ../../../pgadmin/utils/sysLogger.cpp \
 	../../../pgadmin/utils/misc.cpp \
 	../../../pgadmin/db/keywords.c \
 	../../../pgadmin/pgscript/utilities/pgsUtilities.cpp \
@@ -141,5 +143,11 @@ else
   __CXXFLAGS=-Wall -Wno-non-virtual-dtor -fno-strict-aliasing
 endif
 
-AM_CXXFLAGS = $(__CXXFLAGS) -I../../../pgadmin/include -DPGSCLI -DPGADMIN3_H
-AM_CFLAGS = $(__CFLAGS) -I../../../pgadmin/include -DPGSCLI -DPGADMIN3_H
+AM_CXXFLAGS = $(__CXXFLAGS) -I$(top_srcdir)/pgadmin/include -DPGSCLI -DPGADMIN3_H
+AM_CFLAGS = $(__CFLAGS) -I$(top_srcdir)/pgadmin/include -DPGSCLI -DPGADMIN3_H
+
+%.pgso : %.c
+	$(CXXCOMPILE) -c -o $@ $<
+
+%.pgso : %.cpp
+	$(CXXCOMPILE) -c -o $@ $<
diff --git a/xtra/png2c/Makefile.am b/xtra/png2c/Makefile.am
index 4f6e9d2..6f04a57 100644
--- a/xtra/png2c/Makefile.am
+++ b/xtra/png2c/Makefile.am
@@ -15,5 +15,3 @@ png2c_SOURCES = \
 EXTRA_DIST = \
 	png2c.vcxproj \
 	png2c.vcxproj.filters
-
-distclean:
