Index: /main/trunk/package-kits/linux/distros/arch
===================================================================
--- /main/trunk/package-kits/linux/distros/arch	(revision 29606)
+++ /main/trunk/package-kits/linux/distros/arch	(revision 29607)
@@ -11,4 +11,11 @@
 TOMCAT_USER:            tomcat7
 GLI:                    %GREENSTONE_HOME%/gli
+
+ARCH_NATIVE:
+    'x86_64'
+    'i686'
+
+ARCH_ANY:
+    'any'
 
 PKG_SVN:
Index: /main/trunk/package-kits/linux/distros/fedora
===================================================================
--- /main/trunk/package-kits/linux/distros/fedora	(revision 29606)
+++ /main/trunk/package-kits/linux/distros/fedora	(revision 29607)
@@ -11,4 +11,11 @@
 TOMCAT_USER:            tomcat
 GLI:                    %GREENSTONE_HOME%/gli
+
+ARCH_NATIVE:
+    x86_64
+    i686
+
+ARCH_ANY:
+    any
 
 PKG_SVN:
Index: /main/trunk/package-kits/linux/distros/ubuntu
===================================================================
--- /main/trunk/package-kits/linux/distros/ubuntu	(revision 29606)
+++ /main/trunk/package-kits/linux/distros/ubuntu	(revision 29607)
@@ -11,4 +11,10 @@
 TOMCAT_USER:            tomcat7
 GLI:                    %GREENSTONE_HOME%/gli
+
+ARCH_NATIVE:
+    any
+
+ARCH_ANY:
+    all
 
 PKG_SVN:
