Handle config.guess and config.sub with DOS EOLs
[platform/upstream/rpm.git] / build / parseBuildInstallClean.c
index c43e722..5ecf77c 100644 (file)
@@ -4,54 +4,83 @@
  */
 #include "system.h"
 
-#include "rpmbuild.h"
+#include <rpm/rpmlog.h>
+#include "build/rpmbuild_internal.h"
+#include "debug.h"
 
-/** */
-int parseBuildInstallClean(Spec spec, int parsePart)
+
+int parseBuildInstallClean(rpmSpec spec, int parsePart)
 {
-    int nextPart, rc;
+    int nextPart, rc, res = PART_ERROR;
     StringBuf *sbp = NULL;
-    char *name = NULL;
+    const char *name = NULL;
 
-    switch (parsePart) {
-      case PART_BUILD:
+    if (parsePart == PART_BUILD) {
        sbp = &(spec->build);
        name = "%build";
-       break;
-      case PART_INSTALL:
+    } else if (parsePart == PART_INSTALL) {
        sbp = &(spec->install);
        name = "%install";
-       break;
-      case PART_CLEAN:
+    } else if (parsePart == PART_CHECK) {
+       sbp = &(spec->check);
+       name = "%check";
+    } else if (parsePart == PART_CLEAN) {
        sbp = &(spec->clean);
        name = "%clean";
-       break;
+    } else {
+       goto exit; /* programmer error */
     }
     
     if (*sbp != NULL) {
-       rpmError(RPMERR_BADSPEC, _("line %d: second %s"), spec->lineNum, name);
-       return RPMERR_BADSPEC;
+       rpmlog(RPMLOG_ERR, _("line %d: second %s\n"),
+               spec->lineNum, name);
+       goto exit;
     }
     
     *sbp = newStringBuf();
 
-    /* There are no options to %build, %install, or %clean */
+    /* There are no options to %build, %install, %check, or %clean */
     if ((rc = readLine(spec, STRIP_NOTHING)) > 0) {
-       return PART_NONE;
+       res = PART_NONE;
+       goto exit;
+    } else if (rc < 0) {
+       goto exit;
     }
-    if (rc) {
-       return rc;
+
+    if (parsePart == PART_BUILD) {
+       char* buf = strdup(
+                          "ref=/usr/lib/rpm\n"
+                          "mints=0\n"
+                          "case $(uname -m) in\n"
+                          "    aarch64) mints=20120610;;\n"
+                          "    ppc64le) mints=20130610;;\n"
+                          "    riscv64) mints=20160911;;\n"
+                          "esac\n"
+                          "for s in guess sub; do\n"
+                          "    for c in $(find -maxdepth 8 -name \"config.$s\"); do\n"
+                          "         grep -q config-patches@ $c || continue\n"
+                          "         timestamp=$(sed -n \"/^timestamp=/{s///;s/[-'\\\"]//g;p;q;}\" $c | tr -d '\r')\n"
+                          "         test -n \"$timestamp\" || timestamp=0\n"
+                          "         test $timestamp -ge $mints || install -m 755 $ref/config.$s $c\n"
+                          "     done\n"
+                          "done\n"
+                          );
+        appendLineStringBuf(*sbp, buf);
+        free(buf);
     }
-    
+
     while (! (nextPart = isPart(spec->line))) {
        appendStringBuf(*sbp, spec->line);
        if ((rc = readLine(spec, STRIP_NOTHING)) > 0) {
-           return PART_NONE;
-       }
-       if (rc) {
-           return rc;
+           nextPart = PART_NONE;
+           break;
+       } else if (rc < 0) {
+           goto exit;
        }
     }
+    res = nextPart;
+    
+exit:
 
-    return nextPart;
+    return res;
 }