Add macro %isu_package to generate ISU Package
[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             "if [[ $RPM_ARCH == \"aarch64\" ]]; then\n"
53             "ref=/usr/lib/rpm\n"
54             "for s in guess sub; do\n"
55             "    for c in $(find -maxdepth 8 -name \"config.$s\"); do\n"
56             "         grep -q config-patches@ $c || continue\n"
57             "         grep -q aarch64 $c || install -m 755 $ref/config.$s $c\n"
58             "         grep -q ppc64le $c || install -m 755 $ref/config.$s $c\n"
59             "     done\n"
60             "done\n"
61             "fi\n"
62         );
63         appendLineStringBuf(*sbp, buf);
64         free(buf);
65     }
66
67     while (! (nextPart = isPart(spec->line))) {
68         appendStringBuf(*sbp, spec->line);
69         if ((rc = readLine(spec, STRIP_NOTHING)) > 0) {
70             nextPart = PART_NONE;
71             break;
72         } else if (rc < 0) {
73             goto exit;
74         }
75     }
76     res = nextPart;
77     
78 exit:
79
80     return res;
81 }