Index: main/trunk/package-kits/linux/global.conf
===================================================================
--- main/trunk/package-kits/linux/global.conf	(revision 29607)
+++ main/trunk/package-kits/linux/global.conf	(revision 29611)
@@ -1,12 +1,17 @@
 MAINTAINER_NAME:        Greenstone Team
 MAINTAINER_EMAIL:       greenstone_team@cs.waikato.ac.nz
+
+GREENSTONE:             greenstone
+NATIVE:                 native
+TOOLS:                  tools
+
 PKG_GREENSTONE:
-    greenstone
+    %GREENSTONE%
 PKG_GREENSTONE_NATIVE:
-    greenstone-native
+    %GREENSTONE%-%NATIVE%
 PKG_GREENSTONE_TOOLS:
-    greenstone-tools
+    %GREENSTONE%-%TOOLS%
 PKG_GREENSTONE_DEMO:
-    greenstone-demo
+    %GREENSTONE%-demo
 PKG_GLI:
-    greenstone-gli
+    %GREENSTONE%-gli
Index: main/trunk/package-kits/linux/packages/greenstone
===================================================================
--- main/trunk/package-kits/linux/packages/greenstone	(revision 29607)
+++ main/trunk/package-kits/linux/packages/greenstone	(revision 29611)
@@ -1,4 +1,4 @@
 SVN_LOCATION:           http://svn.greenstone.org/main/trunk/greenstone3
-NAME:                   greenstone
+NAME:                   %PKG_GREENSTONE%
 VERSION:                3.06
 RELEASE:                1
@@ -6,4 +6,7 @@
 LICENSE_SHORT:          GPL-2
 LICENSE:                
+DESCRIPTION_SHORT:      'Greenstone Digital Library'
+DESCRIPTION:            'Greenstone is a suite of software for building and distributing digital library collections'
+ARCHITECTURE:           %ARCH_ANY%
 SOURCES:
     build.properties
@@ -36,10 +39,32 @@
     %PKG_RSYNC%
 