Index: /main/trunk/package-kits/linux/managers/apt/conf
===================================================================
--- /main/trunk/package-kits/linux/managers/apt/conf	(revision 29607)
+++ /main/trunk/package-kits/linux/managers/apt/conf	(revision 29607)
@@ -0,0 +1,2 @@
+BUILD_LIB_DIR:  %SYSTEMLIB%
+BUILD_BIN_DIR:  %SYSTEMBIN%
Index: /main/trunk/package-kits/linux/managers/apt/files/debian/changelog
===================================================================
--- /main/trunk/package-kits/linux/managers/apt/files/debian/changelog	(revision 29607)
+++ /main/trunk/package-kits/linux/managers/apt/files/debian/changelog	(revision 29607)
@@ -0,0 +1,5 @@
+%NAME% (%VERSION%) unstable; urgency=medium
+
+  * Initial release. (Closes: #XXXXXX)
+
+ -- Greenstone Team <greenstone_team@cs.waikato.ac.nz>  Tue, 25 Nov 2014 14:38:47 +1300
Index: /main/trunk/package-kits/linux/managers/apt/files/debian/compat
===================================================================
--- /main/trunk/package-kits/linux/managers/apt/files/debian/compat	(revision 29607)
+++ /main/trunk/package-kits/linux/managers/apt/files/debian/compat	(revision 29607)
@@ -0,0 +1,1 @@
+9
Index: /main/trunk/package-kits/linux/managers/apt/files/debian/copyright
===================================================================
--- /main/trunk/package-kits/linux/managers/apt/files/debian/copyright	(revision 29607)
+++ /main/trunk/package-kits/linux/managers/apt/files/debian/copyright	(revision 29607)
@@ -0,0 +1,22 @@
+Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
+Upstream-Name: Greenstone Digital Library
+Upstream-Contact: greenstone_team@cs.waikato.ac.nz
+Source: http://greenstone.org
+
+Files: *
+License: GPL-2
+    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.
+On Debian GNU/Linux and Ubuntu systems, the complete text of the GPL-2 License
+can be found in '/usr/share/common-licenses/GPL-2'
Index: /main/trunk/package-kits/linux/managers/apt/files/debian/rules
===================================================================
--- /main/trunk/package-kits/linux/managers/apt/files/debian/rules	(revision 29607)
+++ /main/trunk/package-kits/linux/managers/apt/files/debian/rules	(revision 29607)
@@ -0,0 +1,7 @@
+#!/usr/bin/make -f
+
+%:
+	dh $@ --with autotools_dev
+
+override_dh_shlibdeps:
+	    dh_shlibdeps --dpkg-shlibdeps-params=--ignore-missing-info
Index: /main/trunk/package-kits/linux/managers/pacman/conf
===================================================================
--- /main/trunk/package-kits/linux/managers/pacman/conf	(revision 29607)
+++ /main/trunk/package-kits/linux/managers/pacman/conf	(revision 29607)
@@ -0,0 +1,2 @@
+BUILD_LIB_DIR:  %SYSTEMLIB%
+BUILD_BIN_DIR:  %SYSTEMBIN%
Index: /main/trunk/package-kits/linux/managers/rpm/conf
===================================================================
--- /main/trunk/package-kits/linux/managers/rpm/conf	(revision 29607)
+++ /main/trunk/package-kits/linux/managers/rpm/conf	(revision 29607)
@@ -0,0 +1,2 @@
+BUILD_LIB_DIR:  %{_libdir}/*
+BUILD_BIN_DIR:  %{_bindir}/*
Index: /main/trunk/package-kits/linux/packages/demo
===================================================================
--- /main/trunk/package-kits/linux/packages/demo	(revision 29606)
+++ /main/trunk/package-kits/linux/packages/demo	(revision 29607)
@@ -6,5 +6,5 @@
 DESCRIPTION:            'Several example collections for Greenstone Digital Library'
 HOMEPAGE:               http://greenstone.org
-ARCHITECTURE:           any
+ARCHITECTURE:           %ARCH_ANY%
 LICENSE_SHORT:          GPL-2
 LICENSE:                
Index: /main/trunk/package-kits/linux/packages/gli
===================================================================
--- /main/trunk/package-kits/linux/packages/gli	(revision 29606)
+++ /main/trunk/package-kits/linux/packages/gli	(revision 29607)
@@ -6,5 +6,5 @@
 DESCRIPTION:            'A GUI interface for using the Greenstone Tools'
 HOMEPAGE:               http://greenstone.org
-ARCHITECTURE:           any
+ARCHITECTURE:           %ARCH_ANY%
 LICENSE_SHORT:          GPL-2
 LICENSE:                
@@ -25,5 +25,5 @@
 FILES:
     %GLI%
-    %{_bindir}/*
+    %BUILD_BIN_DIR%
 
 SOURCES:
Index: /main/trunk/package-kits/linux/packages/greenstone
===================================================================
--- /main/trunk/package-kits/linux/packages/greenstone	(revision 29606)
+++ /main/trunk/package-kits/linux/packages/greenstone	(revision 29607)
@@ -11,4 +11,5 @@
     greenstone
     wvWare
+    perl-util.patch
     gs2build.patch
     servlets.patch
@@ -20,5 +21,5 @@
     src
     clean
-    build-core
+    core
     main
     native
@@ -43,5 +44,5 @@
 NATIVE_DESCRIPTION_SHORT:       'Native libraries for Greenstone'
 NATIVE_DESCRIPTION:             'Architecture-dependent binary files required by the core Greenstone package'
-NATIVE_ARCHITECTURE:            %ARCH%
+NATIVE_ARCHITECTURE:            %ARCH_NATIVE%
 
 NATIVE_DEPENDS:
@@ -52,6 +53,5 @@
 
 NATIVE_FILES:                  
-    %TOMCATLIB%/*
-    %{_libdir}/*
+    %BUILD_LIB_DIR%
 
 
@@ -59,5 +59,5 @@
 TOOLS_DESCRIPTION_SHORT:        'Tools for building Greenstone collections'
 TOOLS_DESCRIPTION:              %TOOLS_DESCRIPTION_SHORT%
-TOOLS_ARCHITECTURE:             %ARCH%
+TOOLS_ARCHITECTURE:             %ARCH_NATIVE%
 
 TOOLS_DEPENDS:
@@ -73,6 +73,7 @@
 
 TOOLS_FILES:
-        %GREENSTONE_HOME%/*
-        %{_bindir}/*
+    %GREENSTONE_HOME%/bin
+    %GREENSTONE_HOME%/gs2build
+    %BUILD_BIN_DIR%
 
 
@@ -80,5 +81,5 @@
 MAIN_DESCRIPTION_SHORT:         'Greenstone Digital Library'
 MAIN_DESCRIPTION:               'Greenstone is a suite of software for building and distributing digital library collections'
-MAIN_ARCHITECTURE:              any
+MAIN_ARCHITECTURE:              %ARCH_ANY%
 
 MAIN_DEPENDS:
@@ -98,5 +99,4 @@
     %TOMCATCONF%/*
     %TOMCATLIB%/*
-    %{_libdir}/*
 
 MAIN_POST_INSTALL:
Index: /main/trunk/package-kits/linux/perllib/Greenstone/Package.pm
===================================================================
--- /main/trunk/package-kits/linux/perllib/Greenstone/Package.pm	(revision 29606)
+++ /main/trunk/package-kits/linux/perllib/Greenstone/Package.pm	(revision 29607)
@@ -59,5 +59,9 @@
     $self->readconf ("global.conf");
     $self->readconf ($distro_conf);
-    $self->{config}->{ARCH} = (uname)[4];
+
+    my $manager_conf = "managers/$self->{config}->{MANAGER}/conf";
+    -f $manager_conf or die "Manager config for '$self->{config}->{MANAGER}' does not exist";
+
+    $self->readconf ($manager_conf);
 
     die "Distro '$args{distro}' is invalid (does not specify a manager)"
@@ -79,5 +83,4 @@
     $self->add_sources;
     $self->add_makefile;
-    $self->add_install;
     $self->add_package;
 }
@@ -130,5 +133,6 @@
     
     # Add the (relatively) static files
-    $self->add ("managers/$self->{config}->{MANAGER}", $self->{output});
+    my $static = "managers/$self->{config}->{MANAGER}/files";
+    -d $static and $self->add ($static, $self->{output});
 
     if (exists $self->{config}->{SUB_PACKAGES}) {
Index: /main/trunk/package-kits/linux/perllib/Greenstone/Package/_apt.pm
===================================================================
--- /main/trunk/package-kits/linux/perllib/Greenstone/Package/_apt.pm	(revision 29606)
+++ /main/trunk/package-kits/linux/perllib/Greenstone/Package/_apt.pm	(revision 29607)
@@ -6,4 +6,5 @@
 use parent 'Greenstone::Package';
 
+# Deb packages expect lists to be comma separated
 sub replacement_array {
     my $self = shift;
@@ -16,5 +17,6 @@
     my $file = "$self->{output}/debian/$name";
     print "    - $file\n";
-    open my $OUT, '>', $file;
+    open my $OUT, '>', $file
+        or die "Failed to open $file: $!";
     for my $line (@lines) {
         print $OUT $line, "\n";
@@ -24,16 +26,19 @@
 }
 
+# Add pre/post install/remove hooks
 sub add_install {
-    my $self = shift;
+    my ($self, $name) = @_;
+    my $prefix = (defined $name ? "$name." : "");
     exists $self->{config}->{PRE_INSTALL} and
-        $self->write_function ("preinst", @{$self->{config}->{PRE_INSTALL}});
+        $self->write_function ("${prefix}preinst", @{$self->{config}->{PRE_INSTALL}});
     exists $self->{config}->{POST_INSTALL} and
-        $self->write_function ("postinst", @{$self->{config}->{POST_INSTALL}});
+        $self->write_function ("${prefix}postinst", @{$self->{config}->{POST_INSTALL}});
     exists $self->{config}->{PRE_REMOVE} and
-        $self->write_function ("prerm", @{$self->{config}->{PRE_REMOVE}});
+        $self->write_function ("${prefix}prerm", @{$self->{config}->{PRE_REMOVE}});
     exists $self->{config}->{POST_REMOVE} and
-        $self->write_function ("postrm", @{$self->{config}->{POST_REMOVE}});
+        $self->write_function ("${prefix}postrm", @{$self->{config}->{POST_REMOVE}});
 }
 
+# Adds a definition for a package or subpackage
 sub add_package_section {
     my ($self, $out) = @_;
@@ -42,8 +47,8 @@
         'Architecture: %ARCHITECTURE%',
         'Homepage: %HOMEPAGE%',
-        'Depends:',
-        '  %DEPENDS%',
-        'Description: %DESCRIPTION_SHORT',
-        '  %DESCRIPTION'
+        'Depends: %DEPENDS%',
+        'Description: %DESCRIPTION_SHORT%',
+        '  %DESCRIPTION%',
+        ''
     ) {
         my $copy = $line;
@@ -53,10 +58,11 @@
 }
 
+# Handles the apt-specific package generation
 sub add_package_impl {
     my ($self, $packages) = @_;
-    $self->add_install;
     my $file = "$self->{output}/debian/control";
     print "    - $file\n";
-    open my $CONTROL, '>', $file;
+    open my $CONTROL, '>', $file
+        or die "Failed to open $file: $!";
     for my $line (
         'Source: %NAME%',
@@ -64,6 +70,6 @@
         'Priority: optional',
         'Maintainer: %MAINTAINER_NAME% <%MAINTAINER_EMAIL%>',
-        'Build-Depends:',
-        '  %MAKEDEPENDS%',
+        'Build-Depends: %MAKEDEPENDS%',
+        ''
     ) {
         my $copy = $line;
@@ -73,11 +79,29 @@
     if (defined $packages) {
         my $config = $self->{config};
+        my @names;
         for my $package (@{$packages}) {
+            push @names, $package->{NAME};
             $package->{HOMEPAGE} = $config->{HOMEPAGE};
             $self->{config} = $package;
+            $self->add_install ($package->{NAME});
             $self->add_package_section ($CONTROL);
+            my $install = "$self->{output}/debian/$self->{config}->{NAME}.install";
+            open my $INSTALL, '>', $install;
+            for my $line (@{$self->{config}->{FILES}}) {
+                print $INSTALL $line, "\n";
+            }
+            close $INSTALL;
         }
         $self->{config} = $config;
+        my $rules = "$self->{output}/debian/rules";
+        open my $RULES, '>>', $rules
+            or die "Failed to open $rules: $!";
+        print $RULES "\noverride_dh_gencontrol:\n";
+        for my $name (@names) {
+            print $RULES "\tdh_gencontrol -p$name\n";
+        }
+        close $RULES;
     } else {
+        $self->add_install;
         $self->add_package_section ($CONTROL);
     }
Index: /main/trunk/package-kits/linux/perllib/Greenstone/Package/_pacman.pm
===================================================================
--- /main/trunk/package-kits/linux/perllib/Greenstone/Package/_pacman.pm	(revision 29606)
+++ /main/trunk/package-kits/linux/perllib/Greenstone/Package/_pacman.pm	(revision 29607)
@@ -94,5 +94,5 @@
         'url=%HOMEPAGE%',
         'license=%LICENSE_SHORT%',
-        'arch=(any)',
+        'arch=(' . (defined $self->{config}->{ARCH} ? '%ARCH%' : 'any') . ')',
         'makedepends=(',
         '%MAKEDEPENDS%',
Index: /main/trunk/package-kits/linux/perllib/Greenstone/Package/_rpm.pm
===================================================================
--- /main/trunk/package-kits/linux/perllib/Greenstone/Package/_rpm.pm	(revision 29606)
+++ /main/trunk/package-kits/linux/perllib/Greenstone/Package/_rpm.pm	(revision 29607)
@@ -90,5 +90,7 @@
                 $self->add_install,
                 '%files',
-                '%FILES%'
+                '%FILES%',
+                '',
+                ''
             ) {
                 my $copy = $line;
Index: in/trunk/package-kits/linux/segments/build-core
===================================================================
--- /main/trunk/package-kits/linux/segments/build-core	(revision 29606)
+++ 	(revision )
@@ -1,22 +1,0 @@
-prepare: src
-	cp -L *.properties *.patch src/
-	cd src ; \
-	export JAVA_HOME=$(java) ; \
-	yes | ant prepare
-	# apply patches
-	for patch in *.patch; do patch -d src/ -p0 -N -i $$patch; done || :
-	cd src/gs2build/build-src ; \
-	autoconf
-	rm -rf src/packages/*.zip
-	rm -rf src/packages/axis/docs
-	rm -rf src/gs2build/build-src/packages
-	touch prepare
-
-build: prepare
-	cd src ; \
-	JAVA_HOME=$(java) ant install
-	mv src/lib/jni/*.jar src/web/WEB-INF/lib/
-	# delete windows/mac stuff
-	find src/ -type d \( -iname "win32" -o -iname "windows" -o -iname "winutil" -o -iname "darwin" \) -exec rm -rf {} \; 2> /dev/null || :
-	find src/ \( -iname "*.dll" -o -iname "*.exe" \) -exec rm -rf {} \; || :
-	touch build
Index: /main/trunk/package-kits/linux/segments/core
===================================================================
--- /main/trunk/package-kits/linux/segments/core	(revision 29607)
+++ /main/trunk/package-kits/linux/segments/core	(revision 29607)
@@ -0,0 +1,24 @@
+prepare: src
+	cp -L *.properties *.patch src/
+	cd src ; \
+	export JAVA_HOME=$(java) ; \
+	yes | ant prepare
+	# apply patches
+	for patch in *.patch; do patch -d src/ -p0 -N -i $$patch; done || :
+	cd src/gs2build/build-src ; \
+	autoconf
+	rm -rf src/packages/*.zip
+	rm -rf src/packages/axis/docs
+	rm -rf src/gs2build/build-src/packages
+	touch prepare
+
+build: prepare
+	cd src ; \
+	JAVA_HOME=$(java) ant install
+	mv src/lib/jni/*.jar src/web/WEB-INF/lib/
+	# delete windows/mac stuff
+	find src/ -type d \( -iname "win32" -o -iname "windows" -o -iname "winutil" -o -iname "darwin" \) -exec rm -rf {} \; 2> /dev/null || :
+	find src/ \( -iname "*.dll" -o -iname "*.exe" \) -exec rm -rf {} \; || :
+	touch build
+
+install: install_greenstone install_greenstone-native install_greenstone-tools
