diff -urN ../rpm-3.0.3/build/build.c ./build/build.c
--- ../rpm-3.0.3/build/build.c	Tue Sep 21 20:34:56 1999
+++ ./build/build.c	Mon May 29 22:19:27 2000
@@ -200,6 +200,9 @@
 	    if ((rc = packageSources(spec))) {
 		return rc;
 	    }
+	    if ((rc = packagePatches(spec))) {
+		return rc;
+	    }
 	}
 	if (what & RPMBUILD_PACKAGEBINARY && !test) {
 	    if ((rc = packageBinaries(spec))) {
diff -urN ../rpm-3.0.3/build/pack.c ./build/pack.c
--- ../rpm-3.0.3/build/pack.c	Fri Sep 24 23:24:38 1999
+++ ./build/pack.c	Mon May 29 22:19:27 2000
@@ -35,6 +35,21 @@
     return 0;
 }
 
+static inline int genPatchRpmName(Spec spec)
+{
+    if (spec->patchRpmName == NULL) {
+	const char *name, *version, *release;
+	char fileName[BUFSIZ];
+
+	headerNVR(spec->packages->header, &name, &version, &release);
+	sprintf(fileName, "%s-%s-%s.%spatch.rpm", name, version, release,
+	    spec->noSource ? "no" : "");
+	spec->patchRpmName = xstrdup(fileName);
+    }
+
+    return 0;
+}
+
 int packageSources(Spec spec)
 {
     CSA_t csabuf, *csa = &csabuf;
@@ -65,6 +80,62 @@
 	csa->cpioFdIn = fdNew();
 	csa->cpioList = spec->sourceCpioList;
 	csa->cpioCount = spec->sourceCpioCount;
+
+	rc = writeRPM(spec->sourceHeader, fn, RPMLEAD_SOURCE,
+		csa, spec->passPhrase, &(spec->cookie));
+	xfree(fn);
+    }
+    return rc;
+}
+
+int packagePatches(Spec spec)
+{
+    CSA_t csabuf, *csa = &csabuf;
+    int rc;
+
+    /* Add some cruft */
+    headerAddEntry(spec->sourceHeader, RPMTAG_RPMVERSION,
+		   RPM_STRING_TYPE, VERSION, 1);
+    headerAddEntry(spec->sourceHeader, RPMTAG_BUILDHOST,
+		   RPM_STRING_TYPE, buildHost(), 1);
+    headerAddEntry(spec->sourceHeader, RPMTAG_BUILDTIME,
+		   RPM_INT32_TYPE, getBuildTime(), 1);
+
+    {	int capability = 0;
+	headerAddEntry(spec->sourceHeader, RPMTAG_CAPABILITY, RPM_INT32_TYPE,
+			&capability, 1);
+    }
+
+    genPatchRpmName(spec);
+
+    FREE(spec->cookie);
+    
+    {	const char *fn = rpmGetPath("%{_prpmdir}/", spec->patchRpmName,NULL);
+	int i;
+
+	memset(csa, 0, sizeof(*csa));
+	csa->cpioArchiveSize = 0;
+	csa->cpioFdIn = fdNew();
+	csa->cpioList = spec->sourceCpioList;
+	csa->cpioCount = spec->sourceCpioCount;
+
+	/* remove tarballs from source list */
+	for (i = 0; i < spec->sourceCpioCount; i++)
+	  {
+	    if (strstr (i[csa->cpioList].fsPath, ".tar.gz"))
+	      {
+		csa->cpioCount--;
+		memset (&i[csa->cpioList], 0, sizeof (struct cpioFileMapping));
+		if (spec->sourceCpioCount - i - 1> 0)
+		  {
+		    memmove (&i[csa->cpioList],
+		      &i[csa->cpioList + 1],
+		      (spec->sourceCpioCount - i - 1) 
+			* sizeof (struct cpioFileMapping));
+		  }
+	      }
+	  }
+	spec->sourceCpioCount = csa->cpioCount;
 
 	rc = writeRPM(spec->sourceHeader, fn, RPMLEAD_SOURCE,
 		csa, spec->passPhrase, &(spec->cookie));
diff -urN ../rpm-3.0.3/build/rpmbuild.h ./build/rpmbuild.h
--- ../rpm-3.0.3/build/rpmbuild.h	Thu Sep 23 23:29:45 1999
+++ ./build/rpmbuild.h	Mon May 29 22:19:27 2000
@@ -150,6 +150,7 @@
 
 int packageBinaries(Spec spec);
 int packageSources(Spec spec);
+int packagePatches(Spec spec);
 
 #ifdef __cplusplus
 }
diff -urN ../rpm-3.0.3/build/rpmspec.h ./build/rpmspec.h
--- ../rpm-3.0.3/build/rpmspec.h	Tue Sep 21 20:34:56 1999
+++ ./build/rpmspec.h	Mon May 29 22:19:27 2000
@@ -75,6 +75,7 @@
 struct SpecStruct {
     /*@only@*/ char *specFile;
     /*@only@*/ char *sourceRpmName;
+    /*@only@*/ char *patchRpmName;
 
     struct speclines *sl;
     struct spectags *st;
diff -urN ../rpm-3.0.3/lib/header.c ./lib/header.c
--- ../rpm-3.0.3/lib/header.c	Fri Sep 24 00:29:10 1999
+++ ./lib/header.c	Mon May 29 23:55:09 2000
@@ -186,7 +186,7 @@
 	    }
 	} else {
 	    src = (char **) p;
-	    while (i--) {
+	    while (src && *src && i--) {
 		/* add one for null termination */
 		length += strlen(*src++) + 1;
 	    }
diff -urN ../rpm-3.0.3/lib/rpmrc.c ./lib/rpmrc.c
--- ../rpm-3.0.3/lib/rpmrc.c	Tue Sep 21 20:34:56 1999
+++ ./lib/rpmrc.c	Mon May 29 22:23:01 2000
@@ -521,6 +521,7 @@
 
     setPathDefault(-1,			"_builddir",	"BUILD");
     setPathDefault(-1,			"_rpmdir",	"RPMS");
+    setPathDefault(-1,			"_srcrpmdir",	"PRPMS");
     setPathDefault(-1,			"_srcrpmdir",	"SRPMS");
     setPathDefault(-1,			"_sourcedir",	"SOURCES");
     setPathDefault(-1,			"_specdir",	"SPECS");
diff -urN ../rpm-3.0.3/macros.in ./macros.in
--- ../rpm-3.0.3/macros.in	Tue Sep 21 20:34:55 1999
+++ ./macros.in	Mon May 29 22:19:27 2000
@@ -85,6 +85,7 @@
 %_sourcedir		%{_topdir}/SOURCES
 %_specdir		%{_topdir}/SPECS
 %_srcrpmdir		%{_topdir}/SRPMS
+%_prpmdir		%{_topdir}/PRPMS
 %_tmppath		%{_var}/tmp
 %_topdir		%{_usrsrc}/redhat
 #
diff -urN ../rpm-3.0.3/python/upgrade.c ./python/upgrade.c
--- ../rpm-3.0.3/python/upgrade.c	Sat Sep 25 01:33:35 1999
+++ ./python/upgrade.c	Mon May 29 23:31:08 2000
@@ -2,7 +2,7 @@
 #include <stdlib.h>
 #include <unistd.h>
 #include <fcntl.h>
-#include <rpm/rpmlib.h>
+#include <lib/rpmlib.h>
 #include <rpm/header.h>
 #include <string.h>
 
diff -urN ../rpm-3.0.3/rpm.spec ./rpm.spec
--- ../rpm-3.0.3/rpm.spec	Sun Sep 26 02:42:37 1999
+++ ./rpm.spec	Mon May 29 22:26:03 2000
@@ -2,9 +2,10 @@
 Name: rpm
 %define version 3.0.3
 Version: %{version}
-Release: 2
+Release: jcn1
 Group: System Environment/Base
 Source: ftp://ftp.rpm.org/pub/rpm/dist/rpm-3.0.x/rpm-%{version}.tar.gz
+Patch: rpm-3.0.3.prpm.diff
 Copyright: GPL
 Conflicts: patch < 2.5
 %ifos linux
@@ -43,6 +44,7 @@
 
 %prep
 %setup -q
+%patch -p1
 
 %build
 CFLAGS="$RPM_OPT_FLAGS" ./configure --prefix=/usr

