3 #include "build/rpmbuild.h"
8 int buildForTarget(char *arg, int buildAmount, char *passPhrase,
9 char *buildRoot, int fromTarball, int test, char *cookie,
13 static int buildForTarget(const char *arg, int buildAmount, const char *passPhrase,
14 const char *buildRoot, int fromTarball, int test, char *cookie,
19 const char * specfile;
27 rpmSetTables(RPM_MACHTABLE_BUILDARCH, RPM_MACHTABLE_BUILDOS);
31 const char * tmpSpecFile;
34 specDir = rpmGetPath("%{_specdir}", NULL);
37 strcpy(tfn, "rpm-spec.XXXXXX");
38 tmpSpecFile = rpmGetPath("%{_specdir}/", mktemp(tfn), NULL);
41 cmd = alloca(strlen(arg) + 50 + strlen(tmpSpecFile));
42 sprintf(cmd, "gunzip < %s | tar xOvf - Specfile 2>&1 > %s",
44 if (!(f = popen(cmd, "r"))) {
45 fprintf(stderr, _("Failed to open tar pipe: %s\n"),
51 if ((!fgets(buf, sizeof(buf) - 1, f)) || !strchr(buf, '/')) {
55 sprintf(cmd, "gunzip < %s | tar xOvf - \\*.spec 2>&1 > %s", arg,
57 if (!(f = popen(cmd, "r"))) {
58 fprintf(stderr, _("Failed to open tar pipe: %s\n"),
64 if (!fgets(buf, sizeof(buf) - 1, f)) {
66 fprintf(stderr, _("Failed to read spec file from %s\n"), arg);
77 if (*cmd == '/') s = cmd + 1;
83 /* remove trailing \n */
84 s = cmd + strlen(cmd) - 1;
87 s = alloca(strlen(specDir) + strlen(cmd) + 5);
88 sprintf(s, "%s/%s", specDir, cmd);
90 if (rename(tmpSpecFile, s)) {
91 fprintf(stderr, _("Failed to rename %s to %s: %s\n"),
92 tmpSpecFile, s, strerror(errno));
99 /* Make the directory which contains the tarball the source
100 directory for this run */
103 (void)getcwd(buf, BUFSIZ);
109 cmd = buf + strlen(buf) - 1;
110 while (*cmd != '/') cmd--;
113 addMacro(&globalMacroContext, "_sourcedir", NULL, buf, RMIL_TARBALL);
117 } else if (arg[0] == '/') {
120 char *s = alloca(BUFSIZ);
121 (void)getcwd(s, BUFSIZ);
127 stat(specfile, &statbuf);
128 if (! S_ISREG(statbuf.st_mode)) {
129 fprintf(stderr, _("File is not a regular file: %s\n"), specfile);
133 if ((fd = open(specfile, O_RDONLY)) < 0) {
134 fprintf(stderr, _("Unable to open spec file: %s\n"), specfile);
137 count = read(fd, buf, sizeof(buf) < 128 ? sizeof(buf) : 128);
141 if (! (isprint(*s) || isspace(*s))) {
142 fprintf(stderr, _("File contains non-printable characters(%c): %s\n"), *s,
149 #define _anyarch(_f) \
150 (((_f)&(RPMBUILD_PREP|RPMBUILD_BUILD|RPMBUILD_INSTALL|RPMBUILD_PACKAGEBINARY)) == 0)
151 if (parseSpec(&spec, specfile, buildRoot, 0, passPhrase, cookie,
152 _anyarch(buildAmount), force)) {
157 if (buildSpec(spec, buildAmount, test)) {
162 if (fromTarball) unlink(specfile);
169 int build(const char *arg, int buildAmount, const char *passPhrase,
170 const char *buildRoot, int fromTarball, int test, char *cookie,
171 const char * rcfile, char *targets, int force)
176 if (targets == NULL) {
177 rc = buildForTarget(arg, buildAmount, passPhrase, buildRoot,
178 fromTarball, test, cookie, force);
182 /* parse up the build operators */
184 printf("Building target platforms: %s\n", targets);
186 for (t = targets; (te = strchr(t, ',')) != NULL; t = te) {
187 char *target = alloca(te-t+1);
188 strncpy(target, t, (te-t));
190 printf("Building for target %s\n", target);
192 rpmReadConfigFiles(rcfile, target);
193 rc = buildForTarget(arg, buildAmount, passPhrase, buildRoot,
194 fromTarball, test, cookie, force);
202 #define POPT_USECATALOG 1000
203 #define POPT_NOLANG 1001
204 #define POPT_RMSOURCE 1002
205 #define POPT_RMBUILD 1003
206 #define POPT_BUILDROOT 1004
207 #define POPT_BUILDARCH 1005
208 #define POPT_BUILDOS 1006
209 #define POPT_TARGETPLATFORM 1007
210 #define POPT_NOBUILD 1008
211 #define POPT_SHORTCIRCUIT 1009
214 static int noBuild = 0;
215 static int useCatalog = 0;
217 static void buildArgCallback(poptContext con, enum poptCallbackReason reason,
218 const struct poptOption * opt, const char * arg,
219 struct rpmBuildArguments * data)
222 case POPT_USECATALOG: data->useCatalog = 1; break;
223 case POPT_NOBUILD: data->noBuild = 1; break;
224 case POPT_NOLANG: data->noLang = 1; break;
225 case POPT_SHORTCIRCUIT: data->shortCircuit = 1; break;
226 case POPT_RMSOURCE: data->buildAmount |= RPMBUILD_RMSOURCE; break;
227 case POPT_RMBUILD: data->buildAmount |= RPMBUILD_RMBUILD; break;
229 if (data->buildRootOverride) {
230 fprintf(stderr, _("buildroot already specified"));
233 data->buildRootOverride = strdup(arg);
236 fprintf(stderr, _("--buildarch has been obsoleted. Use the --target option instead.\n"));
240 fprintf(stderr, _("--buildos has been obsoleted. Use the --target option instead.\n"));
243 case POPT_TARGETPLATFORM:
245 int len = strlen(data->targets) + strlen(arg) + 2;
246 data->targets = realloc(data->targets, len);
247 strcat(data->targets, ",");
249 data->targets = malloc(strlen(arg) + 1);
250 data->targets[0] = '\0';
252 strcat(data->targets, arg);
257 struct poptOption rpmBuildPoptTable[] = {
258 { NULL, '\0', POPT_ARG_CALLBACK | POPT_CBFLAG_INC_DATA,
259 buildArgCallback, 0, NULL, NULL },
260 { "buildarch", '\0', POPT_ARG_STRING, 0, POPT_BUILDARCH,
261 N_("override build architecture"), "ARCH" },
262 { "buildos", '\0', POPT_ARG_STRING, 0, POPT_BUILDOS,
263 N_("override build operating system"), "OS" },
264 { "buildroot", '\0', POPT_ARG_STRING, 0, POPT_BUILDROOT,
265 N_("override build root"), "DIRECTORY" },
266 { "clean", '\0', 0, 0, POPT_RMBUILD,
267 N_("remove build tree when done"), NULL},
268 { "nobuild", '\0', 0, &noBuild, POPT_NOBUILD,
269 N_("do not execute any stages of the build"), NULL },
270 { "nolang", '\0', 0, &noLang, POPT_NOLANG,
271 N_("do not accept I18N msgstr's from specfile"), NULL},
272 { "rmsource", '\0', 0, 0, POPT_RMSOURCE,
273 N_("remove sources and specfile when done"), NULL},
274 { "short-circuit", '\0', 0, 0, POPT_SHORTCIRCUIT,
275 N_("skip straight to specified stage (only for c,i)"), NULL },
276 { "target", '\0', POPT_ARG_STRING, 0, POPT_TARGETPLATFORM,
277 N_("override target platform"), "CPU-VENDOR-OS" },
278 { "usecatalog", '\0', 0, &useCatalog, POPT_USECATALOG,
279 N_("lookup I18N strings in specfile catalog"), NULL},
280 { 0, 0, 0, 0, 0, NULL, NULL }