--- /dev/null
+diff -urpa rpm-4.5.orig/build/parsePrep.c rpm-4.5/build/parsePrep.c
+--- rpm-4.5.orig/build/parsePrep.c 2007-11-08 00:26:48.000000000 +0000
++++ rpm-4.5/build/parsePrep.c 2018-02-23 11:51:54.161446282 +0000
+@@ -189,11 +189,13 @@ static const char *doUntar(Spec spec, in
+ {
+ const char *fn, *Lurlfn;
+ static char buf[BUFSIZ];
+- char *taropts;
++ char taropts[8];
+ char *t = NULL;
+ struct Source *sp;
+ rpmCompressedMagic compressed = COMPRESSED_NOT;
+ int urltype;
++ const char *tar;
++ int rubygem = 0;
+
+ for (sp = spec->sources; sp != NULL; sp = sp->next) {
+ if ((sp->flags & RPMFILE_SOURCE) && (sp->num == c)) {
+@@ -205,8 +207,18 @@ static const char *doUntar(Spec spec, in
+ return NULL;
+ }
+
++ t = strrchr(sp->source, '.');
++ if(t && !strcasecmp(t, ".gem"))
++ rubygem = 1;
++
++ t = stpcpy(taropts, "-x");
+ /*@-internalglobs@*/ /* FIX: shrug */
+- taropts = ((rpmIsVerbose() && !quietly) ? "-xvvf" : "-xf");
++ if(rpmIsVerbose() && !quietly)
++ t = stpcpy(t, "vv");
++ if(rubygem)
++ t = stpcpy(t, "m");
++
++ t = stpcpy(t, "f");
+ /*@=internalglobs@*/
+
+ Lurlfn = rpmGenPath(NULL, "%{_sourcedir}/", sp->source);
+@@ -233,6 +245,12 @@ static const char *doUntar(Spec spec, in
+ /*@notreached@*/ break;
+ }
+
++ tar = rpmGetPath("%{?__tar}", NULL);
++ if (!(tar && *tar != '\0')) {
++ tar = _free(tar);
++ tar = xstrdup("tar");
++ }
++
+ if (compressed != COMPRESSED_NOT) {
+ const char *zipper;
+ int needtar = 1;
+@@ -267,8 +285,13 @@ static const char *doUntar(Spec spec, in
+ *t++ = '\'';
+ t = stpcpy(t, fn);
+ *t++ = '\'';
+- if (needtar)
+- t = stpcpy( stpcpy( stpcpy(t, " | tar "), taropts), " -");
++ if (needtar) {
++ t = stpcpy(t, " | ");
++ t = stpcpy(t, tar);
++ t = stpcpy(t, " ");
++ t = stpcpy(t, taropts);
++ t = stpcpy(t, " -");
++ }
+ t = stpcpy(t,
+ "\n"
+ "STATUS=$?\n"
+@@ -277,11 +300,24 @@ static const char *doUntar(Spec spec, in
+ "fi");
+ } else {
+ buf[0] = '\0';
+- t = stpcpy( stpcpy(buf, "tar "), taropts);
++ t = stpcpy(buf, tar);
++ t = stpcpy(t, " ");
++ t = stpcpy(t, taropts);
+ *t++ = ' ';
+ t = stpcpy(t, fn);
++ if(rubygem) {
++ t = stpcpy(t,
++ "\n"
++ "if [ -f data.tar.gz ]; then\n"
++ " tar ");
++ t = stpcpy(t, taropts);
++ t = stpcpy(t,
++ " data.tar.gz\n"
++ "fi");
++ }
+ }
+
++ tar = _free(tar);
+ Lurlfn = _free(Lurlfn);
+ return buf;
+ }
+@@ -390,6 +426,20 @@ static int doSetupMacro(Spec spec, char
+ appendLineStringBuf(spec->prep, buf);
+ }
+
++ /* check if source is a ruby gem */
++ { struct Source *sp;
++ for (sp = spec->sources; sp != NULL; sp = sp->next) {
++ if ((sp->flags & RPMFILE_SOURCE) && (sp->num == 0)) {
++ break;
++ }
++ }
++ if (sp != NULL) {
++ char *t = strrchr(sp->source, '.');
++ if(t && !strcasecmp(t, ".gem"))
++ createDir = 1;
++ }
++ }
++
+ /* if necessary, create and cd into the proper dir */
+ if (createDir) {
+ sprintf(buf, MKDIR_P " '%s'\ncd '%s'",