- Main Page
- Related Pages
- Modules
- Data Structures
- Files

- File List
- Globals

# build/parseBuildInstallClean.c

Go to the documentation of this file.

    00001
    00005 #include "system.h"
    00006
    00007 #define _RPMTAG_INTERNAL
    00008 #include <rpmio.h>
    00009 #include "rpmbuild.h"
    00010 #include "debug.h"
    00011
    00012 /*@access StringBuf @*/
    00013
    00014 int parseBuildInstallClean(Spec spec, rpmParseState parsePart)
    00015 {
    00016     rpmParseState nextPart;
    00017     StringBuf *sbp = NULL;
    00018     const char *name = NULL;
    00019     rpmRC rc;
    00020
    00021     if (parsePart == PART_BUILD) {
    00022         sbp = &spec->build;
    00023         name = "build";
    00024     } else if (parsePart == PART_INSTALL) {
    00025         sbp = &spec->install;
    00026         name = "install";
    00027     } else if (parsePart == PART_CHECK) {
    00028         sbp = &spec->check;
    00029         name = "check";
    00030     } else if (parsePart == PART_CLEAN) {
    00031         sbp = &spec->clean;
    00032         name = "clean";
    00033     } else if (parsePart == PART_ARBITRARY) {
    00034 assert(spec->nfoo > 0);
    00035         sbp = &spec->foo[spec->nfoo-1].val;
    00036         name = spec->foo[spec->nfoo-1].str;
    00037     }
    00038
    00039     if (*sbp != NULL) {
    00040         rpmlog(RPMLOG_ERR, _("line %d: second %%%s section\n"),
    00041                 spec->lineNum, name);
    00042         return RPMRC_FAIL;
    00043     }
    00044
    00045     *sbp = newStringBuf();
    00046
    00047     /* Make sure the buildroot is removed where needed. */
    00048     if (parsePart == PART_INSTALL) {
    00049         const char * s = rpmExpand("%{!?__spec_install_pre:%{?buildroot:%{__rm} -rf '%{buildroot}'\n%{__mkdir_p} '%{buildroot}'\n}}\n", NULL);
    00050         if (s && *s)
    00051             appendStringBuf(*sbp, s);
    00052         s = _free(s);
    00053     } else if (parsePart == PART_CLEAN) {
    00054         const char * s = rpmExpand("%{?__spec_clean_body}%{!?__spec_clean_body:%{?buildroot:rm -rf '%{buildroot}'\n}}\n", NULL);
    00055         if (s && *s)
    00056             appendStringBuf(*sbp, s);
    00057         s = _free(s);
    00058 #if !defined(RPM_VENDOR_OPENPKG) /* still-support-section-clean */
    00059         /* OpenPKG still wishes to use "%clean" script/section */
    00060         sbp = NULL;     /* XXX skip %clean from spec file. */
    00061 #endif
    00062     }
    00063
    00064     /* There are no options to %build, %install, %check, or %clean */
    00065     if ((rc = readLine(spec, STRIP_NOTHING)) > 0)
    00066         return PART_NONE;
    00067     if (rc != RPMRC_OK)
    00068         return rc;
    00069
    00070     while ((nextPart = isPart(spec)) == PART_NONE) {
    00071         if (sbp)
    00072             appendStringBuf(*sbp, spec->line);
    00073         if ((rc = readLine(spec, STRIP_NOTHING)) > 0)
    00074             return PART_NONE;
    00075         if (rc)
    00076             return rc;
    00077     }
    00078
    00079     return nextPart;
    00080 }