Sync with rpm-4_0 branch.
[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 "rpmbuild.h"
8 #include "debug.h"
9
10 int parseBuildInstallClean(Spec spec, rpmParseState parsePart)
11 {
12     int nextPart, rc;
13     StringBuf *sbp = NULL;
14     const char *name = NULL;
15
16     if (parsePart == PART_BUILD) {
17         sbp = &(spec->build);
18         name = "%build";
19     } else if (parsePart == PART_INSTALL) {
20         sbp = &(spec->install);
21         name = "%install";
22     } else if (parsePart == PART_CLEAN) {
23         sbp = &(spec->clean);
24         name = "%clean";
25     }
26     
27     if (*sbp != NULL) {
28         rpmError(RPMERR_BADSPEC, _("line %d: second %s"), spec->lineNum, name);
29         return RPMERR_BADSPEC;
30     }
31     
32     *sbp = newStringBuf();
33
34     /* There are no options to %build, %install, or %clean */
35     if ((rc = readLine(spec, STRIP_NOTHING)) > 0)
36         return PART_NONE;
37     if (rc)
38         return rc;
39     
40     while (! (nextPart = isPart(spec->line))) {
41         appendStringBuf(*sbp, spec->line);
42         if ((rc = readLine(spec, STRIP_NOTHING)) > 0)
43             return PART_NONE;
44         if (rc)
45             return rc;
46     }
47
48     return nextPart;
49 }