7 static int checkSpec(Header h)
13 struct rpmDependencyConflict * conflicts;
17 if (!headerIsEntry(h, RPMTAG_REQUIREFLAGS))
20 if (rpmdbOpen(rootdir, &db, mode, 0644)) {
22 dn = rpmGetPath( (rootdir ? rootdir : ""), "%{_dbpath}", NULL);
23 rpmMessage(RPMMESS_ERROR, _("cannot open %s/packages.rpm\n"), dn);
27 ts = rpmtransCreateSet(db, rootdir);
29 rc = rpmtransAddPackage(ts, h, NULL, NULL, 0, NULL);
31 rc = rpmdepCheck(ts, &conflicts, &numConflicts);
32 if (rc == 0 && conflicts) {
33 rpmMessage(RPMMESS_ERROR, _("failed build dependencies:\n"));
34 printDepProblems(stderr, conflicts, numConflicts);
35 rpmdepFreeConflicts(conflicts, numConflicts);
48 * Kurwa, durni ameryka?ce sobe zawsze my?l?, ?e ca?y ?wiat mówi po
51 /* XXX this is still a dumb test but at least it's i18n aware */
52 static int isSpecFile(const char *specfile)
60 if (fdFileno((fd = fdOpen(specfile, O_RDONLY, 0))) < 0) {
61 fprintf(stderr, _("Unable to open spec file: %s\n"), specfile);
64 count = fdRead(fd, buf, sizeof(buf));
68 for (s = buf; count--; s++) {
78 if (checking && !(isprint(*s) || isspace(*s))) return 0;
85 static int buildForTarget(const char *arg, struct rpmBuildArguments *ba,
86 const char *passPhrase, int fromTarball, char *cookie,
87 int force, int nodeps)
89 int buildAmount = ba->buildAmount;
90 const char *buildRoot = ba->buildRootOverride;
91 int test = ba->noBuild;
93 const char * specfile;
99 rpmSetTables(RPM_MACHTABLE_BUILDARCH, RPM_MACHTABLE_BUILDOS);
103 const char * tmpSpecFile;
106 specDir = rpmGetPath("%{_specdir}", NULL);
109 strcpy(tfn, "rpm-spec.XXXXXX");
110 tmpSpecFile = rpmGetPath("%{_specdir}/", mktemp(tfn), NULL);
113 cmd = alloca(strlen(arg) + 50 + strlen(tmpSpecFile));
114 sprintf(cmd, "gunzip < %s | tar xOvf - Specfile 2>&1 > %s",
116 if (!(f = popen(cmd, "r"))) {
117 fprintf(stderr, _("Failed to open tar pipe: %s\n"),
123 if ((!fgets(buf, sizeof(buf) - 1, f)) || !strchr(buf, '/')) {
127 sprintf(cmd, "gunzip < %s | tar xOvf - \\*.spec 2>&1 > %s", arg,
129 if (!(f = popen(cmd, "r"))) {
130 fprintf(stderr, _("Failed to open tar pipe: %s\n"),
136 if (!fgets(buf, sizeof(buf) - 1, f)) {
138 fprintf(stderr, _("Failed to read spec file from %s\n"), arg);
149 if (*cmd == '/') s = cmd + 1;
155 /* remove trailing \n */
156 s = cmd + strlen(cmd) - 1;
159 s = alloca(strlen(specDir) + strlen(cmd) + 5);
160 sprintf(s, "%s/%s", specDir, cmd);
162 if (rename(tmpSpecFile, s)) {
163 fprintf(stderr, _("Failed to rename %s to %s: %s\n"),
164 tmpSpecFile, s, strerror(errno));
171 /* Make the directory which contains the tarball the source
172 directory for this run */
175 (void)getcwd(buf, BUFSIZ);
181 cmd = buf + strlen(buf) - 1;
182 while (*cmd != '/') cmd--;
185 addMacro(NULL, "_sourcedir", NULL, buf, RMIL_TARBALL);
189 } else if (arg[0] == '/') {
192 char *s = alloca(BUFSIZ);
193 (void)getcwd(s, BUFSIZ);
199 stat(specfile, &statbuf);
200 if (! S_ISREG(statbuf.st_mode)) {
201 fprintf(stderr, _("File is not a regular file: %s\n"), specfile);
205 /* Try to verify that the file is actually a specfile */
206 if (!isSpecFile(specfile)) {
207 fprintf(stderr, _("File %s does not appear to be a specfile.\n"),
212 /* Parse the spec file */
213 #define _anyarch(_f) \
214 (((_f)&(RPMBUILD_PREP|RPMBUILD_BUILD|RPMBUILD_INSTALL|RPMBUILD_PACKAGEBINARY)) == 0)
215 if (parseSpec(&spec, specfile, buildRoot, 0, passPhrase, cookie,
216 _anyarch(buildAmount), force)) {
221 /* Assemble source header from parsed components */
222 initSourceHeader(spec);
224 /* Check build prerequisites */
225 if (!nodeps && checkSpec(spec->sourceHeader)) {
230 if (buildSpec(spec, buildAmount, test)) {
235 if (fromTarball) unlink(specfile);
242 int build(const char *arg, struct rpmBuildArguments *ba, const char *passPhrase,
243 int fromTarball, char *cookie, const char * rcfile, int force,
248 char *targets = ba->targets;
250 if (targets == NULL) {
251 rc = buildForTarget(arg, ba, passPhrase, fromTarball, cookie,
256 /* parse up the build operators */
258 printf(_("Building target platforms: %s\n"), targets);
260 for (t = targets; *t != '\0'; t = te) {
262 if ((te = strchr(t, ',')) == NULL)
264 target = alloca(te-t+1);
265 strncpy(target, t, (te-t));
267 printf(_("Building for target %s\n"), target);
269 rpmReadConfigFiles(rcfile, target);
270 rc = buildForTarget(arg, ba, passPhrase, fromTarball, cookie,
281 #define POPT_USECATALOG 1000
282 #define POPT_NOLANG 1001
283 #define POPT_RMSOURCE 1002
284 #define POPT_RMBUILD 1003
285 #define POPT_BUILDROOT 1004
286 #define POPT_BUILDARCH 1005
287 #define POPT_BUILDOS 1006
288 #define POPT_TARGETPLATFORM 1007
289 #define POPT_NOBUILD 1008
290 #define POPT_SHORTCIRCUIT 1009
291 #define POPT_RMSPEC 1010
294 static int noBuild = 0;
295 static int useCatalog = 0;
297 static void buildArgCallback( /*@unused@*/ poptContext con,
298 /*@unused@*/ enum poptCallbackReason reason,
299 const struct poptOption * opt, const char * arg, const void * data)
301 struct rpmBuildArguments * rba = (struct rpmBuildArguments *) data;
304 case POPT_USECATALOG: rba->useCatalog = 1; break;
305 case POPT_NOBUILD: rba->noBuild = 1; break;
306 case POPT_NOLANG: rba->noLang = 1; break;
307 case POPT_SHORTCIRCUIT: rba->shortCircuit = 1; break;
308 case POPT_RMSOURCE: rba->buildAmount |= RPMBUILD_RMSOURCE; break;
309 case POPT_RMSPEC: rba->buildAmount |= RPMBUILD_RMSPEC; break;
310 case POPT_RMBUILD: rba->buildAmount |= RPMBUILD_RMBUILD; break;
312 if (rba->buildRootOverride) {
313 fprintf(stderr, _("buildroot already specified"));
317 rba->buildRootOverride = xstrdup(arg);
320 fprintf(stderr, _("--buildarch has been obsoleted. Use the --target option instead.\n"));
322 /*@notreached@*/ break;
324 fprintf(stderr, _("--buildos has been obsoleted. Use the --target option instead.\n"));
326 /*@notreached@*/ break;
327 case POPT_TARGETPLATFORM:
329 int len = strlen(rba->targets) + strlen(arg) + 2;
330 rba->targets = xrealloc(rba->targets, len);
331 strcat(rba->targets, ",");
333 rba->targets = xmalloc(strlen(arg) + 1);
334 rba->targets[0] = '\0';
336 strcat(rba->targets, arg);
341 struct poptOption rpmBuildPoptTable[] = {
342 { NULL, '\0', POPT_ARG_CALLBACK | POPT_CBFLAG_INC_DATA,
343 buildArgCallback, 0, NULL, NULL },
344 { "buildarch", '\0', POPT_ARG_STRING, 0, POPT_BUILDARCH,
345 N_("override build architecture"), "ARCH" },
346 { "buildos", '\0', POPT_ARG_STRING, 0, POPT_BUILDOS,
347 N_("override build operating system"), "OS" },
348 { "buildroot", '\0', POPT_ARG_STRING, 0, POPT_BUILDROOT,
349 N_("override build root"), "DIRECTORY" },
350 { "clean", '\0', 0, 0, POPT_RMBUILD,
351 N_("remove build tree when done"), NULL},
352 { "nobuild", '\0', 0, &noBuild, POPT_NOBUILD,
353 N_("do not execute any stages of the build"), NULL },
354 { "nolang", '\0', 0, &noLang, POPT_NOLANG,
355 N_("do not accept I18N msgstr's from specfile"), NULL},
356 { "rmsource", '\0', 0, 0, POPT_RMSOURCE,
357 N_("remove sources when done"), NULL},
358 { "rmspec", '\0', 0, 0, POPT_RMSPEC,
359 N_("remove specfile when done"), NULL},
360 { "short-circuit", '\0', 0, 0, POPT_SHORTCIRCUIT,
361 N_("skip straight to specified stage (only for c,i)"), NULL },
362 { "target", '\0', POPT_ARG_STRING, 0, POPT_TARGETPLATFORM,
363 N_("override target platform"), "CPU-VENDOR-OS" },
364 { "usecatalog", '\0', 0, &useCatalog, POPT_USECATALOG,
365 N_("lookup I18N strings in specfile catalog"), NULL},
366 { 0, 0, 0, 0, 0, NULL, NULL }