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