+DEPENDS:
+    %PKG_GREENSTONE_NATIVE%
+    %PKG_GREENSTONE_TOOLS%
+    %PKG_JAVA_JRE%
+    %PKG_TOMCAT%
+    %PKG_WGET%
+
+OPTDEPENDS:
+    %PKG_GREENSTONE_DEMO%
+
+PROVIDES:
+
+POST_INSTALL:
+    chown -R %TOMCAT_USER%:%TOMCAT_USER% %WEB%
+
+POST_REMOVE:
+    echo "To fully remove greenstone, delete /usr/share/greenstone/web"
+
+FILES:
+    %WEB%
+    %TOMCATCONF%/*
+    %TOMCATLIB%/*
+
 SUB_PACKAGES:
     NATIVE
     TOOLS
-    MAIN
 
-NATIVE_NAME:                    %PKG_GREENSTONE_NATIVE%
+NATIVE_NAME:                    %NATIVE%
 NATIVE_DESCRIPTION_SHORT:       'Native libraries for Greenstone'
 NATIVE_DESCRIPTION:             'Architecture-dependent binary files required by the core Greenstone package'
@@ -56,5 +81,5 @@
 
 
-TOOLS_NAME:                     %PKG_GREENSTONE_TOOLS%
+TOOLS_NAME:                     %TOOLS%
 TOOLS_DESCRIPTION_SHORT:        'Tools for building Greenstone collections'
 TOOLS_DESCRIPTION:              %TOOLS_DESCRIPTION_SHORT%
@@ -76,31 +101,2 @@
     %GREENSTONE_HOME%/gs2build
     %BUILD_BIN_DIR%
-
-
-MAIN_NAME:                      %PKG_GREENSTONE%
-MAIN_DESCRIPTION_SHORT:         'Greenstone Digital Library'
-MAIN_DESCRIPTION:               'Greenstone is a suite of software for building and distributing digital library collections'
-MAIN_ARCHITECTURE:              %ARCH_ANY%
-
-MAIN_DEPENDS:
-    %PKG_GREENSTONE_NATIVE%
-    %PKG_GREENSTONE_TOOLS%
-    %PKG_JAVA_JRE%
-    %PKG_TOMCAT%
-    %PKG_WGET%
-
-MAIN_OPTDEPENDS:
-    %PKG_GREENSTONE_DEMO%
-
-MAIN_PROVIDES:
-
-MAIN_FILES:
-    %WEB%
-    %TOMCATCONF%/*
-    %TOMCATLIB%/*
-
-MAIN_POST_INSTALL:
-    chown -R %TOMCAT_USER%:%TOMCAT_USER% %WEB%
-
-MAIN_POST_REMOVE:
-    echo "To fully remove greenstone, delete /usr/share/greenstone/web"
Index: main/trunk/package-kits/linux/perllib/Greenstone/Package/_apt.pm
===================================================================
--- main/trunk/package-kits/linux/perllib/Greenstone/Package/_apt.pm	(revision 29607)
+++ main/trunk/package-kits/linux/perllib/Greenstone/Package/_apt.pm	(revision 29611)
@@ -58,4 +58,16 @@
 }
 
+# Adds a definition for files included in a subpackage
+sub add_package_files {
+    my $self = shift;
+    my $file = "$self->{output}/debian/$self->{config}->{NAME}.install";
+    print "    - $file\n";
+    open my $INSTALL, '>', $file;
+    for my $line (@{$self->{config}->{FILES}}) {
+        print $INSTALL $line, "\n";
+    }
+    close $INSTALL;
+}
+
 # Handles the apt-specific package generation
 sub add_package_impl {
@@ -78,6 +90,13 @@
     }
     if (defined $packages) {
+        my @names;
+        # add main package
+        push @names, $self->{config}->{NAME};
+        $self->add_install ($self->{config}->{NAME});
+        $self->add_package_section ($CONTROL);
+        $self->add_package_files;
+
         my $config = $self->{config};
-        my @names;
+        # add subpackages
         for my $package (@{$packages}) {
             push @names, $package->{NAME};
@@ -86,10 +105,5 @@
             $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->add_package_files;
         }
         $self->{config} = $config;
Index: main/trunk/package-kits/linux/perllib/Greenstone/Package/_pacman.pm
===================================================================
--- main/trunk/package-kits/linux/perllib/Greenstone/Package/_pacman.pm	(revision 29607)
+++ main/trunk/package-kits/linux/perllib/Greenstone/Package/_pacman.pm	(revision 29611)
@@ -78,8 +78,8 @@
 sub add_package_impl {
     my ($self, $packages) = @_;
+    $self->{config}->{NAMES} = $self->{config}->{NAME};
     if (defined $packages) {
-        $self->{config}->{NAME} = '';
         for my $package (@{$packages}) {
-            $self->{config}->{NAME} .= " $package->{NAME}";
+            $self->{config}->{NAMES} .= " $package->{NAME}";
         }
     }
@@ -89,10 +89,10 @@
     for my $line (
         '# Maintainer: %MAINTAINER_NAME% <%MAINTAINER_EMAIL%>',
-        'pkgname=(%NAME%)',
+        'pkgname=(%NAMES%)',
         'pkgver=%VERSION%',
         'pkgrel=%RELEASE%',
         'url=%HOMEPAGE%',
         'license=%LICENSE_SHORT%',
-        'arch=(' . (defined $self->{config}->{ARCH} ? '%ARCH%' : 'any') . ')',
+        'arch=(%ARCHITECTURE%)',
         'makedepends=(',
         '%MAKEDEPENDS%',
@@ -114,10 +114,16 @@
     }
     if (defined $packages) {
+        # main package
+        $self->write_function ("package_$self->{config}->{NAME}", $PKGBUILD,
+            $self->add_install,
+            'DESTDIR=${pkgdir} make install'
+        );
         my $config = $self->{config};
+        # subpackages
         for my $package (@{$packages}) {
             $self->{config} = $package;
             $self->write_function ("package_$package->{NAME}", $PKGBUILD,
                 'pkgdesc=%DESCRIPTION%',
-                'arch=(\'%ARCHITECTURE%\')',
+                'arch=(%ARCHITECTURE%)',
                 'depends=(',
                 '%DEPENDS%',
Index: main/trunk/package-kits/linux/perllib/Greenstone/Package/_rpm.pm
===================================================================
--- main/trunk/package-kits/linux/perllib/Greenstone/Package/_rpm.pm	(revision 29607)
+++ main/trunk/package-kits/linux/perllib/Greenstone/Package/_rpm.pm	(revision 29611)
@@ -22,24 +22,24 @@
 sub write_function {
     my ($name, @lines) = @_;
-    my $ret = "";
+    my $ret = "\n";
     $ret .= "%" . $name . "\n";
     for my $line (@lines) {
         $ret .= $line . "\n";
     }
-    $ret .= "\n";
     return $ret;
 }
 
 sub add_install {
-    my $self = shift;
+    my ($self, $package) = shift;
+    my $suffix = (defined $package ? " $package" : "");
     my $ret = '';
     exists $self->{config}->{PRE_INSTALL} and
-        $ret .= write_function "pre", @{$self->{config}->{PRE_INSTALL}};
+        $ret .= write_function "pre$suffix", @{$self->{config}->{PRE_INSTALL}};
     exists $self->{config}->{POST_INSTALL} and
-        $ret .= write_function "post", @{$self->{config}->{POST_INSTALL}};
+        $ret .= write_function "post$suffix", @{$self->{config}->{POST_INSTALL}};
     exists $self->{config}->{PRE_REMOVE} and
-        $ret .= write_function "preun", @{$self->{config}->{PRE_INSTALL}};
+        $ret .= write_function "preun$suffix", @{$self->{config}->{PRE_INSTALL}};
     exists $self->{config}->{POST_REMOVE} and
-        $ret .= write_function "postun", @{$self->{config}->{POST_INSTALL}};
+        $ret .= write_function "postun$suffix", @{$self->{config}->{POST_INSTALL}};
     return $ret;
 }
@@ -50,31 +50,43 @@
     print "    - $file\n";
     open my $SPEC, '>', $file;
-    for my $line (
-        'Name:          %NAME%',
-        'Version:       %VERSION%',
-        'Release:       %RELEASE%',
-        'License:       %LICENSE_SHORT%',
-        'URL:           %HOMEPAGE%',
-        'Source0:       %NAME%',
-        'AutoReqProv:   no',
-        'BuildRequires: %MAKEDEPENDS%',
-        '',
-        '%prep',
-        'cp -pr %SOURCE0 .',
-        '',
-        '%build',
-        'cd %NAME%',
-        'make %{?_smp_mflags}',
-        '',
-        '%install',
-        'cd %NAME%',
-        '%make_install',
-        '',
-        '%changelog',
-        ''
-    ) {
-        my $copy = $line;
-        $self->subst ($copy);
-        print $SPEC $copy, "\n";
+    {
+        my @optional;
+        scalar(@{$self->{config}->{DEPENDS}}) gt 0 and
+            push @optional, 'Requires:  %DEPENDS%';
+        for my $line (
+            'Name:          %NAME%',
+            'Version:       %VERSION%',
+            'Release:       %RELEASE%',
+            'License:       %LICENSE_SHORT%',
+            'URL:           %HOMEPAGE%',
+            'Source0:       %NAME%',
+            'AutoReqProv:   no',
+            'BuildRequires: %MAKEDEPENDS%',
+            @optional,
+            'Summary:       %DESCRIPTION_SHORT%',
+            '',
+            '%description',
+            '%DESCRIPTION%',
+            '',
+            '%prep',
+            'cp -pr %SOURCE0 .',
+            '',
+            '%build',
+            'cd %NAME%',
+            'make %{?_smp_mflags}',
+            '',
+            '%install',
+            'cd %NAME%',
+            '%make_install',
+            $self->add_install,
+            '%files',
+            '%FILES%',
+            '',
+            ''
+        ) {
+            my $copy = $line;
+            $self->subst ($copy);
+            print $SPEC $copy, "\n";
+        }
     }
     if (defined $packages) {
@@ -82,12 +94,17 @@
         for my $package (@{$packages}) {
             $self->{config} = $package;
+            my @optional;
+            scalar(@{$package->{DEPENDS}}) gt 0 and
+                push @optional, 'Requires:  %DEPENDS%';
             for my $line (
                 '%package %NAME%',
-                '%requires',
-                '%DEPENDS%',
-                '%description',
+                'Summary:   %DESCRIPTION_SHORT%',
+                'AutoReqProv:   no',
+                @optional,
+                '',
+                '%description %NAME%',
                 '%DESCRIPTION%',
-                $self->add_install,
-                '%files',
+                $self->add_install ($package->{NAME}),
+                '%files %NAME%',
                 '%FILES%',
                 '',
@@ -100,19 +117,6 @@
         }
         $self->{config} = $config;
-    } else {
-        for my $line (
-            '%requires',
-            '%DEPENDS%',
-            '%description',
-            '%DESCRIPTION%',
-            $self->add_install,
-            '%files',
-            '%FILES%'
-        ) {
-            my $copy = $line;
-            $self->subst ($copy);
-            print $SPEC $copy, "\n";
-        }
     }
+    print $SPEC '%changelog', "\n";
     close $SPEC;
 }
