Update autotools files on riscv64
[platform/upstream/rpm.git] / build / parseBuildInstallClean.c
1 /** \ingroup rpmbuild
2  * \file build/parseBuildInstallClean.c
3  *  Parse %build/%install/%clean section from spec file.
4  */
5 #include "system.h"
6
7 #include <rpm/rpmlog.h>
8 #include "build/rpmbuild_internal.h"
9 #include "debug.h"
10
11
12 int parseBuildInstallClean(rpmSpec spec, int parsePart)
13 {
14     int nextPart, rc, res = PART_ERROR;
15     StringBuf *sbp = NULL;
16     const char *name = NULL;
17
18     if (parsePart == PART_BUILD) {
19         sbp = &(spec->build);
20         name = "%build";
21     } else if (parsePart == PART_INSTALL) {
22         sbp = &(spec->install);
23         name = "%install";
24     } else if (parsePart == PART_CHECK) {
25         sbp = &(spec->check);
26         name = "%check";
27     } else if (parsePart == PART_CLEAN) {
28         sbp = &(spec->clean);
29         name = "%clean";
30     } else {
31         goto exit; /* programmer error */
32     }
33     
34     if (*sbp != NULL) {
35         rpmlog(RPMLOG_ERR, _("line %d: second %s\n"),
36                 spec->lineNum, name);
37         goto exit;
38     }
39     
40     *sbp = newStringBuf();
41
42     /* There are no options to %build, %install, %check, or %clean */
43     if ((rc = readLine(spec, STRIP_NOTHING)) > 0) {
44         res = PART_NONE;
45         goto exit;
46     } else if (rc < 0) {
47         goto exit;
48     }
49
50     if (parsePart == PART_BUILD) {
51         char* buf = strdup(
52                            "ref=/usr/lib/rpm\n"
53                            "mints=0\n"
54                            "case $(uname -m) in\n"
55                            "    aarch64) mints=20120610;;\n"
56                            "    ppc64le) mints=20130610;;\n"
57                            "    riscv64) mints=20160911;;\n"
58                            "esac\n"
59                            "for s in guess sub; do\n"
60                            "    for c in $(find -maxdepth 8 -name \"config.$s\"); do\n"
61                            "         grep -q config-patches@ $c || continue\n"
62                            "         timestamp=$(sed -n \"/^timestamp=/{s///;s/[-'\\\"]//g;p;q;}\" $c)\n"
63                            "         test -n \"$timestamp\" || timestamp=0\n"
64                            "         test $timestamp -ge $mints || install -m 755 $ref/config.$s $c\n"
65                            "     done\n"
66                            "done\n"
67                            );
68         appendLineStringBuf(*sbp, buf);
69         free(buf);
70     }
71
72     while (! (nextPart = isPart(spec->line))) {
73         appendStringBuf(*sbp, spec->line);
74         if ((rc = readLine(spec, STRIP_NOTHING)) > 0) {
75             nextPart = PART_NONE;
76             break;
77         } else if (rc < 0) {
78             goto exit;
79         }
80     }
81     res = nextPart;
82     
83 exit:
84
85     return res;
86 }