rpm  4.9.1.2
rpmbuild.c
Go to the documentation of this file.
00001 #include "system.h"
00002 const char *__progname;
00003 
00004 #include <errno.h>
00005 #include <libgen.h>
00006 #include <ctype.h>
00007 
00008 #include <rpm/rpmcli.h>
00009 #include <rpm/rpmlib.h>                 /* RPMSIGTAG, rpmReadPackageFile .. */
00010 #include <rpm/rpmbuild.h>
00011 #include <rpm/rpmlog.h>
00012 #include <rpm/rpmfileutil.h>
00013 #include <rpm/rpmdb.h>
00014 #include <rpm/rpmps.h>
00015 #include <rpm/rpmts.h>
00016 #include "lib/signature.h"
00017 #include "cliutils.h"
00018 
00019 #include "debug.h"
00020 
00021 static struct rpmBuildArguments_s rpmBTArgs;
00022 
00023 #define POPT_NOLANG             -1012
00024 #define POPT_RMSOURCE           -1013
00025 #define POPT_RMBUILD            -1014
00026 #define POPT_BUILDROOT          -1015
00027 #define POPT_TARGETPLATFORM     -1016
00028 #define POPT_NOBUILD            -1017
00029 #define POPT_RMSPEC             -1019
00030 #define POPT_NODIRTOKENS        -1020
00031 
00032 #define POPT_REBUILD            0x4220
00033 #define POPT_RECOMPILE          0x4320
00034 #define POPT_BA                 0x6261
00035 #define POPT_BB                 0x6262
00036 #define POPT_BC                 0x6263
00037 #define POPT_BI                 0x6269
00038 #define POPT_BL                 0x626c
00039 #define POPT_BP                 0x6270
00040 #define POPT_BS                 0x6273
00041 #define POPT_TA                 0x7461
00042 #define POPT_TB                 0x7462
00043 #define POPT_TC                 0x7463
00044 #define POPT_TI                 0x7469
00045 #define POPT_TL                 0x746c
00046 #define POPT_TP                 0x7470
00047 #define POPT_TS                 0x7473
00048 
00049 extern int _fsm_debug;
00050 
00051 static rpmSpecFlags spec_flags = 0;     
00052 static int noDeps = 0;                  
00053 static int shortCircuit = 0;            
00054 static int skipClean = 0;               
00055 static int skipPrep = 0;                
00056 static char buildMode = 0;              
00057 static char buildChar = 0;              
00058 static ARGV_t build_targets = NULL;     
00060 static void buildArgCallback( poptContext con,
00061         enum poptCallbackReason reason,
00062         const struct poptOption * opt, const char * arg,
00063         const void * data)
00064 {
00065     BTA_t rba = &rpmBTArgs;
00066 
00067     switch (opt->val) {
00068     case POPT_REBUILD:
00069     case POPT_RECOMPILE:
00070     case POPT_BA:
00071     case POPT_BB:
00072     case POPT_BC:
00073     case POPT_BI:
00074     case POPT_BL:
00075     case POPT_BP:
00076     case POPT_BS:
00077     case POPT_TA:
00078     case POPT_TB:
00079     case POPT_TC:
00080     case POPT_TI:
00081     case POPT_TL:
00082     case POPT_TP:
00083     case POPT_TS:
00084         if (opt->val == POPT_BS || opt->val == POPT_TS)
00085             noDeps = 1;
00086         if (buildMode == '\0' && buildChar == '\0') {
00087             buildMode = (((unsigned)opt->val) >> 8) & 0xff;
00088             buildChar = (opt->val     ) & 0xff;
00089         }
00090         break;
00091 
00092     case POPT_NODIRTOKENS: rba->pkgFlags |= RPMBUILD_PKG_NODIRTOKENS; break;
00093     case POPT_NOBUILD: rba->buildAmount |= RPMBUILD_NOBUILD; break;
00094     case POPT_NOLANG: spec_flags |= RPMSPEC_NOLANG; break;
00095     case POPT_RMSOURCE: rba->buildAmount |= RPMBUILD_RMSOURCE; break;
00096     case POPT_RMSPEC: rba->buildAmount |= RPMBUILD_RMSPEC; break;
00097     case POPT_RMBUILD: rba->buildAmount |= RPMBUILD_RMBUILD; break;
00098     case POPT_BUILDROOT:
00099         if (rba->buildRootOverride) {
00100             rpmlog(RPMLOG_ERR, _("buildroot already specified, ignoring %s\n"), arg);
00101             break;
00102         }
00103         rba->buildRootOverride = xstrdup(arg);
00104         break;
00105     case POPT_TARGETPLATFORM:
00106         argvSplit(&build_targets, arg, ",");
00107         break;
00108 
00109     case RPMCLI_POPT_FORCE:
00110         spec_flags |= RPMSPEC_FORCE;
00111         break;
00112 
00113     }
00114 }
00115 
00116 static struct poptOption rpmBuildPoptTable[] = {
00117  { NULL, '\0', POPT_ARG_CALLBACK | POPT_CBFLAG_INC_DATA | POPT_CBFLAG_CONTINUE,
00118         buildArgCallback, 0, NULL, NULL },
00119 
00120  { "bp", 0, POPT_ARGFLAG_ONEDASH, 0, POPT_BP,
00121         N_("build through %prep (unpack sources and apply patches) from <specfile>"),
00122         N_("<specfile>") },
00123  { "bc", 0, POPT_ARGFLAG_ONEDASH, 0, POPT_BC,
00124         N_("build through %build (%prep, then compile) from <specfile>"),
00125         N_("<specfile>") },
00126  { "bi", 0, POPT_ARGFLAG_ONEDASH, 0, POPT_BI,
00127         N_("build through %install (%prep, %build, then install) from <specfile>"),
00128         N_("<specfile>") },
00129  { "bl", 0, POPT_ARGFLAG_ONEDASH, 0, POPT_BL,
00130         N_("verify %files section from <specfile>"),
00131         N_("<specfile>") },
00132  { "ba", 0, POPT_ARGFLAG_ONEDASH, 0, POPT_BA,
00133         N_("build source and binary packages from <specfile>"),
00134         N_("<specfile>") },
00135  { "bb", 0, POPT_ARGFLAG_ONEDASH, 0, POPT_BB,
00136         N_("build binary package only from <specfile>"),
00137         N_("<specfile>") },
00138  { "bs", 0, POPT_ARGFLAG_ONEDASH, 0, POPT_BS,
00139         N_("build source package only from <specfile>"),
00140         N_("<specfile>") },
00141 
00142  { "tp", 0, POPT_ARGFLAG_ONEDASH, 0, POPT_TP,
00143         N_("build through %prep (unpack sources and apply patches) from <tarball>"),
00144         N_("<tarball>") },
00145  { "tc", 0, POPT_ARGFLAG_ONEDASH, 0, POPT_TC,
00146         N_("build through %build (%prep, then compile) from <tarball>"),
00147         N_("<tarball>") },
00148  { "ti", 0, POPT_ARGFLAG_ONEDASH, 0, POPT_TI,
00149         N_("build through %install (%prep, %build, then install) from <tarball>"),
00150         N_("<tarball>") },
00151  { "tl", 0, POPT_ARGFLAG_ONEDASH|POPT_ARGFLAG_DOC_HIDDEN, 0, POPT_TL,
00152         N_("verify %files section from <tarball>"),
00153         N_("<tarball>") },
00154  { "ta", 0, POPT_ARGFLAG_ONEDASH, 0, POPT_TA,
00155         N_("build source and binary packages from <tarball>"),
00156         N_("<tarball>") },
00157  { "tb", 0, POPT_ARGFLAG_ONEDASH, 0, POPT_TB,
00158         N_("build binary package only from <tarball>"),
00159         N_("<tarball>") },
00160  { "ts", 0, POPT_ARGFLAG_ONEDASH, 0, POPT_TS,
00161         N_("build source package only from <tarball>"),
00162         N_("<tarball>") },
00163 
00164  { "rebuild", '\0', 0, 0, POPT_REBUILD,
00165         N_("build binary package from <source package>"),
00166         N_("<source package>") },
00167  { "recompile", '\0', 0, 0, POPT_RECOMPILE,
00168         N_("build through %install (%prep, %build, then install) from <source package>"),
00169         N_("<source package>") },
00170 
00171  { "buildroot", '\0', POPT_ARG_STRING, 0,  POPT_BUILDROOT,
00172         N_("override build root"), "DIRECTORY" },
00173  { "clean", '\0', 0, 0, POPT_RMBUILD,
00174         N_("remove build tree when done"), NULL},
00175  { "force", '\0', POPT_ARGFLAG_DOC_HIDDEN, 0, RPMCLI_POPT_FORCE,
00176         N_("ignore ExcludeArch: directives from spec file"), NULL},
00177  { "fsmdebug", '\0', (POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN), &_fsm_debug, -1,
00178         N_("debug file state machine"), NULL},
00179  { "nobuild", '\0', 0, 0,  POPT_NOBUILD,
00180         N_("do not execute any stages of the build"), NULL },
00181  { "nodeps", '\0', POPT_ARG_VAL, &noDeps, 1,
00182         N_("do not verify build dependencies"), NULL },
00183  { "nodirtokens", '\0', 0, 0, POPT_NODIRTOKENS,
00184         N_("generate package header(s) compatible with (legacy) rpm v3 packaging"),
00185         NULL},
00186 
00187  { "nolang", '\0', POPT_ARGFLAG_DOC_HIDDEN, 0, POPT_NOLANG,
00188         N_("do not accept i18N msgstr's from specfile"), NULL},
00189  { "rmsource", '\0', 0, 0, POPT_RMSOURCE,
00190         N_("remove sources when done"), NULL},
00191  { "rmspec", '\0', 0, 0, POPT_RMSPEC,
00192         N_("remove specfile when done"), NULL},
00193  { "short-circuit", '\0', POPT_ARG_VAL, &shortCircuit,  1,
00194         N_("skip straight to specified stage (only for c,i)"), NULL },
00195  { "skip-clean", '\0', POPT_ARG_VAL, &skipClean,  1,
00196         N_("skip %clean on binary build to permit BUILDROOT reuse"), NULL },
00197  { "skip-prep", '\0', POPT_ARG_VAL, &skipPrep,  1,
00198         N_("skip %prep section when doing tasks that normally include it"), NULL },
00199  { "target", '\0', POPT_ARG_STRING, 0,  POPT_TARGETPLATFORM,
00200         N_("override target platform"), "CPU-VENDOR-OS" },
00201    POPT_TABLEEND
00202 };
00203 
00204 enum modes {
00205     MODE_BUILD          = (1 <<  4),
00206     MODE_REBUILD        = (1 <<  5),
00207     MODE_RECOMPILE      = (1 <<  8),
00208     MODE_TARBUILD       = (1 << 11),
00209 };
00210 
00211 static int quiet;
00212 
00213 /* the structure describing the options we take and the defaults */
00214 static struct poptOption optionsTable[] = {
00215 
00216  { NULL, '\0', POPT_ARG_INCLUDE_TABLE, rpmBuildPoptTable, 0,
00217         N_("Build options with [ <specfile> | <tarball> | <source package> ]:"),
00218         NULL },
00219 
00220  { "quiet", '\0', POPT_ARGFLAG_DOC_HIDDEN, &quiet, 0, NULL, NULL},
00221 
00222  { NULL, '\0', POPT_ARG_INCLUDE_TABLE, rpmcliAllPoptTable, 0,
00223         N_("Common options for all rpm modes and executables:"),
00224         NULL },
00225 
00226    POPT_AUTOALIAS
00227    POPT_AUTOHELP
00228    POPT_TABLEEND
00229 };
00230 
00231 static int checkSpec(rpmts ts, rpmSpec spec)
00232 {
00233     int rc;
00234     rpmps ps = rpmSpecCheckDeps(ts, spec);
00235 
00236     if (ps) {
00237         rpmlog(RPMLOG_ERR, _("Failed build dependencies:\n"));
00238         rpmpsPrint(NULL, ps);
00239     }
00240     rc = (ps != NULL);
00241     ps = rpmpsFree(ps);
00242     return rc;
00243 }
00244 
00245 static int isSpecFile(const char * specfile)
00246 {
00247     char buf[256];
00248     const char * s;
00249     FILE * f;
00250     int count;
00251     int checking;
00252 
00253     f = fopen(specfile, "r");
00254     if (f == NULL || ferror(f)) {
00255         rpmlog(RPMLOG_ERR, _("Unable to open spec file %s: %s\n"),
00256                 specfile, strerror(errno));
00257         return 0;
00258     }
00259     count = fread(buf, sizeof(buf[0]), sizeof(buf), f);
00260     (void) fclose(f);
00261 
00262     if (count == 0)
00263         return 0;
00264 
00265     checking = 1;
00266     for (s = buf; count--; s++) {
00267         switch (*s) {
00268         case '\r':
00269         case '\n':
00270             checking = 1;
00271             break;
00272         case ':':
00273             checking = 0;
00274             break;
00275         default:
00276 #if 0
00277             if (checking && !(isprint(*s) || isspace(*s))) return 0;
00278             break;
00279 #else
00280             if (checking && !(isprint(*s) || isspace(*s)) && *(unsigned char *)s < 32) return 0;
00281             break;
00282 #endif
00283         }
00284     }
00285     return 1;
00286 }
00287 
00288 /* 
00289  * Try to find a spec from a tarball pointed to by arg. 
00290  * Return absolute path to spec name on success, otherwise NULL.
00291  */
00292 static char * getTarSpec(const char *arg)
00293 {
00294     char *specFile = NULL;
00295     char *specDir;
00296     char *specBase;
00297     char *tmpSpecFile;
00298     const char **spec;
00299     char tarbuf[BUFSIZ];
00300     int gotspec = 0, res;
00301     static const char *tryspec[] = { "Specfile", "\\*.spec", NULL };
00302 
00303     specDir = rpmGetPath("%{_specdir}", NULL);
00304     tmpSpecFile = rpmGetPath("%{_specdir}/", "rpm-spec.XXXXXX", NULL);
00305 
00306     (void) close(mkstemp(tmpSpecFile));
00307 
00308     for (spec = tryspec; *spec != NULL; spec++) {
00309         FILE *fp;
00310         char *cmd;
00311 
00312         cmd = rpmExpand("%{uncompress: ", arg, "} | ",
00313                         "%{__tar} xOvf - --wildcards ", *spec,
00314                         " 2>&1 > ", tmpSpecFile, NULL);
00315 
00316         if (!(fp = popen(cmd, "r"))) {
00317             rpmlog(RPMLOG_ERR, _("Failed to open tar pipe: %m\n"));
00318         } else {
00319             char *fok;
00320             for (;;) {
00321                 fok = fgets(tarbuf, sizeof(tarbuf) - 1, fp);
00322                 /* tar sometimes prints "tar: Record size = 16" messages */
00323                 if (!fok || strncmp(fok, "tar: ", 5) != 0)
00324                     break;
00325             }
00326             pclose(fp);
00327             gotspec = (fok != NULL) && isSpecFile(tmpSpecFile);
00328         }
00329 
00330         if (!gotspec) 
00331             unlink(tmpSpecFile);
00332         free(cmd);
00333     }
00334 
00335     if (!gotspec) {
00336         rpmlog(RPMLOG_ERR, _("Failed to read spec file from %s\n"), arg);
00337         goto exit;
00338     }
00339 
00340     specBase = basename(tarbuf);
00341     /* remove trailing \n */
00342     specBase[strlen(specBase)-1] = '\0';
00343 
00344     rasprintf(&specFile, "%s/%s", specDir, specBase);
00345     res = rename(tmpSpecFile, specFile);
00346 
00347     if (res) {
00348         rpmlog(RPMLOG_ERR, _("Failed to rename %s to %s: %m\n"),
00349                 tmpSpecFile, specFile);
00350         free(specFile);
00351         specFile = NULL;
00352     } else {
00353         /* mkstemp() can give unnecessarily strict permissions, fixup */
00354         mode_t mask;
00355         umask(mask = umask(0));
00356         (void) chmod(specFile, 0666 & ~mask);
00357     }
00358 
00359 exit:
00360     (void) unlink(tmpSpecFile);
00361     free(tmpSpecFile);
00362     free(specDir);
00363     return specFile;
00364 }
00365 
00366 static int buildForTarget(rpmts ts, const char * arg, BTA_t ba)
00367 {
00368     int buildAmount = ba->buildAmount;
00369     char * buildRootURL = NULL;
00370     char * specFile = NULL;
00371     rpmSpec spec = NULL;
00372     int rc = 1; /* assume failure */
00373     int justRm = ((buildAmount & ~(RPMBUILD_RMSOURCE|RPMBUILD_RMSPEC)) == 0);
00374     rpmSpecFlags specFlags = spec_flags;
00375 
00376 #ifndef DYING
00377     rpmSetTables(RPM_MACHTABLE_BUILDARCH, RPM_MACHTABLE_BUILDOS);
00378 #endif
00379 
00380     if (ba->buildRootOverride)
00381         buildRootURL = rpmGenPath(NULL, ba->buildRootOverride, NULL);
00382 
00383     /* Create build tree if necessary */
00384     const char * buildtree = "%{_topdir}:%{_specdir}:%{_sourcedir}:%{_builddir}:%{_rpmdir}:%{_srcrpmdir}:%{_buildrootdir}";
00385     const char * rootdir = rpmtsRootDir(ts);
00386     if (rpmMkdirs(!rstreq(rootdir, "/") ? rootdir : NULL , buildtree)) {
00387         goto exit;
00388     }
00389 
00390     if (buildMode == 't') {
00391         char *srcdir = NULL, *dir;
00392 
00393         specFile = getTarSpec(arg);
00394         if (!specFile)
00395             goto exit;
00396 
00397         /* Make the directory of the tarball %_sourcedir for this run */
00398         /* dirname() may modify contents so extra hoops needed. */
00399         if (*arg != '/') {
00400             dir = rpmGetCwd();
00401             rstrscat(&dir, "/", arg, NULL);
00402         } else {
00403             dir = xstrdup(arg);
00404         }
00405         srcdir = dirname(dir);
00406         addMacro(NULL, "_sourcedir", NULL, srcdir, RMIL_TARBALL);
00407         free(dir);
00408     } else {
00409         specFile = xstrdup(arg);
00410     }
00411 
00412     if (*specFile != '/') {
00413         char *cwd = rpmGetCwd();
00414         char *s = NULL;
00415         rasprintf(&s, "%s/%s", cwd, specFile);
00416         free(cwd);
00417         free(specFile);
00418         specFile = s;
00419     }
00420 
00421     struct stat st;
00422     if (stat(specFile, &st) < 0) {
00423         rpmlog(RPMLOG_ERR, _("failed to stat %s: %m\n"), specFile);
00424         goto exit;
00425     }
00426     if (! S_ISREG(st.st_mode)) {
00427         rpmlog(RPMLOG_ERR, _("File %s is not a regular file.\n"), specFile);
00428         goto exit;
00429     }
00430 
00431     /* Try to verify that the file is actually a specfile */
00432     if (!isSpecFile(specFile)) {
00433         rpmlog(RPMLOG_ERR,
00434                 _("File %s does not appear to be a specfile.\n"), specFile);
00435         goto exit;
00436     }
00437     
00438     /* Don't parse spec if only its removal is requested */
00439     if (ba->buildAmount == RPMBUILD_RMSPEC) {
00440         rc = unlink(specFile);
00441         goto exit;
00442     }
00443 
00444     /* Parse the spec file */
00445 #define _anyarch(_f)    \
00446 (((_f)&(RPMBUILD_PREP|RPMBUILD_BUILD|RPMBUILD_INSTALL|RPMBUILD_PACKAGEBINARY)) == 0)
00447     if (_anyarch(buildAmount))
00448         specFlags |= RPMSPEC_ANYARCH;
00449 #undef  _anyarch
00450     
00451     spec = rpmSpecParse(specFile, specFlags, buildRootURL);
00452     if (spec == NULL) {
00453         goto exit;
00454     }
00455 
00456     /* Check build prerequisites if necessary, unless disabled */
00457     if (!justRm && !noDeps && checkSpec(ts, spec)) {
00458         goto exit;
00459     }
00460 
00461     if (rpmSpecBuild(spec, ba)) {
00462         goto exit;
00463     }
00464     
00465     if (buildMode == 't')
00466         (void) unlink(specFile);
00467     rc = 0;
00468 
00469 exit:
00470     free(specFile);
00471     rpmSpecFree(spec);
00472     free(buildRootURL);
00473     return rc;
00474 }
00475 
00476 static int build(rpmts ts, const char * arg, BTA_t ba, const char * rcfile)
00477 {
00478     int rc = 0;
00479     char * targets = argvJoin(build_targets, ",");
00480 #define buildCleanMask  (RPMBUILD_RMSOURCE|RPMBUILD_RMSPEC)
00481     int cleanFlags = ba->buildAmount & buildCleanMask;
00482     rpmVSFlags vsflags, ovsflags;
00483 
00484     vsflags = rpmExpandNumeric("%{_vsflags_build}");
00485     if (rpmcliQueryFlags & VERIFY_DIGEST)
00486         vsflags |= _RPMVSF_NODIGESTS;
00487     if (rpmcliQueryFlags & VERIFY_SIGNATURE)
00488         vsflags |= _RPMVSF_NOSIGNATURES;
00489     if (rpmcliQueryFlags & VERIFY_HDRCHK)
00490         vsflags |= RPMVSF_NOHDRCHK;
00491     ovsflags = rpmtsSetVSFlags(ts, vsflags);
00492 
00493     if (build_targets == NULL) {
00494         rc =  buildForTarget(ts, arg, ba);
00495         goto exit;
00496     }
00497 
00498     /* parse up the build operators */
00499 
00500     printf(_("Building target platforms: %s\n"), targets);
00501 
00502     ba->buildAmount &= ~buildCleanMask;
00503     for (ARGV_const_t target = build_targets; target && *target; target++) {
00504         /* Perform clean-up after last target build. */
00505         if (*(target + 1) == NULL)
00506             ba->buildAmount |= cleanFlags;
00507 
00508         printf(_("Building for target %s\n"), *target);
00509 
00510         /* Read in configuration for target. */
00511         rpmFreeMacros(NULL);
00512         rpmFreeRpmrc();
00513         (void) rpmReadConfigFiles(rcfile, *target);
00514         rc = buildForTarget(ts, arg, ba);
00515         if (rc)
00516             break;
00517     }
00518 
00519 exit:
00520     vsflags = rpmtsSetVSFlags(ts, ovsflags);
00521     /* Restore original configuration. */
00522     rpmFreeMacros(NULL);
00523     rpmFreeRpmrc();
00524     (void) rpmReadConfigFiles(rcfile, NULL);
00525     free(targets);
00526 
00527     return rc;
00528 }
00529 
00530 int main(int argc, char *argv[])
00531 {
00532     rpmts ts = NULL;
00533     enum modes bigMode = MODE_BUILD;
00534     BTA_t ba = &rpmBTArgs;
00535 
00536     const char *pkg = NULL;
00537     int ec = 0;
00538     poptContext optCon = rpmcliInit(argc, argv, optionsTable);
00539 
00540     if (argc <= 1 || poptPeekArg(optCon) == NULL) {
00541         printUsage(optCon, stderr, 0);
00542         exit(EXIT_FAILURE);
00543     }
00544 
00545     switch (buildMode) {
00546     case 'b':   bigMode = MODE_BUILD;           break;
00547     case 't':   bigMode = MODE_TARBUILD;        break;
00548     case 'B':   bigMode = MODE_REBUILD;         break;
00549     case 'C':   bigMode = MODE_RECOMPILE;       break;
00550     }
00551 
00552     if (rpmcliRootDir && rpmcliRootDir[0] != '/') {
00553         argerror(_("arguments to --root (-r) must begin with a /"));
00554     }
00555 
00556     /* rpmbuild is rather chatty by default */
00557     rpmSetVerbosity(quiet ? RPMLOG_WARNING : RPMLOG_INFO);
00558 
00559     if (rpmcliPipeOutput && initPipe())
00560         exit(EXIT_FAILURE);
00561         
00562     ts = rpmtsCreate();
00563     (void) rpmtsSetRootDir(ts, rpmcliRootDir);
00564     switch (bigMode) {
00565     case MODE_REBUILD:
00566     case MODE_RECOMPILE:
00567         ba->buildAmount =
00568             RPMBUILD_PREP | RPMBUILD_BUILD | RPMBUILD_INSTALL | RPMBUILD_CHECK;
00569         if (bigMode == MODE_REBUILD) {
00570             ba->buildAmount |= RPMBUILD_PACKAGEBINARY;
00571             ba->buildAmount |= RPMBUILD_RMSOURCE;
00572             ba->buildAmount |= RPMBUILD_RMSPEC;
00573             ba->buildAmount |= RPMBUILD_CLEAN;
00574             ba->buildAmount |= RPMBUILD_RMBUILD;
00575         }
00576 
00577         while ((pkg = poptGetArg(optCon))) {
00578             char * specFile = NULL;
00579 
00580             ba->cookie = NULL;
00581             ec = rpmInstallSource(ts, pkg, &specFile, &ba->cookie);
00582             if (ec == 0) {
00583                 ba->rootdir = rpmcliRootDir;
00584                 ec = build(ts, specFile, ba, rpmcliRcfile);
00585             }
00586             ba->cookie = _free(ba->cookie);
00587             specFile = _free(specFile);
00588 
00589             if (ec)
00590                 break;
00591         }
00592         break;
00593     case MODE_BUILD:
00594     case MODE_TARBUILD:
00595         switch (buildChar) {
00596         case 'a':
00597             ba->buildAmount |= RPMBUILD_PACKAGESOURCE;
00598         case 'b':
00599             ba->buildAmount |= RPMBUILD_PACKAGEBINARY;
00600             if (!skipClean)
00601                         ba->buildAmount |= RPMBUILD_CLEAN;
00602             if ((buildChar == 'b') && shortCircuit)
00603                 break;
00604         case 'i':
00605             ba->buildAmount |= RPMBUILD_INSTALL;
00606             ba->buildAmount |= RPMBUILD_CHECK;
00607             if ((buildChar == 'i') && shortCircuit)
00608                 break;
00609         case 'c':
00610             ba->buildAmount |= RPMBUILD_BUILD;
00611             if ((buildChar == 'c') && shortCircuit)
00612                 break;
00613         case 'p':
00614             if (!skipPrep)
00615                 ba->buildAmount |= RPMBUILD_PREP;
00616             break;
00617             
00618         case 'l':
00619             ba->buildAmount |= RPMBUILD_FILECHECK;
00620             break;
00621         case 's':
00622             ba->buildAmount |= RPMBUILD_PACKAGESOURCE;
00623             break;
00624         }
00625 
00626         while ((pkg = poptGetArg(optCon))) {
00627             ba->rootdir = rpmcliRootDir;
00628             ba->cookie = NULL;
00629             ec = build(ts, pkg, ba, rpmcliRcfile);
00630             if (ec)
00631                 break;
00632             rpmFreeMacros(NULL);
00633             (void) rpmReadConfigFiles(rpmcliRcfile, NULL);
00634         }
00635         break;
00636     }
00637 
00638     ts = rpmtsFree(ts);
00639     finishPipe();
00640     ba->buildRootOverride = _free(ba->buildRootOverride);
00641     build_targets = argvFree(build_targets);
00642 
00643     rpmcliFini(optCon);
00644 
00645     return RETVAL(ec);
00646 }