3 #include "build/rpmbuild.h"
8 static int checkSpec(Header h)
14 struct rpmDependencyConflict * conflicts;
18 if (!headerIsEntry(h, RPMTAG_REQUIREFLAGS))
21 if (rpmdbOpen(rootdir, &db, mode, 0644)) {
23 dn = rpmGetPath( (rootdir ? rootdir : ""), "%{_dbpath}", NULL);
24 rpmMessage(RPMMESS_ERROR, _("cannot open %s/packages.rpm\n"), dn);
28 ts = rpmtransCreateSet(db, rootdir);
30 rc = rpmtransAddPackage(ts, h, NULL, NULL, 0, NULL);
32 rc = rpmdepCheck(ts, &conflicts, &numConflicts);
33 if (rc == 0 && conflicts) {
34 rpmMessage(RPMMESS_ERROR, _("failed build dependencies:\n"));
35 printDepProblems(stderr, conflicts, numConflicts);
36 rpmdepFreeConflicts(conflicts, numConflicts);
49 * Kurwa, durni ameryka?ce sobe zawsze my?l?, ?e ca?y ?wiat mówi po
52 /* XXX this is still a dumb test but at least it's i18n aware */
53 static int isSpecFile(const char *specfile)
61 if ((fd = fdOpen(specfile, O_RDONLY, 0)) < 0) {
62 fprintf(stderr, _("Unable to open spec file: %s\n"), specfile);
65 count = fdRead(fd, buf, sizeof(buf));
69 for (s = buf; count--; s++) {
79 if (checking && !(isprint(*s) || isspace(*s))) return 0;
86 static int buildForTarget(const char *arg, struct rpmBuildArguments *ba,
87 const char *passPhrase, int fromTarball, char *cookie,
88 int force, int nodeps)
90 int buildAmount = ba->buildAmount;
91 const char *buildRoot = ba->buildRootOverride;
92 int test = ba->noBuild;
94 const char * specfile;
100 rpmSetTables(RPM_MACHTABLE_BUILDARCH, RPM_MACHTABLE_BUILDOS);
104 const char * tmpSpecFile;
107 specDir = rpmGetPath("%{_specdir}", NULL);
110 strcpy(tfn, "rpm-spec.XXXXXX");
111 tmpSpecFile = rpmGetPath("%{_specdir}/", mktemp(tfn), NULL);
114 cmd = alloca(strlen(arg) + 50 + strlen(tmpSpecFile));
115 sprintf(cmd, "gunzip < %s | tar xOvf - Specfile 2>&1 > %s",
117 if (!(f = popen(cmd, "r"))) {
118 fprintf(stderr, _("Failed to open tar pipe: %s\n"),
124 if ((!fgets(buf, sizeof(buf) - 1, f)) || !strchr(buf, '/')) {
128 sprintf(cmd, "gunzip < %s | tar xOvf - \\*.spec 2>&1 > %s", arg,
130 if (!(f = popen(cmd, "r"))) {
131 fprintf(stderr, _("Failed to open tar pipe: %s\n"),
137 if (!fgets(buf, sizeof(buf) - 1, f)) {
139 fprintf(stderr, _("Failed to read spec file from %s\n"), arg);
150 if (*cmd == '/') s = cmd + 1;
156 /* remove trailing \n */
157 s = cmd + strlen(cmd) - 1;
160 s = alloca(strlen(specDir) + strlen(cmd) + 5);
161 sprintf(s, "%s/%s", specDir, cmd);
163 if (rename(tmpSpecFile, s)) {
164 fprintf(stderr, _("Failed to rename %s to %s: %s\n"),
165 tmpSpecFile, s, strerror(errno));
172 /* Make the directory which contains the tarball the source
173 directory for this run */
176 (void)getcwd(buf, BUFSIZ);
182 cmd = buf + strlen(buf) - 1;
183 while (*cmd != '/') cmd--;
186 addMacro(NULL, "_sourcedir", NULL, buf, RMIL_TARBALL);
190 } else if (arg[0] == '/') {
193 char *s = alloca(BUFSIZ);
194 (void)getcwd(s, BUFSIZ);
200 stat(specfile, &statbuf);
201 if (! S_ISREG(statbuf.st_mode)) {
202 fprintf(stderr, _("File is not a regular file: %s\n"), specfile);
206 /* Try to verify that the file is actually a specfile */
207 if (!isSpecFile(specfile)) {
208 fprintf(stderr, _("File %s does not appear to be a specfile.\n"),
213 /* Parse the spec file */
214 #define _anyarch(_f) \
215 (((_f)&(RPMBUILD_PREP|RPMBUILD_BUILD|RPMBUILD_INSTALL|RPMBUILD_PACKAGEBINARY)) == 0)
216 if (parseSpec(&spec, specfile, buildRoot, 0, passPhrase, cookie,
217 _anyarch(buildAmount), force)) {
222 /* Assemble source header from parsed components */
223 initSourceHeader(spec);
225 /* Check build prerequisites */
226 if (!nodeps && checkSpec(spec->sourceHeader)) {
231 if (buildSpec(spec, buildAmount, test)) {
236 if (fromTarball) unlink(specfile);
243 int build(const char *arg, struct rpmBuildArguments *ba, const char *passPhrase,
244 int fromTarball, char *cookie, const char * rcfile, int force,
249 char *targets = ba->targets;
251 if (targets == NULL) {
252 rc = buildForTarget(arg, ba, passPhrase, fromTarball, cookie,
257 /* parse up the build operators */
259 printf(_("Building target platforms: %s\n"), targets);
261 for (t = targets; *t != '\0'; t = te) {
263 if ((te = strchr(t, ',')) == NULL)
265 target = alloca(te-t+1);
266 strncpy(target, t, (te-t));
268 printf(_("Building for target %s\n"), target);
270 rpmReadConfigFiles(rcfile, target);
271 rc = buildForTarget(arg, ba, passPhrase, fromTarball, cookie,
282 #define POPT_USECATALOG 1000
283 #define POPT_NOLANG 1001
284 #define POPT_RMSOURCE 1002
285 #define POPT_RMBUILD 1003
286 #define POPT_BUILDROOT 1004
287 #define POPT_BUILDARCH 1005
288 #define POPT_BUILDOS 1006
289 #define POPT_TARGETPLATFORM 1007
290 #define POPT_NOBUILD 1008
291 #define POPT_SHORTCIRCUIT 1009
292 #define POPT_RMSPEC 1010
295 static int noBuild = 0;
296 static int useCatalog = 0;
298 static void buildArgCallback(poptContext con, enum poptCallbackReason reason,
299 const struct poptOption * opt, const char * arg,
300 struct rpmBuildArguments * data)
303 case POPT_USECATALOG: data->useCatalog = 1; break;
304 case POPT_NOBUILD: data->noBuild = 1; break;
305 case POPT_NOLANG: data->noLang = 1; break;
306 case POPT_SHORTCIRCUIT: data->shortCircuit = 1; break;
307 case POPT_RMSOURCE: data->buildAmount |= RPMBUILD_RMSOURCE; break;
308 case POPT_RMSPEC: data->buildAmount |= RPMBUILD_RMSPEC; break;
309 case POPT_RMBUILD: data->buildAmount |= RPMBUILD_RMBUILD; break;
311 if (data->buildRootOverride) {
312 fprintf(stderr, _("buildroot already specified"));
315 data->buildRootOverride = strdup(arg);
318 fprintf(stderr, _("--buildarch has been obsoleted. Use the --target option instead.\n"));
322 fprintf(stderr, _("--buildos has been obsoleted. Use the --target option instead.\n"));
325 case POPT_TARGETPLATFORM:
327 int len = strlen(data->targets) + strlen(arg) + 2;
328 data->targets = realloc(data->targets, len);
329 strcat(data->targets, ",");
331 data->targets = malloc(strlen(arg) + 1);
332 data->targets[0] = '\0';
334 strcat(data->targets, arg);
339 struct poptOption rpmBuildPoptTable[] = {
340 { NULL, '\0', POPT_ARG_CALLBACK | POPT_CBFLAG_INC_DATA,
341 buildArgCallback, 0, NULL, NULL },
342 { "buildarch", '\0', POPT_ARG_STRING, 0, POPT_BUILDARCH,
343 N_("override build architecture"), "ARCH" },
344 { "buildos", '\0', POPT_ARG_STRING, 0, POPT_BUILDOS,
345 N_("override build operating system"), "OS" },
346 { "buildroot", '\0', POPT_ARG_STRING, 0, POPT_BUILDROOT,
347 N_("override build root"), "DIRECTORY" },
348 { "clean", '\0', 0, 0, POPT_RMBUILD,
349 N_("remove build tree when done"), NULL},
350 { "nobuild", '\0', 0, &noBuild, POPT_NOBUILD,
351 N_("do not execute any stages of the build"), NULL },
352 { "nolang", '\0', 0, &noLang, POPT_NOLANG,
353 N_("do not accept I18N msgstr's from specfile"), NULL},
354 { "rmsource", '\0', 0, 0, POPT_RMSOURCE,
355 N_("remove sources when done"), NULL},
356 { "rmspec", '\0', 0, 0, POPT_RMSPEC,
357 N_("remove specfile when done"), NULL},
358 { "short-circuit", '\0', 0, 0, POPT_SHORTCIRCUIT,
359 N_("skip straight to specified stage (only for c,i)"), NULL },
360 { "target", '\0', POPT_ARG_STRING, 0, POPT_TARGETPLATFORM,
361 N_("override target platform"), "CPU-VENDOR-OS" },
362 { "usecatalog", '\0', 0, &useCatalog, POPT_USECATALOG,
363 N_("lookup I18N strings in specfile catalog"), NULL},
364 { 0, 0, 0, 0, 0, NULL, NULL }